getDependencies() {
}
});
}
- dependencies = Collections.unmodifiableList(new ArrayList<>(deps));
+ dependencies = List.copyOf(deps);
}
return dependencies;
diff --git a/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/buffer/ByteSequenceTensorBuffer.java b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/buffer/ByteSequenceTensorBuffer.java
index bd886d776b7..3bf262bec14 100644
--- a/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/buffer/ByteSequenceTensorBuffer.java
+++ b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/buffer/ByteSequenceTensorBuffer.java
@@ -23,13 +23,11 @@
import static org.tensorflow.internal.c_api.global.tensorflow.TF_TString_GetSize;
import java.nio.ReadOnlyBufferException;
-import java.util.function.Function;
import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.PointerScope;
import org.tensorflow.internal.c_api.TF_TString;
-import org.tensorflow.ndarray.NdArray;
import org.tensorflow.ndarray.buffer.DataBuffer;
import org.tensorflow.ndarray.impl.buffer.AbstractDataBuffer;
import org.tensorflow.ndarray.impl.buffer.Validator;
@@ -40,10 +38,9 @@
* The values are stored as an array of {@link TF_TString}, internally wrapped with {@code
* tensorflow::tstring}, which is essentially a portable version of {@code std::string}.
*
- *
The data of the buffer must be initialized only once, by calling {@link #init(NdArray,
- * Function)}, and the buffer must have been allocated with enough space (use {@link
- * #computeSize(NdArray, Function)} priory to know exactly how many bytes are required to store the
- * data).
+ *
The data of the buffer must be initialized only once, by calling {@link #init}, and the buffer
+ * must have been allocated with enough space (use {@link #computeSize} priory to know exactly how
+ * many bytes are required to store the data).
*
*
After its data has been initialized, the buffer is read-only as it is not possible to change
* safely a value without reinitializing the whole data.
@@ -66,8 +63,8 @@ public static long computeSize(ByteSequenceProvider> byteSequenceProvider)
*
* While it is not enforced programmatically, it is mandatory that this method is called only
* once after the creation of the buffer. The buffer must have been allocated according to the
- * same set of data, calling {@link #computeSize(NdArray, Function)} priory to make sure there is
- * enough space to store it.
+ * same set of data, calling {@link #computeSize} priory to make sure there is enough space to
+ * store it.
*
* @param byteSequenceProvider produces sequences of bytes to use as the tensor data
*/
diff --git a/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/types/TUint16Mapper.java b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/types/TUint16Mapper.java
index d563302319a..43faa1199ed 100644
--- a/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/types/TUint16Mapper.java
+++ b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/types/TUint16Mapper.java
@@ -29,7 +29,7 @@
import org.tensorflow.types.TUint16;
/**
- * Maps memory of {@link org.tensorflow.proto.DataType#DT_Uint16} tensors to a n-dimensional data
+ * Maps memory of {@link org.tensorflow.proto.DataType#DT_UINT16} tensors to a n-dimensional data
* space.
*/
public final class TUint16Mapper extends TensorMapper {
diff --git a/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/package-info.java b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/package-info.java
index 983cda5260c..49cdef2a624 100644
--- a/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/package-info.java
+++ b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/package-info.java
@@ -16,10 +16,12 @@
/**
* Defines classes to build, save, load and execute TensorFlow models.
*
- * WARNING: The API is currently experimental and is not covered by TensorFlow API stability guarantees. See README.md
- * for installation instructions.
+ *
API Stability: Since version 1.0.0, the TensorFlow Java API is covered by TensorFlow API stability guarantees.
+ * Please note that as this library is a wrapper for the TensorFlow C API, its stability is subject
+ * to the stability of the underlying upstream TensorFlow project. See the README.md for installation
+ * instructions.
*
*
The LabelImage
diff --git a/tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types/TBoolTest.java b/tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types/TBoolTest.java
new file mode 100644
index 00000000000..df5e1333b00
--- /dev/null
+++ b/tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types/TBoolTest.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2020 The TensorFlow Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * =======================================================================
+ */
+
+package org.tensorflow.types;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.junit.jupiter.api.Test;
+import org.tensorflow.EagerSession;
+import org.tensorflow.ndarray.NdArray;
+import org.tensorflow.ndarray.NdArrays;
+import org.tensorflow.ndarray.Shape;
+import org.tensorflow.ndarray.index.Indices;
+import org.tensorflow.op.Ops;
+import org.tensorflow.op.core.Constant;
+import org.tensorflow.op.math.LogicalAnd;
+import org.tensorflow.op.math.LogicalNot;
+import org.tensorflow.op.math.LogicalOr;
+
+public class TBoolTest {
+
+ @Test
+ public void createScalar() {
+ TBool tensorT = TBool.scalarOf(true);
+ assertNotNull(tensorT);
+ assertEquals(Shape.scalar(), tensorT.shape());
+ assertEquals(true, tensorT.getObject());
+
+ TBool tensorF = TBool.scalarOf(false);
+ assertNotNull(tensorF);
+ assertEquals(Shape.scalar(), tensorF.shape());
+ assertEquals(false, tensorF.getObject());
+ }
+
+ @Test
+ public void createVector() {
+ TBool tensor = TBool.vectorOf(true, false);
+ assertNotNull(tensor);
+ assertEquals(Shape.of(2), tensor.shape());
+ assertEquals(true, tensor.getObject(0));
+ assertEquals(false, tensor.getObject(1));
+ }
+
+ @Test
+ public void createCopy() {
+ NdArray bools =
+ NdArrays.ofObjects(Boolean.class, Shape.of(2, 2))
+ .setObject(true, 0, 0)
+ .setObject(false, 0, 1)
+ .setObject(false, 1, 0)
+ .setObject(true, 1, 1);
+
+ TBool tensor = TBool.tensorOf(bools);
+ assertNotNull(tensor);
+ bools.scalars().forEachIndexed((idx, s) -> assertEquals(s.getObject(), tensor.getObject(idx)));
+ }
+
+ @Test
+ public void initializeTensorsWithBools() {
+ // Allocate a tensor of booleans of the shape (2, 3, 2)
+ TBool tensor = TBool.tensorOf(Shape.of(2, 3, 2));
+
+ assertEquals(3, tensor.rank());
+ assertEquals(12, tensor.size());
+ NdArray data = (NdArray) tensor;
+
+ try (EagerSession session = EagerSession.create()) {
+ Ops tf = Ops.create(session);
+
+ // Initialize tensor memory with falses and take a snapshot
+ data.scalars().forEach(scalar -> ((NdArray) scalar).setObject(false));
+ Constant x = tf.constantOf(tensor);
+
+ // Initialize the same tensor memory with trues and take a snapshot
+ data.scalars().forEach(scalar -> ((NdArray) scalar).setObject(true));
+ Constant y = tf.constantOf(tensor);
+
+ // Calculate x AND y and validate the result
+ LogicalAnd xAndY = tf.math.logicalAnd(x, y);
+ ((NdArray) xAndY.asTensor())
+ .scalars()
+ .forEach(scalar -> assertEquals(false, scalar.getObject()));
+
+ // Calculate x OR y and validate the result
+ LogicalOr xOrY = tf.math.logicalOr(x, y);
+ ((NdArray) xOrY.asTensor())
+ .scalars()
+ .forEach(scalar -> assertEquals(true, scalar.getObject()));
+
+ // Calculate !x and validate the result against y
+ LogicalNot notX = tf.math.logicalNot(x);
+ assertEquals(y.asTensor(), notX.asTensor());
+ }
+ }
+
+ @Test
+ public void setAndCompute() {
+ NdArray heapData =
+ NdArrays.ofBooleans(Shape.of(4))
+ .setObject(true, 0)
+ .setObject(false, 1)
+ .setObject(true, 2)
+ .setObject(false, 3);
+
+ // Creates a 2x2 matrix
+ try (TBool tensor = TBool.tensorOf(Shape.of(2, 2))) {
+ NdArray data = (NdArray) tensor;
+
+ // Copy first 2 values of the vector to the first row of the matrix
+ data.set(heapData.slice(Indices.range(0, 2)), 0);
+
+ // Copy values at an odd position in the vector as the second row of the matrix
+ data.set(heapData.slice(Indices.odd()), 1);
+
+ assertEquals(true, data.getObject(0, 0));
+ assertEquals(false, data.getObject(0, 1));
+ assertEquals(false, data.getObject(1, 0));
+ assertEquals(false, data.getObject(1, 1));
+
+ // Read rows of the tensor in reverse order
+ NdArray flippedData = data.slice(Indices.flip(), Indices.flip());
+
+ assertEquals(false, flippedData.getObject(0, 0));
+ assertEquals(false, flippedData.getObject(0, 1));
+ assertEquals(false, flippedData.getObject(1, 0));
+ assertEquals(true, flippedData.getObject(1, 1));
+
+ try (EagerSession session = EagerSession.create()) {
+ Ops tf = Ops.create(session);
+
+ LogicalNot sub = tf.math.logicalNot(tf.constantOf(tensor));
+ NdArray result = (NdArray) sub.asTensor();
+
+ assertEquals(false, result.getObject(0, 0));
+ assertEquals(true, result.getObject(0, 1));
+ assertEquals(true, result.getObject(1, 0));
+ assertEquals(true, result.getObject(1, 1));
+ }
+ }
+ }
+}
diff --git a/tensorflow-core/tensorflow-core-generator/pom.xml b/tensorflow-core/tensorflow-core-generator/pom.xml
index dd544eaaa89..bb532f5deab 100644
--- a/tensorflow-core/tensorflow-core-generator/pom.xml
+++ b/tensorflow-core/tensorflow-core-generator/pom.xml
@@ -5,7 +5,7 @@
org.tensorflow
tensorflow-core
- 1.1.0
+ 1.2.0-SNAPSHOT
tensorflow-core-generator
jar
diff --git a/tensorflow-core/tensorflow-core-generator/src/main/java/module-info.java b/tensorflow-core/tensorflow-core-generator/src/main/java/module-info.java
index 1b155bc3af1..a6efd2561a3 100644
--- a/tensorflow-core/tensorflow-core-generator/src/main/java/module-info.java
+++ b/tensorflow-core/tensorflow-core-generator/src/main/java/module-info.java
@@ -14,13 +14,18 @@
limitations under the License.
=======================================================================
*/
+
+/**
+ * Code to generate the Java side implementations of TensorFlow's ops based on the TensorFlow op
+ * definition files.
+ */
module tensorflow.generator {
requires tensorflow.nativelib;
- requires java.compiler;
+ requires transitive java.compiler;
requires com.github.javaparser.core;
requires com.google.protobuf;
requires com.google.common;
- requires com.squareup.javapoet;
+ requires transitive com.squareup.javapoet;
requires org.commonmark;
requires spring.core;
diff --git a/tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/generator/op/ClassGenerator.java b/tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/generator/op/ClassGenerator.java
index 78b8ea04964..91d66134880 100644
--- a/tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/generator/op/ClassGenerator.java
+++ b/tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/generator/op/ClassGenerator.java
@@ -105,7 +105,7 @@ enum RenderMode {
/**
* The generated options class, or null if it doesn't have one or {@link #buildOptionsClass()} has
- * not been ran.
+ * not been run.
*/
private TypeSpec optionsClass = null;
@@ -748,6 +748,10 @@ private void buildSecondaryFactory(
body.add("$T.class", defaultTypes.get(attr));
} else {
factoryBuilder.addParameter(param);
+ // Checking if the parameter being added is the variadic options or not
+ if (param.name.equals("options")) {
+ factoryBuilder.varargs();
+ }
factoryBuilder.addJavadoc("\n@param $L $L", param.name, paramTags.get(param.name));
typeVars.addAll(new ResolvedType(param.type).findGenerics());
body.add("$L", param.name);
diff --git a/tensorflow-core/tensorflow-core-native/pom.xml b/tensorflow-core/tensorflow-core-native/pom.xml
index 13864845568..bb9eb053c33 100644
--- a/tensorflow-core/tensorflow-core-native/pom.xml
+++ b/tensorflow-core/tensorflow-core-native/pom.xml
@@ -6,7 +6,7 @@
org.tensorflow
tensorflow-core
- 1.1.0
+ 1.2.0-SNAPSHOT
tensorflow-core-native
jar
@@ -639,34 +639,6 @@