Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

Commit d10262e

Browse files
authored
Allow SparseNdArray impls to be inherited (#5)
1 parent 887fc19 commit d10262e

File tree

8 files changed

+68
-68
lines changed

8 files changed

+68
-68
lines changed

ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArray.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class BooleanSparseNdArray extends AbstractSparseNdArray<Boolean, Boolean
6363
implements BooleanNdArray {
6464

6565
/**
66-
* Creates a BooleanSparseNdArray with a default value of false.
66+
* Creates a BooleanSparseNdArray
6767
*
6868
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
6969
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -74,14 +74,19 @@ public class BooleanSparseNdArray extends AbstractSparseNdArray<Boolean, Boolean
7474
* parameter {@code values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse
7575
* NdArray has a value of {@code 18}, and element {@code [2,4]} of the NdArray has a value of
7676
* {@code 3.6}.
77+
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
7778
* @param dimensions the dimensional space for the dense object represented by this sparse array,
7879
*/
79-
BooleanSparseNdArray(LongNdArray indices, BooleanNdArray values, DimensionalSpace dimensions) {
80-
this(indices, values, false, dimensions);
80+
protected BooleanSparseNdArray(
81+
LongNdArray indices,
82+
BooleanNdArray values,
83+
boolean defaultValue,
84+
DimensionalSpace dimensions) {
85+
super(indices, values, defaultValue, dimensions);
8186
}
8287

8388
/**
84-
* Creates a BooleanSparseNdArray
89+
* Creates a BooleanSparseNdArray with a default value of false.
8590
*
8691
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
8792
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -92,15 +97,10 @@ public class BooleanSparseNdArray extends AbstractSparseNdArray<Boolean, Boolean
9297
* parameter {@code values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse
9398
* NdArray has a value of {@code 18}, and element {@code [2,4]} of the NdArray has a value of
9499
* {@code 3.6}.
95-
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
96100
* @param dimensions the dimensional space for the dense object represented by this sparse array,
97101
*/
98-
BooleanSparseNdArray(
99-
LongNdArray indices,
100-
BooleanNdArray values,
101-
boolean defaultValue,
102-
DimensionalSpace dimensions) {
103-
super(indices, values, defaultValue, dimensions);
102+
BooleanSparseNdArray(LongNdArray indices, BooleanNdArray values, DimensionalSpace dimensions) {
103+
this(indices, values, false, dimensions);
104104
}
105105

106106
/**

ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArray.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class ByteSparseNdArray extends AbstractSparseNdArray<Byte, ByteNdArray>
6363
implements ByteNdArray {
6464

6565
/**
66-
* Creates a ByteSparseNdArray
66+
* Creates a ByteSparseNdArray with a default value of zero.
6767
*
6868
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
6969
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -73,14 +73,16 @@ public class ByteSparseNdArray extends AbstractSparseNdArray<Byte, ByteNdArray>
7373
* each element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter
7474
* {@code values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a
7575
* value of {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
76+
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
7677
* @param dimensions the dimensional space for the dense object represented by this sparse array,
7778
*/
78-
ByteSparseNdArray(LongNdArray indices, ByteNdArray values, DimensionalSpace dimensions) {
79-
this(indices, values, (byte) 0, dimensions);
79+
protected ByteSparseNdArray(
80+
LongNdArray indices, ByteNdArray values, byte defaultValue, DimensionalSpace dimensions) {
81+
super(indices, values, defaultValue, dimensions);
8082
}
8183

8284
/**
83-
* Creates a ByteSparseNdArray with a default value of zero.
85+
* Creates a ByteSparseNdArray
8486
*
8587
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
8688
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -90,12 +92,10 @@ public class ByteSparseNdArray extends AbstractSparseNdArray<Byte, ByteNdArray>
9092
* each element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter
9193
* {@code values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a
9294
* value of {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
93-
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
9495
* @param dimensions the dimensional space for the dense object represented by this sparse array,
9596
*/
96-
ByteSparseNdArray(
97-
LongNdArray indices, ByteNdArray values, byte defaultValue, DimensionalSpace dimensions) {
98-
super(indices, values, defaultValue, dimensions);
97+
ByteSparseNdArray(LongNdArray indices, ByteNdArray values, DimensionalSpace dimensions) {
98+
this(indices, values, (byte) 0, dimensions);
9999
}
100100

101101
/**

ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArray.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class DoubleSparseNdArray extends AbstractSparseNdArray<Double, DoubleNdA
6363
implements DoubleNdArray {
6464

6565
/**
66-
* Creates a DoubleSparseNdArray with a default value of zero.
66+
* Creates a DoubleSparseNdArray
6767
*
6868
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
6969
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -73,14 +73,16 @@ public class DoubleSparseNdArray extends AbstractSparseNdArray<Double, DoubleNdA
7373
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
7474
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
7575
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
76+
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
7677
* @param dimensions the dimensional space for the dense object represented by this sparse array,
7778
*/
78-
DoubleSparseNdArray(LongNdArray indices, DoubleNdArray values, DimensionalSpace dimensions) {
79-
this(indices, values, 0d, dimensions);
79+
protected DoubleSparseNdArray(
80+
LongNdArray indices, DoubleNdArray values, double defaultValue, DimensionalSpace dimensions) {
81+
super(indices, values, defaultValue, dimensions);
8082
}
8183

8284
/**
83-
* Creates a DoubleSparseNdArray
85+
* Creates a DoubleSparseNdArray with a default value of zero.
8486
*
8587
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
8688
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -90,12 +92,10 @@ public class DoubleSparseNdArray extends AbstractSparseNdArray<Double, DoubleNdA
9092
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
9193
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
9294
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
93-
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
9495
* @param dimensions the dimensional space for the dense object represented by this sparse array,
9596
*/
96-
DoubleSparseNdArray(
97-
LongNdArray indices, DoubleNdArray values, double defaultValue, DimensionalSpace dimensions) {
98-
super(indices, values, defaultValue, dimensions);
97+
DoubleSparseNdArray(LongNdArray indices, DoubleNdArray values, DimensionalSpace dimensions) {
98+
this(indices, values, 0d, dimensions);
9999
}
100100

101101
/**

ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArray.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class FloatSparseNdArray extends AbstractSparseNdArray<Float, FloatNdArra
6363
implements FloatNdArray {
6464

6565
/**
66-
* Creates a FloatSparseNdArray with a default value of zero.
66+
* Creates a FloatSparseNdArray
6767
*
6868
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
6969
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -73,14 +73,16 @@ public class FloatSparseNdArray extends AbstractSparseNdArray<Float, FloatNdArra
7373
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
7474
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
7575
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
76+
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
7677
* @param dimensions the dimensional space for the dense object represented by this sparse array,
7778
*/
78-
FloatSparseNdArray(LongNdArray indices, FloatNdArray values, DimensionalSpace dimensions) {
79-
this(indices, values, 0f, dimensions);
79+
protected FloatSparseNdArray(
80+
LongNdArray indices, FloatNdArray values, float defaultValue, DimensionalSpace dimensions) {
81+
super(indices, values, defaultValue, dimensions);
8082
}
8183

8284
/**
83-
* Creates a FloatSparseNdArray
85+
* Creates a FloatSparseNdArray with a default value of zero.
8486
*
8587
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
8688
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -90,12 +92,10 @@ public class FloatSparseNdArray extends AbstractSparseNdArray<Float, FloatNdArra
9092
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
9193
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
9294
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
93-
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
9495
* @param dimensions the dimensional space for the dense object represented by this sparse array,
9596
*/
96-
FloatSparseNdArray(
97-
LongNdArray indices, FloatNdArray values, float defaultValue, DimensionalSpace dimensions) {
98-
super(indices, values, defaultValue, dimensions);
97+
FloatSparseNdArray(LongNdArray indices, FloatNdArray values, DimensionalSpace dimensions) {
98+
this(indices, values, 0f, dimensions);
9999
}
100100

101101
/**

ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArray.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class IntSparseNdArray extends AbstractSparseNdArray<Integer, IntNdArray>
6363
implements IntNdArray {
6464

6565
/**
66-
* Creates a IntSparseNdArray with a default value of zero.
66+
* Creates a IntSparseNdArray
6767
*
6868
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
6969
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -73,14 +73,16 @@ public class IntSparseNdArray extends AbstractSparseNdArray<Integer, IntNdArray>
7373
* in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
7474
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
7575
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
76+
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
7677
* @param dimensions the dimensional space for the dense object represented by this sparse array,
7778
*/
78-
IntSparseNdArray(LongNdArray indices, IntNdArray values, DimensionalSpace dimensions) {
79-
this(indices, values, 0, dimensions);
79+
protected IntSparseNdArray(
80+
LongNdArray indices, IntNdArray values, int defaultValue, DimensionalSpace dimensions) {
81+
super(indices, values, defaultValue, dimensions);
8082
}
8183

8284
/**
83-
* Creates a IntSparseNdArray
85+
* Creates a IntSparseNdArray with a default value of zero.
8486
*
8587
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
8688
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -90,12 +92,10 @@ public class IntSparseNdArray extends AbstractSparseNdArray<Integer, IntNdArray>
9092
* in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
9193
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
9294
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
93-
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
9495
* @param dimensions the dimensional space for the dense object represented by this sparse array,
9596
*/
96-
IntSparseNdArray(
97-
LongNdArray indices, IntNdArray values, int defaultValue, DimensionalSpace dimensions) {
98-
super(indices, values, defaultValue, dimensions);
97+
IntSparseNdArray(LongNdArray indices, IntNdArray values, DimensionalSpace dimensions) {
98+
this(indices, values, 0, dimensions);
9999
}
100100

101101
/**

ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArray.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class LongSparseNdArray extends AbstractSparseNdArray<Long, LongNdArray>
6262
implements LongNdArray {
6363

6464
/**
65-
* Creates a LongSparseNdArray with a default value of zero.
65+
* Creates a LongSparseNdArray
6666
*
6767
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
6868
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -72,14 +72,16 @@ public class LongSparseNdArray extends AbstractSparseNdArray<Long, LongNdArray>
7272
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
7373
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
7474
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
75+
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
7576
* @param dimensions the dimensional space for the dense object represented by this sparse array,
7677
*/
77-
LongSparseNdArray(LongNdArray indices, LongNdArray values, DimensionalSpace dimensions) {
78-
this(indices, values, 0L, dimensions);
78+
protected LongSparseNdArray(
79+
LongNdArray indices, LongNdArray values, long defaultValue, DimensionalSpace dimensions) {
80+
super(indices, values, defaultValue, dimensions);
7981
}
8082

8183
/**
82-
* Creates a LongSparseNdArray
84+
* Creates a LongSparseNdArray with a default value of zero.
8385
*
8486
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
8587
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -89,12 +91,10 @@ public class LongSparseNdArray extends AbstractSparseNdArray<Long, LongNdArray>
8991
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
9092
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
9193
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
92-
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
9394
* @param dimensions the dimensional space for the dense object represented by this sparse array,
9495
*/
95-
LongSparseNdArray(
96-
LongNdArray indices, LongNdArray values, long defaultValue, DimensionalSpace dimensions) {
97-
super(indices, values, defaultValue, dimensions);
96+
LongSparseNdArray(LongNdArray indices, LongNdArray values, DimensionalSpace dimensions) {
97+
this(indices, values, 0L, dimensions);
9898
}
9999

100100
/**

ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArray.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class ShortSparseNdArray extends AbstractSparseNdArray<Short, ShortNdArra
6363
implements ShortNdArray {
6464

6565
/**
66-
* Creates a ShortSparseNdArray with a default value of zero.
66+
* Creates a ShortSparseNdArray
6767
*
6868
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
6969
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -73,14 +73,16 @@ public class ShortSparseNdArray extends AbstractSparseNdArray<Short, ShortNdArra
7373
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
7474
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
7575
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
76+
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
7677
* @param dimensions the dimensional space for the dense object represented by this sparse array,
7778
*/
78-
ShortSparseNdArray(LongNdArray indices, ShortNdArray values, DimensionalSpace dimensions) {
79-
this(indices, values, (short) 0, dimensions);
79+
protected ShortSparseNdArray(
80+
LongNdArray indices, ShortNdArray values, short defaultValue, DimensionalSpace dimensions) {
81+
super(indices, values, defaultValue, dimensions);
8082
}
8183

8284
/**
83-
* Creates a ShortSparseNdArray
85+
* Creates a ShortSparseNdArray with a default value of zero.
8486
*
8587
* @param indices A 2-D LongNdArray of shape {@code [N, ndims]}, that specifies the indices of the
8688
* elements in the sparse array that contain non-default values (elements are zero-indexed).
@@ -90,12 +92,10 @@ public class ShortSparseNdArray extends AbstractSparseNdArray<Short, ShortNdArra
9092
* element in indices. For example, given {@code indices=[[1,3], [2,4]]}, the parameter {@code
9193
* values=[18, 3.6]} specifies that element {@code [1,3]} of the sparse NdArray has a value of
9294
* {@code 18}, and element {@code [2,4]} of the NdArray has a value of {@code 3.6}.
93-
* @param defaultValue Scalar value to set for indices not specified in {@link #getIndices()}
9495
* @param dimensions the dimensional space for the dense object represented by this sparse array,
9596
*/
96-
ShortSparseNdArray(
97-
LongNdArray indices, ShortNdArray values, short defaultValue, DimensionalSpace dimensions) {
98-
super(indices, values, defaultValue, dimensions);
97+
ShortSparseNdArray(LongNdArray indices, ShortNdArray values, DimensionalSpace dimensions) {
98+
this(indices, values, (short) 0, dimensions);
9999
}
100100

101101
/**

0 commit comments

Comments
 (0)