@TensorType(dataType=DT_BFLOAT16, byteSize=2, mapperClass=TBfloat16Mapper.class) public interface TBfloat16 extends org.tensorflow.ndarray.FloatNdArray, TFloating
This type differs from TFloat16
as it truncates the mantissa of a 32-bit float and
preserve all exponent bits for faster conversion, while the latter shrink the exponent and have a
longer mantissa for more precision.
Since there is no floating-point type that fits in 16 bits in Java, a conversion (with
potentially a precision loss) is required for each 32 bits value written or read on a tensor of
this type from the JVM. Therefore, if a lot of I/O operations are to be expected on a tensor,
performances will be improved by working with TFloat32
or TFloat64
data types
whenever possible.
Note that some CPUs support the bfloat16 format natively, which can result in faster
computation compared to TFloat16
when GPUs are not used.
Modifier and Type | Method and Description |
---|---|
static TBfloat16 |
scalarOf(float value)
Allocates a new tensor for storing a single float value.
|
static TBfloat16 |
tensorOf(org.tensorflow.ndarray.NdArray<Float> src)
Allocates a new tensor which is a copy of a given array of floats.
|
static TBfloat16 |
tensorOf(org.tensorflow.ndarray.Shape shape)
Allocates a new tensor of the given shape.
|
static TBfloat16 |
tensorOf(org.tensorflow.ndarray.Shape shape,
Consumer<TBfloat16> dataInit)
Allocates a new tensor of the given shape and initialize its data.
|
static TBfloat16 |
tensorOf(org.tensorflow.ndarray.Shape shape,
org.tensorflow.ndarray.buffer.FloatDataBuffer data)
Allocates a new tensor of the given shape, initialized with the provided data.
|
static TBfloat16 |
vectorOf(float... values)
Allocates a new tensor for storing a vector of floats.
|
static TBfloat16 scalarOf(float value)
value
- float to store in the new tensorstatic TBfloat16 vectorOf(float... values)
values
- floats to store in the new tensorstatic TBfloat16 tensorOf(org.tensorflow.ndarray.NdArray<Float> src)
The tensor will have the same shape as the source array and its data will be copied.
src
- the source array giving the shape and data to the new tensorstatic TBfloat16 tensorOf(org.tensorflow.ndarray.Shape shape)
shape
- shape of the tensor to allocatestatic TBfloat16 tensorOf(org.tensorflow.ndarray.Shape shape, org.tensorflow.ndarray.buffer.FloatDataBuffer data)
shape
- shape of the tensor to allocatedata
- buffer of floats to initialize the tensor withstatic TBfloat16 tensorOf(org.tensorflow.ndarray.Shape shape, Consumer<TBfloat16> dataInit)
shape
- shape of the tensor to allocatedataInit
- tensor data initializerTensorFlowException
- if the tensor cannot be allocated or initializedCopyright © 2015–2022. All rights reserved.