use of java.util.stream.DoubleStream in project MindsEye by SimiaCryptus.
the class MaxImageBandLayer method eval.
@Nonnull
@Override
public Result eval(@Nonnull final Result... inObj) {
assert 1 == inObj.length;
final TensorList inputData = inObj[0].getData();
inputData.addRef();
inputData.length();
@Nonnull final int[] inputDims = inputData.getDimensions();
assert 3 == inputDims.length;
Arrays.stream(inObj).forEach(nnResult -> nnResult.addRef());
final Coordinate[][] maxCoords = inputData.stream().map(data -> {
Coordinate[] coordinates = IntStream.range(0, inputDims[2]).mapToObj(band -> {
return data.coordStream(true).filter(e -> e.getCoords()[2] == band).max(Comparator.comparing(c -> data.get(c))).get();
}).toArray(i -> new Coordinate[i]);
data.freeRef();
return coordinates;
}).toArray(i -> new Coordinate[i][]);
return new Result(TensorArray.wrap(IntStream.range(0, inputData.length()).mapToObj(dataIndex -> {
Tensor tensor = inputData.get(dataIndex);
final DoubleStream doubleStream = IntStream.range(0, inputDims[2]).mapToDouble(band -> {
final int[] maxCoord = maxCoords[dataIndex][band].getCoords();
double v = tensor.get(maxCoord[0], maxCoord[1], band);
return v;
});
Tensor tensor1 = new Tensor(1, 1, inputDims[2]).set(Tensor.getDoubles(doubleStream, inputDims[2]));
tensor.freeRef();
return tensor1;
}).toArray(i -> new Tensor[i])), (@Nonnull final DeltaSet<Layer> buffer, @Nonnull final TensorList delta) -> {
if (inObj[0].isAlive()) {
@Nonnull TensorArray tensorArray = TensorArray.wrap(IntStream.range(0, delta.length()).parallel().mapToObj(dataIndex -> {
Tensor deltaTensor = delta.get(dataIndex);
@Nonnull final Tensor passback = new Tensor(inputData.getDimensions());
IntStream.range(0, inputDims[2]).forEach(b -> {
final int[] maxCoord = maxCoords[dataIndex][b].getCoords();
passback.set(new int[] { maxCoord[0], maxCoord[1], b }, deltaTensor.get(0, 0, b));
});
deltaTensor.freeRef();
return passback;
}).toArray(i -> new Tensor[i]));
inObj[0].accumulate(buffer, tensorArray);
}
}) {
@Override
protected void _free() {
Arrays.stream(inObj).forEach(nnResult -> nnResult.freeRef());
inputData.freeRef();
}
@Override
public boolean isAlive() {
return inObj[0].isAlive();
}
};
}
use of java.util.stream.DoubleStream in project MindsEye by SimiaCryptus.
the class DoubleArrayStatsFacade method sumSq.
/**
* Sum sq double.
*
* @return the double
*/
public double sumSq() {
final DoubleStream doubleStream = Arrays.stream(data).map((final double x) -> x * x);
final DoubleSummaryStatistics statistics = doubleStream.summaryStatistics();
return statistics.getSum();
}
use of java.util.stream.DoubleStream in project guava by google.
the class StreamsTest method testMapWithIndex_doubleStream_closeIsPropagated.
private void testMapWithIndex_doubleStream_closeIsPropagated(DoubleStream source) {
AtomicInteger doubleStreamCloseCount = new AtomicInteger();
DoubleStream doubleStream = source.onClose(doubleStreamCloseCount::incrementAndGet);
Stream<String> withIndex = Streams.mapWithIndex(doubleStream, (str, i) -> str + ":" + i);
withIndex.close();
Truth.assertThat(doubleStreamCloseCount.get()).isEqualTo(1);
}
use of java.util.stream.DoubleStream in project groovy by apache.
the class DefaultTypeTransformation method asArray.
public static Object asArray(final Object object, final Class type) {
if (type.isAssignableFrom(object.getClass())) {
return object;
}
if (object instanceof IntStream) {
if (type.equals(int[].class)) {
return ((IntStream) object).toArray();
} else if (type.equals(long[].class)) {
return ((IntStream) object).asLongStream().toArray();
} else if (type.equals(double[].class)) {
return ((IntStream) object).asDoubleStream().toArray();
} else if (type.equals(Integer[].class)) {
return ((IntStream) object).boxed().toArray(Integer[]::new);
}
} else if (object instanceof LongStream) {
if (type.equals(long[].class)) {
return ((LongStream) object).toArray();
} else if (type.equals(double[].class)) {
return ((LongStream) object).asDoubleStream().toArray();
} else if (type.equals(Long[].class)) {
return ((LongStream) object).boxed().toArray(Long[]::new);
}
} else if (object instanceof DoubleStream) {
if (type.equals(double[].class)) {
return ((DoubleStream) object).toArray();
} else if (type.equals(Double[].class)) {
return ((DoubleStream) object).boxed().toArray(Double[]::new);
}
}
Class<?> elementType = type.getComponentType();
Collection<?> collection = asCollection(object);
Object array = Array.newInstance(elementType, collection.size());
int i = 0;
for (Object element : collection) {
Array.set(array, i++, castToType(element, elementType));
}
return array;
}
use of java.util.stream.DoubleStream in project assertj-core by joel-costigliola.
the class Assertions_assertThat_with_DoubleStream_Test method should_initialise_actual.
@SuppressWarnings("unchecked")
@Test
void should_initialise_actual() {
DoubleStream iterator = DoubleStream.of(823952.8, 1947230585.9);
List<? extends Double> actual = assertThat(iterator).actual;
assertThat((List<Double>) actual).contains(823952.8, atIndex(0)).contains(1947230585.9, atIndex(1));
}
Aggregations