public class Tensor extends Object implements Serializable
Constructor and Description |
---|
Tensor(float... values)
Creates a single row tensor with specified values.
|
Tensor(float[][] vals)
Creates a 2D tensor / matrix with specified values.
|
Tensor(float[][][] vals)
Creates a 3D tensor from specified 3D array
|
Tensor(float[][][][] vals) |
Tensor(int cols)
Creates an empty single row tensor with specified number of columns.
|
Tensor(int cols,
float val) |
Tensor(int rows,
int cols)
Creates a tensor with specified number of rows and columns.
|
Tensor(int rows,
int cols,
float[] values) |
Tensor(int rows,
int cols,
int depth)
Creates a 3D tensor with specified number of rows, cols and depth.
|
Tensor(int rows,
int cols,
int depth,
float[] values) |
Tensor(int rows,
int cols,
int depth,
int fourthDim) |
Tensor(int rows,
int cols,
int depth,
int fourthDim,
float[] values) |
Tensor(Shape shape,
float... values) |
Tensor(Tensor t)
Public deep copy / clone constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(float value,
int idx) |
void |
add(float value,
int row,
int col)
Adds specified value to matrix value at position x, y
|
void |
add(float value,
int row,
int col,
int z) |
void |
add(float value,
int row,
int col,
int z,
int fourth) |
void |
add(Tensor t)
Adds specified tensor t to this tensor.
|
void |
apply(Function<Float,Float> f) |
Tensor |
clone() |
Tensor |
copy() |
void |
copyFrom(float[] src) |
static Tensor |
create(int rows,
int cols,
float[] values)
Factory method for creating tensor instance,
|
static Tensor |
create(int rows,
int cols,
int depth,
float[] values) |
static Tensor |
create(int rows,
int cols,
int depth,
int fourthDim,
float[] values) |
void |
div(float value)
Divide all values in this tensor with specified value.
|
void |
div(float[] divisors) |
void |
div(Tensor t) |
boolean |
equals(Object obj) |
boolean |
equals(Tensor t2,
float delta) |
void |
fill(float value)
Fills the entire tensor with specified value.
|
static void |
fill(float[] array,
float val) |
float |
get(int idx)
Gets value at specified index position.
|
float |
get(int row,
int col)
Returns matrix value at row, col
|
float |
get(int row,
int col,
int z)
Returns value at specified index [row, col, z].
|
float |
get(int row,
int col,
int z,
int fourth) |
int |
getCols() |
int |
getDepth() |
int |
getFourthDim() |
int |
getRank()
Rank corresponds to number of dimensions in tensor.
|
int |
getRows() |
float[] |
getValues() |
float |
getWithStride(int[] idxs) |
int |
hashCode() |
float |
mean() |
void |
multiply(float m) |
void |
multiply(float mul,
int idx) |
void |
multiplyElementWise(Tensor tensor2) |
static Tensor |
of(float[] values) |
void |
randomize()
Randomize all values in tensor
|
void |
replace(float toReplace,
float replaceWith) |
void |
set(float val,
int idx)
Sets value at specified index position.
|
void |
set(float val,
int row,
int col)
Set value at specified [row, col] position.
|
void |
set(float val,
int row,
int col,
int z) |
void |
set(float val,
int row,
int col,
int z,
int fourth) |
void |
setValues(float... values) |
void |
setValuesFromString(String values)
Sets tensor values from CSV string.
|
int |
size()
Total number of values in tensor.
|
void |
sqrt() |
float |
std(float mean) |
void |
sub(float val) |
void |
sub(float val,
int row,
int col) |
void |
sub(float val,
int row,
int col,
int z) |
void |
sub(float val,
int row,
int col,
int z,
int fourth) |
void |
sub(Tensor t)
Subtracts specified tensor t from this tensor.
|
static void |
sub(Tensor t1,
Tensor t2)
Subtracts tensor t2 from t1.
|
float |
sumAbs()
Returns sum of abs values of this tensor - L1 norm
|
float |
sumSqr()
Returns sum of squared values of this tensor - L2 norm
|
String |
toString() |
static String |
valuesAsString(Tensor[] tensors) |
public Tensor(float... values)
values
- values of column tensorpublic Tensor(Shape shape, float... values)
public Tensor(float[][] vals)
vals
- values to put into matrixpublic Tensor(float[][][] vals)
vals
- 2D array of tensor valuespublic Tensor(float[][][][] vals)
public Tensor(int cols)
cols
- number of columnspublic Tensor(int cols, float val)
public Tensor(int rows, int cols)
rows
- number of rowscols
- number of columnspublic Tensor(int rows, int cols, float[] values)
public Tensor(int rows, int cols, int depth)
rows
- number of rowscols
- number of columnsdepth
- tensor depthpublic Tensor(int rows, int cols, int depth, int fourthDim)
public Tensor(int rows, int cols, int depth, int fourthDim, float[] values)
public Tensor(int rows, int cols, int depth, float[] values)
public Tensor(Tensor t)
t
- public final float get(int idx)
idx
- public final void set(float val, int idx)
idx
- val
- public final float get(int row, int col)
col
- row
- public final void set(float val, int row, int col)
val
- value to setrow
- tensor's row indexcol
- tensor's col indexpublic final float get(int row, int col, int z)
col
- row
- z
- public final void set(float val, int row, int col, int z)
public final float get(int row, int col, int z, int fourth)
public final void set(float val, int row, int col, int z, int fourth)
public final float getWithStride(int[] idxs)
public final float[] getValues()
public final void setValues(float... values)
public final void copyFrom(float[] src)
public final int getCols()
public final int getRows()
public final int getDepth()
public final int getFourthDim()
public final int getRank()
public final int size()
public final void add(float value, int idx)
public final void add(float value, int row, int col)
col
- row
- value
- public final void add(float value, int row, int col, int z)
public final void add(float value, int row, int col, int z, int fourth)
public final void add(Tensor t)
t
- tensor to addpublic final void sub(float val, int row, int col)
public final void sub(float val, int row, int col, int z)
public final void sub(float val, int row, int col, int z, int fourth)
public final void sub(Tensor t)
t
- tensor to subtractpublic final void sub(float val)
public static final void sub(Tensor t1, Tensor t2)
t1
- t2
- public final void div(float value)
value
- public final void div(float[] divisors)
public final void fill(float value)
value
- value used to fill tensorpublic static final void fill(float[] array, float val)
public final void div(Tensor t)
public Tensor copy()
public boolean equals(Tensor t2, float delta)
public void setValuesFromString(String values)
values
- string with comma separated tensor valuesexception
- if number of values in string does not match number of values in tensorpublic static Tensor create(int rows, int cols, float[] values)
rows
- cols
- values
- public static Tensor create(int rows, int cols, int depth, float[] values)
public static Tensor create(int rows, int cols, int depth, int fourthDim, float[] values)
public static Tensor of(float[] values)
public float sumAbs()
public float sumSqr()
public void randomize()
public void multiplyElementWise(Tensor tensor2)
public void multiply(float m)
public void multiply(float mul, int idx)
public void sqrt()
public float mean()
public float std(float mean)
public void replace(float toReplace, float replaceWith)
Copyright © 2022. All rights reserved.