Package deepnetts.tensor
Class TensorBase
java.lang.Object
deepnetts.tensor.TensorBase
- All Implemented Interfaces:
Tensor,Serializable
This class represents a wrapper for multidimensional array.
It a basic data structure for storing inputs, outputs and internal parameters(weights) of the deep learning model.
It supports up to 4 dimensions - it can be 1D, 2D, 3D or 4D.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTensorBase(Shape shape, float... values) Public deep copy / clone constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidadd(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()copy()final voidcopyFrom(float[] src) final voidcopyFrom(TensorBase src) voidvoidfinal 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 values 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) final voidsetValues(float... values) voidsetValuesFromString(String values) Sets tensor values from CSV string.voidsetValuesFromStringTransposed(String values) shape()Returns the shape of this tensor.sqr()voidsqrt()floatstd(float mean) final voidsub(float val) final voidsub(TensorBase t) Subtracts specified tensor t from this tensor.static final voidsubInplace(TensorBase t1, TensorBase t2) Subtracts tensor t2 from t1.final TensorBasesubInto(TensorBase t, TensorBase result) floatsum()floatsumAbs()Returns sum of abs values of this tensor - L1 normfloatsumSqr()Returns sum of squared values of this tensor - L2 normtoString()static StringvaluesAsString(TensorBase[] tensors)
-
Constructor Details
-
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:
-
shape
-
numElements
public final int numElements()Total number of values in tensor.- Returns:
-
toString
-
add
Adds specified tensor t to this tensor.- Parameters:
t- tensor to add
-
addInto
-
add
public final void add(float val) -
sub
Subtracts specified tensor t from this tensor.- Parameters:
t- tensor to subtract
-
subInto
-
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
public void 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()
-