Numerix v0.6.0 Numerix.Tensor View Source
Defines a data structure for a tensor and its operations.
You can construct a Tensor
by calling Tensor.new/1
and passing it a list, or a list of lists, or a list of lists of...you get the idea.
Example
use Numerix.Tensor
x = Tensor.new([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Once you have a Tensor
(or three), you can then use it in normal math operations, e.g. elementwise matrix operations.
Example
x = Tensor.new([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
y = Tensor.new([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
assert x / y == Tensor.new([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
As it turns out, this is very handy when you need to implement complex math formulae as the code looks more like math functions than noisy code with a bunch of calls to Enum.map/2
, Enum.zip/2
and the like.
Example
x = Tensor.new([[0, 0.1, 0.5, 0.9, 1.0]])
m = max(x)
e = exp(x - m)
s = sum(e)
assert e / s == Tensor.new([[0.1119598021340303, 0.12373471731203411, 0.18459050724175335, 0.2753766776533774, 0.30433829565880477]])
Oh, I should also mention that this API uses Flow
to parallelize independent pieces of computation to speed things up! Depending on the type of calculations you're doing, the bigger the data and the more cores you have, the faster it gets.
Link to this section Summary
Functions
Returns the result of applying *
to the given tensors element-wise.
Returns the result of applying +
to the given tensor element-wise.
Returns the result of applying +
to the given tensors element-wise.
Returns the result of applying -
to the given tensor element-wise.
Returns the result of applying -
to the given tensors element-wise.
Returns the result of applying /
to the given tensors element-wise.
Returns the result of applying abs
to the given tensor element-wise.
Returns the exp
of the given tensor element-wise.
Returns the log
of the given tensor element-wise.
Returns the biggest element in the given tensor.
Compares each element of the two given tensors element-wise and returns the biggest value.
Creates a new tensor from the given scalar, list or nested list.
Returns the result of applying pow
to the given tensor element-wise.
Returns the sqrt
of the given tensor element-wise.
Calculates the sum of all the elements in the given tensor.
Applies the given function to the tensor element-wise and returns the result as a new tensor.
Applies the given function to the two tensors element-wise and returns the result as a new tensor.
Returns the tanh
of the given tensor element-wise.
Link to this section Functions
Returns the result of applying *
to the given tensors element-wise.
Returns the result of applying +
to the given tensor element-wise.
Returns the result of applying +
to the given tensors element-wise.
Returns the result of applying -
to the given tensor element-wise.
Returns the result of applying -
to the given tensors element-wise.
Returns the result of applying /
to the given tensors element-wise.
Returns the result of applying abs
to the given tensor element-wise.
Returns the exp
of the given tensor element-wise.
Returns the log
of the given tensor element-wise.
Returns the biggest element in the given tensor.
max(s, x)
View Sourcemax(number(), %Numerix.Tensor{dims: term(), items: term(), shape: term()}) :: %Numerix.Tensor{dims: term(), items: term(), shape: term()}
max( %Numerix.Tensor{dims: term(), items: term(), shape: term()}, %Numerix.Tensor{dims: term(), items: term(), shape: term()} ) :: %Numerix.Tensor{dims: term(), items: term(), shape: term()}
Compares each element of the two given tensors element-wise and returns the biggest value.
Creates a new tensor from the given scalar, list or nested list.
Returns the result of applying pow
to the given tensor element-wise.
Returns the sqrt
of the given tensor element-wise.
Calculates the sum of all the elements in the given tensor.
Applies the given function to the tensor element-wise and returns the result as a new tensor.
Applies the given function to the two tensors element-wise and returns the result as a new tensor.
Returns the tanh
of the given tensor element-wise.