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 void
add
(float val) final TensorBase
add
(TensorBase t) Adds specified tensor t to this tensor.final TensorBase
addInto
(TensorBase t, TensorBase result) void
Applies specified function to all elements in tensor in-place.clone()
copy()
final void
copyFrom
(float[] src) final void
copyFrom
(TensorBase src) void
void
final void
div
(float value) Divide all values in this tensor with specified value.final void
div
(float[] divisors) final void
div
(TensorBase t) Element-wise divison with specified tensor.boolean
equals
(TensorBase t2, float delta) boolean
final void
fill
(float value) Fills the entire tensor with specified value.final float[]
Returns values stored in this tensor.int
hashCode()
float
mean()
multiply
(float m) Multiplies all the values in tensor with a specified input parameter.void
multiply
(float mul, int idx) void
multiplyElementWise
(TensorBase tensor2) final int
Rank corresponds to number of dimensions in tensor.final int
Total number of values in tensor.void
Randomize all values in tensorvoid
replace
(float toReplace, float replaceWith) final void
setValues
(float... values) void
setValuesFromString
(String values) Sets tensor values from CSV string.void
setValuesFromStringTransposed
(String values) shape()
Returns the shape of this tensor.sqr()
void
sqrt()
float
std
(float mean) final void
sub
(float val) final void
sub
(TensorBase t) Subtracts specified tensor t from this tensor.static final void
subInplace
(TensorBase t1, TensorBase t2) Subtracts tensor t2 from t1.final TensorBase
subInto
(TensorBase t, TensorBase result) float
sum()
float
sumAbs()
Returns sum of abs values of this tensor - L1 normfloat
sumSqr()
Returns sum of squared values of this tensor - L2 normtoString()
static String
valuesAsString
(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:
numDimensions
in 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()
-