-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
22 lines (19 loc) · 718 Bytes
/
Test.java
File metadata and controls
22 lines (19 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import org.tensorflow.DeviceSpec;
import org.tensorflow.DeviceSpec.DeviceType;
import org.tensorflow.ndarray.StdArrays;
import org.tensorflow.op.Ops;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
Ops tf = Ops.create().withDevice(
//DeviceSpec.newBuilder().deviceType(DeviceType.CPU).build()
DeviceSpec.newBuilder().deviceType(DeviceType.GPU).deviceIndex(0).build()
);
var x = tf.array(1f, 2f, 4f);
var y = tf.array(2f, 4f, 6f);
var z = tf.math.add(x, y);
try (var zTensor = z.asTensor()) {
System.out.println(Arrays.toString(StdArrays.array1dCopyOf(zTensor)));
}
}
}