Class Tensor
java.lang.Object
io.github.kirstenali.deepj.tensor.Tensor
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidadamWUpdate(Tensor w, Tensor g, Tensor mt, Tensor vt, float lr, float beta1, float beta2, float eps, float weightDecay, float bc1, float bc2) addBroadcastCols(Tensor colVector) addBroadcastRows(Tensor rowVector) addInPlace(Tensor b) addRowVector(Tensor rowVector) addScalar(float s) addScalarInPlace(float s) static TensorBackendbackend()static TensorcausalMask(int size) clamp(float min, float max) crossEntropyGradient(int[] targets) floatcrossEntropyLoss(int[] targets) divideBroadcastCols(Tensor colVector) divideScalar(float s) divideScalarInPlace(float s) exp()static Tensorfrom2D(float[][] data) Build a tensor from 2-D row-major data.geluBackward(Tensor gradOutput) floatget(int r, int c) Get the GPU handle (used by GPU backends).getRow(int row) static TensorlayerNormBackward(Tensor dXHat, Tensor xHat, Tensor std, int dim) log()voidEnsures this tensor'sdata[]is up to date with any pending GPU computation.multiplyBroadcastCols(Tensor colVector) multiplyBroadcastRows(Tensor rowVector) multiplyScalar(float s) multiplyScalarInPlace(float s) neg()static Tensorones(int rows, int cols) pow(float exponent) voidstatic TensorreluBackward(Tensor gradOutput) static voidrequireSameShape(Tensor a, Tensor b, String op) static voidrequireTargetsMatchRows(Tensor logits, int[] targets) float[]rowData(int r) Returns a freshfloat[]copy of rowr.static TensorsampleRows(Tensor t, int n, Random rnd) static voidscatterAddRows(Tensor target, int[] indices, Tensor grad) voidset(int r, int c, float value) static voidsetBackend(TensorBackend backend) voidSet the GPU handle (used by GPU backends).voidstatic TensorsoftmaxBackward(Tensor softmaxOut) sqrt()subtractBroadcastCols(Tensor colVector) floatsum()floatsumAbs()sumRows()static Tensorzeros(int rows, int cols)
-
Field Details
-
data
public final float[] dataFlat row-major storage: element (r, c) lives at data[r * cols + c]. -
rows
public final int rows -
cols
public final int cols
-
-
Constructor Details
-
Tensor
public Tensor(int rows, int cols) -
Tensor
Copy constructor — creates an independent deep copy.
-
-
Method Details
-
getGpuTag
Get the GPU handle (used by GPU backends). -
setGpuTag
Set the GPU handle (used by GPU backends). -
setBackend
-
backend
-
rowData
public float[] rowData(int r) Returns a freshfloat[]copy of rowr. Convenience for tests and debugging; not a view. -
materialize
public void materialize()Ensures this tensor'sdata[]is up to date with any pending GPU computation. No-op if this tensor has no GPU handle or is already materialized. Call this before readingdata[]directly. -
matmul
-
add
-
subtract
-
multiply
-
divide
-
addRowVector
-
addBroadcastCols
-
divideBroadcastCols
-
subtractBroadcastCols
-
multiplyBroadcastCols
-
addBroadcastRows
-
multiplyBroadcastRows
-
multiplyScalar
-
addScalar
-
divideScalar
-
sumRows
-
sumAlongRows
-
sumAlongCols
-
meanAlongRows
-
varianceAlongRows
-
transpose
-
sqrt
-
neg
-
exp
-
log
-
tanhActivation
-
sigmoidActivation
-
reluActivation
-
reluBackward
-
geluActivation
-
geluBackward
-
addInPlace
-
subtractInPlace
-
multiplyInPlace
-
divideInPlace
-
multiplyScalarInPlace
-
addScalarInPlace
-
divideScalarInPlace
-
sqrtInPlace
-
negInPlace
-
expInPlace
-
logInPlace
-
reluInPlace
-
geluInPlace
-
tanhInPlace
-
sigmoidInPlace
-
softmaxRows
-
softmaxBackward
-
crossEntropyGradient
-
adamWUpdate
-
layerNormBackward
-
maxAlongRows
-
clamp
-
pow
-
scatterAddRows
-
from2D
Build a tensor from 2-D row-major data. Preferred API for literal matrix construction. -
sum
public float sum() -
sumAbs
public float sumAbs() -
crossEntropyLoss
public float crossEntropyLoss(int[] targets) -
get
public float get(int r, int c) -
set
public void set(int r, int c, float value) -
getRow
-
setRow
-
sliceRows
-
sampleRows
-
print
-
zeros
-
ones
-
random
-
causalMask
-
requireSameShape
-
requireTargetsMatchRows
-