+mvn -q compile exec:java ++ +The command prints TensorFlow version and a simple calculation. + +Success! TensorFlow Java is configured. diff --git a/docs/docs/references.md b/docs/docs/references.md new file mode 100644 index 00000000000..524b23dc675 --- /dev/null +++ b/docs/docs/references.md @@ -0,0 +1,8 @@ +--- +hide: + - navigation + - toc + - title +--- +# + \ No newline at end of file diff --git a/docs/docs/stylesheets/extra.css b/docs/docs/stylesheets/extra.css new file mode 100644 index 00000000000..70aefe6843e --- /dev/null +++ b/docs/docs/stylesheets/extra.css @@ -0,0 +1,14 @@ +:root > * { + /*--md-primary-fg-color: #EE782F;*/ + /*--md-primary-fg-color--light: #455960;*/ + /*--md-primary-fg-color--dark: #90030C;*/ +} + +.md-typeset h1, .md-typeset h2 { + font-weight: 800; + letter-spacing: -.01em; +} + +.md-sidebar--primary { + display: none; +} \ No newline at end of file diff --git a/docs/legacy_tools/build_java_api_docs.py b/docs/legacy_tools/build_java_api_docs.py new file mode 100644 index 00000000000..77d3ba80f31 --- /dev/null +++ b/docs/legacy_tools/build_java_api_docs.py @@ -0,0 +1,132 @@ +# Lint as: python3 +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +###################################################################################################################### +# IMPORTANT: Files in legacy_tools are no longer used to generate the TensorFlow-Java API docs as there are unfixed issues +# when using DocLava outside of the Google environment. We are keeping these for reference in case they are useful later. +###################################################################################################################### + + +"""Generate TensorFlow Java reference docs for TensorFlow.org.""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import pathlib +import shutil +import tempfile +import io +import requests +import zipfile +from git import Repo + +from absl import app +from absl import flags + +from tensorflow_docs.api_generator import gen_java + +FLAGS = flags.FLAGS + +NDARRAY_VERSION = 'v1.0.0' +JAVACPP_VERSION = '1.5.11' +PROTOBUF_VERSION = 'v3.21.9' + +# __file__ is the path to this file +TOOLS_DIR = pathlib.Path(__file__).resolve().parent +DOCS_DIR = TOOLS_DIR.parent +REPO_ROOT = DOCS_DIR.parent +DOC_OUTPUT_DIR = DOCS_DIR.joinpath("output") + +SECTION_LABELS = { + 'org.tensorflow': 'Core', + 'org.tensorflow.ndarray': 'NdArray', + 'org.tensorflow.framework': 'Framework', +} + +# These flags are required by infrastructure, not all of them are used. +flags.DEFINE_string('output_dir', f"{DOC_OUTPUT_DIR}", + ("Use this branch as the root version and don't" + ' create in version directory')) + +flags.DEFINE_string('site_path', 'api_docs/', + 'Path prefix in the _toc.yaml') + +flags.DEFINE_string('code_url_prefix', None, + '[UNUSED] The url prefix for links to code.') + +flags.DEFINE_bool( + 'search_hints', True, + '[UNUSED] Include metadata search hints in the generated files') + + +def checkout_repo(repo_url: str, target_dir_name: str, version: str): + local_repo_path = f"{REPO_ROOT}/{target_dir_name}" + if not pathlib.Path(local_repo_path).exists(): + local_repo = Repo.clone_from(repo_url, local_repo_path) + else: + local_repo = Repo(local_repo_path) + local_repo.remotes['origin'].fetch() + local_repo.git.checkout(version) + + +def overlay(from_root, to_root): + for from_path in pathlib.Path(from_root).rglob('*'): + relpath = from_path.relative_to(from_root) + to_path = to_root/relpath + if from_path.is_file(): + assert not to_path.exists() + shutil.copyfile(from_path, to_path) + else: + to_path.mkdir(exist_ok=True) + + +def main(unused_argv): + checkout_repo('https://github.com/tensorflow/java-ndarray', 'ndarray', NDARRAY_VERSION) + checkout_repo('https://github.com/bytedeco/javacpp', 'javacpp', JAVACPP_VERSION) + response = requests.get('https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.21.9/protobuf-java-3.21.9-sources.jar') + with zipfile.ZipFile(io.BytesIO(response.content)) as z: + z.extractall(f"{REPO_ROOT}/protobuf") + response = requests.get('https://repo1.maven.org/maven2/org/osgi/osgi.annotation/8.1.0/osgi.annotation-8.1.0-sources.jar') + with zipfile.ZipFile(io.BytesIO(response.content)) as z: + z.extractall(f"{REPO_ROOT}/osgi") + + merged_source = pathlib.Path(tempfile.mkdtemp()) + (merged_source / 'java/org').mkdir(parents=True) + shutil.copytree(REPO_ROOT/'tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/', merged_source/'java/org/tensorflow') + overlay(REPO_ROOT/'tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow', merged_source/'java/org/tensorflow') + overlay(REPO_ROOT/'tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow', merged_source/'java/org/tensorflow') + overlay(REPO_ROOT/'tensorflow-core/tensorflow-core-native/src/gen/java/org/tensorflow/', merged_source/'java/org/tensorflow/') + overlay(REPO_ROOT/'tensorflow-core/tensorflow-core-native/src/main/java/org/tensorflow/', merged_source/'java/org/tensorflow/') + shutil.copytree(REPO_ROOT/'tensorflow-framework/src/main/java/org/tensorflow/framework', merged_source/'java/org/tensorflow/framework') + shutil.copytree(REPO_ROOT/'ndarray/ndarray/src/main/java/org/tensorflow/ndarray', merged_source/'java/org/tensorflow/ndarray') + shutil.copytree(REPO_ROOT/'javacpp/src/main/java/org/bytedeco', merged_source/'java/org/bytedeco') + shutil.copytree(REPO_ROOT/'protobuf/com/', merged_source/'java/com') + shutil.copytree(REPO_ROOT/'osgi/org/osgi', merged_source/'java/org/osgi') + + gen_java.gen_java_docs( + package='org.tensorflow', + source_path=merged_source / 'java', + output_dir=pathlib.Path(FLAGS.output_dir), + site_path=pathlib.Path(FLAGS.site_path), + section_labels=SECTION_LABELS, + # Uncomment for local testing: + script_path=pathlib.Path(TOOLS_DIR, 'run-javadoc-for-tf-local.sh'), + ) + + +if __name__ == '__main__': + flags.mark_flags_as_required(['output_dir']) + app.run(main) diff --git a/docs/legacy_tools/requirements.txt b/docs/legacy_tools/requirements.txt new file mode 100644 index 00000000000..4435ca4d4a9 --- /dev/null +++ b/docs/legacy_tools/requirements.txt @@ -0,0 +1,8 @@ +###################################################################################################################### +# IMPORTANT: Files in legacy_tools are no longer used to generate the TensorFlow-Java API docs as there are unfixed issues +# when using DocLava outside of the Google environment. We are keeping these for reference in case they are useful later. +###################################################################################################################### + +GitPython +requests +tensorflow-docs \ No newline at end of file diff --git a/docs/legacy_tools/run-javadoc-for-tf-local.sh b/docs/legacy_tools/run-javadoc-for-tf-local.sh new file mode 100644 index 00000000000..97d59ddfd6e --- /dev/null +++ b/docs/legacy_tools/run-javadoc-for-tf-local.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +###################################################################################################################### +# IMPORTANT: Files in legacy_tools are no longer used to generate the TensorFlow-Java API docs as there are unfixed issues +# when using DocLava outside of the Google environment. We are keeping these for reference in case they are useful later. +###################################################################################################################### + +set -ex + +export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home # Or change to any JDK 11 home path + +# https://android.googlesource.com/platform/external/doclava/ +# There's a debian package: +# https://packages.debian.org/unstable/doclava-aosp +# Install with: +# +# $ sudo apt install doclava-aosp #v 6.0.1+r55-1+build1 +# +# https://unix.stackexchange.com/questions/594841/how-do-i-assign-a-value-to-a-bash-variable-iff-that-variable-is-null-unassigned +DOCLAVA_JAR=${DOCLAVA_JAR:-'tools/lib/doclava.jar'} # Build lib locally + + +# Install java clear silver templates with: +# +# $ sudo apt install libjsilver-aosp-java #v 6.0.1+r55-1+build1 +JSILVER_JAR=${JSILVER_JAR:-'tools/lib/jsilver.jar'} # Build lib locally + + +######### DELETE OUTPUT_DIR ################# + +# Empty the output directory in case a class has been deleted +rm -rf "${OUTPUT_DIR:?}"/* +############ RUN DOCLAVA ################### + +# $FEDERATED_DOCS is a space-separated string of url,file pairs. +read -a api_pairs <<< "${FEDERATED_DOCS}" +FEDERATED_PARAMS="" +for i in "${!api_pairs[@]}"; do + api_pair_str="${api_pairs[$i]}" # "url,api.txt" + read -a api_pair <<< "${api_pair_str//,/ }" + # Using the index as the API "name", build the federation params. Note that + # using 0 as an API name will evaluate to false and cause rendering bugs, + # so we preface with "api_". + FEDERATED_PARAMS+=" -federate api_${i} ${api_pair[0]}" + FEDERATED_PARAMS+=" -federationapi api_${i} ${api_pair[1]}" +done + +# To install javadoc, for example, use +# +# sudo apt install openjdk-11-jdk +# +# doclava doesn't work with openjdk-13 +# ``` +# javadoc: error - Class com.google.doclava.Doclava is not a valid doclet. +# Note: As of JDK 13, the com.sun.javadoc API is no longer supported. +# ``` +# It's used here: https://android.googlesource.com/platform/external/doclava/+/refs/heads/master/src/com/google/doclava/Doclava.java + +# Each package in $PACKAGE needs to prefaced with -subpackages, so do that. +SUBPACKAGES="" +read -r -a packages <<< "${PACKAGE}" +for pkg in "${packages[@]}"; do + SUBPACKAGES+=" -subpackages ${pkg}" +done +( # Capture the return code. it may be non-zero for minor errors. + /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/javadoc \ + -sourcepath "${SOURCE_PATH}" \ + -docletpath "${DOCLAVA_JAR}:${JSILVER_JAR}" \ + -doclet com.google.doclava.Doclava \ + -toroot "${SITE_PATH}"/ \ + -yaml _toc.yaml \ + -templatedir "${TEMPLATES}" \ + -public \ + -d "${OUTPUT_DIR}" \ + ${FEDERATED_PARAMS} \ + ${SUBPACKAGES} +) + + +mv "${OUTPUT_DIR}"/reference/* "${OUTPUT_DIR}" + +################################################################### +################### START OF POST-PROCESSING ###################### +################################################################### +rm "${OUTPUT_DIR}/navtree_data.js" || true +rm "${OUTPUT_DIR}/hierarchy.html" || true + +find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|${SITE_PATH}/reference|${SITE_PATH}|g" +find ${OUTPUT_DIR} -name "*.yaml" | xargs sed -i '' "s|${SITE_PATH}/reference|${SITE_PATH}|g" +find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|a href=\"reference/org/tensorflow|a href=\"${SITE_PATH}/org/tensorflow|g" +find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|a href=\"reference/com/google|a href=\"${SITE_PATH}/com/google|g" + +JAVA_LANG=https://docs.oracle.com/javase/8/docs/api +find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|a href=\"reference/java/lang|a href=\"${JAVA_LANG}/java/lang|g" + +find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' 's|
||g'
+
+rm ${OUTPUT_DIR}/timestamp.js || true
+rm ${OUTPUT_DIR}/lists.js || true
+rm ${OUTPUT_DIR}/index.html || true
+
+cp ${TEMPLATES}/screen.css ${OUTPUT_DIR}/
+
+
diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml
new file mode 100644
index 00000000000..8729bca5af5
--- /dev/null
+++ b/docs/mkdocs.yml
@@ -0,0 +1,49 @@
+site_name: ''
+site_url: https://tensorflow.org
+repo_url: https://github.com/tensorflow/java
+site_description: Documentation of TensorFlow Java API and tools.
+copyright: "© TensorFlow Authors 2025"
+
+theme:
+ name: material
+ logo: assets/tensorflow.svg
+ features:
+ - navigation.indexes
+ - navigation.instant
+ - navigation.sections
+ - navigation.tabs
+ - navigation.tabs.sticky
+ - toc.follow
+ palette:
+ # Palette toggle for automatic mode
+ - media: "(prefers-color-scheme)"
+ toggle:
+ icon: material/brightness-auto
+ name: Switch to light mode
+ # Palette toggle for light mode
+ - media: "(prefers-color-scheme: light)"
+ scheme: default
+ primary: white
+ accent: orange
+ toggle:
+ icon: material/brightness-7
+ name: Switch to dark mode
+ # Palette toggle for dark mode
+ - media: "(prefers-color-scheme: dark)"
+ scheme: slate
+ primary: black
+ accent: orange
+ toggle:
+ icon: material/brightness-4
+ name: Switch to system preference
+
+extra_css:
+ - stylesheets/extra.css
+
+nav:
+ - Home:
+ - index.md
+ - Install:
+ - install.md
+ - References:
+ - apidocs/index.html
diff --git a/ndarray/README.md b/ndarray/README.md
deleted file mode 100644
index b823422bbfd..00000000000
--- a/ndarray/README.md
+++ /dev/null
@@ -1,122 +0,0 @@
-# NdArray Java Library
-
-## Introduction
-
-NdArray is a library exposing utilities for manipulating data in a n-dimensional space in Java.
-Unlike other Java artifacts distributed by TensorFlow, this library does not depend on the TensorFlow
-runtime, therefore is very lightweight and can be used by any kind of Java project.
-
-To import the NdArray library in your project, simply add the following dependency:
-```xml
-
- org.tensorflow
- ndarray
- 0.2.0-SNAPSHOT
-
-```
-
-### Data Buffers
-
-Instances of `DataBuffer` map contiguous segments of memory with 64-bits indexing and supports
-generic parametrization while still allowing direct access to primitive types. Such segments
-could be standard Java arrays, JDK NIO buffers or native memory. In addition, it can serialize and
-deserialize data of any type (and not only primitive types, as with `java.util.nio`).
-
-```java
-// Allocate a buffer of 4K int values
-IntDataBuffer bufferA = DataBuffers.ofInts(4096L);
-assertEquals(4096L, bufferA.size());
-
-// Write an int array at the beginning of the buffer
-bufferA.write(new int[] { 1, 2, 3 });
-assertEquals(3, bufferA.getInt(2));
-
-// Slice buffer after its first value
-IntDataBuffer bufferB = bufferA.offset(1);
-assertEquals(4095L, bufferB.size());
-assertEquals(2, bufferB.getInt(0));
-
-// Resize a buffer to 10 elements
-IntDataBuffer bufferC = bufferA.narrow(10);
-assertEquals(10L, bufferB.size());
-assertEquals(2, bufferB.getInt(0));
-```
-
-### ND Arrays
-
-Instances of `NdArray` are used to view memory segments stored in a `DataBuffer` as a
-multidimensional arrays and to provide an API for traversing, reading, writing and slicing
-their data. The goal of these tools is to replace the usage of standard multidimensional Java arrays
-(e.g. `new int[][][]`) since those results in slow performances, from the non-contiguous
-storage of their data and the multiple dereferences required to access their values.
-
-```java
-// Allocating a 3D matrix of 2x3x2
-IntNdArray matrix3d = NdArrays.ofInts(Shape.of(2, 3, 2));
-assertEquals(3, matrix3d.rank());
-
-// Initializing 3D matrix data with vectors from the first dimension (index 0)
-matrix3d.elements(0).forEach(matrix -> {
- assertEquals(2, matrix.rank());
- assertEquals(Shape.of(3, 2), matrix.shape());
- matrix
- .set(NdArrays.vectorOf(1, 2), 0)
- .set(NdArrays.vectorOf(3, 4), 1)
- .set(NdArrays.vectorOf(5, 6), 2);
-});
-
-// Visit all scalars of 3D matrix, printing their coordinates and value
-matrix3d.scalars().forEachIdx((coords, scalar) ->
- System.out.println("Scalar at " + Arrays.toString(coords) + " has value " + scalar.getInt())
-);
-
-// Retrieving the second vector of the first matrix
-IntNdArray vector = matrix3d.get(0, 1);
-assertEquals(1, vector.rank());
-
-// Rewriting the values of the vector using a primitive array
-vector.write(new int[] { 7, 8 });
-assertEquals(7, matrix3d.getInt(0, 1, 0));
-assertEquals(8, matrix3d.getInt(0, 1, 1));
-
-// Slicing the 3D matrix so we only keep the second element of the second dimension
-IntNdArray slice = matrix3d.slice(all(), at(1));
-assertEquals(2, slice.rank());
-assertEquals(Shape.of(2, 2), slice.shape());
-assertEquals(7, slice.getInt(0, 0)); // (0, 1, 0) in the original matrix
-assertEquals(3, slice.getInt(1, 0)); // (1, 1, 0) in the original matrix
-```
-
-## Integration with TensorFlow
-
-The NdArray library is independent of the TensorFlow runtime library, making it a good choice for
-manipulating multi-dimensional data structures from anywhere. But as an example, here
-is how it is actually being used by the [TensorFlow Core API](https://github.com/tensorflow/java/tree/master/tensorflow-core/tensorflow-core-api):
-
-```java
-// Allocate a tensor of 32-bits integer of the shape (2, 3, 2)
-Tensor tensor = TInt32.ofShape(2, 3, 2);
-
-// Access tensor memory directly
-IntNdArray tensorData = tensor.data();
-assertEquals(3, tensorData.rank());
-assertEquals(12, tensorData.size());
-
-try (EagerSession session = EagerSession.create()) {
- Ops tf = Ops.create(session);
-
- // Initialize tensor memory with zeros and take a snapshot
- tensorData.scalars().forEach(scalar -> scalar.setInt(0));
- Constant x = tf.constant(tensor);
-
- // Initialize the same tensor memory with ones and take a snapshot
- tensorData.scalars().forEach(scalar -> scalar.setInt(1));
- Constant y = tf.constant(tensor);
-
- // Subtract y from x and validate the result
- Sub sub = tf.math.sub(x, y);
- sub.data().scalars().forEach(scalar ->
- assertEquals(-1, scalar.getInt())
- );
-}
-```
diff --git a/ndarray/pom.xml b/ndarray/pom.xml
deleted file mode 100644
index 4139b8b7929..00000000000
--- a/ndarray/pom.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-
-
- 4.0.0
-
-
- org.tensorflow
- tensorflow-java
- 0.3.0-SNAPSHOT
-
- ndarray
- jar
-
- TensorFlow NdArray Library
-
- Utility library for N-dimensional data I/O operations.
-
-
-
- org.tensorflow.ndarray
-
-
-
-
- org.junit.jupiter
- junit-jupiter-api
- test
-
-
- org.junit.jupiter
- junit-jupiter-engine
- test
-
-
- org.openjdk.jmh
- jmh-core
- test
-
-
- org.openjdk.jmh
- jmh-generator-annprocess
- test
-
-
-
-
-
-
- maven-jar-plugin
- 3.2.0
-
-
-
- ${java.module.name}
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.22.2
-
- 1
- false
- -Xmx2G -XX:MaxPermSize=256m
-
- **/*Test.java
-
-
-
-
-
-
-
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java
deleted file mode 100644
index 5b4bedb1c84..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of booleans.
- */
-public interface BooleanNdArray extends NdArray {
-
- /**
- * Returns the boolean value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2
- * matrix.getBoolean(0, 1); // succeeds, returns false
- * matrix.getBoolean(0); // throws IllegalRankException
- *
- * BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getBoolean(); // succeeds, returns false
- * }
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- boolean getBoolean(long... coordinates);
-
- /**
- * Assigns the boolean value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2
- * matrix.setBoolean(true, 0, 1); // succeeds
- * matrix.setBoolean(true, 0); // throws IllegalRankException
- *
- * BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setBoolean(true); // succeeds
- * }
- *
- * @param value the value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- BooleanNdArray setBoolean(boolean value, long... coordinates);
-
- @Override
- BooleanNdArray slice(Index... indices);
-
- @Override
- BooleanNdArray get(long... coordinates);
-
- @Override
- BooleanNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Boolean getObject(long... coordinates) {
- return getBoolean(coordinates);
- }
-
- @Override
- default BooleanNdArray setObject(Boolean value, long... coordinates) {
- return setBoolean(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- BooleanNdArray copyTo(NdArray dst);
-
- @Override
- BooleanNdArray read(DataBuffer dst);
-
- BooleanNdArray read(BooleanDataBuffer dst);
-
- @Override
- BooleanNdArray write(DataBuffer src);
-
- BooleanNdArray write(BooleanDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java
deleted file mode 100644
index 0e6f118f5ef..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.buffer.ByteDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of bytes.
- */
-public interface ByteNdArray extends NdArray {
-
- /**
- * Returns the byte value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * ByteNdArray matrix = NdArrays.ofBytes(shape(2, 2)); // matrix rank = 2
- * matrix.getByte(0, 1); // succeeds, returns 0
- * matrix.getByte(0); // throws IllegalRankException
- *
- * ByteNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getByte(); // succeeds, returns 0
- * }
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- byte getByte(long... coordinates);
-
- /**
- * Assigns the byte value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * ByteNdArray matrix = NdArrays.ofBytes(shape(2, 2)); // matrix rank = 2
- * matrix.setByte(10, 0, 1); // succeeds
- * matrix.setByte(10, 0); // throws IllegalRankException
- *
- * ByteNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setByte(10); // succeeds
- * }
- *
- * @param value the value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- ByteNdArray setByte(byte value, long... coordinates);
-
- @Override
- ByteNdArray slice(Index... indices);
-
- @Override
- ByteNdArray get(long... coordinates);
-
- @Override
- ByteNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Byte getObject(long... coordinates) {
- return getByte(coordinates);
- }
-
- @Override
- default ByteNdArray setObject(Byte value, long... coordinates) {
- return setByte(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- ByteNdArray copyTo(NdArray dst);
-
- @Override
- ByteNdArray read(DataBuffer dst);
-
- ByteNdArray read(ByteDataBuffer dst);
-
- @Override
- ByteNdArray write(DataBuffer src);
-
- ByteNdArray write(ByteDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java
deleted file mode 100644
index 80e99b01877..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DoubleDataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of doubles.
- */
-public interface DoubleNdArray extends NdArray {
-
- /**
- * Returns the double value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * DoubleNdArray matrix = NdArrays.ofDoubles(shape(2, 2)); // matrix rank = 2
- * matrix.getDouble(0, 1); // succeeds, returns 0.0
- * matrix.getDouble(0); // throws IllegalRankException
- *
- * DoubleNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getDouble(); // succeeds, returns 0.0
- * }
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- double getDouble(long... coordinates);
-
- /**
- * Assigns the double value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * DoubleNdArray matrix = NdArrays.ofDoubles(shape(2, 2)); // matrix rank = 2
- * matrix.setDouble(10.0, 0, 1); // succeeds
- * matrix.setDouble(10.0, 0); // throws IllegalRankException
- *
- * DoubleNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setDouble(10.0); // succeeds
- * }
- *
- * @param value value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- DoubleNdArray setDouble(double value, long... coordinates);
-
- @Override
- DoubleNdArray slice(Index... indices);
-
- @Override
- DoubleNdArray get(long... coordinates);
-
- @Override
- DoubleNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Double getObject(long... coordinates) {
- return getDouble(coordinates);
- }
-
- @Override
- default DoubleNdArray setObject(Double value, long... coordinates) {
- return setDouble(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- DoubleNdArray copyTo(NdArray dst);
-
- @Override
- DoubleNdArray read(DataBuffer dst);
-
- DoubleNdArray read(DoubleDataBuffer dst);
-
- @Override
- DoubleNdArray write(DataBuffer src);
-
- DoubleNdArray write(DoubleDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java
deleted file mode 100644
index 8d4fbf5c1ed..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.FloatDataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of floats.
- */
-public interface FloatNdArray extends NdArray {
-
- /**
- * Returns the float value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.getFloat(0, 1); // succeeds, returns 0.0f
- * matrix.getFloat(0); // throws IllegalRankException
- *
- * FloatNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getFloat(); // succeeds, returns 0.0f
- * }
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- float getFloat(long... coordinates);
-
- /**
- * Assigns the float value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.setFloat(10.0f, 0, 1); // succeeds
- * matrix.setFloat(10.0f, 0); // throws IllegalRankException
- *
- * FloatNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setFloat(10.0f); // succeeds
- * }
- *
- * @param value value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- FloatNdArray setFloat(float value, long... coordinates);
-
- @Override
- FloatNdArray slice(Index... coordinates);
-
- @Override
- FloatNdArray get(long... coordinates);
-
- @Override
- FloatNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Float getObject(long... coordinates) {
- return getFloat(coordinates);
- }
-
- @Override
- default FloatNdArray setObject(Float value, long... coordinates) {
- return setFloat(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- FloatNdArray copyTo(NdArray dst);
-
- @Override
- FloatNdArray read(DataBuffer dst);
-
- FloatNdArray read(FloatDataBuffer dst);
-
- @Override
- FloatNdArray write(DataBuffer src);
-
- FloatNdArray write(FloatDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/IllegalRankException.java b/ndarray/src/main/java/org/tensorflow/ndarray/IllegalRankException.java
deleted file mode 100644
index b816d338d7e..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/IllegalRankException.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-/**
- * Exception thrown when an operation cannot be completed because of the rank of the targeted array.
- */
-public class IllegalRankException extends IllegalArgumentException {
-
- public IllegalRankException(String message) {
- super(message);
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java
deleted file mode 100644
index aa2cc652d69..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.IntDataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of integers.
- */
-public interface IntNdArray extends NdArray {
-
- /**
- * Returns the integer value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * IntNdArray matrix = NdArrays.ofInts(shape(2, 2)); // matrix rank = 2
- * matrix.getInt(0, 1); // succeeds, returns 0
- * matrix.getInt(0); // throws IllegalRankException
- *
- * IntNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getInt(); // succeeds, returns 0
- * }
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- int getInt(long... coordinates);
-
- /**
- * Assigns the integer value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * IntNdArray matrix = NdArrays.ofInts(shape(2, 2)); // matrix rank = 2
- * matrix.setInt(10, 0, 1); // succeeds
- * matrix.setInt(10, 0); // throws IllegalRankException
- *
- * IntNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setInt(10); // succeeds
- * }
- *
- * @param value value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- IntNdArray setInt(int value, long... coordinates);
-
- @Override
- IntNdArray slice(Index... indices);
-
- @Override
- IntNdArray get(long... coordinates);
-
- @Override
- IntNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Integer getObject(long... coordinates) {
- return getInt(coordinates);
- }
-
- @Override
- default IntNdArray setObject(Integer value, long... coordinates) {
- return setInt(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- IntNdArray copyTo(NdArray dst);
-
- @Override
- IntNdArray read(DataBuffer dst);
-
- IntNdArray read(IntDataBuffer dst);
-
- @Override
- IntNdArray write(DataBuffer src);
-
- IntNdArray write(IntDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java
deleted file mode 100644
index 3e5be6dc7ec..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.LongDataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of longs.
- */
-public interface LongNdArray extends NdArray {
-
- /**
- * Returns the long value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * LongNdArray matrix = NdArrays.ofLongs(shape(2, 2)); // matrix rank = 2
- * matrix.getLong(0, 1); // succeeds, returns 0L
- * matrix.getLong(0); // throws IllegalRankException
- *
- * LongNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getLong(); // succeeds, returns 0L
- * }
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- long getLong(long... coordinates);
-
- /**
- * Assigns the long value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * LongNdArray matrix = NdArrays.ofLongs(shape(2, 2)); // matrix rank = 2
- * matrix.setLong(10L, 0, 1); // succeeds
- * matrix.setLong(10L, 0); // throws IllegalRankException
- *
- * LongNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setLong(10L); // succeeds
- * }
- *
- * @param value value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- LongNdArray setLong(long value, long... coordinates);
-
- @Override
- LongNdArray slice(Index... indices);
-
- @Override
- LongNdArray get(long... coordinates);
-
- @Override
- LongNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Long getObject(long... coordinates) {
- return getLong(coordinates);
- }
-
- @Override
- default LongNdArray setObject(Long value, long... coordinates) {
- return setLong(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- LongNdArray copyTo(NdArray dst);
-
- @Override
- LongNdArray read(DataBuffer dst);
-
- LongNdArray read(LongDataBuffer dst);
-
- @Override
- LongNdArray write(DataBuffer src);
-
- LongNdArray write(LongDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java
deleted file mode 100644
index 6686abd9148..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * A data structure of N-dimensions.
- *
- * The `NdArray` interface creates an abstraction between the physical storage of a data record,
- * which can be linear or segmented, and its logical representation. In general, they achieve
- * better performances than standard multi-dimensional arrays in Java by mapping directly linear
- * data segments in memory.
- *
- *
Like {@link DataBuffer}, {@code NdArray} instances support 64-bits indexing so they can be
- * used to map very large data records. They also support special coordinates that allow traversing
- * their values in any direction or to select only a subset of them.
- *
- *
Example of usage:
- *
{@code
- * // Creates a 2x3x2 matrix (of rank 3)
- * FloatNdArray matrix3d = NdArrays.ofFloats(shape(2, 3, 2));
- *
- * // Initialize sub-matrices data with vectors
- * matrix.set(NdArrays.vectorOf(1.0f, 2.0f), 0, 0)
- * .set(NdArrays.vectorOf(3.0f, 4.0f), 0, 1)
- * .set(NdArrays.vectorOf(5.0f, 6.0f), 0, 2)
- * .set(NdArrays.vectorOf(7.0f, 8.0f), 1, 0)
- * .set(NdArrays.vectorOf(9.0f, 10.0f), 1, 1)
- * .set(NdArrays.vectorOf(11.0f, 12.0f), 1, 2);
- *
- * // Access the second 3x2 matrix (of rank 2)
- * FloatNdArray matrix = matrix3d.get(1);
- *
- * // Access directly the float value at (1, 0) from the second matrix
- * assertEquals(9.0f, matrix.getFloat(1, 0));
- * }
- *
- * @param the type of values to be mapped
- */
-public interface NdArray extends Shaped {
-
- /**
- * Returns a sequence of all elements at a given dimension.
- *
- * Logically, the N-dimensional array can be flatten in a single vector, where the scalars of
- * the {@code (n - 1)}th element precedes those of the {@code (n)}th element, for a total of
- * {@link #size()} values.
- *
- *
For example, given a {@code n x m} matrix on the {@code [x, y]} axes, elements are iterated in
- * the following order:
- *
x0y0, x0y1, ..., x0ym-1, x1y0, x1y1, ..., xn-1ym-1
- *
- *
The returned sequence can then be iterated to visit each elements, either by calling
- * {@link NdArraySequence#forEach(Consumer)} or {@link NdArraySequence#forEachIndexed(BiConsumer)}.
- *
{@code
- * // Iterate matrix for initializing each of its vectors
- * matrixOfFloats.elements(0).forEach(v -> {
- * v.set(vector(1.0f, 2.0f, 3.0f));
- * });
- *
- * // Iterate a vector for reading each of its scalar
- * vectorOfFloats.scalars().forEachIdx((coords, s) -> {
- * System.out.println("Value " + s.getFloat() + " found at " + coords);
- * });
- * }
- *
- * @param dimensionIdx index of the dimension
- * @return an {@code NdArray} sequence
- * @throws IllegalArgumentException if {@code dimensionIdx} is greater or equal to the total
- * number of dimensions of this array
- */
- NdArraySequence extends NdArray> elements(int dimensionIdx);
-
- /**
- * Returns a sequence of all scalars in this array.
- *
- * This is equivalent to call {@code elements(shape().numDimensions() - 1)}
- *
- * @return an {@code NdArray} sequence
- */
- NdArraySequence extends NdArray> scalars();
-
- /**
- * Creates a multi-dimensional view (or slice) of this array by mapping one or more dimensions
- * to the given index selectors.
- *
- * Slices allow to traverse an N-dimensional array in any of its axis and/or to filter only
- * elements of interest. For example, for a given matrix on the {@code [x, y]} axes, it is
- * possible to iterate elements at {@code y=0} for all {@code x}.
- *
- *
Any changes applied to the returned slice affect the data of this array as well, as there
- * is no copy involved.
- *
- *
Example of usage:
- *
{@code
- * FloatNdArray matrix3d = NdArrays.ofFloats(shape(3, 2, 4)); // with [x, y, z] axes
- *
- * // Iterates elements on the x axis by preserving only the 3rd value on the z axis,
- * // (i.e. [x, y, 2])
- * matrix3d.slice(all(), all(), at(2)).elements(0).forEach(m -> {
- * assertEquals(shape(2), m); // y=2, z=0 (scalar)
- * });
- *
- * // Creates a slice that contains only the last element of the y axis and elements with an
- * // odd `z` coordinate.
- * FloatNdArray slice = matrix3d.slice(all(), at(1), odd());
- * assertEquals(shape(3, 2), slice.shape()); // x=3, y=0 (scalar), z=2 (odd coordinates)
- *
- * // Iterates backward the elements on the x axis
- * matrix3d.slice(flip()).elements(0).forEach(m -> {
- * assertEquals(shape(2, 4), m); // y=2, z=4
- * });
- * }
- *
- * @param indices index selectors per dimensions, starting from dimension 0 of this array.
- * @return the element resulting of the index selection
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- */
- NdArray slice(Index... indices);
-
- /**
- * Returns the N-dimensional element of this array at the given coordinates.
- *
- * Elements of any of the dimensions of this array can be retrieved. For example, if the number
- * of coordinates is equal to the number of dimensions of this array, then a rank-0 (scalar) array
- * is returned, which value can then be obtained by calling `array.getObject()`.
- *
- *
Any changes applied to the returned elements affect the data of this array as well, as there
- * is no copy involved.
- *
- *
Note that invoking this method is an equivalent and more efficient way to slice this array
- * on single scalar, i.e. {@code array.get(x, y, z)} is equal to
- * {@code array.slice(at(x), at(y), at(z))}
- *
- * @param coordinates coordinates of the element to access, none will return this array
- * @return the element at this index
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- */
- NdArray get(long... coordinates);
-
- /**
- * Assigns the value of the N-dimensional element found at the given coordinates.
- *
- * The number of coordinates provided can be anywhere between 0 and rank - 1. For example:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.set(vector(10.0f, 20.0f), 0); // success
- * matrix.set(scalar(10.0f), 1, 0); // success
- * }
- *
- * @param src an array of the values to assign
- * @param coordinates coordinates of the element to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- */
- NdArray set(NdArray src, long... coordinates);
-
- /**
- * Returns the value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.getObject(0, 1); // succeeds, returns 0.0f
- * matrix.getObject(0); // throws IllegalRankException
- *
- * FloatNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getObject(); // succeeds, returns 0.0f
- * }
- *
- * Note: if this array stores values of a primitive type, prefer the usage of the specialized
- * method in the subclass for that type. For example, {@code floatArray.getFloat(0); }.
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar
- * element
- */
- T getObject(long... coordinates);
-
- /**
- * Assigns the value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.setObject(10.0f, 0, 1); // succeeds
- * matrix.setObject(10.0f, 0); // throws IllegalRankException
- *
- * FloatNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setObject(10.0f); // succeeds
- * }
- *
- * Note: if this array stores values of a primitive type, prefer the usage of the specialized
- * method in the subclass for that type. For example, {@code floatArray.setFloat(10.0f, 0); }
- *
- * @param value the value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar
- * element
- */
- NdArray setObject(T value, long... coordinates);
-
- /**
- * Copy the content of this array to the destination array.
- *
- * The {@link #shape()} of the destination array must be equal to the shape of this array, or
- * an exception is thrown. After the copy, the content of both arrays can be altered
- * independently, without affecting each other.
- *
- * @param dst array to receive a copy of the content of this array
- * @return this array
- * @throws IllegalArgumentException if the shape of {@code dst} is not equal to the shape of this
- * array
- */
- NdArray copyTo(NdArray dst);
-
- /**
- * Read the content of this N-dimensional array into the destination buffer.
- *
- * The size of the buffer must be equal or greater to the {@link #size()} of this
- * array, or an exception is thrown. After the copy, content of the buffer and of the array can be
- * altered independently, without affecting each other.
- *
- * @param dst the destination buffer
- * @return this array
- * @throws java.nio.BufferOverflowException if the buffer cannot hold the content of this array
- * @see DataBuffer#size()
- */
- NdArray read(DataBuffer dst);
-
- /**
- * Write the content of this N-dimensional array from the source buffer.
- *
- * The size of the buffer must be equal or greater to the {@link #size()} of this
- * array, or an exception is thrown. After the copy, content of the buffer and of the array can be
- * altered independently, without affecting each other.
- *
- * @param src the source buffer
- * @return this array
- * @throws java.nio.BufferUnderflowException if the buffer has not enough remaining data to write
- * into this array
- * @see DataBuffer#size()
- */
- NdArray write(DataBuffer src);
-
- /**
- * Checks equality between n-dimensional arrays.
- *
- * An array is equal to another object if this object is another {@link NdArray} of the
- * same shape, type and the elements are equal and in the same order. For example:
- *
- *
{@code
- * IntNdArray array = NdArrays.ofInts(Shape.of(2, 2))
- * .set(NdArrays.vectorOf(1, 2), 0)
- * .set(NdArrays.vectorOf(3, 4), 1);
- *
- * assertEquals(array, StdArrays.ndCopyOf(new int[][] {{1, 2}, {3, 4}})); // true
- * assertEquals(array, StdArrays.ndCopyOf(new Integer[][] {{1, 2}, {3, 4}})); // true, as Integers are equal to ints
- * assertNotEquals(array, NdArrays.vectorOf(1, 2, 3, 4)); // false, different shapes
- * assertNotEquals(array, StdArrays.ndCopyOf(new int[][] {{3, 4}, {1, 2}})); // false, different order
- * assertNotEquals(array, StdArrays.ndCopyOf(new long[][] {{1L, 2L}, {3L, 4L}})); // false, different types
- * }
- *
- * Note that the computation required to verify equality between two arrays can be expensive
- * in some cases and therefore, it is recommended to not use this method in a critical path
- * where performances matter.
- *
- * @param obj object to compare this array with
- * @return true if this array is equal to the provided object
- */
- @Override
- boolean equals(Object obj);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/NdArraySequence.java b/ndarray/src/main/java/org/tensorflow/ndarray/NdArraySequence.java
deleted file mode 100644
index afb930e278b..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/NdArraySequence.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * =======================================================================
- */
-
-package org.tensorflow.ndarray;
-
-import java.util.function.BiConsumer;
-import org.tensorflow.ndarray.buffer.DataBufferWindow;
-
-/**
- * A sequence of elements of an N-dimensional array.
- *
- *
An {@code NdArraySequence} is used to traverse an {@code NdArray} in a given dimension
- * and visit each of its elements. For example, given a {@code n x m} matrix on the {@code [x, y]} axes,
- * elements are iterated in the following order:
- *
x0y0, x0y1, ..., x0ym-1, x1y0, x1y1, ..., xn-1ym-1
- *
- * @param data type of the array being iterated
- */
-public interface NdArraySequence> extends Iterable {
-
- /**
- * Visit each elements of this iteration and their respective coordinates.
- *
- * Important: the consumer method should not keep a reference to the coordinates
- * as they might be mutable and reused during the iteration to improve performance.
- *
- * @param consumer method to invoke for each elements
- */
- void forEachIndexed(BiConsumer consumer);
-
- /**
- * Returns each element as a new slice.
- *
- * Unlike conventional Java collections, elements of a {@code NdArraySequence} are transient, i.e. new {@code NdArray}
- * instances are allocated for each iteration. To improve performance, the same instance can be recycled to view
- * all elements of this sequence, using a {@link DataBufferWindow}.
- *
- *
In some cases though, it might be preferable to disable such optimizations to ensure that each element returned is a
- * new slice of the original array. For example, if one or more elements visited must live beyond the scope of the sequence
- * iteration, {@code asSlices()} makes sure that all elements returned by the sequence are unique instances.
- *
- *
{@code
- * final List vectors = new ArrayList<>();
- * IntNdArray matrix = NdArrays.ofInts(Shape.of(6, 6));
- * ndArray.elements(0).forEach(e -> vectors::add); // Not safe, as `e` might always be the same recycled instance
- * ndArray.elements(0).asSlices().forEach(e -> vectors::add); // Safe, each `e` is a distinct NdArray instance
- * }
- *
- * @return a sequence that returns each elements iterated as a new slice
- * @see DataBufferWindow
- */
- NdArraySequence asSlices();
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/NdArrays.java b/ndarray/src/main/java/org/tensorflow/ndarray/NdArrays.java
deleted file mode 100644
index 8ad55cae7ed..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/NdArrays.java
+++ /dev/null
@@ -1,495 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.impl.dense.DenseNdArray;
-import org.tensorflow.ndarray.impl.dense.IntDenseNdArray;
-import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
-import org.tensorflow.ndarray.buffer.ByteDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffers;
-import org.tensorflow.ndarray.buffer.DoubleDataBuffer;
-import org.tensorflow.ndarray.buffer.FloatDataBuffer;
-import org.tensorflow.ndarray.buffer.IntDataBuffer;
-import org.tensorflow.ndarray.buffer.LongDataBuffer;
-import org.tensorflow.ndarray.buffer.ShortDataBuffer;
-import org.tensorflow.ndarray.impl.dense.BooleanDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.ByteDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.DoubleDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.FloatDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.LongDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.ShortDenseNdArray;
-
-/**
- * Utility class for instantiating {@link NdArray} objects.
- */
-public final class NdArrays {
-
- // BYTE ARRAYS
-
- /**
- * Creates byte scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new byte scalar
- */
- public static ByteNdArray scalarOf(byte value) {
- return ofBytes(Shape.scalar()).setByte(value);
- }
-
- /**
- * Creates a byte vector (rank 1) initialized with the given values.
- *
- * Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new byte vector
- * @throws IllegalArgumentException if values is null
- */
- public static ByteNdArray vectorOf(byte... values) {
- if (values == null) {
- throw new IllegalArgumentException("Values cannot be null");
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of bytes of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new byte N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static ByteNdArray ofBytes(Shape shape) {
- if (shape == null) {
- throw new IllegalArgumentException("Shape cannot be null");
- }
- return wrap(shape, DataBuffers.ofBytes(shape.size()));
- }
-
- /**
- * Wraps a buffer in a byte N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new byte N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static ByteNdArray wrap(Shape shape, ByteDataBuffer buffer) {
- return ByteDenseNdArray.create(buffer, shape);
- }
-
- // LONG ARRAYS
-
- /**
- * Creates long scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new long scalar
- */
- public static LongNdArray scalarOf(long value) {
- return ofLongs(Shape.scalar()).setLong(value);
- }
-
- /**
- * Creates a long vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new long vector
- * @throws IllegalArgumentException if values is null
- */
- public static LongNdArray vectorOf(long... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of longs of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new long N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static LongNdArray ofLongs(Shape shape) {
- return wrap(shape, DataBuffers.ofLongs(shape.size()));
- }
-
- /**
- * Wraps a buffer in a long N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new long N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static LongNdArray wrap(Shape shape, LongDataBuffer buffer) {
- return LongDenseNdArray.create(buffer, shape);
- }
-
- // INT ARRAYS
-
- /**
- * Creates long scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new long scalar
- */
- public static IntNdArray scalarOf(int value) {
- return ofInts(Shape.scalar()).setInt(value);
- }
-
- /**
- * Creates a int vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new int vector
- * @throws IllegalArgumentException if values is null
- */
- public static IntNdArray vectorOf(int... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of ints of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new int N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static IntNdArray ofInts(Shape shape) {
- return wrap(shape, DataBuffers.ofInts(shape.size()));
- }
-
- /**
- * Wraps a buffer in an int N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new int N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static IntNdArray wrap(Shape shape, IntDataBuffer buffer) {
- return IntDenseNdArray.create(buffer, shape);
- }
-
- // SHORT ARRAYS
-
- /**
- * Creates short scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new short scalar
- */
- public static ShortNdArray scalarOf(short value) {
- return ofShorts(Shape.scalar()).setShort(value);
- }
-
- /**
- * Creates a short vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new short vector
- * @throws IllegalArgumentException if values is null
- */
- public static ShortNdArray vectorOf(short... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of shorts of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new short N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static ShortNdArray ofShorts(Shape shape) {
- return wrap(shape, DataBuffers.ofShorts(shape.size()));
- }
-
- /**
- * Wraps a buffer in a short N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new short N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static ShortNdArray wrap(Shape shape, ShortDataBuffer buffer) {
- return ShortDenseNdArray.create(buffer, shape);
- }
-
- // FLOAT ARRAYS
-
- /**
- * Creates float scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new float scalar
- */
- public static FloatNdArray scalarOf(float value) {
- return ofFloats(Shape.scalar()).setFloat(value);
- }
-
- /**
- * Creates a float vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new float vector
- * @throws IllegalArgumentException if values is null
- */
- public static FloatNdArray vectorOf(float... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of floats of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new float N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static FloatNdArray ofFloats(Shape shape) {
- return wrap(shape, DataBuffers.ofFloats(shape.size()));
- }
-
- /**
- * Wraps a buffer in a float N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new float N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static FloatNdArray wrap(Shape shape, FloatDataBuffer buffer) {
- return FloatDenseNdArray.create(buffer, shape);
- }
-
- // DOUBLE ARRAYS
-
- /**
- * Creates double scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new double scalar
- */
- public static DoubleNdArray scalarOf(double value) {
- return ofDoubles(Shape.scalar()).setDouble(value);
- }
-
- /**
- * Creates a double vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new double vector
- * @throws IllegalArgumentException if values is null
- */
- public static DoubleNdArray vectorOf(double... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of doubles of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new double N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static DoubleNdArray ofDoubles(Shape shape) {
- return wrap(shape, DataBuffers.ofDoubles(shape.size()));
- }
-
- /**
- * Wraps a buffer in a double N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new double N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static DoubleNdArray wrap(Shape shape, DoubleDataBuffer buffer) {
- return DoubleDenseNdArray.create(buffer, shape);
- }
-
- // BOOLEAN ARRAYS
-
- /**
- * Creates boolean scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new boolean scalar
- */
- public static BooleanNdArray scalarOf(boolean value) {
- return ofBooleans(Shape.scalar()).setBoolean(value);
- }
-
- /**
- * Creates a boolean vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new boolean vector
- * @throws IllegalArgumentException if values is null
- */
- public static BooleanNdArray vectorOf(boolean... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of booleans of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new boolean N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static BooleanNdArray ofBooleans(Shape shape) {
- return wrap(shape, DataBuffers.ofBooleans(shape.size()));
- }
-
- /**
- * Wraps a buffer in a boolean N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new boolean N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static BooleanNdArray wrap(Shape shape, BooleanDataBuffer buffer) {
- return BooleanDenseNdArray.create(buffer, shape);
- }
-
- // OBJECT ARRAYS
-
- /**
- * Creates scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @param the data type
- * @return new scalar
- */
- @SuppressWarnings("unchecked")
- public static NdArray scalarOfObject(T value) {
- if (value == null) {
- throw new IllegalArgumentException();
- }
- return ofObjects((Class)value.getClass(), Shape.scalar()).setObject(value);
- }
-
- /**
- * Creates a vector (rank 1) initialized with the given values.
- *
- * Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @param the data type
- * @return new vector
- * @throws IllegalArgumentException if values is null
- */
- @SafeVarargs
- public static NdArray vectorOfObjects(T... values) {
- if (values == null || values.length == 0) {
- throw new IllegalArgumentException("Null or zero length input supplied to vectorOfObjects.");
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of the given shape.
- *
- * All values are initialized to zeros.
- *
- * @param clazz class of the data to be stored in this array
- * @param shape shape of the array
- * @param the data type
- * @return new N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static NdArray ofObjects(Class clazz, Shape shape) {
- return wrap(shape, DataBuffers.ofObjects(clazz, shape.size()));
- }
-
- /**
- * Wraps a buffer in an N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @param the data type
- * @return new N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static NdArray wrap(Shape shape, DataBuffer buffer) {
- return DenseNdArray.wrap(buffer, shape);
- }
-}
-
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/Shaped.java b/ndarray/src/main/java/org/tensorflow/ndarray/Shaped.java
deleted file mode 100644
index fbe19d75623..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/Shaped.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- Copyright 2020 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * Any data container with a given {@link Shape}.
- */
-public interface Shaped {
-
- /**
- * @return the shape of this container
- */
- Shape shape();
-
- /**
- * @return the rank of this container
- */
- default int rank() {
- return shape().numDimensions();
- }
-
- /**
- * Computes and returns the total size of this container, in number of values.
- *
- * For example, given a 3x3x2 matrix, the return value will be 18.
- *
- * @return number of values in this element
- */
- default long size() {
- return shape().size();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java
deleted file mode 100644
index f9335b4d5d2..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray;
-
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.ShortDataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of shorts.
- */
-public interface ShortNdArray extends NdArray {
-
- /**
- * Returns the short value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * ShortNdArray matrix = NdArrays.ofShorts(shape(2, 2)); // matrix rank = 2
- * matrix.getShort(0, 1); // succeeds, returns 0.0f
- * matrix.getShort(0); // throws IllegalRankException
- *
- * ShortNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getShort(); // succeeds, returns 0.0f
- * }
- *
- * @param coordinates coordinates of the scalar to resolve
- * @return value of that scalar
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- short getShort(long... coordinates);
-
- /**
- * Assigns the short value of the scalar found at the given coordinates.
- *
- * To access the scalar element, the number of coordinates provided must be equal to the number
- * of dimensions of this array (i.e. its rank). For example:
- *
{@code
- * ShortNdArray matrix = NdArrays.ofShorts(shape(2, 2)); // matrix rank = 2
- * matrix.setShort(10.0f, 0, 1); // succeeds
- * matrix.setShort(10.0f, 0); // throws IllegalRankException
- *
- * ShortNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setShort(10.0f); // succeeds
- * }
- *
- * @param value value to assign
- * @param coordinates coordinates of the scalar to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
- * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
- */
- ShortNdArray setShort(short value, long... coordinates);
-
- @Override
- ShortNdArray slice(Index... coordinates);
-
- @Override
- ShortNdArray get(long... coordinates);
-
- @Override
- ShortNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Short getObject(long... coordinates) {
- return getShort(coordinates);
- }
-
- @Override
- default ShortNdArray setObject(Short value, long... coordinates) {
- return setShort(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- ShortNdArray copyTo(NdArray dst);
-
- @Override
- ShortNdArray read(DataBuffer dst);
-
- ShortNdArray read(ShortDataBuffer dst);
-
- @Override
- ShortNdArray write(DataBuffer src);
-
- ShortNdArray write(ShortDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/BooleanDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/BooleanDataBuffer.java
deleted file mode 100644
index 73a570d4fe8..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/BooleanDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of booleans.
- */
-public interface BooleanDataBuffer extends DataBuffer {
-
- /**
- * Reads the boolean at the given index.
- *
- * @param index the index from which the float will be read
- * @return the boolean at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- boolean getBoolean(long index);
-
- /**
- * Writes the given boolean into this buffer at the given index.
- *
- * @param value the boolean to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- BooleanDataBuffer setBoolean(boolean value, long index);
-
- /**
- * Bulk get method, using boolean arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default BooleanDataBuffer read(boolean[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using boolean arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- BooleanDataBuffer read(boolean[] dst, int offset, int length);
-
- /**
- * Bulk put method, using boolean arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default BooleanDataBuffer write(boolean[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using boolean arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- BooleanDataBuffer write(boolean[] src, int offset, int length);
-
- @Override
- default Boolean getObject(long index) {
- return getBoolean(index);
- }
-
- @Override
- default BooleanDataBuffer setObject(Boolean value, long index) {
- return setBoolean(value, index);
- }
-
- @Override
- BooleanDataBuffer copyTo(DataBuffer dst, long size);
-
- @Override
- default BooleanDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default BooleanDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- BooleanDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ByteDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ByteDataBuffer.java
deleted file mode 100644
index b1cce441b13..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ByteDataBuffer.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of bytes.
- */
-public interface ByteDataBuffer extends DataBuffer {
-
- /**
- * Reads the byte at the given index.
- *
- * @param index the index from which the float will be read
- * @return the byte at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- byte getByte(long index);
-
- /**
- * Writes the given byte into this buffer at the given index.
- *
- * @param value the byte to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- ByteDataBuffer setByte(byte value, long index);
-
- /**
- * Bulk get method, using byte arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default ByteDataBuffer read(byte[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using byte arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- ByteDataBuffer read(byte[] dst, int offset, int length);
-
- /**
- * Bulk put method, using byte arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default ByteDataBuffer write(byte[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using byte arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- ByteDataBuffer write(byte[] src, int offset, int length);
-
- /**
- * Return this byte buffer as a buffer of ints.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link IntDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- IntDataBuffer asInts();
-
- /**
- * Return this byte buffer as a buffer of shorts.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link ShortDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- ShortDataBuffer asShorts();
-
- /**
- * Return this byte buffer as a buffer of longs.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link LongDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- LongDataBuffer asLongs();
-
- /**
- * Return this byte buffer as a buffer of floats.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link FloatDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- FloatDataBuffer asFloats();
-
- /**
- * Return this byte buffer as a buffer of doubles.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link DoubleDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- DoubleDataBuffer asDoubles();
-
- /**
- * Return this byte buffer as a buffer of booleans.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link BooleanDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- BooleanDataBuffer asBooleans();
-
- @Override
- default Byte getObject(long index) {
- return getByte(index);
- }
-
- @Override
- default ByteDataBuffer setObject(Byte value, long index) {
- return setByte(value, index);
- }
-
- @Override
- ByteDataBuffer copyTo(DataBuffer dst, long size);
-
-
- @Override
- default ByteDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default ByteDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- ByteDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffer.java
deleted file mode 100644
index e62ba87ce6e..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffer.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A container of data of a specific type.
- *
- * Instances of {@code DataBuffer} map native or heap memory segments to a linear view that
- * supports:
- *
- * - 64-bits indexing, allowing to work with buffer larger than 231 bytes
- * - Storage of object of any types and not only primitives
- * - Generic types allows to work directly with boxed types as well, which does not require
- * explicit buffer types as with the standard JDK buffers.
- *
- * It is important to note that there is no guarantee the memory managed by a {@code DataBuffer}
- * is linear, specially when dealing with non-primitive types or large buffers.
- *
- * @param type of data stored in this buffer
- */
-public interface DataBuffer {
-
- /**
- * Size of the buffer, in elements.
- *
- * For exemple, in case of a byte buffer, this value is equal to the number of bytes this buffer
- * can hold. For an integer buffer, it is equal to the number of integers, therefore the size
- * in bytes of this buffer is {@code size() * Integer.BYTES}.
- *
- * @return the buffer size
- */
- long size();
-
- /**
- * Tells whether or not this buffer is backed by an accessible array.
- *
- * @return true if, and only if, this buffer is read-only
- */
- boolean isReadOnly();
-
- /**
- * Reads the value at the given index.
- *
- * Important: Usage of this method should be limited to buffers of non-primitive types or
- * when the data type is not deterministically known by the caller. In any other case, prefer
- * the usage of its primitive variant which will significantly improve performances
- * (e.g. {@code IntDataBuffer.getInt(idx)}
- *
- * @param index the index from which the float will be read
- * @return the value at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- T getObject(long index);
-
- /**
- * Writes the given value into this buffer at the given index.
- *
- * Important: Usage of this method should be limited to buffers of non-primitive types or
- * when the data type is not deterministically known by the caller. In any other case, prefer
- * the usage of its primitive variant which will significantly improve performances
- * (e.g. {@code IntDataBuffer.setInt(idx)}
- *
- * @param value the value to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- DataBuffer setObject(T value, long index);
-
- /**
- * Read the references of the objects in this buffer into the destination array.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default DataBuffer read(T[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Read the references of the objects in this buffer into the destination array.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- DataBuffer read(T[] dst, int offset, int length);
-
- /**
- * Write the references of the objects in the source array into this buffer.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default DataBuffer write(T[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using int arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- DataBuffer write(T[] src, int offset, int length);
-
- /**
- * Write the references of the objects in the source array into this buffer.
- *
- * If there are more values to copy than the destination buffer size, i.e.
- * {@code size > dst.size()}, then no values are transferred and a
- * BufferOverflowException is thrown. On the other hand, if there are more values to copy that
- * the source buffer size, i.e. {@code > src.size()}, then a BufferUnderfloatException is thrown.
- *
- * Otherwise, this method copies {@code n = size} values from this buffer into
- * the destination buffer.
- *
- * @param dst the destination buffer into which values are copied; must not be this buffer
- * @param size number of values to copy to the destination buffer
- * @return this buffer
- * @throws IllegalArgumentException if the destination buffer is this buffer
- * @throws ReadOnlyBufferException if the destination buffer is read-only
- * @throws java.nio.BufferOverflowException if there is not enough space in destination buffer
- * @throws java.nio.BufferUnderflowException if there are not enough values in the source buffer
- */
- DataBuffer copyTo(DataBuffer dst, long size);
-
- /**
- * Creates a new buffer whose content is a shared subsequence of this buffer's content, starting
- * at the given index.
- *
- * The index must not be greater than this buffer size. Changes to this buffer's content will
- * be visible in the new buffer and vice versa. The new buffer will be read-only if, and only if,
- * this buffer is read-only.
- *
- * This call is equivalent to {@link #slice(long, long) slice(index, size() - index)}
- *
- * @param index index of the first value of the new buffer created, must not be greater than
- * {@code size()}
- * @return the new buffer
- * @throws IllegalArgumentException if index do not pass validation checks
- */
- default DataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- /**
- * Creates a new buffer whose content is a shared subsequence of this buffer's content, whose
- * size is set to the given value.
- *
- * The new size must not be greater than this buffer size. Changes to this buffer's
- * content will be visible in the new buffer and vice versa. The new buffer will be read-only if,
- * and only if, this buffer is read-only.
- *
- * This call is equivalent to {@link #slice(long, long) slice(0, size)}
- *
- * @param size size of this new buffer
- * @return the new buffer
- * @throws IllegalArgumentException if index and/or size values do not pass validation checks
- */
- default DataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- /**
- * Creates a new buffer whose content is a shared subsequence of this buffer's content, starting
- * at the given index and of the given size.
- *
- * The index plus the new size must not be greater than this buffer size. Changes to this
- * buffer's content will be visible in the new buffer and vice versa. The new buffer will be
- * read-only if, and only if, this buffer is read-only.
- *
- * @param index index of the first value of the new buffer created
- * @param size size of this new buffer, must not be greater than {@code size()}
- * @return the new buffer
- * @throws IllegalArgumentException if size value do not pass validation checks
- */
- DataBuffer slice(long index, long size);
-
- /**
- * Creates a {@link DataBufferWindow} that provides a partial view of this buffer.
- *
- * The created window has a fixed size and can {@link DataBufferWindow#slide(long) "slide"}
- * along this buffer to provide different views of the data without allocating a new buffer
- * instance, like {@link #offset(long)} does. This improves overall performance when this
- * operation is repeated frequently. For example:
- *
- *
{@code
- * IntDataBuffer bufferA = DataBuffers.ofInts(1024);
- * // ... init buffer data
- * IntDataBuffer bufferB = DataBuffers.ofInts(1, 2, 3, 4);
- *
- * // Return the index of the first occurrence of bufferB in bufferA using a sliding window
- * DataBufferWindow windowA = bufferA.window(4);
- * for (int i = 0; i < bufferA.size() - bufferB.size(); ++i) {
- * if (windowA.slideTo(i).buffer().equals(bufferB)) {
- * return i;
- * }
- * }
- * }
- *
- * The returned object is stateful and is not thread-safe.
- *
- * @param size size of the window
- * @return a new window that starts at the index 0 of this buffer
- * @throws UnsupportedOperationException if this type of buffer does not support buffer windows
- */
- default DataBufferWindow extends DataBuffer> window(long size) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Visits the backing storage of this buffer.
- *
- * The buffer implementation is responsible of passing back a reference to the actual data
- * storage to the provided visitor. The visitor does not have to handle all possible types of
- * data storage and can override only methods for storage it is actually interested in. For any
- * other type of storage, this call will fallback to {@link DataStorageVisitor#fallback()} so the
- * visitor can execute some generic routine if needed.
- *
- * @param visitor visits the data storage of this buffer
- * @param type of value returned by the visitor
- * @return the same value returned by the visitor
- */
- default R accept(DataStorageVisitor visitor) {
- return visitor.fallback();
- }
-
- /**
- * Checks equality between data buffers.
- *
- * A data buffer is equal to another object if this object is another {@link DataBuffer} of the
- * same size, type and the elements are equal and in the same order. For example:
- *
- *
{@code
- * IntDataBuffer buffer = DataBuffers.of(1, 2, 3);
- *
- * assertEquals(buffer, DataBuffers.of(1, 2, 3)); // true
- * assertEquals(buffer, DataBuffers.ofObjects(1, 2, 3)); // true, as Integers are equal to ints
- * assertNotEquals(buffer, DataBuffers.of(1, 2, 3, 0)); // false, different sizes
- * assertNotEquals(buffer, DataBuffers.of(1, 3, 2)); // false, different order
- * assertNotEquals(buffer, DataBuffers.of(1L, 2L, 3L)); // false, different types
- * }
- *
- * Note that the computation required to verify equality between two buffers can be expensive
- * in some cases and therefore, it is recommended to not use this method in a critical path
- * where performances matter.
- *
- * @param obj object to compare this buffer with
- * @return true if this buffer is equal to the provided object
- */
- @Override
- boolean equals(Object obj);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DoubleDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DoubleDataBuffer.java
deleted file mode 100644
index f2db925eb78..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DoubleDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of doubles.
- */
-public interface DoubleDataBuffer extends DataBuffer {
-
- /**
- * Reads the double at the given index.
- *
- * @param index the index from which the float will be read
- * @return the double at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- double getDouble(long index);
-
- /**
- * Writes the given double into this buffer at the given index.
- *
- * @param value the double to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- DoubleDataBuffer setDouble(double value, long index);
-
- /**
- * Bulk get method, using double arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default DoubleDataBuffer read(double[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using double arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- DoubleDataBuffer read(double[] dst, int offset, int length);
-
- /**
- * Bulk put method, using double arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default DoubleDataBuffer write(double[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using double arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- DoubleDataBuffer write(double[] src, int offset, int length);
-
- @Override
- default Double getObject(long index) {
- return getDouble(index);
- }
-
- @Override
- default DoubleDataBuffer setObject(Double value, long index) {
- return setDouble(value, index);
- }
-
- @Override
- DoubleDataBuffer copyTo(DataBuffer dst, long size);
-
- @Override
- default DoubleDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default DoubleDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- DoubleDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/FloatDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/FloatDataBuffer.java
deleted file mode 100644
index 4961c1b3445..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/FloatDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of floats.
- */
-public interface FloatDataBuffer extends DataBuffer {
-
- /**
- * Reads the float at the given index.
- *
- * @param index the index from which the float will be read
- * @return the float at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- float getFloat(long index);
-
- /**
- * Writes the given float into this buffer at the given index.
- *
- * @param value the float to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- FloatDataBuffer setFloat(float value, long index);
-
- /**
- * Bulk get method, using float arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default FloatDataBuffer read(float[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using float arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- FloatDataBuffer read(float[] dst, int offset, int length);
-
- /**
- * Bulk put method, using float arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default FloatDataBuffer write(float[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using float arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- FloatDataBuffer write(float[] src, int offset, int length);
-
- @Override
- default Float getObject(long index) {
- return getFloat(index);
- }
-
- @Override
- default FloatDataBuffer setObject(Float value, long index) {
- return setFloat(value, index);
- }
-
- @Override
- FloatDataBuffer copyTo(DataBuffer dst, long size);
-
- @Override
- default FloatDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default FloatDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- FloatDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/IntDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/IntDataBuffer.java
deleted file mode 100644
index 2d660756e09..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/IntDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of ints.
- */
-public interface IntDataBuffer extends DataBuffer {
-
- /**
- * Reads the int at the given index.
- *
- * @param index the index from which the float will be read
- * @return the int at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- int getInt(long index);
-
- /**
- * Writes the given int into this buffer at the given index.
- *
- * @param value the int to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- IntDataBuffer setInt(int value, long index);
-
- /**
- * Bulk get method, using int arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default IntDataBuffer read(int[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using int arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- IntDataBuffer read(int[] dst, int offset, int length);
-
- /**
- * Bulk put method, using int arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default IntDataBuffer write(int[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using int arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- IntDataBuffer write(int[] src, int offset, int length);
-
- @Override
- default Integer getObject(long index) {
- return getInt(index);
- }
-
- @Override
- default IntDataBuffer setObject(Integer value, long index) {
- return setInt(value, index);
- }
-
- @Override
- IntDataBuffer copyTo(DataBuffer dst, long size);
-
- @Override
- default IntDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default IntDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- IntDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/LongDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/LongDataBuffer.java
deleted file mode 100644
index f88ae4a80b4..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/LongDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of longs.
- */
-public interface LongDataBuffer extends DataBuffer {
-
- /**
- * Reads the long at the given index.
- *
- * @param index the index from which the float will be read
- * @return the long at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- long getLong(long index);
-
- /**
- * Writes the given long into this buffer at the given index.
- *
- * @param value the long to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- LongDataBuffer setLong(long value, long index);
-
- /**
- * Bulk get method, using long arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default LongDataBuffer read(long[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using long arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- LongDataBuffer read(long[] dst, int offset, int length);
-
- /**
- * Bulk put method, using long arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default LongDataBuffer write(long[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using long arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- LongDataBuffer write(long[] src, int offset, int length);
-
- @Override
- default Long getObject(long index) {
- return getLong(index);
- }
-
- @Override
- default LongDataBuffer setObject(Long value, long index) {
- return setLong(value, index);
- }
-
- @Override
- LongDataBuffer copyTo(DataBuffer dst, long size);
-
- @Override
- default LongDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default LongDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- LongDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ShortDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ShortDataBuffer.java
deleted file mode 100644
index 290e2d57619..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ShortDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of shorts.
- */
-public interface ShortDataBuffer extends DataBuffer {
-
- /**
- * Reads the short at the given index.
- *
- * @param index the index from which the float will be read
- * @return the short at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- short getShort(long index);
-
- /**
- * Writes the given short into this buffer at the given index.
- *
- * @param value the short to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- ShortDataBuffer setShort(short value, long index);
-
- /**
- * Bulk get method, using short arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default ShortDataBuffer read(short[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using short arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- ShortDataBuffer read(short[] dst, int offset, int length);
-
- /**
- * Bulk put method, using short arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default ShortDataBuffer write(short[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using short arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- ShortDataBuffer write(short[] src, int offset, int length);
-
- @Override
- default Short getObject(long index) {
- return getShort(index);
- }
-
- @Override
- default ShortDataBuffer setObject(Short value, long index) {
- return setShort(value, index);
- }
-
- @Override
- ShortDataBuffer copyTo(DataBuffer dst, long size);
-
- @Override
- default ShortDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default ShortDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- ShortDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/layout/ByteDataLayout.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/layout/ByteDataLayout.java
deleted file mode 100644
index e4d4bf9c8cf..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/layout/ByteDataLayout.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.buffer.layout;
-
-import org.tensorflow.ndarray.buffer.ByteDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.impl.buffer.adapter.DataBufferAdapterFactory;
-
-/**
- * A {@link DataLayout} that converts data stored in a buffer to bytes.
- *
- * @param type of buffer this layout can be applied to
- * @see DataLayout
- */
-public interface ByteDataLayout> extends DataLayout {
-
- @Override
- default ByteDataBuffer applyTo(S buffer) {
- return DataBufferAdapterFactory.create(buffer, this);
- }
-
- /**
- * Writes a byte into the buffer at the given index after converting it to the buffer type.
- *
- * @param buffer the buffer to write to
- * @param value the byte to convert and write
- * @param index index in the buffer where the converted value should be written
- * @see #writeObject(DataBuffer, Byte, long)
- */
- void writeByte(S buffer, byte value, long index);
-
- /**
- * Reads {@code n = scale()} values from the buffer at the given index and return them as a byte.
- *
- * @param buffer the buffer to read from
- * @param index position of the buffer to read in the buffer
- * @return the byte value
- * @see #readObject(DataBuffer, long)
- */
- byte readByte(S buffer, long index);
-
- @Override
- default void writeObject(S buffer, Byte value, long index) {
- writeByte(buffer, value, index);
- }
-
- @Override
- default Byte readObject(S buffer, long index) {
- return readByte(buffer, index);
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/AbstractNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/AbstractNdArray.java
deleted file mode 100644
index 690dedc2042..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/AbstractNdArray.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.impl;
-
-import java.util.Iterator;
-import org.tensorflow.ndarray.NdArray;
-import org.tensorflow.ndarray.NdArraySequence;
-import org.tensorflow.ndarray.Shape;
-import org.tensorflow.ndarray.impl.dimension.DimensionalSpace;
-
-@SuppressWarnings("unchecked")
-public abstract class AbstractNdArray> implements NdArray {
-
- public abstract U slice(long position, DimensionalSpace dimensions);
-
- public DimensionalSpace dimensions() {
- return dimensions;
- }
-
- @Override
- public Shape shape() {
- return dimensions.shape();
- }
-
- @Override
- public NdArraySequence scalars() {
- // negative if this array is a scalar, should be handled in `elements(dimIdx)`
- return (NdArraySequence)elements(shape().numDimensions() - 1);
- }
-
- @Override
- public int hashCode() {
- return slowHashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof NdArray)) {
- return false;
- }
- return slowEquals((NdArray>)obj);
- }
-
- protected AbstractNdArray(DimensionalSpace dimensions) {
- this.dimensions = dimensions;
- }
-
- protected void slowCopyTo(NdArray array) {
- scalars().forEachIndexed((coords, e) -> array.setObject(e.getObject(), coords));
- }
-
- protected int slowHashCode() {
- final int prime = 31;
- int result = 1;
- for (NdArray scalar : scalars()) {
- result = prime * result + scalar.getObject().hashCode();
- }
- result = prime * result + shape().hashCode();
- return result;
- }
-
- protected boolean slowEquals(NdArray> array) {
- if (!shape().equals(array.shape())) { // this guarantees also that we have the same number of scalar values
- return false;
- }
- for (Iterator extends NdArray>> thisIter = scalars().iterator(), otherIter = array.scalars().iterator(); thisIter.hasNext();) {
- if (!thisIter.next().getObject().equals(otherIter.next().getObject())) {
- return false;
- }
- }
- return true;
- }
-
- protected final DimensionalSpace dimensions;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/Validator.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/Validator.java
deleted file mode 100644
index 285d09966de..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/Validator.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.impl;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import org.tensorflow.ndarray.NdArray;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-
-public class Validator {
-
- public static void copyToNdArrayArgs(NdArray> ndArray, NdArray> otherNdArray) {
- if (!ndArray.shape().equals(otherNdArray.shape())) {
- throw new IllegalArgumentException("Can only copy to arrays of the same shape (" +
- ndArray.shape() + " != " + otherNdArray.shape() + ")");
- }
- }
-
- public static void readToBufferArgs(NdArray> ndArray, DataBuffer> dst) {
- if (dst.size() < ndArray.size()) {
- throw new BufferOverflowException();
- }
- }
-
- public static void writeFromBufferArgs(NdArray> ndArray, DataBuffer> src) {
- if (src.size() < ndArray.size()) {
- throw new BufferUnderflowException();
- }
- }
-
- private static void copyArrayArgs(int arrayLength, int arrayOffset) {
- if (arrayOffset < 0) {
- throw new IndexOutOfBoundsException("Offset must be non-negative");
- }
- if (arrayOffset > arrayLength) {
- throw new IndexOutOfBoundsException("Offset must be no larger than array length");
- }
- }
-
- protected Validator() {}
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/AbstractDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/AbstractDataBuffer.java
deleted file mode 100644
index e5103a2c17a..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/AbstractDataBuffer.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.impl.buffer;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-
-public abstract class AbstractDataBuffer implements DataBuffer {
-
- @Override
- public DataBuffer read(T[] dst, int offset, int length) {
- Validator.readArgs(this, dst.length, offset, length);
- for (int i = 0; i < length; ++i) {
- dst[i + offset] = getObject(i);
- }
- return this;
- }
-
- @Override
- public DataBuffer write(T[] src, int offset, int length) {
- Validator.writeArgs(this, src.length, offset, length);
- for (int i = 0; i < length; ++i) {
- setObject(src[i + offset], i);
- }
- return this;
- }
-
- @Override
- public DataBuffer copyTo(DataBuffer dst, long size) {
- return slowCopyTo(dst, size);
- }
-
- @Override
- public int hashCode() {
- // This hash code computation is generic to all types of data buffers and accurate but not optimized
- // for performances, it needs to be improved if there is a present use case for such hash codes.
- return slowHashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof DataBuffer)) {
- return false;
- }
- return slowEquals((DataBuffer>)obj);
- }
-
- @SuppressWarnings("unchecked")
- protected > U slowCopyTo(DataBuffer dst, long size) {
- Validator.copyToArgs(this, dst, size);
- for (long idx = 0L; idx < size; ++idx) {
- dst.setObject(getObject(idx), idx);
- }
- return (U)this;
- }
-
- protected int slowHashCode() {
- final int prime = 31;
- int result = 1;
-
- // First check from the first non-null element if we are dealing with a buffer of arrays
- long idx = 0L;
- for (; idx < size(); ++idx) {
- T o = getObject(idx);
- if (o != null) {
- if (o.getClass().isArray()) {
- result = prime * result + arrayHashCode(idx, o.getClass()); // compute hash codes based on array elements
- return result;
- }
- result = prime * result + o.hashCode();
- break; // continue hash code computation without array type check
- }
- result = prime * result;
- }
- while (++idx < size()) {
- result = prime * result + Objects.hashCode(getObject(idx));
- }
- return result;
- }
-
- protected boolean slowEquals(DataBuffer> other) {
- if (other.size() != size()) {
- return false;
- }
- long idx = 0L;
- for (; idx < size(); ++idx) {
- Object thisObject = getObject(idx);
- if (thisObject != null) {
- if (thisObject.getClass().isArray()) {
- return arrayEquals(idx, thisObject.getClass(), other);
- }
- if (!Objects.equals(other.getObject(idx), thisObject)) {
- return false;
- }
- break; // continue equality comparison without array type check
- }
- if (other.getObject(idx) != null) {
- return false;
- }
- }
- while (++idx < size()) {
- if (!Objects.equals(other.getObject(idx), getObject(idx))) {
- return false;
- }
- }
- return true;
- }
-
- private int arrayHashCode(long startIdx, Class> arrayClass) {
- ArrayHashCoder hashCoder = ARRAY_HASH_CODERS.getOrDefault(arrayClass, DEFAULT_ARRAY_HASH_CODER);
- final int prime = 31;
- int result = 1;
- for (long idx = startIdx; idx < size(); ++idx) {
- result = prime * result + hashCoder.hashCode(this, idx);
- }
- return result;
- }
-
- private boolean arrayEquals(long startIdx, Class> arrayClass, DataBuffer> other) {
- ArrayComparator comparator = ARRAY_COMPARATORS.getOrDefault(arrayClass, DEFAULT_ARRAY_COMPARATOR);
- for (long idx = startIdx; idx < size(); ++idx) {
- if (!comparator.equals(this, other, idx)) {
- return false;
- }
- }
- return true;
- }
-
- @FunctionalInterface
- private static interface ArrayHashCoder {
- int hashCode(DataBuffer> buffer, long index);
- }
- private static final Map, ArrayHashCoder> ARRAY_HASH_CODERS = new HashMap<>();
- private static final ArrayHashCoder DEFAULT_ARRAY_HASH_CODER;
-
- @FunctionalInterface
- private static interface ArrayComparator {
- boolean equals(DataBuffer> buffer, DataBuffer> otherBuffer, long index);
- }
- private static final Map, ArrayComparator> ARRAY_COMPARATORS = new HashMap<>();
- private static final ArrayComparator DEFAULT_ARRAY_COMPARATOR;
-
- static {
- ARRAY_HASH_CODERS.put(byte[].class, (b, idx) -> Arrays.hashCode((byte[])b.getObject(idx)));
- ARRAY_HASH_CODERS.put(int[].class, (b, idx) -> Arrays.hashCode((int[])b.getObject(idx)));
- ARRAY_HASH_CODERS.put(short[].class, (b, idx) -> Arrays.hashCode((short[])b.getObject(idx)));
- ARRAY_HASH_CODERS.put(long[].class, (b, idx) -> Arrays.hashCode((long[])b.getObject(idx)));
- ARRAY_HASH_CODERS.put(float[].class, (b, idx) -> Arrays.hashCode((float[])b.getObject(idx)));
- ARRAY_HASH_CODERS.put(double[].class, (b, idx) -> Arrays.hashCode((double[])b.getObject(idx)));
- ARRAY_HASH_CODERS.put(boolean[].class, (b, idx) -> Arrays.hashCode((boolean[])b.getObject(idx)));
- DEFAULT_ARRAY_HASH_CODER = (b, idx) -> Arrays.deepHashCode((Object[])b.getObject(idx));
-
- ARRAY_COMPARATORS.put(byte[].class, (b1, b2, idx) -> Arrays.equals((byte[])b1.getObject(idx), (byte[])b2.getObject(idx)));
- ARRAY_COMPARATORS.put(int[].class, (b1, b2, idx) -> Arrays.equals((int[])b1.getObject(idx), (int[])b2.getObject(idx)));
- ARRAY_COMPARATORS.put(short[].class, (b1, b2, idx) -> Arrays.equals((short[])b1.getObject(idx), (short[])b2.getObject(idx)));
- ARRAY_COMPARATORS.put(long[].class, (b1, b2, idx) -> Arrays.equals((long[])b1.getObject(idx), (long[])b2.getObject(idx)));
- ARRAY_COMPARATORS.put(float[].class, (b1, b2, idx) -> Arrays.equals((float[])b1.getObject(idx), (float[])b2.getObject(idx)));
- ARRAY_COMPARATORS.put(double[].class, (b1, b2, idx) -> Arrays.equals((double[])b1.getObject(idx), (double[])b2.getObject(idx)));
- ARRAY_COMPARATORS.put(boolean[].class, (b1, b2, idx) -> Arrays.equals((boolean[])b1.getObject(idx), (boolean[])b2.getObject(idx)));
- DEFAULT_ARRAY_COMPARATOR = (b1, b2, idx) -> Arrays.deepEquals((Object[])b1.getObject(idx), (Object[])b2.getObject(idx));
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/Validator.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/Validator.java
deleted file mode 100644
index 8f18e620b90..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/Validator.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.impl.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-
-public class Validator {
-
- public static void createArgs(long size, long maxSize) {
- if (size < 0) {
- throw new IllegalArgumentException("Size must be non-negative");
- }
- if (size > maxSize) {
- throw new IllegalArgumentException("Buffer size must be no greater than maximum size allowed (" + maxSize + ")");
- }
- }
-
- public static void getArgs(DataBuffer buffer, long index) {
- if (index < 0) {
- throw new IndexOutOfBoundsException("Index must be non-negative");
- }
- if (index >= buffer.size()) {
- throw new IndexOutOfBoundsException("Index must be smaller than the buffer size");
- }
- }
-
- public static void setArgs(DataBuffer buffer, long index) {
- if (index < 0) {
- throw new IndexOutOfBoundsException("Index must be non-negative");
- }
- if (index >= buffer.size()) {
- throw new IndexOutOfBoundsException("Index must be smaller than the buffer size");
- }
- if (buffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- }
-
- public static void copyToArgs(DataBuffer src, DataBuffer dst, long size) {
- if (dst == src) {
- throw new IllegalArgumentException("Source cannot be the same buffer as destination");
- }
- if (size > dst.size()) {
- throw new BufferOverflowException();
- }
- if (size > src.size()) {
- throw new BufferUnderflowException();
- }
- if (dst.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- }
-
- public static void readArgs(DataBuffer buffer, int arrayLength, int offset, int length) {
- if (length > buffer.size()) {
- throw new BufferUnderflowException();
- }
- arrayArgs(arrayLength, offset, length);
- }
-
- public static void writeArgs(DataBuffer buffer, int arrayLength, int offset, int length) {
- if (length > buffer.size()) {
- throw new BufferOverflowException();
- }
- if (buffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- arrayArgs(arrayLength, offset, length);
- }
-
- public static void offsetArgs(DataBuffer buffer, long index) {
- if (index < 0) {
- throw new IllegalArgumentException("Index must be non-negative");
- }
- if (index > buffer.size()) {
- throw new IllegalArgumentException("Index must not exceed buffer size");
- }
- }
-
- public static void narrowArgs(DataBuffer buffer, long size) {
- if (size < 0) {
- throw new IllegalArgumentException("Size must be non-negative");
- }
- if (size > buffer.size()) {
- throw new IllegalArgumentException("Cannot narrow a buffer of size " + buffer.size() + " to " + size);
- }
- }
-
- public static void sliceArgs(DataBuffer buffer, long index, long size) {
- if (index < 0) {
- throw new IllegalArgumentException("Index must be non-negative");
- }
- if (size < 0) {
- throw new IllegalArgumentException("Size must be non-negative");
- }
- if (index + size > buffer.size()) {
- throw new IllegalArgumentException("Buffer view must not exceed original buffer limits");
- }
- }
-
- private static void arrayArgs(int arrayLength, int offset, int length) {
- if (offset < 0) {
- throw new IndexOutOfBoundsException("Offset must be non-negative");
- }
- if (offset > arrayLength) {
- throw new IndexOutOfBoundsException("Offset must be no larger than array length");
- }
- if (length < 0) {
- throw new IndexOutOfBoundsException("Length must be non-negative");
- }
- if (length > arrayLength - offset) {
- throw new IndexOutOfBoundsException("Length must be no larger than array length minus the offset");
- }
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/layout/Float16Layout.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/layout/Float16Layout.java
deleted file mode 100644
index b19744bbd13..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/layout/Float16Layout.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2020 The TensorFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * =======================================================================
- */
-
-package org.tensorflow.ndarray.impl.buffer.layout;
-
-import org.tensorflow.ndarray.buffer.ShortDataBuffer;
-import org.tensorflow.ndarray.buffer.layout.FloatDataLayout;
-
-/**
- * Data layout that converts 32-bit floats from/to 16-bit, accordingly to the IEEE-754 half-precision
- * floating point specification.
- */
-public final class Float16Layout implements FloatDataLayout {
-
- @Override
- public void writeFloat(ShortDataBuffer buffer, float value, long index) {
- buffer.setShort(float32to16(value), index);
- }
-
- @Override
- public float readFloat(ShortDataBuffer buffer, long index) {
- return float16to32(buffer.getShort(index));
- }
-
- //
- // FLOAT 32-bit to/from 16-bit conversions
- //
- // The following conversion algorithms are issued from the C++ implementation found in the
- // Eigen library used by TensorFlow native library.
- // See https://eigen.tuxfamily.org/dox-devel/Half_8h_source.html for more details.
- //
-
- // VisibleForTesting
- static short float32to16(float f32) {
- int i16;
- int i32 = Float.floatToIntBits(f32);
- short sign16 = (short) ((i32 >>> 16) & 0x8000);
- i32 &= 0x7FFFFFFF; // remove sign
-
- if (i32 >= (E32BIAS + E16MAX + 1) << E32SHIFT) {
- // float32 value is higher than float16 max value (max16 -> 2^15 * 2 -> 2^16)
- // - if float32 value is higher than infinite (i.e. s32 > 0), then it is NaN and should also
- // be NaN in float16 (0x7e00)
- // - else, float16 value is forced to infinite (0x7c00)
- i16 = i32 > E32MASK ? 0x7E00 : 0x7C00;
-
- } else if (i32 < (E32BIAS + E16MIN) << E32SHIFT){
- // float32 abs value is smaller than float16 min abs value (min16 = 2^-14), could also be 0
- // - apply magic number to align significand 10 bits at the bottom on the float and subtract bias
- i16 = Float.floatToIntBits(Float.intBitsToFloat(i32) + MAGIC_32_16_FLOAT) - MAGIC_32_16;
-
- } else {
- // float32 value can be rounded up to a normalized float16 value (i.e. exp32 = [113(-14), 142(15)])
- // - rebase exponent to float16
- // - round up significand to the 13nd bit if s16 is even, on the 12nd bit if it is odd
- int round = 0xFFF + ((i32 >>> 13) & 0x1);
- i16 = (i32 + ((E16BIAS - E32BIAS) << E32SHIFT) + round) >>> 13;
- }
- return (short)(i16 | sign16);
- }
-
- // Visible for testing
- static float float16to32(short i16) {
- int i32 = (i16 & 0x7FFF) << (S32BITS - S16BITS); // remove sign and align in float32
- i32 += (E32BIAS - E16BIAS) << E32SHIFT; // rebase exponent to float32
-
- // Handle float16 exponent special cases
- switch (i16 & E16MASK) {
- case E16MASK:
- // float16 value is infinite or NaN
- // - adjust float32 exponent one more time
- i32 += (E32BIAS - E16BIAS) << E32SHIFT;
- break;
- case 0x0:
- // float16 value is zero or subnormal
- // - adjust float32 exponent
- // - renormalize using magic number
- i32 = Float.floatToIntBits(Float.intBitsToFloat(i32 + (1 << E32SHIFT)) - MAGIC_16_32_FLOAT);
- break;
- default:
- break;
- }
- return Float.intBitsToFloat(i32 | ((i16 & 0x8000) << 16)); // reapply sign
- }
-
- // float32 format
- private static final int E32SHIFT = 23; // position of the exponent in float32
- private static final int E32MASK = 0xFF << E32SHIFT; // mask for float32 exponent (== Infinity)
- private static final int E32BIAS = 127; // exponent bias for float32
- private static final int S32BITS = 23; // number of bits in float32 significand
-
- // float16 format
- private static final int E16SHIFT = 10; // position of the exponent in float16
- private static final int E16MASK = 0x1F << E16SHIFT; // mask for float16 exponent (== Infinity)
- private static final int E16BIAS = 15; // exponent bias for float16
- private static final int E16MAX = 15; // max value for float16 exponent
- private static final int E16MIN = -14; // min value for float16 exponent
- private static final int S16BITS = 10; // number of bits in float16 significand
-
- // magic numbers used when converting denormalized values
- private static final int MAGIC_32_16 = ((E32BIAS - E16BIAS) + (S32BITS - S16BITS) + 1) << E32SHIFT;
- private static final float MAGIC_32_16_FLOAT = Float.intBitsToFloat(MAGIC_32_16);
- private static final int MAGIC_16_32 = (E32BIAS - E16BIAS + 1) << E32SHIFT;
- private static final float MAGIC_16_32_FLOAT = Float.intBitsToFloat(MAGIC_16_32);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/ArrayDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/ArrayDataBuffer.java
deleted file mode 100644
index 676e291357a..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/ArrayDataBuffer.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.impl.buffer.misc;
-
-import java.util.Arrays;
-import org.tensorflow.ndarray.impl.buffer.AbstractDataBuffer;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataStorageVisitor;
-
-class ArrayDataBuffer extends AbstractDataBuffer {
-
- @Override
- public long size() {
- return length;
- }
-
- @Override
- public boolean isReadOnly() {
- return readOnly;
- }
-
- @Override
- public T getObject(long index) {
- Validator.getArgs(this, index);
- return values[(int)index + offset];
- }
-
- @Override
- public DataBuffer setObject(T value, long index) {
- Validator.setArgs(this, index);
- values[(int)index + offset] = value;
- return this;
- }
-
- @Override
- public DataBuffer copyTo(DataBuffer dst, long size) {
- Validator.copyToArgs(this, dst, size);
- return dst.accept(new DataStorageVisitor>() {
-
- @Override
- public DataBuffer visit(Object[] array, int arrayOffset, int arrayLength) {
- System.arraycopy(values, offset, array, arrayOffset, (int)size);
- return ArrayDataBuffer.this;
- }
-
- @Override
- public DataBuffer fallback() {
- for (int idx = 0; idx < size; ++idx) {
- dst.setObject(values[idx + offset], idx);
- }
- return ArrayDataBuffer.this;
- }
- });
- }
-
- @Override
- public DataBuffer slice(long index, long size) {
- Validator.sliceArgs(this, index, size);
- return new ArrayDataBuffer<>(values, readOnly, offset + (int)index, (int)size);
- }
-
- @Override
- public R accept(DataStorageVisitor visitor) {
- return visitor.visit(values, offset, length);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof DataBuffer)) {
- return false;
- }
- DataBuffer> other = (DataBuffer>)obj;
- if (size() != other.size()) {
- return false;
- }
- return other.accept(new DataStorageVisitor() {
-
- @Override
- public Boolean visit(Object[] array, int arrayOffset, int arrayLength) {
- if (offset == 0 && values.length == length && arrayOffset == 0 && array.length == arrayLength) {
- return Arrays.deepEquals(array, values);
- }
- return slowEquals(other);
- }
-
- @Override
- public Boolean fallback() {
- return slowEquals(other);
- }
- });
- }
-
- ArrayDataBuffer(T[] values, boolean readOnly) {
- this(values, readOnly, 0, values.length);
- }
-
- private ArrayDataBuffer(T[] values, boolean readOnly, int offset, int length) {
- this.values = values;
- this.readOnly = readOnly;
- this.offset = offset;
- this.length = length;
- }
-
- private final T[] values;
- private final boolean readOnly;
- private final int offset;
- private final int length;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/BitSetDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/BitSetDataBuffer.java
deleted file mode 100644
index 5b5ec15294b..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/BitSetDataBuffer.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * =======================================================================
- */
-
-package org.tensorflow.ndarray.impl.buffer.misc;
-
-import java.util.BitSet;
-import org.tensorflow.ndarray.impl.buffer.AbstractDataBuffer;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataStorageVisitor;
-
-class BitSetDataBuffer extends AbstractDataBuffer implements BooleanDataBuffer {
-
- @Override
- public long size() {
- return numBits;
- }
-
- @Override
- public boolean isReadOnly() {
- return readOnly;
- }
-
- @Override
- public boolean getBoolean(long index) {
- Validator.getArgs(this, index);
- return bitSet.get((int)index + offset);
- }
-
- @Override
- public BooleanDataBuffer setBoolean(boolean value, long index) {
- Validator.setArgs(this, index);
- bitSet.set((int)index + offset, value);
- return this;
- }
-
- @Override
- public BooleanDataBuffer read(boolean[] dst, int offset, int length) {
- Validator.readArgs(this, dst.length, offset, length);
- for (int i = this.offset, j = offset; i < this.offset + length; ++i, ++j) {
- dst[j] = bitSet.get(i);
- }
- return this;
- }
-
- @Override
- public BooleanDataBuffer write(boolean[] src, int offset, int length) {
- Validator.readArgs(this, src.length, offset, length);
- for (int i = this.offset, j = offset; i < this.offset + length; ++i, ++j) {
- bitSet.set(i, src[j]);
- }
- return this;
- }
-
- @Override
- public BooleanDataBuffer copyTo(DataBuffer dst, long size) {
- Validator.copyToArgs(this, dst, size);
- return dst.accept(new DataStorageVisitor() {
-
- @Override
- public BooleanDataBuffer visit(boolean[] array, int arrayOffset, int arrayLength) {
- for (int idx = 0; idx < size; ++idx) {
- array[idx + arrayOffset] = bitSet.get(idx + offset);
- }
- return BitSetDataBuffer.this;
- }
-
- @Override
- public BooleanDataBuffer visit(BitSet dstBitSet, int dstOffset, long numBits) {
- for (int idx = 0; idx < size; ++idx) {
- dstBitSet.set(idx + dstOffset, bitSet.get(idx + offset));
- }
- return BitSetDataBuffer.this;
- }
-
- @Override
- public BooleanDataBuffer fallback() {
- if (dst instanceof BooleanDataBuffer) {
- BooleanDataBuffer booleanDst = (BooleanDataBuffer)dst;
- for (int idx = 0; idx < size; ++idx) {
- booleanDst.setBoolean(bitSet.get(idx + offset), idx);
- }
- } else {
- for (int idx = 0; idx < size; ++idx) {
- dst.setObject(bitSet.get(idx + offset), idx);
- }
- }
- return BitSetDataBuffer.this;
- }
- });
- }
-
- @Override
- public BooleanDataBuffer slice(long index, long size) {
- Validator.sliceArgs(this, index, size);
- return new BitSetDataBuffer(bitSet, size, readOnly, offset + (int)index);
- }
-
- @Override
- public R accept(DataStorageVisitor visitor) {
- return visitor.visit(bitSet, offset, numBits);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof BooleanDataBuffer)) {
- return super.equals(obj);
- }
- BooleanDataBuffer other = (BooleanDataBuffer)obj;
- if (size() != other.size()) {
- return false;
- }
- return other.accept(new DataStorageVisitor() {
-
- @Override
- public Boolean visit(boolean[] array, int arrayOffset, int length) {
- for (int idx = 0; idx < size(); ++idx) {
- if (array[idx + arrayOffset] != bitSet.get(idx + offset)) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public Boolean visit(BitSet otherBitSet, int otherOffset, long otherNumBits) {
- if (offset == 0 && otherOffset == 0 && numBits == otherNumBits) {
- return bitSet.equals(otherBitSet);
- }
- for (int idx = 0; idx < size(); ++idx) {
- if (otherBitSet.get(idx + otherOffset) != bitSet.get(idx + offset)) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public Boolean fallback() {
- for (int idx = 0; idx < size(); ++idx) {
- if (other.getBoolean(idx) != bitSet.get(idx + offset)) {
- return false;
- }
- }
- return true;
- }
- });
- }
-
- BitSetDataBuffer(BitSet bitSet, long numBits, boolean readOnly) {
- this(bitSet, numBits, readOnly, 0);
- }
-
- private BitSetDataBuffer(BitSet bitSet, long numBits, boolean readOnly, int offset) {
- this.bitSet = bitSet;
- this.numBits = numBits;
- this.readOnly = readOnly;
- this.offset = offset;
- }
-
- private final BitSet bitSet;
- private final long numBits;
- private final boolean readOnly;
- private final int offset;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/BooleanArrayDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/BooleanArrayDataBuffer.java
deleted file mode 100644
index f8d033519ec..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/misc/BooleanArrayDataBuffer.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-package org.tensorflow.ndarray.impl.buffer.misc;
-
-import java.util.Arrays;
-import java.util.BitSet;
-import org.tensorflow.ndarray.impl.buffer.AbstractDataBuffer;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataStorageVisitor;
-
-class BooleanArrayDataBuffer extends AbstractDataBuffer implements
- BooleanDataBuffer {
-
- @Override
- public long size() {
- return length;
- }
-
- @Override
- public boolean isReadOnly() {
- return readOnly;
- }
-
- @Override
- public boolean getBoolean(long index) {
- Validator.getArgs(this, index);
- return values[(int)index + offset];
- }
-
- @Override
- public BooleanDataBuffer setBoolean(boolean value, long index) {
- Validator.setArgs(this, index);
- values[(int)index + offset] = value;
- return this;
- }
-
- @Override
- public BooleanDataBuffer read(boolean[] dst, int offset, int length) {
- System.arraycopy(values, this.offset, dst, offset, length);
- return this;
- }
-
- @Override
- public BooleanDataBuffer write(boolean[] src, int offset, int length) {
- System.arraycopy(src, offset, values, this.offset, length);
- return null;
- }
-
- @Override
- public BooleanDataBuffer copyTo(DataBuffer dst, long size) {
- Validator.copyToArgs(this, dst, size);
- return dst.accept(new DataStorageVisitor() {
-
- @Override
- public BooleanDataBuffer visit(boolean[] array, int arrayOffset, int arrayLength) {
- System.arraycopy(values, offset, array, arrayOffset, (int)size);
- return BooleanArrayDataBuffer.this;
- }
-
- @Override
- public BooleanDataBuffer visit(BitSet bitSet, int bitSetOffset, long numBits) {
- for (int idx = 0; idx < size; ++idx) {
- bitSet.set(idx + bitSetOffset, values[idx + offset]);
- }
- return BooleanArrayDataBuffer.this;
- }
-
- @Override
- public BooleanDataBuffer fallback() {
- if (dst instanceof BooleanDataBuffer) {
- BooleanDataBuffer booleanDst = (BooleanDataBuffer)dst;
- for (int idx = 0; idx < size; ++idx) {
- booleanDst.setBoolean(values[idx + offset], idx);
- }
- } else {
- for (int idx = 0; idx < size; ++idx) {
- dst.setObject(values[idx + offset], idx);
- }
- }
- return BooleanArrayDataBuffer.this;
- }
- });
- }
-
- @Override
- public BooleanDataBuffer slice(long index, long size) {
- Validator.sliceArgs(this, index, size);
- return new BooleanArrayDataBuffer(values, readOnly, offset + (int)index, (int)size);
- }
-
- @Override
- public R accept(DataStorageVisitor visitor) {
- return visitor.visit(values, offset, length);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof BooleanDataBuffer)) {
- return super.equals(obj);
- }
- BooleanDataBuffer other = (BooleanDataBuffer)obj;
- if (size() != other.size()) {
- return false;
- }
- return other.accept(new DataStorageVisitor() {
-
- @Override
- public Boolean visit(boolean[] array, int arrayOffset, int arrayLength) {
- if (offset == 0 && values.length == length && arrayOffset == 0 && array.length == arrayLength) {
- return Arrays.equals(array, values);
- }
- for (int idx = 0; idx < size(); ++idx) {
- if (array[idx + arrayOffset] != values[idx + offset]) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public Boolean visit(BitSet bitSet, int bitSetOffset, long numBits) {
- for (int idx = 0; idx < size(); ++idx) {
- if (bitSet.get(idx + bitSetOffset) != values[idx + offset]) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public Boolean fallback() {
- for (int idx = 0; idx < size(); ++idx) {
- if (other.getBoolean(idx) != values[idx + offset]) {
- return false;
- }
- }
- return true;
- }
- });
- }
-
- BooleanArrayDataBuffer(boolean[] values, boolean readOnly) {
- this(values, readOnly, 0, values.length);
- }
-
- private BooleanArrayDataBuffer(boolean[] values, boolean readOnly, int offset, int length) {
- this.values = values;
- this.readOnly = readOnly;
- this.offset = offset;
- this.length = length;
- }
-
- private final boolean[] values;
- private final boolean readOnly;
- private final int offset;
- private final int length;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/AbstractNioDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/AbstractNioDataBuffer.java
deleted file mode 100644
index 82bc981ad46..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/AbstractNioDataBuffer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-
-package org.tensorflow.ndarray.impl.buffer.nio;
-
-import java.nio.Buffer;
-import org.tensorflow.ndarray.impl.buffer.AbstractDataBuffer;
-
-/**
- * Base class for all JDK-based data buffers.
- *
- * @param type of elements (or values) stored in this buffer
- */
-abstract class AbstractNioDataBuffer extends AbstractDataBuffer {
-
- @Override
- public long size() {
- return buf().capacity();
- }
-
- @Override
- public boolean isReadOnly() {
- return buf().isReadOnly();
- }
-
- abstract Buffer buf();
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/ByteNioDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/ByteNioDataBuffer.java
deleted file mode 100644
index 5ede97cef78..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/ByteNioDataBuffer.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-
-package org.tensorflow.ndarray.impl.buffer.nio;
-
-import java.nio.ByteBuffer;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.impl.buffer.adapter.DataBufferAdapterFactory;
-import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
-import org.tensorflow.ndarray.buffer.ByteDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataStorageVisitor;
-import org.tensorflow.ndarray.buffer.DoubleDataBuffer;
-import org.tensorflow.ndarray.buffer.FloatDataBuffer;
-import org.tensorflow.ndarray.buffer.IntDataBuffer;
-import org.tensorflow.ndarray.buffer.LongDataBuffer;
-import org.tensorflow.ndarray.buffer.ShortDataBuffer;
-import org.tensorflow.ndarray.buffer.layout.DataLayouts;
-
-/**
- * A buffer of bytes using a JDK {@link ByteBuffer} for storage.
- */
-final class ByteNioDataBuffer extends AbstractNioDataBuffer
- implements ByteDataBuffer {
-
- @Override
- public byte getByte(long index) {
- return buf.get((int)index);
- }
-
- @Override
- public ByteDataBuffer setByte(byte value, long index) {
- buf.put((int)index, value);
- return this;
- }
-
- @Override
- public ByteDataBuffer read(byte[] dst, int offset, int length) {
- buf.duplicate().get(dst, offset, length);
- return this;
- }
-
- @Override
- public ByteDataBuffer write(byte[] src, int offset, int length) {
- buf.duplicate().put(src, offset, length);
- return this;
- }
-
- @Override
- public ByteDataBuffer copyTo(DataBuffer dst, long size) {
- Validator.copyToArgs(this, dst, size);
- return dst.accept(new DataStorageVisitor() {
-
- @Override
- public ByteDataBuffer visit(ByteBuffer buffer) {
- buffer.duplicate().put((ByteBuffer)buf.duplicate().limit((int)size));
- return ByteNioDataBuffer.this;
- }
-
- @Override
- public ByteDataBuffer fallback() {
- if (dst instanceof ByteDataBuffer) {
- ByteDataBuffer byteDst = (ByteDataBuffer)dst;
- for (long idx = 0L; idx < size; ++idx) {
- byteDst.setByte(getByte(idx), idx);
- }
- return ByteNioDataBuffer.this;
- }
- return slowCopyTo(dst, size);
- }
- });
- }
-
- @Override
- public IntDataBuffer asInts() {
- return new IntNioDataBuffer(buf.asIntBuffer());
- }
-
- @Override
- public ShortDataBuffer asShorts() {
- return new ShortNioDataBuffer(buf.asShortBuffer());
- }
-
- @Override
- public LongDataBuffer asLongs() {
- return new LongNioDataBuffer(buf.asLongBuffer());
- }
-
- @Override
- public FloatDataBuffer asFloats() {
- return new FloatNioDataBuffer(buf.asFloatBuffer());
- }
-
- @Override
- public DoubleDataBuffer asDoubles() {
- return new DoubleNioDataBuffer(buf.asDoubleBuffer());
- }
-
- @Override
- public BooleanDataBuffer asBooleans() {
- return DataBufferAdapterFactory.create(this, DataLayouts.BOOL);
- }
-
- @Override
- public ByteDataBuffer offset(long index) {
- Validator.offsetArgs(this, index);
- return new ByteNioDataBuffer(((ByteBuffer)buf.duplicate().position((int)index)).slice());
- }
-
- @Override
- public ByteDataBuffer narrow(long size) {
- Validator.narrowArgs(this, size);
- return new ByteNioDataBuffer(((ByteBuffer)buf.duplicate().limit((int)size)).slice());
- }
-
- @Override
- public ByteDataBuffer slice(long index, long size) {
- Validator.sliceArgs(this, index, size);
- ByteBuffer sliceBuf = buf.duplicate();
- sliceBuf.position((int)index);
- sliceBuf.limit((int)index + (int)size);
- return new ByteNioDataBuffer(sliceBuf.slice());
- }
-
- @Override
- public R accept(DataStorageVisitor visitor) {
- return visitor.visit(buf);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof ByteDataBuffer)) {
- return super.equals(obj);
- }
- ByteDataBuffer other = (ByteDataBuffer)obj;
- if (size() != other.size()) {
- return false;
- }
- return other.accept(new DataStorageVisitor() {
-
- @Override
- public Boolean visit(ByteBuffer buffer) {
- return buf.equals(buffer);
- }
-
- @Override
- public Boolean fallback() {
- for (int idx = 0; idx < size(); ++idx) {
- if (other.getByte(idx) != getByte(idx)) {
- return false;
- }
- }
- return true;
- }
- });
- }
-
- @Override
- ByteBuffer buf() {
- return buf;
- }
-
- ByteNioDataBuffer(ByteBuffer buf) {
- this.buf = buf;
- }
-
- private ByteBuffer buf;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/DoubleNioDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/DoubleNioDataBuffer.java
deleted file mode 100644
index bddc5db1e3f..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/DoubleNioDataBuffer.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-
-package org.tensorflow.ndarray.impl.buffer.nio;
-
-import java.nio.DoubleBuffer;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataStorageVisitor;
-import org.tensorflow.ndarray.buffer.DoubleDataBuffer;
-
-/**
- * A buffer of bytes using a JDK {@link DoubleBuffer} for storage.
- */
-final class DoubleNioDataBuffer extends AbstractNioDataBuffer
- implements DoubleDataBuffer {
-
- @Override
- public double getDouble(long index) {
- return buf.get((int)index);
- }
-
- @Override
- public DoubleDataBuffer setDouble(double value, long index) {
- buf.put((int)index, value);
- return this;
- }
-
- @Override
- public DoubleDataBuffer read(double[] dst, int offset, int length) {
- buf.duplicate().get(dst, offset, length);
- return this;
- }
-
- @Override
- public DoubleDataBuffer write(double[] src, int offset, int length) {
- buf.duplicate().put(src, offset, length);
- return this;
- }
-
- @Override
- public DoubleDataBuffer copyTo(DataBuffer dst, long size) {
- Validator.copyToArgs(this, dst, size);
- return dst.accept(new DataStorageVisitor() {
-
- @Override
- public DoubleDataBuffer visit(DoubleBuffer buffer) {
- buffer.duplicate().put((DoubleBuffer)buf.duplicate().limit((int)size));
- return DoubleNioDataBuffer.this;
- }
-
- @Override
- public DoubleDataBuffer fallback() {
- if (dst instanceof DoubleDataBuffer) {
- DoubleDataBuffer doubleDst = (DoubleDataBuffer)dst;
- for (long idx = 0L; idx < size; ++idx) {
- doubleDst.setDouble(getDouble(idx), idx);
- }
- return DoubleNioDataBuffer.this;
- }
- return slowCopyTo(dst, size);
- }
- });
- }
-
- @Override
- public DoubleDataBuffer offset(long index) {
- Validator.offsetArgs(this, index);
- return new DoubleNioDataBuffer(((DoubleBuffer)buf.duplicate().position((int)index)).slice());
- }
-
- @Override
- public DoubleDataBuffer narrow(long size) {
- Validator.narrowArgs(this, size);
- return new DoubleNioDataBuffer(((DoubleBuffer)buf.duplicate().limit((int)size)).slice());
- }
-
- @Override
- public DoubleDataBuffer slice(long index, long size) {
- Validator.sliceArgs(this, index, size);
- DoubleBuffer sliceBuf = buf.duplicate();
- sliceBuf.position((int)index);
- sliceBuf.limit((int)index + (int)size);
- return new DoubleNioDataBuffer(sliceBuf.slice());
- }
-
- @Override
- public R accept(DataStorageVisitor visitor) {
- return visitor.visit(buf);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof DoubleDataBuffer)) {
- return super.equals(obj);
- }
- DoubleDataBuffer other = (DoubleDataBuffer)obj;
- if (size() != other.size()) {
- return false;
- }
- return other.accept(new DataStorageVisitor() {
-
- @Override
- public Boolean visit(DoubleBuffer buffer) {
- return buf.equals(buffer);
- }
-
- @Override
- public Boolean fallback() {
- for (int idx = 0; idx < size(); ++idx) {
- if (other.getDouble(idx) != getDouble(idx)) {
- return false;
- }
- }
- return true;
- }
- });
- }
-
- @Override
- DoubleBuffer buf() {
- return buf;
- }
-
- DoubleNioDataBuffer(DoubleBuffer buf) {
- this.buf = buf;
- }
-
- private DoubleBuffer buf;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/FloatNioDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/FloatNioDataBuffer.java
deleted file mode 100644
index 06a9a31b56a..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/FloatNioDataBuffer.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-
-package org.tensorflow.ndarray.impl.buffer.nio;
-
-import java.nio.FloatBuffer;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataStorageVisitor;
-import org.tensorflow.ndarray.buffer.FloatDataBuffer;
-
-/**
- * A buffer of bytes using a JDK {@link FloatBuffer} for storage.
- */
-final class FloatNioDataBuffer extends AbstractNioDataBuffer
- implements FloatDataBuffer {
-
- @Override
- public float getFloat(long index) {
- return buf.get((int)index);
- }
-
- @Override
- public FloatDataBuffer setFloat(float value, long index) {
- buf.put((int)index, value);
- return this;
- }
-
- @Override
- public FloatDataBuffer read(float[] dst, int offset, int length) {
- buf.duplicate().get(dst, offset, length);
- return this;
- }
-
- @Override
- public FloatDataBuffer write(float[] src, int offset, int length) {
- buf.duplicate().put(src, offset, length);
- return this;
- }
-
- @Override
- public FloatDataBuffer copyTo(DataBuffer dst, long size) {
- Validator.copyToArgs(this, dst, size);
- return dst.accept(new DataStorageVisitor() {
-
- @Override
- public FloatDataBuffer visit(FloatBuffer buffer) {
- buffer.duplicate().put((FloatBuffer)buf.duplicate().limit((int)size));
- return FloatNioDataBuffer.this;
- }
-
- @Override
- public FloatDataBuffer fallback() {
- if (dst instanceof FloatDataBuffer) {
- FloatDataBuffer floatDst = (FloatDataBuffer)dst;
- for (long idx = 0L; idx < size; ++idx) {
- floatDst.setFloat(getFloat(idx), idx);
- }
- return FloatNioDataBuffer.this;
- }
- return slowCopyTo(dst, size);
- }
- });
- }
-
- @Override
- public FloatDataBuffer offset(long index) {
- Validator.offsetArgs(this, index);
- return new FloatNioDataBuffer(((FloatBuffer)buf.duplicate().position((int)index)).slice());
- }
-
- @Override
- public FloatDataBuffer narrow(long size) {
- Validator.narrowArgs(this, size);
- return new FloatNioDataBuffer(((FloatBuffer)buf.duplicate().limit((int)size)).slice());
- }
-
- @Override
- public FloatDataBuffer slice(long index, long size) {
- Validator.sliceArgs(this, index, size);
- FloatBuffer sliceBuf = buf.duplicate();
- sliceBuf.position((int)index);
- sliceBuf.limit((int)index + (int)size);
- return new FloatNioDataBuffer(sliceBuf.slice());
- }
-
- @Override
- public R accept(DataStorageVisitor visitor) {
- return visitor.visit(buf);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof FloatDataBuffer)) {
- return super.equals(obj);
- }
- FloatDataBuffer other = (FloatDataBuffer)obj;
- if (size() != other.size()) {
- return false;
- }
- return other.accept(new DataStorageVisitor() {
-
- @Override
- public Boolean visit(FloatBuffer buffer) {
- return buf.equals(buffer);
- }
-
- @Override
- public Boolean fallback() {
- for (int idx = 0; idx < size(); ++idx) {
- if (other.getFloat(idx) != getFloat(idx)) {
- return false;
- }
- }
- return true;
- }
- });
- }
-
- @Override
- FloatBuffer buf() {
- return buf;
- }
-
- FloatNioDataBuffer(FloatBuffer buf) {
- this.buf = buf;
- }
-
- private FloatBuffer buf;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/IntNioDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/IntNioDataBuffer.java
deleted file mode 100644
index cea729e86a7..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/nio/IntNioDataBuffer.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- Copyright 2019 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =======================================================================
- */
-
-package org.tensorflow.ndarray.impl.buffer.nio;
-
-import java.nio.IntBuffer;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataStorageVisitor;
-import org.tensorflow.ndarray.buffer.IntDataBuffer;
-
-/**
- * A buffer of bytes using a JDK {@link IntBuffer} for storage.
- */
-final class IntNioDataBuffer extends AbstractNioDataBuffer
- implements IntDataBuffer {
-
- @Override
- public int getInt(long index) {
- return buf.get((int)index);
- }
-
- @Override
- public IntDataBuffer setInt(int value, long index) {
- buf.put((int)index, value);
- return this;
- }
-
- @Override
- public IntDataBuffer read(int[] dst, int offset, int length) {
- buf.duplicate().get(dst, offset, length);
- return this;
- }
-
- @Override
- public IntDataBuffer write(int[] src, int offset, int length) {
- buf.duplicate().put(src, offset, length);
- return this;
- }
-
- @Override
- public IntDataBuffer copyTo(DataBuffer