Java Code Examples for org.tensorflow.Tensor#of()

The following examples show how to use org.tensorflow.Tensor#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TBfloat16.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates a new tensor for storing a vector of floats.
 *
 * @param values floats to store in the new tensor
 * @return the new tensor
 */
static Tensor<TBfloat16> vectorOf(float... values) {
  if (values == null) {
    throw new IllegalArgumentException();
  }
  return Tensor.of(DTYPE, Shape.of(values.length), data -> StdArrays.copyTo(data, values));
}
 
Example 2
Source File: TFloat32.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates a new tensor for storing a vector of floats.
 *
 * @param values floats to store in the new tensor
 * @return the new tensor
 */
static Tensor<TFloat32> vectorOf(float... values) {
  if (values == null) {
    throw new IllegalArgumentException();
  }
  return Tensor.of(DTYPE, Shape.of(values.length), data -> StdArrays.copyTo(data, values));
}
 
Example 3
Source File: TInt64.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates a new tensor for storing a vector of longs.
 *
 * @param values longs to store in the new tensor
 * @return the new tensor
 */
static Tensor<TInt64> vectorOf(long... values) {
  if (values == null) {
    throw new IllegalArgumentException();
  }
  return Tensor.of(DTYPE, Shape.of(values.length), data -> StdArrays.copyTo(data, values));
}
 
Example 4
Source File: TFloat16.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates a new tensor for storing a vector of floats.
 *
 * @param values floats to store in the new tensor
 * @return the new tensor
 */
static Tensor<TFloat16> vectorOf(float... values) {
  if (values == null) {
    throw new IllegalArgumentException();
  }
  return Tensor.of(DTYPE, Shape.of(values.length), data -> StdArrays.copyTo(data, values));
}
 
Example 5
Source File: TUint8.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates a new tensor for storing a vector of bytes.
 *
 * @param values bytes to store in the new tensor
 * @return the new tensor
 */
static Tensor<TUint8> vectorOf(byte... values) {
  if (values == null) {
    throw new IllegalArgumentException();
  }
  return Tensor.of(DTYPE, Shape.of(values.length), data -> StdArrays.copyTo(data, values));
}
 
Example 6
Source File: TfNDArray.java    From djl with Apache License 2.0 4 votes vote down vote up
TfNDArray(NDManager manager, Shape shape, ByteBuffer data) {
    this(manager, Tensor.of(TUint8.DTYPE, toTfShape(shape), DataBuffers.of(data)));
}
 
Example 7
Source File: TFloat32.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor of the given shape, initialized with the provided data.
 *
 * @param shape shape of the tensor to allocate
 * @param data buffer of floats to initialize the tensor with
 * @return the new tensor
 */
static Tensor<TFloat32> tensorOf(Shape shape, FloatDataBuffer data) {
  return Tensor.of(DTYPE, shape, d -> d.write(data));
}
 
Example 8
Source File: TUint8.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor which is a copy of a given array of bytes.
 *
 * <p>The tensor will have the same shape as the source array and its data will be copied.
 *
 * @param src the source array giving the shape and data to the new tensor
 * @return the new tensor
 */
static Tensor<TUint8> tensorOf(NdArray<Byte> src) {
  return Tensor.of(DTYPE, src.shape(), src::copyTo);
}
 
Example 9
Source File: TFloat32.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor of the given shape and initialize its data.
 *
 * @param shape shape of the tensor to allocate
 * @param dataInit tensor data initializer
 * @return the new tensor
 * @throws TensorFlowException if the tensor cannot be allocated or initialized
 */
static Tensor<TFloat32> tensorOf(Shape shape, Consumer<TFloat32> dataInit) {
  return Tensor.of(DTYPE, shape, dataInit);
}
 
Example 10
Source File: TInt32.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor of the given shape.
 *
 * @param shape shape of the tensor to allocate
 * @return the new tensor
 */
static Tensor<TInt32> tensorOf(Shape shape) {
  return Tensor.of(DTYPE, shape);
}
 
Example 11
Source File: TFloat64.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor of the given shape and initialize its data.
 *
 * @param shape shape of the tensor to allocate
 * @param dataInit tensor data initializer
 * @return the new tensor
 * @throws TensorFlowException if the tensor cannot be allocated or initialized
 */
static Tensor<TFloat64> tensorOf(Shape shape, Consumer<TFloat64> dataInit) {
  return Tensor.of(DTYPE, shape, dataInit);
}
 
Example 12
Source File: TFloat32.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor of the given shape.
 *
 * @param shape shape of the tensor to allocate
 * @return the new tensor
 */
static Tensor<TFloat32> tensorOf(Shape shape) {
  return Tensor.of(DTYPE, shape);
}
 
Example 13
Source File: TFloat16.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor for storing a single float value.
 *
 * @param value float to store in the new tensor
 * @return the new tensor
 */
static Tensor<TFloat16> scalarOf(float value) {
  return Tensor.of(DTYPE, Shape.scalar(), data -> data.setFloat(value));
}
 
Example 14
Source File: TInt64.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor which is a copy of a given array of longs.
 *
 * <p>The tensor will have the same shape as the source array and its data will be copied.
 *
 * @param src the source array giving the shape and data to the new tensor
 * @return the new tensor
 */
static Tensor<TInt64> tensorOf(NdArray<Long> src) {
  return Tensor.of(DTYPE, src.shape(), src::copyTo);
}
 
Example 15
Source File: TBfloat16.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor for storing a single float value.
 *
 * @param value float to store in the new tensor
 * @return the new tensor
 */
static Tensor<TBfloat16> scalarOf(float value) {
  return Tensor.of(DTYPE, Shape.scalar(), data -> data.setFloat(value));
}
 
Example 16
Source File: TBfloat16.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor of the given shape and initialize its data.
 *
 * @param shape shape of the tensor to allocate
 * @param dataInit tensor data initializer
 * @return the new tensor
 * @throws TensorFlowException if the tensor cannot be allocated or initialized
 */
static Tensor<TBfloat16> tensorOf(Shape shape, Consumer<TBfloat16> dataInit) {
  return Tensor.of(DTYPE, shape, dataInit);
}
 
Example 17
Source File: TFloat64.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor for storing a single double value.
 *
 * @param value double to store in the new tensor
 * @return the new tensor
 */
static Tensor<TFloat64> scalarOf(double value) {
  return Tensor.of(DTYPE, Shape.scalar(), data -> data.setDouble(value));
}
 
Example 18
Source File: TFloat16.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor which is a copy of a given array of floats.
 *
 * <p>The tensor will have the same shape as the source array and its data will be copied.
 *
 * @param src the source array giving the shape and data to the new tensor
 * @return the new tensor
 */
static Tensor<TFloat16> tensorOf(NdArray<Float> src) {
  return Tensor.of(DTYPE, src.shape(), src::copyTo);
}
 
Example 19
Source File: TFloat32.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor for storing a single float value.
 *
 * @param value float to store in the new tensor
 * @return the new tensor
 */
static Tensor<TFloat32> scalarOf(float value) {
  return Tensor.of(DTYPE, Shape.scalar(), data -> data.setFloat(value));
}
 
Example 20
Source File: TBool.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Allocates a new tensor which is a copy of a given array of booleans.
 *
 * <p>The tensor will have the same shape as the source array and its data will be copied.
 *
 * @param src the source array giving the shape and data to the new tensor
 * @return the new tensor
 */
static Tensor<TBool> tensorOf(NdArray<Boolean> src) {
  return Tensor.of(DTYPE, src.shape(), src::copyTo);
}