From 9aaa9b16bae613c52f576bda8c1bf75915a9090f Mon Sep 17 00:00:00 2001 From: "karl@kubx.ca" Date: Thu, 2 Aug 2018 21:25:03 -0400 Subject: 2nd code review: Documentation fixes --- .../src/main/java/org/tensorflow/DataType.java | 2 +- .../main/java/org/tensorflow/op/core/Constant.java | 124 ++++++++++----------- 2 files changed, 63 insertions(+), 63 deletions(-) (limited to 'tensorflow/java') diff --git a/tensorflow/java/src/main/java/org/tensorflow/DataType.java b/tensorflow/java/src/main/java/org/tensorflow/DataType.java index 9dfa9cc68c..516655040b 100644 --- a/tensorflow/java/src/main/java/org/tensorflow/DataType.java +++ b/tensorflow/java/src/main/java/org/tensorflow/DataType.java @@ -61,7 +61,7 @@ public enum DataType { } /** - * @return size of an element of this type, in bytes, or -1 if element size is variable + * Returns the size of an element of this type, in bytes, or -1 if element size is variable. */ public int byteSize() { return byteSize; diff --git a/tensorflow/java/src/main/java/org/tensorflow/op/core/Constant.java b/tensorflow/java/src/main/java/org/tensorflow/op/core/Constant.java index d7a06380c7..00b6726be3 100644 --- a/tensorflow/java/src/main/java/org/tensorflow/op/core/Constant.java +++ b/tensorflow/java/src/main/java/org/tensorflow/op/core/Constant.java @@ -37,26 +37,6 @@ import org.tensorflow.op.annotation.Operator; @Operator public final class Constant extends PrimitiveOp implements Operand { - /** - * Create a {@link DataType#INT32} constant with data from the given buffer. - * - *

Creates a constant with the given shape by copying elements from the buffer (starting from - * its current position) into the tensor. For example, if {@code shape = {2,3} } (which represents - * a 2x3 matrix) then the buffer must have 6 elements remaining, which will be consumed by this - * method. - * - * @param scope is a scope used to add the underlying operation. - * @param shape the tensor shape. - * @param data a buffer containing the tensor data. - * @return an integer constant - * @throws IllegalArgumentException If the tensor shape is not compatible with the buffer - */ - public static Constant create(Scope scope, long[] shape, IntBuffer data) { - try (Tensor value = Tensor.create(shape, data)) { - return createWithTensor(scope, value); - } - } - /** * Creates a constant containing a single {@code int} element. * @@ -135,7 +115,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Create a {@link DataType#FLOAT} constant with data from the given buffer. + * Create a {@link DataType#INT32} constant with data from the given buffer. * *

Creates a constant with the given shape by copying elements from the buffer (starting from * its current position) into the tensor. For example, if {@code shape = {2,3} } (which represents @@ -145,11 +125,11 @@ public final class Constant extends PrimitiveOp implements Operand { * @param scope is a scope used to add the underlying operation. * @param shape the tensor shape. * @param data a buffer containing the tensor data. - * @return a float constant + * @return an integer constant * @throws IllegalArgumentException If the tensor shape is not compatible with the buffer */ - public static Constant create(Scope scope, long[] shape, FloatBuffer data) { - try (Tensor value = Tensor.create(shape, data)) { + public static Constant create(Scope scope, long[] shape, IntBuffer data) { + try (Tensor value = Tensor.create(shape, data)) { return createWithTensor(scope, value); } } @@ -232,7 +212,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Create a {@link DataType#DOUBLE} constant with data from the given buffer. + * Create a {@link DataType#FLOAT} constant with data from the given buffer. * *

Creates a constant with the given shape by copying elements from the buffer (starting from * its current position) into the tensor. For example, if {@code shape = {2,3} } (which represents @@ -242,11 +222,11 @@ public final class Constant extends PrimitiveOp implements Operand { * @param scope is a scope used to add the underlying operation. * @param shape the tensor shape. * @param data a buffer containing the tensor data. - * @return a double constant + * @return a float constant * @throws IllegalArgumentException If the tensor shape is not compatible with the buffer */ - public static Constant create(Scope scope, long[] shape, DoubleBuffer data) { - try (Tensor value = Tensor.create(shape, data)) { + public static Constant create(Scope scope, long[] shape, FloatBuffer data) { + try (Tensor value = Tensor.create(shape, data)) { return createWithTensor(scope, value); } } @@ -329,7 +309,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Create a {@link DataType#INT64} constant with data from the given buffer. + * Create a {@link DataType#DOUBLE} constant with data from the given buffer. * *

Creates a constant with the given shape by copying elements from the buffer (starting from * its current position) into the tensor. For example, if {@code shape = {2,3} } (which represents @@ -339,11 +319,11 @@ public final class Constant extends PrimitiveOp implements Operand { * @param scope is a scope used to add the underlying operation. * @param shape the tensor shape. * @param data a buffer containing the tensor data. - * @return a long constant + * @return a double constant * @throws IllegalArgumentException If the tensor shape is not compatible with the buffer */ - public static Constant create(Scope scope, long[] shape, LongBuffer data) { - try (Tensor value = Tensor.create(shape, data)) { + public static Constant create(Scope scope, long[] shape, DoubleBuffer data) { + try (Tensor value = Tensor.create(shape, data)) { return createWithTensor(scope, value); } } @@ -425,6 +405,26 @@ public final class Constant extends PrimitiveOp implements Operand { return create(scope, data, Long.class); } + /** + * Create a {@link DataType#INT64} constant with data from the given buffer. + * + *

Creates a constant with the given shape by copying elements from the buffer (starting from + * its current position) into the tensor. For example, if {@code shape = {2,3} } (which represents + * a 2x3 matrix) then the buffer must have 6 elements remaining, which will be consumed by this + * method. + * + * @param scope is a scope used to add the underlying operation. + * @param shape the tensor shape. + * @param data a buffer containing the tensor data. + * @return a long constant + * @throws IllegalArgumentException If the tensor shape is not compatible with the buffer + */ + public static Constant create(Scope scope, long[] shape, LongBuffer data) { + try (Tensor value = Tensor.create(shape, data)) { + return createWithTensor(scope, value); + } + } + /** * Creates a constant containing a single {@code boolean} element. * @@ -503,7 +503,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Creates a String constant using the default, UTF-8 encoding. + * Creates a {@code String} constant using the default, UTF-8 encoding. * * @param scope is a scope used to add the underlying operation. * @param data The string to put into the new constant. @@ -514,7 +514,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Creates a String constant using a specified encoding. + * Creates a {@code String} constant using a specified encoding. * * @param scope is a scope used to add the underlying operation. * @param charset The encoding from String to bytes. @@ -528,29 +528,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Create a constant with data from the given buffer. - * - *

Creates a Constant with the provided shape of any type where the constant data has been - * encoded into {@code data} as per the specification of the TensorFlow C - * API. - * - * @param scope is a scope used to add the underlying operation. - * @param type the tensor datatype. - * @param shape the tensor shape. - * @param data a buffer containing the tensor data. - * @return a constant of type `type` - * @throws IllegalArgumentException If the tensor datatype or shape is not compatible with the - * buffer - */ - public static Constant create(Scope scope, Class type, long[] shape, ByteBuffer data) { - try (Tensor value = Tensor.create(type, shape, data)) { - return createWithTensor(scope, value); - } - } - - /** - * Creates a rank-1 constant of {@code byte} elements. + * Creates a constant containing a single {@code String} element, represented as an array of {@code byte}s. * * @param scope is a scope used to add the underlying operation. * @param data An array containing the values to put into the new constant. String elements are @@ -561,7 +539,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Creates a rank-2 constant of {@code byte} elements. + * Creates a rank-1 constant of {@code String} elements, each represented as an array of {@code byte}s. * * @param scope is a scope used to add the underlying operation. * @param data An array containing the values to put into the new constant. String elements are @@ -572,7 +550,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Creates a rank-3 constant of {@code byte} elements. + * Creates a rank-2 constant of {@code String} elements, each represented as an array of {@code byte}s. * * @param scope is a scope used to add the underlying operation. * @param data An array containing the values to put into the new constant. String elements are @@ -583,7 +561,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Creates a rank-4 constant of {@code byte} elements. + * Creates a rank-3 constant of {@code String} elements, each represented as an array of {@code byte}s. * * @param scope is a scope used to add the underlying operation. * @param data An array containing the values to put into the new constant. String elements are @@ -594,7 +572,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Creates a rank-5 constant of {@code byte} elements. + * Creates a rank-4 constant of {@code String} elements, each represented as an array of {@code byte}s. * * @param scope is a scope used to add the underlying operation. * @param data An array containing the values to put into the new constant. String elements are @@ -605,7 +583,7 @@ public final class Constant extends PrimitiveOp implements Operand { } /** - * Creates a rank-6 constant of {@code byte} elements. + * Creates a rank-5 constant of {@code String} elements, each represented as an array of {@code byte}s. * * @param scope is a scope used to add the underlying operation. * @param data An array containing the values to put into the new constant. String elements are @@ -615,6 +593,28 @@ public final class Constant extends PrimitiveOp implements Operand { return create(scope, data, String.class); } + /** + * Create a constant with data from the given buffer. + * + *

Creates a Constant with the provided shape of any type where the constant data has been + * encoded into {@code data} as per the specification of the TensorFlow C + * API. + * + * @param scope is a scope used to add the underlying operation. + * @param type the tensor datatype. + * @param shape the tensor shape. + * @param data a buffer containing the tensor data. + * @return a constant of type `type` + * @throws IllegalArgumentException If the tensor datatype or shape is not compatible with the + * buffer + */ + public static Constant create(Scope scope, Class type, long[] shape, ByteBuffer data) { + try (Tensor value = Tensor.create(type, shape, data)) { + return createWithTensor(scope, value); + } + } + /** * Create a constant from a Java object. * -- cgit v1.2.3