|
| 1 | +/* |
| 2 | +Copyright 2019 The TensorFlow Authors. All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +======================================================================= |
| 16 | +*/ |
| 17 | +package org.tensorflow.ndarray; |
| 18 | + |
| 19 | +import org.tensorflow.ndarray.buffer.BooleanDataBuffer; |
| 20 | +import org.tensorflow.ndarray.buffer.DataBuffer; |
| 21 | +import org.tensorflow.ndarray.index.Index; |
| 22 | + |
| 23 | +/** An {@link NdArray} of booleans. */ |
| 24 | +public interface BooleanNdArray extends NdArray<Boolean> { |
| 25 | + |
| 26 | + /** |
| 27 | + * Returns the boolean value of the scalar found at the given coordinates. |
| 28 | + * |
| 29 | + * <p>To access the scalar element, the number of coordinates provided must be equal to the number |
| 30 | + * of dimensions of this array (i.e. its rank). For example: |
| 31 | + * |
| 32 | + * <pre>{@code |
| 33 | + * BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2 |
| 34 | + * matrix.getBoolean(0, 1); // succeeds, returns false |
| 35 | + * matrix.getBoolean(0); // throws IllegalRankException |
| 36 | + * |
| 37 | + * BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0 |
| 38 | + * scalar.getBoolean(); // succeeds, returns false |
| 39 | + * }</pre> |
| 40 | + * |
| 41 | + * @param coordinates coordinates of the scalar to resolve |
| 42 | + * @return value of that scalar |
| 43 | + * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their |
| 44 | + * respective dimension |
| 45 | + * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar |
| 46 | + * element |
| 47 | + */ |
| 48 | + boolean getBoolean(long... coordinates); |
| 49 | + |
| 50 | + /** |
| 51 | + * Assigns the boolean value of the scalar found at the given coordinates. |
| 52 | + * |
| 53 | + * <p>To access the scalar element, the number of coordinates provided must be equal to the number |
| 54 | + * of dimensions of this array (i.e. its rank). For example: |
| 55 | + * |
| 56 | + * <pre>{@code |
| 57 | + * BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2 |
| 58 | + * matrix.setBoolean(true, 0, 1); // succeeds |
| 59 | + * matrix.setBoolean(true, 0); // throws IllegalRankException |
| 60 | + * |
| 61 | + * BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0 |
| 62 | + * scalar.setBoolean(true); // succeeds |
| 63 | + * }</pre> |
| 64 | + * |
| 65 | + * @param value the value to assign |
| 66 | + * @param coordinates coordinates of the scalar to assign |
| 67 | + * @return this array |
| 68 | + * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their |
| 69 | + * respective dimension |
| 70 | + * @throws IllegalRankException if number of coordinates is not sufficient to access a scalar |
| 71 | + * element |
| 72 | + */ |
| 73 | + BooleanNdArray setBoolean(boolean value, long... coordinates); |
| 74 | + |
| 75 | + @Override |
| 76 | + BooleanNdArray withShape(Shape shape); |
| 77 | + |
| 78 | + @Override |
| 79 | + BooleanNdArray slice(Index... indices); |
| 80 | + |
| 81 | + @Override |
| 82 | + BooleanNdArray get(long... coordinates); |
| 83 | + |
| 84 | + @Override |
| 85 | + BooleanNdArray set(NdArray<Boolean> src, long... coordinates); |
| 86 | + |
| 87 | + @Override |
| 88 | + default Boolean getObject(long... coordinates) { |
| 89 | + return getBoolean(coordinates); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + default BooleanNdArray setObject(Boolean value, long... coordinates) { |
| 94 | + return setBoolean(value, coordinates); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + NdArraySequence<BooleanNdArray> elements(int dimensionIdx); |
| 99 | + |
| 100 | + @Override |
| 101 | + NdArraySequence<BooleanNdArray> scalars(); |
| 102 | + |
| 103 | + @Override |
| 104 | + BooleanNdArray copyTo(NdArray<Boolean> dst); |
| 105 | + |
| 106 | + @Override |
| 107 | + BooleanNdArray copyTo(DataBuffer<Boolean> dst); |
| 108 | + |
| 109 | + BooleanNdArray copyTo(BooleanDataBuffer dst); |
| 110 | + |
| 111 | + @Override |
| 112 | + BooleanNdArray copyFrom(DataBuffer<Boolean> src); |
| 113 | + |
| 114 | + BooleanNdArray copyFrom(BooleanDataBuffer src); |
| 115 | +} |
0 commit comments