public abstract class Tensor<T extends Tensor> extends BaseTensor
Sub-tensors are tensors which are wrapped around an external array which it doesn't own. Most of the time,
sub-tensors will have a non-zero startIndex. They can't be reshaped if the change
in shape requires the data array to grow.
| Modifier and Type | Field and Description |
|---|---|
int |
startIndex
The index in the input array that this tensor starts at.
|
int[] |
strides
Stride for each axis
|
boolean |
subtensor
If this tensor is wrapped around another array which it doesn't own then it is a sub-tensor.
|
shape| Constructor and Description |
|---|
Tensor() |
| Modifier and Type | Method and Description |
|---|---|
void |
computeStrides()
Computes how many indexes must be steped over to increment a value in each axis
|
T |
copy()
Returns a copy of this tensor
|
void |
copyShape(int[] shape)
Copies the shape of this tensor into the provided int[]
|
abstract T |
create(int... shape)
Creates a tensor of the same type with the specified shape
|
int[] |
createCoor()
Creates a new coordinate for this tensor.
|
T |
createLike()
Creates a tensor of the same type and same shape as this one
|
abstract java.lang.Object |
getData()
Returns internal array used to store tensor data.
|
abstract double |
getDouble(int... coordinate)
Accessor function which allows any tensor's element to be read as a double.
|
int |
idx(int... coordinate)
Returns the index of the coordinate.
|
int |
idx(int axis0)
Specialized version of
idx(int...) for 1-D tensors. |
int |
idx(int axis1,
int axis0)
Specialized version of
idx(int...) for 2-D tensors. |
int |
idx(int axis2,
int axis1,
int axis0)
Specialized version of
idx(int...) for 3-D tensors. |
int |
idx(int axis3,
int axis2,
int axis1,
int axis0)
Specialized version of
idx(int...) for 4-D tensors. |
int |
idx(int axis4,
int axis3,
int axis2,
int axis1,
int axis0)
Specialized version of
idx(int...) for 5-D tensors. |
int[] |
indexToCoor(int index,
int[] storage)
Converts an array index into a coordinate
|
protected abstract void |
innerArrayGrow(int N)
Re-declare inner array so that it is at least of length N
|
protected abstract int |
innerArrayLength()
Length of inner array as returned by "data.length"
|
boolean |
isSub()
Returns true if it is a sub-tensor.
|
int |
length()
Length of used elements in Tensor's data array.
|
int |
length(int dimension)
Returns the length of a dimension/axis.
|
void |
reshape()
Reshape for when the inner shape variable has already been adjusted.
|
void |
reshape(int... shape)
Reshape for an arbitrary number of dimensions
|
void |
reshape(int length0)
Reshape for 1-D tensors. |
void |
reshape(int length1,
int length0)
Reshape for 2-D tensors. |
void |
reshape(int length2,
int length1,
int length0)
Reshape for 3-D tensors. |
void |
reshape(int length3,
int length2,
int length1,
int length0)
Reshape for 4-D tensors. |
void |
reshape(int length4,
int length3,
int length2,
int length1,
int length0)
Reshape for 5-D tensors. |
abstract void |
setData(java.lang.Object data)
Used to change the internal array in an abstract way
|
void |
setTo(T original)
Turns 'this' tensor into a copy of the provided tensor.
|
int |
stride(int index)
Returns the stride at the specified dimension.
|
T |
subtensor(int startIndex,
int[] shape)
Creates a subtensor from this tensor.
|
abstract void |
zero()
Sets all elements in the tensor to the value of zero
|
getDimension, getShape, isShapeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetDataTypepublic int startIndex
public boolean subtensor
public int[] strides
public abstract double getDouble(int... coordinate)
coordinate - Coordinate of the element which is to be readpublic abstract java.lang.Object getData()
public abstract void setData(java.lang.Object data)
public void reshape(int... shape)
shape - New shape. Length must be the same as the number of dimensions. Array reference
not saved internally. Highest to lowest dimensionpublic void reshape(int length0)
Reshape for 1-D tensors. Convenience function, but can be used
to avoid declaring a new arraylength0 - Length of axis-0public void reshape(int length1,
int length0)
Reshape for 2-D tensors. Convenience function, but can be used
to avoid declaring a new arraylength1 - Length of axis-1length0 - Length of axis-0public void reshape(int length2,
int length1,
int length0)
Reshape for 3-D tensors. Convenience function, but can be used
to avoid declaring a new arraylength2 - Length of axis-2length1 - Length of axis-1length0 - Length of axis-0public void reshape(int length3,
int length2,
int length1,
int length0)
Reshape for 4-D tensors. Convenience function, but can be used
to avoid declaring a new arraylength3 - Length of axis-3length2 - Length of axis-2length1 - Length of axis-1length0 - Length of axis-0public void reshape(int length4,
int length3,
int length2,
int length1,
int length0)
Reshape for 5-D tensors. Convenience function, but can be used
to avoid declaring a new arraylength4 - Length of axis-4length3 - Length of axis-3length2 - Length of axis-2length1 - Length of axis-1length0 - Length of axis-0public void reshape()
protected abstract void innerArrayGrow(int N)
N - Desired minimum length of inner arrayprotected abstract int innerArrayLength()
public int idx(int... coordinate)
coordinate - Coordinate from highest to lowest axis number/dimensionpublic int idx(int axis0)
idx(int...) for 1-D tensors.axis0 - axis-0 of coordinatepublic int idx(int axis1,
int axis0)
idx(int...) for 2-D tensors.axis1 - axis-1 of coordinateaxis0 - axis-0 of coordinatepublic int idx(int axis2,
int axis1,
int axis0)
idx(int...) for 3-D tensors.axis2 - axis-2 of coordinateaxis1 - axis-1 of coordinateaxis0 - axis-0 of coordinatepublic int idx(int axis3,
int axis2,
int axis1,
int axis0)
idx(int...) for 4-D tensors.axis3 - axis-3 of coordinateaxis2 - axis-2 of coordinateaxis1 - axis-1 of coordinateaxis0 - axis-0 of coordinatepublic int idx(int axis4,
int axis3,
int axis2,
int axis1,
int axis0)
idx(int...) for 5-D tensors.axis4 - axis-4 of coordinateaxis3 - axis-3 of coordinateaxis2 - axis-2 of coordinateaxis1 - axis-1 of coordinateaxis0 - axis-0 of coordinatepublic void computeStrides()
public int stride(int index)
public void copyShape(int[] shape)
shape - Where the shape is to be written to. Must be the correct sizepublic int length(int dimension)
length in interface ITensorlength in class BaseTensordimension - The dimension/axispublic int length()
public abstract T create(int... shape)
shape - Shape of the new tensorpublic T createLike()
public int[] createCoor()
createCoor in interface ITensorcreateCoor in class BaseTensorpublic int[] indexToCoor(int index,
int[] storage)
index - internal array index offset from startIndexstorage - (Optional) storage for coordinate. If null a new instance is createdpublic void setTo(T original)
original - Original tensor that's to be copied into this one. Not modified.public abstract void zero()
public T copy()
public boolean isSub()
public T subtensor(int startIndex, int[] shape)
startIndex - The start index in this tensor's internal data arrayshape - Shape of the output tensor