Skip to content

Commit 80e53f6

Browse files
committed
forEach methods in the Tensorics API
1 parent 0378915 commit 80e53f6

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

gradle/wrapper/gradle-wrapper.jar

1.35 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Sat Jul 01 10:54:52 CEST 2017
1+
#Mon Apr 09 09:45:48 CEST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME

gradlew

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

33
##############################################################################
44
##
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
3333
# Use the maximum available, or set MAX_FD != -1 to use that value.
3434
MAX_FD="maximum"
3535

36-
warn ( ) {
36+
warn () {
3737
echo "$*"
3838
}
3939

40-
die ( ) {
40+
die () {
4141
echo
4242
echo "$*"
4343
echo
@@ -154,11 +154,19 @@ if $cygwin ; then
154154
esac
155155
fi
156156

157-
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158-
function splitJvmOpts() {
159-
JVM_OPTS=("$@")
157+
# Escape application args
158+
save () {
159+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160+
echo " "
160161
}
161-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
162+
APP_ARGS=$(save "$@")
163163

164-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
164+
# Collect all arguments for the java command, following the shell quoting and substitution rules
165+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166+
167+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169+
cd "$(dirname "$0")"
170+
fi
171+
172+
exec "$JAVACMD" "$@"

gradlew.bat

-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ goto fail
4949
@rem Get command-line arguments, handling Windows variants
5050

5151
if not "%OS%" == "Windows_NT" goto win9xME_args
52-
if "%@eval[2+2]" == "4" goto 4NT_args
5352

5453
:win9xME_args
5554
@rem Slurp the command line arguments.
@@ -60,11 +59,6 @@ set _SKIP=2
6059
if "x%~1" == "x" goto execute
6160

6261
set CMD_LINE_ARGS=%*
63-
goto execute
64-
65-
:4NT_args
66-
@rem Get arguments from the 4NT Shell from JP Software
67-
set CMD_LINE_ARGS=%$
6862

6963
:execute
7064
@rem Setup the command line

src/java/org/tensorics/core/lang/Tensorics.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
import java.util.Map;
2626
import java.util.Map.Entry;
2727
import java.util.Set;
28-
import java.util.function.BiFunction;
29-
import java.util.function.Function;
30-
import java.util.function.Supplier;
28+
import java.util.function.*;
3129
import java.util.stream.Stream;
3230

3331
import org.tensorics.core.math.ExtendedField;
@@ -369,6 +367,13 @@ public static <S, T> Tensor<T> map(Tensor<S> tensor, BiFunction<Position, S, T>
369367
return TensorStructurals.transformScalars(tensor, function);
370368
}
371369

370+
public static <S> void forEach(Tensor<S> tensor, Consumer<S> consumer) {
371+
TensorStructurals.consumeScalars(tensor, consumer);
372+
}
373+
374+
public static <S> void forEach(Tensor<S> tensor, BiConsumer<Position, S> consumer) {
375+
TensorStructurals.consumeScalars(tensor, consumer);
376+
}
372377
public static final Scalar<QuantifiedValue<Double>> zeroDimensionalOf(double value,
373378
javax.measure.unit.Unit<?> unit) {
374379
QuantifiedValue<Double> quantity = quantityOf(value, unit);

src/java/org/tensorics/core/tensor/lang/TensorStructurals.java

+12
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
import static com.google.common.base.Preconditions.checkNotNull;
2626

2727
import java.util.HashSet;
28+
import java.util.Map;
2829
import java.util.Map.Entry;
2930
import java.util.Set;
31+
import java.util.function.BiConsumer;
3032
import java.util.function.BiFunction;
33+
import java.util.function.Consumer;
3134
import java.util.function.Function;
3235

36+
import org.tensorics.core.lang.Tensorics;
3337
import org.tensorics.core.tensor.ImmutableTensor;
3438
import org.tensorics.core.tensor.ImmutableTensor.Builder;
3539
import org.tensorics.core.tensor.Position;
@@ -151,6 +155,14 @@ public static <S, T> Tensor<T> transformScalars(Tensor<S> tensor, BiFunction<Pos
151155
return builder.build();
152156
}
153157

158+
public static <S> void consumeScalars(Tensor<S> tensor, Consumer<S> consumer) {
159+
Tensorics.stream(tensor).map(Map.Entry::getValue).forEach(consumer);
160+
}
161+
162+
public static <S> void consumeScalars(Tensor<S> tensor, BiConsumer<Position, S> consumer) {
163+
Tensorics.stream(tensor).forEach(e -> consumer.accept(e.getKey(), e.getValue()));
164+
}
165+
154166
public static final <S> Tensor<S> stripContext(Tensor<S> tensor) {
155167
Builder<S> builder = ImmutableTensor.builder(tensor.shape().dimensionSet());
156168
builder.putAll(tensor);

0 commit comments

Comments
 (0)