it.unimi.dsi.fastutil.doubles.DoubleArrayList Java Examples
The following examples show how to use
it.unimi.dsi.fastutil.doubles.DoubleArrayList.
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: SynchronizedVariableSpace.java From samantha with MIT License | 6 votes |
final public void ensureScalarVar(String name, int size, double initial, boolean randomize) { writeLock.lock(); try { int curSize = scalarVars.get(name).size(); if (curSize < size) { DoubleList toAdd = new DoubleArrayList(size - curSize); for (int i=0; i<size - curSize; i++) { toAdd.add(0.0); } initializeDoubleList(toAdd, initial, randomize); scalarVars.get(name).addAll(toAdd); } curSize = readLocks.size(); SpaceUtilities.fillReadWriteLocks(readLocks, writeLocks, curSize, size); } finally { writeLock.unlock(); } }
Example #2
Source File: DoubleColumn.java From tablesaw with Apache License 2.0 | 6 votes |
@Override public DoubleColumn lag(int n) { final int srcPos = n >= 0 ? 0 : 0 - n; final double[] dest = new double[size()]; final int destPos = n <= 0 ? 0 : n; final int length = n >= 0 ? size() - n : size() + n; for (int i = 0; i < size(); i++) { dest[i] = FloatColumnType.missingValueIndicator(); } double[] array = data.toDoubleArray(); System.arraycopy(array, srcPos, dest, destPos, length); return new DoubleColumn(name() + " lag(" + n + ")", new DoubleArrayList(dest)); }
Example #3
Source File: MultiDimDoubleDataSet.java From chart-fx with Apache License 2.0 | 6 votes |
/** * Creates a new instance of <code>MultiDimDoubleDataSet</code>. * * @param name name of this DataSet. * @param nDims the number of dimensions * @param initialSizes initial capacity of buffer. If multiple sizes are supplied, they are used to after one * another * and afterwards the product of all sizes is used, e.g. nDims=3 and initialSizes=4,5 results in a * three-dimensional dataset with 4 points in x, 5 points in y and 20 points in z direction. * @throws IllegalArgumentException if {@code name} is {@code null} */ public MultiDimDoubleDataSet(final String name, final int nDims, final int... initialSizes) { super(name, nDims); AssertUtils.gtThanZero("nDims", nDims); AssertUtils.nonEmptyArray("initialSizes", initialSizes); values = new DoubleArrayList[nDims]; int acumulatedSize = 1; for (int i = 0; i < nDims; i++) { if (initialSizes.length > i) { values[i] = new DoubleArrayList(initialSizes[i]); values[i].size(initialSizes[i]); acumulatedSize *= initialSizes[i]; } else { values[i] = new DoubleArrayList(acumulatedSize); values[i].size(acumulatedSize); } } }
Example #4
Source File: CachedNeighborhood.java From RankSys with Mozilla Public License 2.0 | 6 votes |
/** * Constructor that caches a stream of previously calculated neighborhoods. * * @param n number of users/items * @param neighborhoods stream of already calculated neighborhoods */ public CachedNeighborhood(int n, Stream<Tuple2io<Stream<Tuple2id>>> neighborhoods) { this.idxla = new IntArrayList[n]; this.simla = new DoubleArrayList[n]; neighborhoods.forEach(un -> { int idx = un.v1; IntArrayList idxl = new IntArrayList(); DoubleArrayList siml = new DoubleArrayList(); un.v2.forEach(is -> { idxl.add(is.v1); siml.add(is.v2); }); idxla[idx] = idxl; simla[idx] = siml; }); }
Example #5
Source File: MultiDimDoubleDataSet.java From chart-fx with Apache License 2.0 | 6 votes |
/** * <p> * Update the data for a given dimension * * @param dimIndex dimension index (e.g. DataSet.DIM_X) * @param values values for dimension * @param copy true: makes an internal copy, false: use the pointer as is (saves memory allocation * @return itself */ public MultiDimDoubleDataSet setValues(final int dimIndex, final double[] values, final boolean copy) { AssertUtils.notNull("X coordinates", values); AssertUtils.gtOrEqual("Available dimensions", dimIndex, this.values.length); lock().writeLockGuard(() -> { getDataLabelMap().clear(); getDataStyleMap().clear(); if (copy) { this.values[dimIndex].clear(); this.values[dimIndex].addElements(0, values); } else { this.values[dimIndex] = DoubleArrayList.wrap(values); } // invalidate ranges getAxisDescriptions().forEach(AxisDescription::clear); }); return fireInvalidated(new UpdatedDataEvent(this)); }
Example #6
Source File: AvroRecordConverter.java From parquet-mr with Apache License 2.0 | 6 votes |
@Override public void end() { if (elementClass == boolean.class) { parent.add(((BooleanArrayList) container).toBooleanArray()); } else if (elementClass == byte.class) { parent.add(((ByteArrayList) container).toByteArray()); } else if (elementClass == char.class) { parent.add(((CharArrayList) container).toCharArray()); } else if (elementClass == short.class) { parent.add(((ShortArrayList) container).toShortArray()); } else if (elementClass == int.class) { parent.add(((IntArrayList) container).toIntArray()); } else if (elementClass == long.class) { parent.add(((LongArrayList) container).toLongArray()); } else if (elementClass == float.class) { parent.add(((FloatArrayList) container).toFloatArray()); } else if (elementClass == double.class) { parent.add(((DoubleArrayList) container).toDoubleArray()); } else { parent.add(((ArrayList) container).toArray()); } }
Example #7
Source File: OCRManager.java From MSPaintIDE with MIT License | 6 votes |
public double getFontSize(ScannedImage scannedImage) { var descriptiveStatistics = new DescriptiveStatistics(); var sizes = scannedImage .getGrid() .values() .stream() .flatMap(List::stream) .filter(imageLetter -> imageLetter.getLetter() != ' ') .map(getActions()::getFontSize) .filter(OptionalDouble::isPresent) .map(OptionalDouble::getAsDouble) .peek(descriptiveStatistics::addValue) .collect(Collectors.toCollection(DoubleArrayList::new)); var lowerBound = descriptiveStatistics.getPercentile(20); var upperBound = descriptiveStatistics.getPercentile(80); sizes.removeIf((Predicate<Double>) value -> value > upperBound || value < lowerBound); return sizes.stream().mapToDouble(Double::valueOf).average().orElse(0D); }
Example #8
Source File: CachedNeighborhood.java From RankSys with Mozilla Public License 2.0 | 6 votes |
/** * Constructor that calculates and caches neighborhoods. * * @param n number of users/items * @param neighborhood generic neighborhood to be cached */ public CachedNeighborhood(int n, Neighborhood neighborhood) { this.idxla = new IntArrayList[n]; this.simla = new DoubleArrayList[n]; range(0, n).parallel().forEach(idx -> { IntArrayList idxl = new IntArrayList(); DoubleArrayList siml = new DoubleArrayList(); neighborhood.getNeighbors(idx).forEach(is -> { idxl.add(is.v1); siml.add(is.v2); }); idxla[idx] = idxl; simla[idx] = siml; }); }
Example #9
Source File: HistogramChartFactory.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Converts from double array to histogram array * * @param data * @param binwidth * @param min real minimum of data * @param max real maximum of data * @param function function to transform data axis * @return A histogram array with length = datawidth/binwidth +1 (datawidth = max-min) */ public static XYSeries createHistoSeries(DoubleArrayList data, double binwidth, double min, double max, DoubleFunction<Double> function) { double datawidth = (max - min); int cbin = (int) Math.ceil(datawidth / binwidth); int[] bins = new int[cbin + 1]; // count intensities in bins // if value>bin.upper put in next for (double v : data) { int i = (int) Math.ceil((v - min) / binwidth) - 1; if (i < 0) // does only happen if min>than minimum value of data i = 0; if (i >= bins.length) i = bins.length - 1; bins[i]++; } // add zeros around data boolean peakStarted = false; XYSeries series = new XYSeries("histo", true, true); for (int i = 0; i < bins.length; i++) { // start peak and add data if>0 if (bins[i] > 0) { // add previous zero once if (!peakStarted && i > 0) addDPToSeries(series, bins, i - 1, binwidth, min, max, function); // add data addDPToSeries(series, bins, i, binwidth, min, max, function); peakStarted = true; } else { // add trailing zero addDPToSeries(series, bins, i, binwidth, min, max, function); peakStarted = false; } } return series; }
Example #10
Source File: CachedNeighborhood.java From RankSys with Mozilla Public License 2.0 | 5 votes |
/** * Returns the neighborhood of a user/index. * * @param idx user/index whose neighborhood is calculated * @return stream of user/item-similarity pairs. */ @Override public Stream<Tuple2id> getNeighbors(int idx) { if (idx < 0) { return empty(); } IntArrayList idxl = idxla[idx]; DoubleArrayList siml = simla[idx]; if (idxl == null || siml == null) { return empty(); } return range(0, idxl.size()).mapToObj(i -> tuple(idxl.getInt(i), siml.getDouble(i))); }
Example #11
Source File: ObjectSerDeUtilsTest.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Test public void testDoubleArrayList() { for (int i = 0; i < NUM_ITERATIONS; i++) { int size = RANDOM.nextInt(100); DoubleArrayList expected = new DoubleArrayList(size); for (int j = 0; j < size; j++) { expected.add(RANDOM.nextDouble()); } byte[] bytes = ObjectSerDeUtils.serialize(expected); DoubleArrayList actual = ObjectSerDeUtils.deserialize(bytes, ObjectSerDeUtils.ObjectType.DoubleArrayList); assertEquals(actual, expected, ERROR_MESSAGE); } }
Example #12
Source File: PercentileAggregationFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public Double extractFinalResult(DoubleArrayList intermediateResult) { int size = intermediateResult.size(); if (size == 0) { return DEFAULT_FINAL_RESULT; } else { double[] values = intermediateResult.elements(); Arrays.sort(values, 0, size); if (_percentile == 100) { return values[size - 1]; } else { return values[(int) ((long) size * _percentile / 100)]; } } }
Example #13
Source File: PercentileAggregationFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public DoubleArrayList extractGroupByResult(GroupByResultHolder groupByResultHolder, int groupKey) { DoubleArrayList doubleArrayList = groupByResultHolder.getResult(groupKey); if (doubleArrayList == null) { return new DoubleArrayList(); } else { return doubleArrayList; } }
Example #14
Source File: PercentileAggregationFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public DoubleArrayList extractAggregationResult(AggregationResultHolder aggregationResultHolder) { DoubleArrayList doubleArrayList = aggregationResultHolder.getResult(); if (doubleArrayList == null) { return new DoubleArrayList(); } else { return doubleArrayList; } }
Example #15
Source File: PercentileAggregationFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public void aggregateGroupByMV(int length, int[][] groupKeysArray, GroupByResultHolder groupByResultHolder, Map<ExpressionContext, BlockValSet> blockValSetMap) { double[] valueArray = blockValSetMap.get(_expression).getDoubleValuesSV(); for (int i = 0; i < length; i++) { double value = valueArray[i]; for (int groupKey : groupKeysArray[i]) { DoubleArrayList valueList = getValueList(groupByResultHolder, groupKey); valueList.add(value); } } }
Example #16
Source File: PercentileAggregationFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public void aggregateGroupBySV(int length, int[] groupKeyArray, GroupByResultHolder groupByResultHolder, Map<ExpressionContext, BlockValSet> blockValSetMap) { double[] valueArray = blockValSetMap.get(_expression).getDoubleValuesSV(); for (int i = 0; i < length; i++) { DoubleArrayList valueList = getValueList(groupByResultHolder, groupKeyArray[i]); valueList.add(valueArray[i]); } }
Example #17
Source File: PercentileAggregationFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public void aggregate(int length, AggregationResultHolder aggregationResultHolder, Map<ExpressionContext, BlockValSet> blockValSetMap) { DoubleArrayList valueList = getValueList(aggregationResultHolder); double[] valueArray = blockValSetMap.get(_expression).getDoubleValuesSV(); for (int i = 0; i < length; i++) { valueList.add(valueArray[i]); } }
Example #18
Source File: PercentileMVAggregationFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public void aggregate(int length, AggregationResultHolder aggregationResultHolder, Map<ExpressionContext, BlockValSet> blockValSetMap) { double[][] valuesArray = blockValSetMap.get(_expression).getDoubleValuesMV(); DoubleArrayList valueList = getValueList(aggregationResultHolder); for (int i = 0; i < length; i++) { for (double value : valuesArray[i]) { valueList.add(value); } } }
Example #19
Source File: DoubleColumn.java From tablesaw with Apache License 2.0 | 5 votes |
public static DoubleColumn create(String name, Number[] numbers) { DoubleColumn newColumn = new DoubleColumn(name, new DoubleArrayList(0)); for (Number number : numbers) { newColumn.append(number); } return newColumn; }
Example #20
Source File: HistogramChartFactory.java From old-mzmine3 with GNU General Public License v2.0 | 5 votes |
/** * Converts from double array to histogram array * * @param data * @param binwidth * @param min real minimum of data * @param max real maximum of data * @param function function to transform data axis * @return A histogram array with length = datawidth/binwidth +1 (datawidth = max-min) */ public static List<DataPoint> createHistoList(DoubleArrayList data, double binwidth, double min, double max, DoubleFunction<Double> function) { double datawidth = (max - min); int cbin = (int) Math.ceil(datawidth / binwidth); int[] bins = new int[cbin + 1]; // count intensities in bins // if value>bin.upper put in next for (double v : data) { int i = (int) Math.ceil((v - min) / binwidth) - 1; if (i < 0) // does only happen if min>than minimum value of data i = 0; if (i >= bins.length) i = bins.length - 1; bins[i]++; } // add zeros around data List<DataPoint> result = new ArrayList<>(); boolean peakStarted = false; for (int i = 0; i < bins.length; i++) { // start peak and add data if>0 if (bins[i] > 0) { // add previous zero once if (!peakStarted && i > 0) addDPToList(result, bins, i - 1, binwidth, min, max, function); // add data addDPToList(result, bins, i, binwidth, min, max, function); peakStarted = true; } else { // add trailing zero addDPToList(result, bins, i, binwidth, min, max, function); peakStarted = false; } } return result; }
Example #21
Source File: HistogramChartFactory.java From old-mzmine3 with GNU General Public License v2.0 | 5 votes |
/** * Converts from double array to histogram array * * @param data * @param binwidth * @param min real minimum of data * @param max real maximum of data * @param function function to transform data axis * @return A histogram array with length = datawidth/binwidth +1 (datawidth = max-min) */ public static XYSeries createHistoSeries(DoubleArrayList data, double binwidth, double min, double max, DoubleFunction<Double> function) { double datawidth = (max - min); int cbin = (int) Math.ceil(datawidth / binwidth); int[] bins = new int[cbin + 1]; // count intensities in bins // if value>bin.upper put in next for (double v : data) { int i = (int) Math.ceil((v - min) / binwidth) - 1; if (i < 0) // does only happen if min>than minimum value of data i = 0; if (i >= bins.length) i = bins.length - 1; bins[i]++; } // add zeros around data boolean peakStarted = false; XYSeries series = new XYSeries("histo", true, true); for (int i = 0; i < bins.length; i++) { // start peak and add data if>0 if (bins[i] > 0) { // add previous zero once if (!peakStarted && i > 0) addDPToSeries(series, bins, i - 1, binwidth, min, max, function); // add data addDPToSeries(series, bins, i, binwidth, min, max, function); peakStarted = true; } else { // add trailing zero addDPToSeries(series, bins, i, binwidth, min, max, function); peakStarted = false; } } return series; }
Example #22
Source File: InvertedNeighborhood.java From RankSys with Mozilla Public License 2.0 | 5 votes |
/** * Returns the neighborhood of a user/index. * * @param idx user/index whose neighborhood is calculated * @return stream of user/item-similarity pairs. */ @Override public Stream<Tuple2id> getNeighbors(int idx) { IntArrayList idxl = idxla[idx]; DoubleArrayList siml = simla[idx]; return IntStream.range(0, idxl.size()).mapToObj(i -> tuple(idxl.getInt(i), siml.getDouble(i))); }
Example #23
Source File: MarketDataList.java From FX-AlgorithmTrading with MIT License | 5 votes |
public MarketDataList(Symbol symbol) { this.symbol = symbol; this.dateTimeList = new ArrayList<>(); this.bidList = new DoubleArrayList(); this.askList = new DoubleArrayList(); this.midList = new DoubleArrayList(); }
Example #24
Source File: SmallArrayBasedLongToDoubleMapTest.java From GraphJet with Apache License 2.0 | 5 votes |
@Test public void testRepeatedKeys() { SmallArrayBasedLongToDoubleMap map = insertRandomKeyValuePairsIntoMap(new Random(90238490238409L), 1000, 1, 1000, 3); long[] expectedKeys = {0L}; double[] expectedValues = {326.0}; assertEquals(new LongArrayList(expectedKeys), new LongArrayList(map.keys())); assertEquals(new DoubleArrayList(expectedValues), new DoubleArrayList(map.values())); }
Example #25
Source File: SmallArrayBasedLongToDoubleMapTest.java From GraphJet with Apache License 2.0 | 5 votes |
@Test public void testManyLargeRangeKeys() { SmallArrayBasedLongToDoubleMap map = insertRandomKeyValuePairsIntoMap(new Random(90238490238409L), 1000, 100, 1000, 3); long[] expectedKeys = {32L, 90L, 20L}; double[] expectedValues = {996.0, 995.0, 995.0}; assertEquals(new LongArrayList(expectedKeys), new LongArrayList(map.keys())); assertEquals(new DoubleArrayList(expectedValues), new DoubleArrayList(map.values())); }
Example #26
Source File: SmallArrayBasedLongToDoubleMapTest.java From GraphJet with Apache License 2.0 | 5 votes |
@Test public void testFewSmallRangeKeys() { SmallArrayBasedLongToDoubleMap map = insertRandomKeyValuePairsIntoMap(new Random(90238490238409L), 2, 10, 1000, 3); long[] expectedKeys = {6L, 4L}; double[] expectedValues = {970.0, 326.0}; assertEquals(new LongArrayList(expectedKeys), new LongArrayList(map.keys())); assertEquals(new DoubleArrayList(expectedValues), new DoubleArrayList(map.values())); }
Example #27
Source File: SmallArrayBasedLongToDoubleMapTest.java From GraphJet with Apache License 2.0 | 5 votes |
@Test public void testManySmallRangeKeys() { SmallArrayBasedLongToDoubleMap map = insertRandomKeyValuePairsIntoMap(new Random(90238490238409L), 1000, 10, 1000, 3); long[] expectedKeys = {2L, 0L, 4L}; double[] expectedValues = {996.0, 995.0, 994.0}; assertEquals(new LongArrayList(expectedKeys), new LongArrayList(map.keys())); assertEquals(new DoubleArrayList(expectedValues), new DoubleArrayList(map.values())); }
Example #28
Source File: DoubleColumn.java From tablesaw with Apache License 2.0 | 5 votes |
public static DoubleColumn create(String name, Collection<? extends Number> numberList) { DoubleColumn newColumn = new DoubleColumn(name, new DoubleArrayList(0)); for (Number number : numberList) { newColumn.append(number); } return newColumn; }
Example #29
Source File: DoubleColumn.java From tablesaw with Apache License 2.0 | 5 votes |
public static DoubleColumn create(String name, long... arr) { final double[] doubles = new double[arr.length]; for (int i = 0; i < arr.length; i++) { doubles[i] = arr[i]; } return new DoubleColumn(name, new DoubleArrayList(doubles)); }
Example #30
Source File: DoubleColumn.java From tablesaw with Apache License 2.0 | 5 votes |
public static DoubleColumn create(String name, int... arr) { final double[] doubles = new double[arr.length]; for (int i = 0; i < arr.length; i++) { doubles[i] = arr[i]; } return new DoubleColumn(name, new DoubleArrayList(doubles)); }