it.unimi.dsi.fastutil.ints.IntList Java Examples

The following examples show how to use it.unimi.dsi.fastutil.ints.IntList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private boolean isSubset(IntList actuelList, Map<Integer, IntSet> index) {

        boolean first = true;
        IntSet positions = new IntArraySet();
        for (int e : actuelList) {
            if (!index.containsKey(Integer.valueOf(e))) {
                return false;
            }
            if (first) {
                positions.addAll(index.get(Integer.valueOf(e)));
                first = false;
            } else {

                this.intersect(positions, index.get(Integer.valueOf(e)));
                // FIXME: Throws UnsupportedOperationExeption within fastUtil
                // positions.retainAll(index.get(e));
            }
            if (positions.size() == 0) {
                return false;
            }
        }
        return true;
    }
 
Example #2
Source File: SPIDER.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private void output() throws CouldNotReceiveResultException, ColumnNameMismatchException {
	// Read the discovered INDs from the attributes
	Int2ObjectOpenHashMap<IntList> dep2ref = new Int2ObjectOpenHashMap<IntList>(this.numColumns);
	for (Attribute spiderAttribute : this.attributeId2attributeObject.values())
		if (!spiderAttribute.getReferenced().isEmpty())
			dep2ref.put(spiderAttribute.getAttributeId(), new IntArrayList(spiderAttribute.getReferenced()));
	
	// Write the result to the resultReceiver
	for (int dep : dep2ref.keySet()) {
		String depTableName = this.getTableNameFor(dep, this.tableColumnStartIndexes);
		String depColumnName = this.columnNames.get(dep);
		
		for (int ref : dep2ref.get(dep)) {
			String refTableName = this.getTableNameFor(ref, this.tableColumnStartIndexes);
			String refColumnName = this.columnNames.get(ref);
			
			this.resultReceiver.receiveResult(new InclusionDependency(new ColumnPermutation(new ColumnIdentifier(depTableName, depColumnName)), new ColumnPermutation(new ColumnIdentifier(refTableName, refColumnName))));
			this.numUnaryINDs++;
		}
	}
}
 
Example #3
Source File: StrippedPartition.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public List<IntList> getValues() {

        return this.value;

        // if (finalized) {
        // // TODO: notwendig?
        // List<LongList> temp = new LinkedList<LongList>();
        // for (LongList il : this.value) {
        // LongList temp_ = new LongArrayList();
        // temp_.addAll(il);
        // temp.add(temp_);
        // }
        // return temp;
        // } else {
        // return this.value;
        // }
    }
 
Example #4
Source File: FunctionalDependencyGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private void executePara(int attribute) throws CouldNotReceiveResultException, ColumnNameMismatchException {

        for (BitSet lhs : this.lhss.get(attribute)) {
            if (lhs.get(attribute)) {
                continue;
            }
            IntList bits = new IntArrayList();
            int lastIndex = lhs.nextSetBit(0);
            while (lastIndex != -1) {
                bits.add(lastIndex);
                lastIndex = lhs.nextSetBit(lastIndex + 1);
            }

            FunctionalDependencyGroup2 fdg = new FunctionalDependencyGroup2(attribute, bits);
            this.fdrr.receiveResult((fdg.buildDependency(this.relationName, this.columns)));
            this.result.add(fdg);
        }
    }
 
Example #5
Source File: ParquetReader.java    From paraflow with Apache License 2.0 6 votes vote down vote up
public Block readPrimitive(ColumnDescriptor columnDescriptor, Type type, IntList offsets)
        throws IOException
{
    ParquetColumnReader columnReader = columnReadersMap.get(columnDescriptor);
    if (columnReader.getPageReader() == null) {
        validateParquet(currentBlockMetadata.getRowCount() > 0, "Row group has 0 rows");
        ColumnChunkMetaData metadata = getColumnChunkMetaData(columnDescriptor);
        long startingPosition = metadata.getStartingPos();
        int totalSize = checkedCast(metadata.getTotalSize());
        byte[] buffer = new byte[totalSize];
        dataSource.readFully(startingPosition, buffer);
        ParquetColumnChunkDescriptor descriptor = new ParquetColumnChunkDescriptor(columnDescriptor, metadata, totalSize);
        ParquetColumnChunk columnChunk = new ParquetColumnChunk(descriptor, buffer, 0);
        columnReader.setPageReader(columnChunk.readAllPages());
    }
    return columnReader.readPrimitive(type, offsets);
}
 
Example #6
Source File: MAPEvaluator.java    From jstarcraft-ai with Apache License 2.0 6 votes vote down vote up
@Override
protected float measure(IntSet checkCollection, IntList rankList) {
    if (rankList.size() > size) {
        rankList = rankList.subList(0, size);
    }
    int count = 0;
    float map = 0F;
    for (int index = 0; index < rankList.size(); index++) {
        int itemIndex = rankList.get(index);
        if (checkCollection.contains(itemIndex)) {
            count++;
            map += 1F * count / (index + 1);
        }
    }
    return map / (checkCollection.size() < rankList.size() ? checkCollection.size() : rankList.size());
}
 
Example #7
Source File: StrippedPartition.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public List<IntList> getValues() {

        return this.value;

        // if (finalized) {
        // // TODO: notwendig?
        // List<IntList> temp = new LinkedList<IntList>();
        // for (IntList il : this.value) {
        // IntList temp_ = new LongArrayList();
        // temp_.addAll(il);
        // temp.add(temp_);
        // }
        // return temp;
        // } else {
        // return this.value;
        // }
    }
 
Example #8
Source File: AttributeBasedStratiAmountSelectorAndAssignerTester.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testAssignmentOnlyTargetAttributeMixedParallel() {
	ILabeledDataset<ILabeledInstance> dataset = this.createToyDatasetMixed();
	Integer[] attributeIndices = { 2 };
	AttributeBasedStratiAmountSelectorAndAssigner selectorAndAssigner = new AttributeBasedStratiAmountSelectorAndAssigner(Arrays.asList(attributeIndices),
			DiscretizationStrategy.EQUAL_SIZE, 2);
	selectorAndAssigner.setLoggerName(GeneralAlgorithmTester.TESTEDALGORITHM_LOGGERNAME);
	selectorAndAssigner.setNumCPUs(4);
	selectorAndAssigner.init(dataset);
	IntList stratiAssignment = new IntArrayList();
	for (ILabeledInstance i : dataset) {
		stratiAssignment.add(selectorAndAssigner.assignToStrati(i));
	}
	// Number of strati must be 2
	assertEquals(2, new HashSet<>(stratiAssignment).size());

	assertTrue("Instances 1 and 3 need to be in the same stratum", stratiAssignment.getInt(0) == stratiAssignment.getInt(2));

	assertTrue("Instances 1 and 4 need to be in the same stratum", stratiAssignment.getInt(0) == stratiAssignment.getInt(3));

	assertFalse("Instances 1 and 2 need to be in the different strati", stratiAssignment.getInt(0) == stratiAssignment.getInt(1));

	assertFalse("Instances 1 and 5 need to be in the different strati", stratiAssignment.getInt(0) == stratiAssignment.getInt(4));

	assertFalse("Instances 1 and 6 need to be in the different strati", stratiAssignment.getInt(0) == stratiAssignment.getInt(5));
}
 
Example #9
Source File: NoveltyEvaluator.java    From jstarcraft-ai with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate on the test set with the the list of recommended items.
 *
 * @param testMatrix      the given test set
 * @param recommendedList the list of recommended items
 * @return evaluate result
 */
@Override
protected float measure(IntSet checkCollection, IntList rankList) {
    if (rankList.size() > size) {
        rankList = rankList.subList(0, size);
    }
    float sum = 0F;
    for (int rank : rankList) {
        int count = itemCounts[rank];
        if (count > 0) {
            float probability = ((float) count) / numberOfUsers;
            float entropy = (float) -Math.log(probability);
            sum += entropy;
        }
    }
    return (float) (sum / Math.log(2F));
}
 
Example #10
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private boolean isSubset(IntList actuelList, Map<Long, LongSet> index) {

        boolean first = true;
        LongSet positions = new LongArraySet();
        for (long e : actuelList) {
            if (!index.containsKey(Long.valueOf(e))) {
                return false;
            }
            if (first) {
                positions.addAll(index.get(Long.valueOf(e)));
                first = false;
            } else {

                this.intersect(positions, index.get(Long.valueOf(e)));
                // FIXME: Throws UnsupportedOperationExeption within fastUtil
                // positions.retainAll(index.get(e));
            }
            if (positions.size() == 0) {
                return false;
            }
        }
        return true;
    }
 
Example #11
Source File: PrimitiveColumnReader.java    From presto with Apache License 2.0 6 votes vote down vote up
public ColumnChunk readPrimitive(Field field)
{
    IntList definitionLevels = new IntArrayList();
    IntList repetitionLevels = new IntArrayList();
    seek();
    BlockBuilder blockBuilder = field.getType().createBlockBuilder(null, nextBatchSize);
    int valueCount = 0;
    while (valueCount < nextBatchSize) {
        if (page == null) {
            readNextPage();
        }
        int valuesToRead = Math.min(remainingValueCountInPage, nextBatchSize - valueCount);
        readValues(blockBuilder, valuesToRead, field.getType(), definitionLevels, repetitionLevels);
        valueCount += valuesToRead;
    }
    checkArgument(valueCount == nextBatchSize, "valueCount %s not equals to batchSize %s", valueCount, nextBatchSize);

    readOffset = 0;
    nextBatchSize = 0;
    return new ColumnChunk(blockBuilder.build(), definitionLevels.toIntArray(), repetitionLevels.toIntArray());
}
 
Example #12
Source File: ParquetReader.java    From presto with Apache License 2.0 6 votes vote down vote up
private ColumnChunk readMap(GroupField field)
        throws IOException
{
    List<Type> parameters = field.getType().getTypeParameters();
    checkArgument(parameters.size() == 2, "Maps must have two type parameters, found %s", parameters.size());
    Block[] blocks = new Block[parameters.size()];

    ColumnChunk columnChunk = readColumnChunk(field.getChildren().get(0).get());
    blocks[0] = columnChunk.getBlock();
    blocks[1] = readColumnChunk(field.getChildren().get(1).get()).getBlock();
    IntList offsets = new IntArrayList();
    BooleanList valueIsNull = new BooleanArrayList();
    calculateCollectionOffsets(field, offsets, valueIsNull, columnChunk.getDefinitionLevels(), columnChunk.getRepetitionLevels());
    Block mapBlock = ((MapType) field.getType()).createBlockFromKeyValue(Optional.of(valueIsNull.toBooleanArray()), offsets.toIntArray(), blocks[0], blocks[1]);
    return new ColumnChunk(mapBlock, columnChunk.getDefinitionLevels(), columnChunk.getRepetitionLevels());
}
 
Example #13
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private void calculateRelationship(StrippedPartition partitions, Long2ObjectMap<TupleEquivalenceClassRelation> relationships) {

        int partitionNr = 0;
        for (IntList partition : partitions.getValues()) {
            if (this.debugSysout)
                System.out.println(".");
            for (long index : partition) {
                if (!relationships.containsKey(index)) {
                    relationships.put(index, new TupleEquivalenceClassRelation());
                }
                relationships.get(index).addNewRelationship(partitions.getAttributeID(), partitionNr);
            }
            partitionNr++;
        }

    }
 
Example #14
Source File: FixedLifespanScheduler.java    From presto with Apache License 2.0 6 votes vote down vote up
public FixedLifespanScheduler(BucketNodeMap bucketNodeMap, List<ConnectorPartitionHandle> partitionHandles, OptionalInt concurrentLifespansPerTask)
{
    checkArgument(!partitionHandles.equals(ImmutableList.of(NOT_PARTITIONED)));
    checkArgument(partitionHandles.size() == bucketNodeMap.getBucketCount());

    Map<InternalNode, IntList> nodeToDriverGroupMap = new HashMap<>();
    Int2ObjectMap<InternalNode> driverGroupToNodeMap = new Int2ObjectOpenHashMap<>();
    for (int bucket = 0; bucket < bucketNodeMap.getBucketCount(); bucket++) {
        InternalNode node = bucketNodeMap.getAssignedNode(bucket).get();
        nodeToDriverGroupMap.computeIfAbsent(node, key -> new IntArrayList()).add(bucket);
        driverGroupToNodeMap.put(bucket, node);
    }

    this.driverGroupToNodeMap = driverGroupToNodeMap;
    this.nodeToDriverGroupsMap = nodeToDriverGroupMap.entrySet().stream()
            .collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().iterator()));
    this.partitionHandles = requireNonNull(partitionHandles, "partitionHandles is null");
    if (concurrentLifespansPerTask.isPresent()) {
        checkArgument(concurrentLifespansPerTask.getAsInt() >= 1, "concurrentLifespansPerTask must be great or equal to 1 if present");
    }
    this.concurrentLifespansPerTask = requireNonNull(concurrentLifespansPerTask, "concurrentLifespansPerTask is null");
}
 
Example #15
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private void handleList(IntList list, Long2ObjectMap<Set<IntList>> maxSets, boolean firstStep) {

        for (int i = 0; i < list.size(); i++) {
            int removedElement = list.removeInt(i);
            if (maxSets.containsKey(list.size()) && maxSets.get(list.size()).contains(list))
                maxSets.get(list.size()).remove(list);
            else {
                if (list.size() > 2) {
                    this.handleList(list, maxSets, false);
                }
            }
            list.add(i, removedElement);
        }

        if (firstStep)
            maxSets.get(list.size()).add(list);
    }
 
Example #16
Source File: BitSetUtil.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public static IntList convertToIntList(BitSet set) {
    IntList bits = new IntArrayList();
    int lastIndex = set.nextSetBit(0);
    while (lastIndex != -1) {
        bits.add(lastIndex);
        lastIndex = set.nextSetBit(lastIndex + 1);
    }
    return bits;
}
 
Example #17
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private void handlePartition(IntList actuelList, int position, Int2ObjectMap<IntSet> index, Set<IntList> max) {

        if (!this.isSubset(actuelList, index)) {
            max.add(actuelList);
            for (int e : actuelList) {
                if (!index.containsKey(e)) {
                    index.put(e, new IntArraySet());
                }
                index.get(e).add(position);
            }
        }
    }
 
Example #18
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private HandlePartitionTask(IntList actuelList, int actuelIndex, Map<Integer, IntSet> index, Map<IntList, Object> max) {

            this.index = index;
            this.max = max;
            this.actuelList = actuelList;
            this.actuelIndex = actuelIndex;
        }
 
Example #19
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private IntersectWithAndAddToAgreeSetTask(int i, int j, IntList maxEquiClass,
                                          Int2ObjectMap<TupleEquivalenceClassRelation> relationships, Map<AgreeSet, Object> agreeSets) {

    this.i = i;
    this.j = j;
    this.maxEquiClass = maxEquiClass;
    this.relationships = relationships;
    this.agreeSets = agreeSets;
}
 
Example #20
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(IntList l1, IntList l2) {

    if (l1.size() - l2.size() != 0)
        return l1.size() - l2.size();
    for (int i = 0; i < l1.size(); i++) {
        if (l1.getInt(i) == l2.getInt(i))
            continue;
        return l1.getInt(i) - l2.getInt(i);
    }
    return 0;
}
 
Example #21
Source File: StrippedPartition.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Override
protected String toString_() {

    String s = "sp(";
    for (IntList il : this.value) {
        s += il.toString() + "-";
    }
    return s + ")";
}
 
Example #22
Source File: BitSetUtil.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public static IntList convertToIntList(BitSet set) {
    IntList bits = new IntArrayList();
    int lastIndex = set.nextSetBit(0);
    while (lastIndex != -1) {
        bits.add(lastIndex);
        lastIndex = set.nextSetBit(lastIndex + 1);
    }
    return bits;
}
 
Example #23
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(IntList l1, IntList l2) {

    if (l1.size() - l2.size() != 0)
        return l2.size() - l1.size();
    for (int i = 0; i < l1.size(); i++) {
        if (l1.getInt(i) == l2.getInt(i))
            continue;
        return l2.getInt(i) - l1.getInt(i);
    }
    return 0;
}
 
Example #24
Source File: NegativeSamplingExpander.java    From samantha with MIT License 5 votes vote down vote up
private IntList getSampledIndices(IntSet trues, int maxVal) {
    IntList samples = new IntArrayList();
    int num = trues.size();
    if (maxNumSample != null) {
        num = maxNumSample;
    }
    for (int i=0; i<num; i++) {
        int dice = new Random().nextInt(maxVal);
        if (!trues.contains(dice)) {
            samples.add(dice);
        }
    }
    return samples;
}
 
Example #25
Source File: RegexpLikePredicateEvaluatorFactory.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Override
public int[] getMatchingDictIds() {
  if (_matchingDictIds == null) {
    IntList matchingDictIds = new IntArrayList();
    int dictionarySize = _dictionary.length();
    for (int dictId = 0; dictId < dictionarySize; dictId++) {
      if (applySV(dictId)) {
        matchingDictIds.add(dictId);
      }
    }
    _matchingDictIds = matchingDictIds.toIntArray();
  }
  return _matchingDictIds;
}
 
Example #26
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private IntersectWithAndAddToAgreeSetTask(int i, int j, IntList maxEquiClass,
                                          Long2ObjectMap<TupleEquivalenceClassRelation> relationships, Map<AgreeSet, Object> agreeSets) {

    this.i = i;
    this.j = j;
    this.maxEquiClass = maxEquiClass;
    this.relationships = relationships;
    this.agreeSets = agreeSets;
}
 
Example #27
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private Set<IntList> sortPartitions(List<StrippedPartition> partitions, Comparator<IntList> comparator) {

        Set<IntList> sortedPartitions = new TreeSet<IntList>(comparator);
        for (StrippedPartition p : partitions) {
            sortedPartitions.addAll(p.getValues());
        }
        return sortedPartitions;
    }
 
Example #28
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private void handlePartition(IntList actuelList, long position, Long2ObjectMap<LongSet> index, Set<IntList> max) {

        if (!this.isSubset(actuelList, index)) {
            max.add(actuelList);
            for (long e : actuelList) {
                if (!index.containsKey(e)) {
                    index.put(e, new LongArraySet());
                }
                index.get(e).add(position);
            }
        }
    }
 
Example #29
Source File: TestBoundaryOrder.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private static ExecStats validateOperator(String msg,
    Function<ColumnIndexBase<?>.ValueComparator, PrimitiveIterator.OfInt> validatorOp,
    Function<ColumnIndexBase<?>.ValueComparator, PrimitiveIterator.OfInt> actualOp,
    ColumnIndexBase<?>.ValueComparator comparator) {
  ExecStats stats = new ExecStats();

  IntList expected = stats.measureLinear(validatorOp, comparator);
  IntList actual = stats.measureBinary(actualOp, comparator);

  Assert.assertEquals(msg, expected, actual);

  return stats;
}
 
Example #30
Source File: ColumnIndexFilterUtils.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
static OffsetIndex filterOffsetIndex(OffsetIndex offsetIndex, RowRanges rowRanges, long totalRowCount) {
  IntList indexMap = new IntArrayList();
  for (int i = 0, n = offsetIndex.getPageCount(); i < n; ++i) {
    long from = offsetIndex.getFirstRowIndex(i);
    if (rowRanges.isOverlapping(from, offsetIndex.getLastRowIndex(i, totalRowCount))) {
      indexMap.add(i);
    }
  }
  return new FilteredOffsetIndex(offsetIndex, indexMap.toIntArray());
}