Java Code Examples for com.google.common.primitives.Ints#toArray()

The following examples show how to use com.google.common.primitives.Ints#toArray() . 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: RawDataFileImpl.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see net.sf.mzmine.datamodel.RawDataFile#getMSLevels()
 */
@Override
public @Nonnull int[] getMSLevels() {

  Set<Integer> msLevelsSet = new HashSet<Integer>();

  Enumeration<StorableScan> scansEnum = scans.elements();
  while (scansEnum.hasMoreElements()) {
    Scan scan = scansEnum.nextElement();
    msLevelsSet.add(scan.getMSLevel());
  }

  int[] msLevels = Ints.toArray(msLevelsSet);
  Arrays.sort(msLevels);
  return msLevels;

}
 
Example 2
Source File: CoinChangeTest.java    From Algorithms with MIT License 6 votes vote down vote up
@Test
public void testCoinChange() {
  for (int i = 1; i < LOOPS; i++) {
    List<Integer> values = TestUtils.randomIntegerList(i, 1, 1000);
    int[] coinValues = Ints.toArray(values);

    int amount = TestUtils.randValue(1, 1000);

    int v1 = CoinChange.coinChange(coinValues, amount);
    int v2 = CoinChange.coinChangeSpaceEfficient(coinValues, amount);
    int v3 = CoinChange.coinChangeRecursive(coinValues, amount);

    assertThat(v1).isEqualTo(v2);
    assertThat(v2).isEqualTo(v3);
  }
}
 
Example 3
Source File: RawDataFileImpl.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see io.github.mzmine.datamodel.RawDataFile#getMSLevels()
 */
@Override
public @Nonnull int[] getMSLevels() {

  Set<Integer> msLevelsSet = new HashSet<Integer>();

  Enumeration<StorableScan> scansEnum = scans.elements();
  while (scansEnum.hasMoreElements()) {
    Scan scan = scansEnum.nextElement();
    msLevelsSet.add(scan.getMSLevel());
  }

  int[] msLevels = Ints.toArray(msLevelsSet);
  Arrays.sort(msLevels);
  return msLevels;

}
 
Example 4
Source File: SidedInventoryAdapter.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public int[] getSlotsForFace(EnumFacing dir) {
	Set<Integer> result = Sets.newHashSet();
	for (Entry<Integer, SlotInfo> entry : slots.entrySet()) {
		if (entry.getValue().canAccessFromSide(dir)) result.add(entry.getKey());
	}

	return Ints.toArray(result);
}
 
Example 5
Source File: FeatureForest.java    From EasySRL with Apache License 2.0 5 votes vote down vote up
private int[] getFeatureIndicesCached(final List<InputWord> words, final FeatureSet featureSet,
		final Map<FeatureKey, Integer> featureToIndexMap) {
	if (featureIndicesCache == null) {
		featureIndicesCache = Ints.toArray(getFeatureIndices(words, featureSet, featureToIndexMap));
	}
	return featureIndicesCache;
}
 
Example 6
Source File: Shape.java    From nd4j with Apache License 2.0 5 votes vote down vote up
public static int[] uniquify(int[] array) {
    if (array.length <= 1)
        return array;

    Set<Integer> ints = new LinkedHashSet<>();

    for (val v: array)
        ints.add(v);

    return Ints.toArray(ints);
}
 
Example 7
Source File: OrderByOperator.java    From presto with Apache License 2.0 5 votes vote down vote up
public OrderByOperator(
        OperatorContext operatorContext,
        List<Type> sourceTypes,
        List<Integer> outputChannels,
        int expectedPositions,
        List<Integer> sortChannels,
        List<SortOrder> sortOrder,
        PagesIndex.Factory pagesIndexFactory,
        boolean spillEnabled,
        Optional<SpillerFactory> spillerFactory,
        OrderingCompiler orderingCompiler)
{
    requireNonNull(pagesIndexFactory, "pagesIndexFactory is null");

    this.operatorContext = requireNonNull(operatorContext, "operatorContext is null");
    this.outputChannels = Ints.toArray(requireNonNull(outputChannels, "outputChannels is null"));
    this.sortChannels = ImmutableList.copyOf(requireNonNull(sortChannels, "sortChannels is null"));
    this.sortOrder = ImmutableList.copyOf(requireNonNull(sortOrder, "sortOrder is null"));
    this.sourceTypes = ImmutableList.copyOf(requireNonNull(sourceTypes, "sourceTypes is null"));
    this.localUserMemoryContext = operatorContext.localUserMemoryContext();
    this.revocableMemoryContext = operatorContext.localRevocableMemoryContext();

    this.pageIndex = pagesIndexFactory.newPagesIndex(sourceTypes, expectedPositions);
    this.spillEnabled = spillEnabled;
    this.spillerFactory = requireNonNull(spillerFactory, "spillerFactory is null");
    this.orderingCompiler = requireNonNull(orderingCompiler, "orderingCompiler is null");
    checkArgument(!spillEnabled || spillerFactory.isPresent(), "Spiller Factory is not present when spill is enabled");
}
 
Example 8
Source File: TestIterators.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
private static int[] takeSortedAndDistinct(Random source, int count) {
  LinkedHashSet<Integer> ints = new LinkedHashSet<Integer>(count);
  for (int size = 0; size < count; size++) {
    int next;
    do {
      next = Math.abs(source.nextInt());
    } while (!ints.add(next));
  }
  int[] unboxed = Ints.toArray(ints);
  Arrays.sort(unboxed);
  return unboxed;
}
 
Example 9
Source File: PeptideScan.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a fragment scan
 * 
 * @param fragmentScan
 */
public void addFragmentScan(int fragmentScan) {
  TreeSet<Integer> fragmentsSet = new TreeSet<Integer>();
  if (fragmentScans != null) {
    for (int frag : fragmentScans)
      fragmentsSet.add(frag);
  }
  fragmentsSet.add(fragmentScan);
  fragmentScans = Ints.toArray(fragmentsSet);
}
 
Example 10
Source File: RenameDetector.java    From copybara with Apache License 2.0 5 votes vote down vote up
@Override
public int[] getResult() {
  hashes.add(hash);
  int[] hashesArray = Ints.toArray(hashes);
  Arrays.sort(hashesArray);
  return hashesArray;
}
 
Example 11
Source File: FishingPlugin.java    From 07kit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start() {
    Set<String> actionSet = new HashSet<>();
    for (Spot spot : Spot.values()) {
        actionSet.addAll(Arrays.asList(spot.actions));
    }
    actions = actionSet.toArray(new String[actionSet.size()]);

    Set<Integer> equipmentSet = new HashSet<>();
    for (Equipment equipment : Equipment.values()) {
        equipmentSet.addAll(Ints.asList(equipment.ids));
    }
    equipments = Ints.toArray(equipmentSet);
    ui.registerBoxOverlay(box);
}
 
Example 12
Source File: Tree.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
public int[] getChildrenRight(){
	return Ints.toArray(getNodeAttribute("right_child"));
}
 
Example 13
Source File: DasRemoteDelegate.java    From das with Apache License 2.0 4 votes vote down vote up
@Override
public <T> int[] batchInsert(List<T> entities, Hints hints) throws SQLException {
    return Ints.toArray(call(DasOperation.BatchInsert, entities, hints, int.class));
}
 
Example 14
Source File: TreePredictor.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
public int[] isLeaf(){
	return Ints.toArray(getNodeAttribute("is_leaf"));
}
 
Example 15
Source File: ADAPChromatogram.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public void finishChromatogram() {

    int allScanNumbers[] = Ints.toArray(dataPointsMap.keySet());
    Arrays.sort(allScanNumbers);

    mz = highPointMZ;

    // Update raw data point ranges, height, rt and representative scan
    height = Double.MIN_VALUE;
    for (int i = 0; i < allScanNumbers.length; i++) {

      DataPoint mzPeak = dataPointsMap.get(allScanNumbers[i]);

      // Replace the MzPeak instance with an instance of SimpleDataPoint,
      // to reduce the memory usage. After we finish this Chromatogram, we
      // don't need the additional data provided by the MzPeak

      dataPointsMap.put(allScanNumbers[i], mzPeak);

      if (i == 0) {
        rawDataPointsIntensityRange = Range.singleton(mzPeak.getIntensity());
        rawDataPointsMZRange = Range.singleton(mzPeak.getMZ());
      } else {
        rawDataPointsIntensityRange =
            rawDataPointsIntensityRange.span(Range.singleton(mzPeak.getIntensity()));
        rawDataPointsMZRange = rawDataPointsMZRange.span(Range.singleton(mzPeak.getMZ()));
      }

      if (height < mzPeak.getIntensity()) {
        height = mzPeak.getIntensity();
        rt = dataFile.getScan(allScanNumbers[i]).getRetentionTime();
        representativeScan = allScanNumbers[i];
      }
    }

    // Update area
    area = 0;
    for (int i = 1; i < allScanNumbers.length; i++) {
      // For area calculation, we use retention time in seconds
      double previousRT = dataFile.getScan(allScanNumbers[i - 1]).getRetentionTime() * 60d;
      double currentRT = dataFile.getScan(allScanNumbers[i]).getRetentionTime() * 60d;
      double previousHeight = dataPointsMap.get(allScanNumbers[i - 1]).getIntensity();
      double currentHeight = dataPointsMap.get(allScanNumbers[i]).getIntensity();
      area += (currentRT - previousRT) * (currentHeight + previousHeight) / 2;
    }

    // Update fragment scan
    fragmentScan =
        ScanUtils.findBestFragmentScan(dataFile, dataFile.getDataRTRange(1), rawDataPointsMZRange);

    allMS2FragmentScanNumbers = ScanUtils.findAllMS2FragmentScans(dataFile,
        dataFile.getDataRTRange(1), rawDataPointsMZRange);

    if (fragmentScan > 0) {
      Scan fragmentScanObject = dataFile.getScan(fragmentScan);
      int precursorCharge = fragmentScanObject.getPrecursorCharge();
      if (precursorCharge > 0)
        this.charge = precursorCharge;
    }

    rawDataPointsRTRange = null;

    for (int scanNum : allScanNumbers) {
      double scanRt = dataFile.getScan(scanNum).getRetentionTime();
      DataPoint dp = getDataPoint(scanNum);

      if ((dp == null) || (dp.getIntensity() == 0.0))
        continue;

      if (rawDataPointsRTRange == null)
        rawDataPointsRTRange = Range.singleton(scanRt);
      else
        rawDataPointsRTRange = rawDataPointsRTRange.span(Range.singleton(scanRt));
    }

    // Discard the fields we don't need anymore
    buildingSegment = null;
    lastMzPeak = null;

  }
 
Example 16
Source File: ConjunctionIndexBuilder.java    From vespa with Apache License 2.0 4 votes vote down vote up
public ConjunctionIndex build() {
    int[] zList = Ints.toArray(zListBuilder);
    IntObjectMap<ConjunctionIndex.FeatureIndex> kIndex = buildKIndex(kIndexBuilder);
    long[] idMapping = Longs.toArray(seenIds);
    return new ConjunctionIndex(kIndex, zList, idMapping);
}
 
Example 17
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray tensorAlongDimension(int index, int... dimension) {
    if (dimension == null || dimension.length == 0)
        throw new IllegalArgumentException("Invalid input: dimensions not specified (null or length 0)");

    if (dimension.length >= rank()  || dimension.length == 1 && dimension[0] == Integer.MAX_VALUE)
        return this;
    for (int i = 0; i < dimension.length; i++)
        if (dimension[i] < 0)
            dimension[i] += rank();

    //dedup
    if (dimension.length > 1)
        dimension = Ints.toArray(new ArrayList<>(new TreeSet<>(Ints.asList(dimension))));

    if (dimension.length > 1) {
        Arrays.sort(dimension);
    }

    long tads = tensorssAlongDimension(dimension);
    if (index >= tads)
        throw new IllegalArgumentException("Illegal index " + index + " out of tads " + tads);


    if (dimension.length == 1) {
        if (dimension[0] == 0 && isColumnVector()) {
            return this.transpose();
        } else if (dimension[0] == 1 && isRowVector()) {
            return this;
        }
    }

    Pair<DataBuffer, DataBuffer> tadInfo =
            Nd4j.getExecutioner().getTADManager().getTADOnlyShapeInfo(this, dimension);
    DataBuffer shapeInfo = tadInfo.getFirst();
    val shape = Shape.shape(shapeInfo);
    val stride = Shape.stride(shapeInfo).asLong();
    long offset = offset() + tadInfo.getSecond().getLong(index);
    INDArray toTad = Nd4j.create(data(), shape, stride, offset);
    BaseNDArray baseNDArray = (BaseNDArray) toTad;

    //preserve immutability
    char newOrder = Shape.getOrder(shape, stride, 1);

    int ews = baseNDArray.shapeInfoDataBuffer().getInt(baseNDArray.shapeInfoDataBuffer().length() - 2);

    //TAD always calls permute. Permute EWS is always -1. This is not true
    // for row vector shapes though.
    if (!Shape.isRowVectorShape(baseNDArray.shapeInfoDataBuffer()))
        ews = -1;

    // we create new shapeInfo with possibly new ews & order
    /**
     * NOTE HERE THAT ZERO IS PRESET FOR THE OFFSET AND SHOULD STAY LIKE THAT.
     * Zero is preset for caching purposes.
     * We don't actually use the offset defined in the
     * shape info data buffer.
     * We calculate and cache the offsets separately.
     *
     */
    baseNDArray.setShapeInformation(
            Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, ews, newOrder));

    return toTad;
}
 
Example 18
Source File: Tree.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
public int[] getNodeSamples(){
	return Ints.toArray(getNodeAttribute("n_node_samples"));
}
 
Example 19
Source File: ColumnFilteringFormattingInterceptor.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(Context context)
{
  String formatter = context.getString(COLUMNS_FORMATTER);
  if (Strings.isNullOrEmpty(formatter)) {
    throw new IllegalArgumentException("This interceptor requires columns format to be specified!");
  }
  List<String> lSeparators = Lists.newArrayList();
  List<Integer> lColumns = Lists.newArrayList();
  Pattern colPat = Pattern.compile("\\{\\d+?\\}");
  Matcher matcher = colPat.matcher(formatter);
  int separatorStart = 0;
  String lPrefix = "";
  while (matcher.find()) {
    String col = matcher.group();
    lColumns.add(Integer.parseInt(col.substring(1, col.length() - 1)));
    if (separatorStart == 0 && matcher.start() > 0) {
      lPrefix = formatter.substring(0, matcher.start());
    } else if (separatorStart > 0) {
      lSeparators.add(formatter.substring(separatorStart, matcher.start()));
    }

    separatorStart = matcher.end();
  }
  if (separatorStart < formatter.length()) {
    lSeparators.add(formatter.substring(separatorStart, formatter.length()));
  }
  columns = Ints.toArray(lColumns);
  byte[] emptyStringBytes = "".getBytes();

  dstSeparators = new byte[columns.length][];

  for (int i = 0; i < columns.length; i++) {
    if (i < lSeparators.size()) {
      dstSeparators[i] = lSeparators.get(i).getBytes();
    } else {
      dstSeparators[i] = emptyStringBytes;
    }
  }
  srcSeparator = context.getInteger(ColumnFilteringInterceptor.Constants.SRC_SEPARATOR, (int)ColumnFilteringInterceptor.Constants.SRC_SEPARATOR_DFLT).byteValue();
  this.prefix = lPrefix.getBytes();
}
 
Example 20
Source File: Indices.java    From nd4j with Apache License 2.0 4 votes vote down vote up
/**
 * Return the stride to be used for indexing
 * @param arr the array to get the strides for
 * @param indexes the indexes to use for computing stride
 * @param shape the shape of the output
 * @return the strides used for indexing
 */
public static int[] stride(INDArray arr, INDArrayIndex[] indexes, int... shape) {
    List<Integer> strides = new ArrayList<>();
    int strideIndex = 0;
    //list of indexes to prepend to for new axes
    //if all is encountered
    List<Integer> prependNewAxes = new ArrayList<>();

    for (int i = 0; i < indexes.length; i++) {
        //just like the shape, drops the stride
        if (indexes[i] instanceof PointIndex) {
            strideIndex++;
            continue;
        } else if (indexes[i] instanceof NewAxis) {

        }
    }

    /**
     * For each dimension
     * where we want to prepend a dimension
     * we need to add it at the index such that
     * we account for the offset of the number of indexes
     * added up to that point.
     *
     * We do this by doing an offset
     * for each item added "so far"
     *
     * Note that we also have an offset of - 1
     * because we want to prepend to the given index.
     *
     * When prepend new axes for in the middle is triggered
     * i is already > 0
     */
    for (int i = 0; i < prependNewAxes.size(); i++) {
        strides.add(prependNewAxes.get(i) - i, 1);
    }

    return Ints.toArray(strides);

}