Constant

public final class Constant

An operator producing a constant value.

Public Methods

Output<T>
asOutput()
Returns the symbolic handle of a tensor.
static Constant<Boolean>
create(Scope scope, boolean[][][][] data)
Creates a rank-4 constant of boolean elements.
static Constant<Long>
create(Scope scope, long[] data)
Creates a rank-1 constant of long elements.
static Constant<Double>
create(Scope scope, double[][][][][][] data)
Creates a rank-6 constant of double elements.
static Constant<Float>
create(Scope scope, float data)
Creates a constant containing a single float element.
static <T> Constant<T>
create(Scope scope, Object object, Class<T> type)
Create a constant from a Java object.
static Constant<String>
create(Scope scope, byte[] data)
Creates a constant containing a single String element, represented as an array of bytes.
static Constant<Float>
create(Scope scope, float[][][] data)
Creates a rank-3 constant of float elements.
static Constant<Float>
create(Scope scope, long[] shape, FloatBuffer data)
Create a DataType.FLOAT constant with data from the given buffer.
static Constant<Long>
create(Scope scope, long[][] data)
Creates a rank-2 constant of long elements.
static Constant<Double>
create(Scope scope, double[][][][] data)
Creates a rank-4 constant of double elements.
static Constant<Double>
create(Scope scope, long[] shape, DoubleBuffer data)
Create a DataType.DOUBLE constant with data from the given buffer.
static Constant<Integer>
create(Scope scope, int[][][] data)
Creates a rank-3 constant of int elements.
static Constant<String>
create(Scope scope, byte[][][][][] data)
Creates a rank-4 constant of String elements, each represented as an array of bytes.
static Constant<String>
create(Scope scope, String data)
Creates a String constant using the default, UTF-8 encoding.
static Constant<Float>
create(Scope scope, float[][][][][] data)
Creates a rank-5 constant of float elements.
static Constant<Integer>
create(Scope scope, int data)
Creates a constant containing a single int element.
static Constant<String>
create(Scope scope, byte[][][][] data)
Creates a rank-3 constant of String elements, each represented as an array of bytes.
static Constant<Float>
create(Scope scope, float[][] data)
Creates a rank-2 constant of float elements.
static Constant<Boolean>
create(Scope scope, boolean[][][] data)
Creates a rank-3 constant of boolean elements.
static Constant<Integer>
create(Scope scope, int[][] data)
Creates a rank-2 constant of int elements.
static Constant<Integer>
create(Scope scope, long[] shape, IntBuffer data)
Create a DataType.INT32 constant with data from the given buffer.
static Constant<Float>
create(Scope scope, float[][][][] data)
Creates a rank-4 constant of float elements.
static Constant<Long>
create(Scope scope, long[][][] data)
Creates a rank-3 constant of long elements.
static Constant<Integer>
create(Scope scope, int[][][][][] data)
Creates a rank-5 constant of int elements.
static Constant<String>
create(Scope scope, String data, Charset charset)
Creates a String constant using a specified encoding.
static Constant<String>
create(Scope scope, byte[][][][][][] data)
Creates a rank-5 constant of String elements, each represented as an array of bytes.
static Constant<Float>
create(Scope scope, float[] data)
Creates a rank-1 constant of float elements.
static Constant<Float>
create(Scope scope, float[][][][][][] data)
Creates a rank-6 constant of float elements.
static Constant<Integer>
create(Scope scope, int[][][][] data)
Creates a rank-4 constant of int elements.
static Constant<Double>
create(Scope scope, double data)
Creates a constant containing a single double element.
static Constant<Long>
create(Scope scope, long[][][][][][] data)
Creates a rank-6 constant of long elements.
static Constant<Double>
create(Scope scope, double[] data)
Creates a rank-1 constant of double elements.
static Constant<Long>
create(Scope scope, long[][][][] data)
Creates a rank-4 constant of long elements.
static <T> Constant<T>
create(Scope scope, Class<T> type, long[] shape, ByteBuffer data)
Create a constant with data from the given buffer.
static Constant<Integer>
create(Scope scope, int[] data)
Creates a rank-1 constant of int elements.
static Constant<Double>
create(Scope scope, double[][][] data)
Creates a rank-3 constant of double elements.
static Constant<Boolean>
create(Scope scope, boolean[] data)
Creates a rank-1 constant of boolean elements.
static Constant<Integer>
create(Scope scope, int[][][][][][] data)
Creates a rank-6 constant of int elements.
static Constant<String>
create(Scope scope, byte[][][] data)
Creates a rank-2 constant of String elements, each represented as an array of bytes.
static Constant<Boolean>
create(Scope scope, boolean[][] data)
Creates a rank-2 constant of boolean elements.
static Constant<Boolean>
create(Scope scope, boolean[][][][][][] data)
Creates a rank-6 constant of boolean elements.
static Constant<Double>
create(Scope scope, double[][][][][] data)
Creates a rank-5 constant of double elements.
static Constant<Double>
create(Scope scope, double[][] data)
Creates a rank-2 constant of double elements.
static Constant<String>
create(Scope scope, byte[][] data)
Creates a rank-1 constant of String elements, each represented as an array of bytes.
static Constant<Boolean>
create(Scope scope, boolean[][][][][] data)
Creates a rank-5 constant of boolean elements.
static Constant<Long>
create(Scope scope, long data)
Creates a constant containing a single long element.
static Constant<Long>
create(Scope scope, long[][][][][] data)
Creates a rank-5 constant of long elements.
static Constant<Long>
create(Scope scope, long[] shape, LongBuffer data)
Create a DataType.INT64 constant with data from the given buffer.
static Constant<Boolean>
create(Scope scope, boolean data)
Creates a constant containing a single boolean element.

Inherited Methods

Public Methods

public Output<T> asOutput ()

Returns the symbolic handle of a tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is used to obtain a symbolic handle that represents the computation of the input.

public static Constant<Boolean> create (Scope scope, boolean[][][][] data)

Creates a rank-4 constant of boolean elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Long> create (Scope scope, long[] data)

Creates a rank-1 constant of long elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, double[][][][][][] data)

Creates a rank-6 constant of double elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Float> create (Scope scope, float data)

Creates a constant containing a single float element.

Parameters
scope is a scope used to add the underlying operation.
data The value to put into the new constant.
Returns
  • a float constant

public static Constant<T> create (Scope scope, Object object, Class<T> type)

Create a constant from a Java object.

The argument object is first converted into a Tensor using Tensor.create(Object), so only Objects supported by this method must be provided. For example:

Constant.create(scope, new int[]{ {1, 2}, {3, 4} }, Integer.class); // returns a 2x2 integer matrix
 

Parameters
scope is a scope used to add the underlying operation.
object a Java object representing the constant.
type
Returns
  • a constant of type `type`
See Also

public static Constant<String> create (Scope scope, byte[] data)

Creates a constant containing a single String element, represented as an array of bytes.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. String elements are sequences of bytes from the last array dimension.

public static Constant<Float> create (Scope scope, float[][][] data)

Creates a rank-3 constant of float elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Float> create (Scope scope, long[] shape, FloatBuffer data)

Create a 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 shape = {2,3} (which represents a 2x3 matrix) then the buffer must have 6 elements remaining, which will be consumed by this method.

Parameters
scope is a scope used to add the underlying operation.
shape the tensor shape.
data a buffer containing the tensor data.
Returns
  • a float constant
Throws
IllegalArgumentException If the tensor shape is not compatible with the buffer

public static Constant<Long> create (Scope scope, long[][] data)

Creates a rank-2 constant of long elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, double[][][][] data)

Creates a rank-4 constant of double elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, long[] shape, DoubleBuffer data)

Create a 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 shape = {2,3} (which represents a 2x3 matrix) then the buffer must have 6 elements remaining, which will be consumed by this method.

Parameters
scope is a scope used to add the underlying operation.
shape the tensor shape.
data a buffer containing the tensor data.
Returns
  • a double constant
Throws
IllegalArgumentException If the tensor shape is not compatible with the buffer

public static Constant<Integer> create (Scope scope, int[][][] data)

Creates a rank-3 constant of int elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<String> create (Scope scope, byte[][][][][] data)

Creates a rank-4 constant of String elements, each represented as an array of bytes.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. String elements are sequences of bytes from the last array dimension.

public static Constant<String> create (Scope scope, String data)

Creates a String constant using the default, UTF-8 encoding.

Parameters
scope is a scope used to add the underlying operation.
data The string to put into the new constant.
Returns
  • a string constant

public static Constant<Float> create (Scope scope, float[][][][][] data)

Creates a rank-5 constant of float elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Integer> create (Scope scope, int data)

Creates a constant containing a single int element.

Parameters
scope is a scope used to add the underlying operation.
data The value to put into the new constant.
Returns
  • an integer constant

public static Constant<String> create (Scope scope, byte[][][][] data)

Creates a rank-3 constant of String elements, each represented as an array of bytes.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. String elements are sequences of bytes from the last array dimension.

public static Constant<Float> create (Scope scope, float[][] data)

Creates a rank-2 constant of float elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Boolean> create (Scope scope, boolean[][][] data)

Creates a rank-3 constant of boolean elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Integer> create (Scope scope, int[][] data)

Creates a rank-2 constant of int elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Integer> create (Scope scope, long[] shape, IntBuffer data)

Create a 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 shape = {2,3} (which represents a 2x3 matrix) then the buffer must have 6 elements remaining, which will be consumed by this method.

Parameters
scope is a scope used to add the underlying operation.
shape the tensor shape.
data a buffer containing the tensor data.
Returns
  • an integer constant
Throws
IllegalArgumentException If the tensor shape is not compatible with the buffer

public static Constant<Float> create (Scope scope, float[][][][] data)

Creates a rank-4 constant of float elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Long> create (Scope scope, long[][][] data)

Creates a rank-3 constant of long elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Integer> create (Scope scope, int[][][][][] data)

Creates a rank-5 constant of int elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<String> create (Scope scope, String data, Charset charset)

Creates a String constant using a specified encoding.

Parameters
scope is a scope used to add the underlying operation.
data The string to put into the new constant.
charset The encoding from String to bytes.
Returns
  • a string constant

public static Constant<String> create (Scope scope, byte[][][][][][] data)

Creates a rank-5 constant of String elements, each represented as an array of bytes.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. String elements are sequences of bytes from the last array dimension.

public static Constant<Float> create (Scope scope, float[] data)

Creates a rank-1 constant of float elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Float> create (Scope scope, float[][][][][][] data)

Creates a rank-6 constant of float elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Integer> create (Scope scope, int[][][][] data)

Creates a rank-4 constant of int elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, double data)

Creates a constant containing a single double element.

Parameters
scope is a scope used to add the underlying operation.
data The value to put into the new constant.
Returns
  • a double constant

public static Constant<Long> create (Scope scope, long[][][][][][] data)

Creates a rank-6 constant of long elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, double[] data)

Creates a rank-1 constant of double elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Long> create (Scope scope, long[][][][] data)

Creates a rank-4 constant of long elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<T> create (Scope scope, Class<T> type, long[] shape, ByteBuffer data)

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 data as per the specification of the TensorFlow C API.

Parameters
scope is a scope used to add the underlying operation.
type the tensor datatype.
shape the tensor shape.
data a buffer containing the tensor data.
Returns
  • a constant of type `type`
Throws
IllegalArgumentException If the tensor datatype or shape is not compatible with the buffer

public static Constant<Integer> create (Scope scope, int[] data)

Creates a rank-1 constant of int elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, double[][][] data)

Creates a rank-3 constant of double elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Boolean> create (Scope scope, boolean[] data)

Creates a rank-1 constant of boolean elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Integer> create (Scope scope, int[][][][][][] data)

Creates a rank-6 constant of int elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<String> create (Scope scope, byte[][][] data)

Creates a rank-2 constant of String elements, each represented as an array of bytes.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. String elements are sequences of bytes from the last array dimension.

public static Constant<Boolean> create (Scope scope, boolean[][] data)

Creates a rank-2 constant of boolean elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Boolean> create (Scope scope, boolean[][][][][][] data)

Creates a rank-6 constant of boolean elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, double[][][][][] data)

Creates a rank-5 constant of double elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Double> create (Scope scope, double[][] data)

Creates a rank-2 constant of double elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<String> create (Scope scope, byte[][] data)

Creates a rank-1 constant of String elements, each represented as an array of bytes.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. String elements are sequences of bytes from the last array dimension.

public static Constant<Boolean> create (Scope scope, boolean[][][][][] data)

Creates a rank-5 constant of boolean elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Long> create (Scope scope, long data)

Creates a constant containing a single long element.

Parameters
scope is a scope used to add the underlying operation.
data The value to put into the new constant.
Returns
  • a long constant

public static Constant<Long> create (Scope scope, long[][][][][] data)

Creates a rank-5 constant of long elements.

Parameters
scope is a scope used to add the underlying operation.
data An array containing the values to put into the new constant. The dimensions of the new constant will match those of the array.

public static Constant<Long> create (Scope scope, long[] shape, LongBuffer data)

Create a 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 shape = {2,3} (which represents a 2x3 matrix) then the buffer must have 6 elements remaining, which will be consumed by this method.

Parameters
scope is a scope used to add the underlying operation.
shape the tensor shape.
data a buffer containing the tensor data.
Returns
  • a long constant
Throws
IllegalArgumentException If the tensor shape is not compatible with the buffer

public static Constant<Boolean> create (Scope scope, boolean data)

Creates a constant containing a single boolean element.

Parameters
scope is a scope used to add the underlying operation.
data The value to put into the new constant.
Returns
  • a boolean constant