DataLayouts
Stay organized with collections
Save and categorize content based on your preferences.
Exposes DataLayout
instances of data formats frequently used in linear algebra computation.
Example of usage:
// Storing boolean values in a ByteDataBuffer
BooleanDataBuffer boolBuffer = DataLayouts.BOOL.applyTo(byteDataBuffer);
// Allocating a new buffer of 256 half floats
FloatDataBuffer halfBuffer = DataLayouts.FLOAT16.applyTo(DataBuffers.ofShorts(256 * DataLayouts.FLOAT16.scale());
Inherited Methods
From class
java.lang.Object
boolean
|
equals(Object arg0)
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
Fields
Data layout for converting 16-bit bfloats to/from short values.
This format used to be specific to TensorFlow but has now been adopted more broadly in the
machine learning field. It is optimized for fast conversion with single-precision 32-bit
floating points by simply shifting their value and truncating the mantissa to only 7 bits.
Therefore, this is a lost of precision in the fraction part compared to the IEEE-754
half-precision floating point specification (see FLOAT16
but it has a larger range of
possible values in the whole part as it preserves the 8-bit exponent and uses the same bias,
(i.e. an absolute range above 0 of approximately [10-40, 3.39 × 1038]
Some CPUs support the bfloat16 format natively for better performances.
Data layout for converting booleans to/from byte values.
Since there is no Java NIO boolean buffer, this layout is particularly useful for mapping
booleans values to standard byte buffers. The conversion between a boolean and a byte requires
explicit type casting.
Data layout for converting 16-bit half floats to/from short values.
Half floats are stored in memory accordingly to the IEEE-754 half-precision floating point
specification, and are converted to/from 32-bit floats in the user space.
There is a potential loss of precision when converting a single float (32-bit) to a half
float (16-bit). Absolute range of values above 0 for a half float is approximately
[5.96 × 10-8, 6.55 × 104] and their decimal part is rounded up
to a 10 bits mantissa.
In general, half float computation perform better on GPUs since, in general, CPUs do not
support this format natively.
Public Methods
public
static
DataLayout<DataBuffer<byte[]>, String>
ofStrings
(Charset charset)
Creates a data layout for converting strings to/from byte sequences.
This layout requires a charset
in parameter to specify how the strings must be
encoded/decoded as byte sequences. So a new layout instance is always returned.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-11-29 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-11-29 UTC."],[],[],null,["# DataLayouts\n\npublic final class **DataLayouts** \nExposes [DataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayout) instances of data formats frequently used in linear algebra computation.\n\nExample of usage: \n\n // Storing boolean values in a ByteDataBuffer\n BooleanDataBuffer boolBuffer = DataLayouts.BOOL.applyTo(byteDataBuffer);\n\n // Allocating a new buffer of 256 half floats\n FloatDataBuffer halfBuffer = DataLayouts.FLOAT16.applyTo(DataBuffers.ofShorts(256 * DataLayouts.FLOAT16.scale());\n \n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Fields\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------|\n| public static final [FloatDataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/FloatDataLayout)\\\u003c[ShortDataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/ShortDataBuffer)\\\u003e | [BFLOAT16](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayouts#BFLOAT16) | Data layout for converting 16-bit bfloats to/from short values. |\n| public static final [BooleanDataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/BooleanDataLayout)\\\u003c[ByteDataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/ByteDataBuffer)\\\u003e | [BOOL](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayouts#BOOL) | Data layout for converting booleans to/from byte values. |\n| public static final [FloatDataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/FloatDataLayout)\\\u003c[ShortDataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/ShortDataBuffer)\\\u003e | [FLOAT16](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayouts#FLOAT16) | Data layout for converting 16-bit half floats to/from short values. |\n\n### Public Constructors\n\n|---|----------------------------------------------------------------------------------------------------|\n| | [DataLayouts](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayouts#DataLayouts())() |\n\n### Public Methods\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [DataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayout)\\\u003c[DataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBuffer)\\\u003cbyte\\[\\]\\\u003e, String\\\u003e | [ofStrings](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayouts#ofStrings(java.nio.charset.Charset))(Charset charset) Creates a data layout for converting strings to/from byte sequences. |\n\n### Inherited Methods\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFields\n------\n\n#### public static final [FloatDataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/FloatDataLayout)\\\u003c[ShortDataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/ShortDataBuffer)\\\u003e\n**BFLOAT16**\n\nData layout for converting 16-bit bfloats to/from short values.\n\nThis format used to be specific to TensorFlow but has now been adopted more broadly in the\nmachine learning field. It is optimized for fast conversion with single-precision 32-bit\nfloating points by simply shifting their value and truncating the mantissa to only 7 bits.\n\nTherefore, this is a lost of precision in the fraction part compared to the IEEE-754\nhalf-precision floating point specification (see [FLOAT16](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayouts#FLOAT16) but it has a larger range of\npossible values in the whole part as it preserves the 8-bit exponent and uses the same bias,\n(i.e. an absolute range above 0 of approximately \\[10^-40^, 3.39 × 10^38^\\]\n\nSome CPUs support the bfloat16 format natively for better performances.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final [BooleanDataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/BooleanDataLayout)\\\u003c[ByteDataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/ByteDataBuffer)\\\u003e\n**BOOL**\n\nData layout for converting booleans to/from byte values.\n\nSince there is no Java NIO boolean buffer, this layout is particularly useful for mapping\nbooleans values to standard byte buffers. The conversion between a boolean and a byte requires\nexplicit type casting.\n\n\u003cbr /\u003e\n\n#### public static final [FloatDataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/FloatDataLayout)\\\u003c[ShortDataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/ShortDataBuffer)\\\u003e\n**FLOAT16**\n\nData layout for converting 16-bit half floats to/from short values.\n\nHalf floats are stored in memory accordingly to the IEEE-754 half-precision floating point\nspecification, and are converted to/from 32-bit floats in the user space.\n\nThere is a potential loss of precision when converting a single float (32-bit) to a half\nfloat (16-bit). Absolute range of values above 0 for a half float is approximately\n\\[5.96 × 10^-8^, 6.55 × 10^4^\\] and their decimal part is rounded up\nto a 10 bits mantissa.\n\nIn general, half float computation perform better on GPUs since, in general, CPUs do not\nsupport this format natively.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic Constructors\n-------------------\n\n#### public\n**DataLayouts**\n()\n\n\u003cbr /\u003e\n\nPublic Methods\n--------------\n\n#### public static [DataLayout](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/layout/DataLayout)\\\u003c[DataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBuffer)\\\u003cbyte\\[\\]\\\u003e, String\\\u003e\n**ofStrings**\n(Charset charset)\n\nCreates a data layout for converting strings to/from byte sequences.\n\nThis layout requires a `charset` in parameter to specify how the strings must be\nencoded/decoded as byte sequences. So a new layout instance is always returned.\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| charset | charset to use |\n|---------|----------------|\n\n##### Returns\n\n- a new string layout"]]