Class TensorBase
java.lang.Object
deepnetts.tensor.TensorBase
- All Implemented Interfaces:
Tensor, Serializable
The base call for multidimensional array/tensors. It us used as a basic data
structure for storing inputs, outputs and internal parameters(weights) of the
deep learning model. Provides common arithmetic operations on tensors, and
interface to accelerator devices like GPU.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected Shapeprotected float[]Values stored in this tensor make it final , only input layer and tests sets valuesprotected static final TensorVectorizationProvider -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTensorBase(Shape shape) TensorBase(Shape shape, float... values) protectedPublic deep copy / clone constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal TensorBaseadd(float val) final TensorBaseadd(TensorBase t) Adds specified tensor t to this tensor.final TensorBaseaddInto(TensorBase t, TensorBase result) voidApplies specified function to all elements in tensor in-place.clone()booleancopy()final voidcopyFrom(float[] src) final voidcopyFrom(TensorBase src) Copies values from specified tensorvoidvoidfinal voiddiv(float value) Divide all values in this tensor with specified value.final voiddiv(float[] divisors) final voiddiv(TensorBase t) Element-wise divison with specified tensor.booleanequals(TensorBase t2, float delta) booleanfinal voidfill(float value) Fills the entire tensor with specified value.final float[]Returns an array of values/elements stored in this tensor.inthashCode()floatmean()multiply(float m) Multiplies all the values in tensor with a specified input parameter.voidmultiply(float mul, int idx) voidmultiplyElementWise(TensorBase tensor2) final intRank corresponds to number of dimensions in tensor.final intTotal number of values in tensor.voidRandomize all values in tensorvoidreplace(float toReplace, float replaceWith) protected voidfinal voidsetValues(float... values) voidsetValuesFromString(String values) Sets tensor values from CSV string.voidsetValuesFromStringTransposed(String values) shape()Returns a shape of this tensor.sqr()sqrt()floatstd(float mean) final voidsub(float val) final voidsub(TensorBase t) Subtracts specified tensor t from this tensor.final TensorBasesub(TensorBase t, TensorBase result) static final voidsubInplace(TensorBase t1, TensorBase t2) Subtracts tensor t2 from t1.floatsum()floatsumAbs()Returns sum of abs values of this tensor - L1 normfloatsumSqr()Returns sum of squared values of this tensor - L2 normtoString()toTsr()static StringvaluesAsString(TensorBase[] tensors)
-
Field Details
-
vectorizationImpl
-
shape
-
numDimensions
protected int numDimensions -
values
protected float[] valuesValues stored in this tensor make it final , only input layer and tests sets values
-
-
Constructor Details
-
TensorBase
-
TensorBase
-
TensorBase
-
-
Method Details
-
clone
-
getValues
-
setValues
public final void setValues(float... values) -
copyFrom
public final void copyFrom(float[] src) -
copyFrom
-
numDimensions
public final int numDimensions()Rank corresponds to number of dimensions in tensor.- Specified by:
numDimensionsin interfaceTensor- Returns:
-
setShape
-
shape
-
numElements
public final int numElements()Total number of values in tensor.- Specified by:
numElementsin interfaceTensor- Returns:
-
toString
-
toTsr
-
add
Adds specified tensor t to this tensor.- Parameters:
t- tensor to add
-
addInto
-
add
-
sub
Subtracts specified tensor t from this tensor.- Parameters:
t- tensor to subtract
-
sub
-
sub
public final void sub(float val) -
subInplace
Subtracts tensor t2 from t1. The result is stored in t1.- Parameters:
t1-t2-
-
div
public final void div(float value) Divide all values in this tensor with specified value.- Parameters:
value-
-
div
public final void div(float[] divisors) -
fill
public final void fill(float value) Fills the entire tensor with specified value.- Parameters:
value- value used to fill tensor
-
div
-
copy
-
apply
-
apply
-
equals
-
hashCode
-
equals
-
valuesAsString
-
setValuesFromString
Sets tensor values from CSV string.- Parameters:
values- string with comma separated tensor values
-
setValuesFromStringTransposed
-
sum
public float sum() -
sumAbs
public float sumAbs()Returns sum of abs values of this tensor - L1 norm- Returns:
- L1 norm
-
sumSqr
public float sumSqr()Returns sum of squared values of this tensor - L2 norm- Returns:
- L2 norm
-
randomize
public void randomize()Randomize all values in tensor -
multiplyElementWise
-
multiply
Multiplies all the values in tensor with a specified input parameter.- Parameters:
m- a multiplier for all values in tensor
-
multiply
public void multiply(float mul, int idx) -
sqrt
-
sqr
-
mean
public float mean() -
std
public float std(float mean) -
replace
public void replace(float toReplace, float replaceWith) -
getOrCreateAccBridge
-
createAcceleratorBridge
-
getAcceleratorBridge
-
copyToGPU
public void copyToGPU() -
copyFromGPU
public void copyFromGPU() -
containsNaN
public boolean containsNaN()
-