module Num
Extended Modules
Defined in:
cl_tensor/internal/cache_op.crnum.cr
tensor/build.cr
tensor/internal/constants.cr
tensor/manipulate.cr
tensor/operators.cr
tensor/reductions.cr
tensor/work.cr
Constant Summary
-
ColMajor =
OrderType::ColMajor -
RowMajor =
OrderType::RowMajor -
VERSION =
"0.4.0dev" -
WORK_POOL =
WorkPool.new
Instance Method Summary
- #acos(a : Tensor | Enumerable)
- #acos(a : Number)
- #acos!(a : Tensor)
- #acosh(a : Tensor | Enumerable)
- #acosh(a : Number)
- #acosh!(a : Tensor)
- #acospi(a : ClTensor(Float32))
- #acospi!(a : ClTensor(Float32))
- #add(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #add(a : Tensor | Enumerable, b : Number)
- #add(a : Number, b : Tensor | Enumerable)
- #add(a : Number, b : Number)
- #add(a : ClTensor(Float32), b : ClTensor(Float32))
- #add!(a : Tensor, b : Tensor | Enumerable)
- #add!(a : Tensor, b : Number)
- #add!(a : ClTensor(Float32), b : ClTensor(Float32))
- #all(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
-
#all(a : Tensor | Enumerable)
Reduces a
Tensorto a boolean by asserting the truthiness of all elements -
#all_close(a : Tensor | Enumerable, b : Tensor | Enumerable, epsilon = 1e-6)
Asserts that two
Tensors are equal, allowing for small margins of errors with floating point values using an EPSILON value. - #any(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
-
#any(a : Tensor | Enumerable)
Reduces a
Tensorto a boolean by asserting the truthiness of any element - #asin(a : Tensor | Enumerable)
- #asin(a : Number)
- #asin(a : ClTensor(Float32))
- #asin!(a : Tensor)
- #asin!(a : ClTensor(Float32))
- #asinh(a : Tensor | Enumerable)
- #asinh(a : Number)
- #asinh(a : ClTensor(Float32))
- #asinh!(a : Tensor)
- #asinh!(a : ClTensor(Float32))
- #asinpi(a : ClTensor(Float32))
- #asinpi!(a : ClTensor(Float32))
- #atan(a : Tensor | Enumerable)
- #atan(a : Number)
- #atan(a : ClTensor(Float32))
- #atan!(a : Tensor)
- #atan!(a : ClTensor(Float32))
- #atan2(a : Tensor, b : Tensor | Enumerable)
- #atan2(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #atan2(a : Tensor | Enumerable, b : Number)
- #atan2(a : Number, b : Tensor | Enumerable)
- #atan2(a : Number, b : Number)
- #atan2!(a : Tensor, b : Number)
- #atanh(a : Tensor | Enumerable)
- #atanh(a : Number)
- #atanh(a : ClTensor(Float32))
- #atanh!(a : Tensor)
- #atanh!(a : ClTensor(Float32))
- #atanpi(a : ClTensor(Float32))
- #atanpi!(a : ClTensor(Float32))
- #besselj(a : Tensor, b : Tensor | Enumerable)
- #besselj(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #besselj(a : Tensor | Enumerable, b : Number)
- #besselj(a : Number, b : Tensor | Enumerable)
- #besselj(a : Number, b : Number)
- #besselj!(a : Tensor, b : Number)
- #besselj0(a : Tensor | Enumerable)
- #besselj0(a : Number)
- #besselj0!(a : Tensor)
- #besselj1(a : Tensor | Enumerable)
- #besselj1(a : Number)
- #besselj1!(a : Tensor)
- #bessely(a : Tensor, b : Tensor | Enumerable)
- #bessely(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #bessely(a : Tensor | Enumerable, b : Number)
- #bessely(a : Number, b : Tensor | Enumerable)
- #bessely(a : Number, b : Number)
- #bessely!(a : Tensor, b : Number)
- #bessely0(a : Tensor | Enumerable)
- #bessely0(a : Number)
- #bessely0!(a : Tensor)
- #bessely1(a : Tensor | Enumerable)
- #bessely1(a : Number)
- #bessely1!(a : Tensor)
- #bitwise_and(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #bitwise_and(a : Tensor | Enumerable, b : Number)
- #bitwise_and(a : Number, b : Tensor | Enumerable)
- #bitwise_and(a : Number, b : Number)
- #bitwise_and!(a : Tensor, b : Tensor | Enumerable)
- #bitwise_and!(a : Tensor, b : Number)
- #bitwise_or(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #bitwise_or(a : Tensor | Enumerable, b : Number)
- #bitwise_or(a : Number, b : Tensor | Enumerable)
- #bitwise_or(a : Number, b : Number)
- #bitwise_or!(a : Tensor, b : Tensor | Enumerable)
- #bitwise_or!(a : Tensor, b : Number)
- #bitwise_xor(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #bitwise_xor(a : Tensor | Enumerable, b : Number)
- #bitwise_xor(a : Number, b : Tensor | Enumerable)
- #bitwise_xor(a : Number, b : Number)
- #bitwise_xor!(a : Tensor, b : Tensor | Enumerable)
- #bitwise_xor!(a : Tensor, b : Number)
- #cbrt(a : Tensor | Enumerable)
- #cbrt(a : Number)
- #cbrt(a : ClTensor(Float32))
- #cbrt!(a : Tensor)
- #cbrt!(a : ClTensor(Float32))
- #ceil(a : ClTensor(Float32))
- #ceil!(a : ClTensor(Float32))
-
#concat(t_array : Array(Tensor | Enumerable), axis : Int)
Join a sequence of
Tensors along an existing axis. -
#concat(t_array : Array(Tensor | Enumerable))
Join a sequence of one dimensional
Tensors along the first axis, creating a one-dimensional output -
#concat(*t_args : Tensor | Enumerable, axis : Int)
Join a sequence of
Tensors along an existing axis. -
#concat(*t_args : Tensor | Enumerable)
Join a sequence of one dimensional
Tensors along the first axis, creating a one-dimensional output - #conj(t : Tensor(U)) forall U
- #copysign(a : Tensor, b : Tensor | Enumerable)
- #copysign(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #copysign(a : Tensor | Enumerable, b : Number)
- #copysign(a : Number, b : Tensor | Enumerable)
- #copysign(a : Number, b : Number)
- #copysign!(a : Tensor, b : Number)
- #cos(a : Tensor | Enumerable)
- #cos(a : Number)
- #cos(a : ClTensor(Float32))
- #cos!(a : Tensor)
- #cos!(a : ClTensor(Float32))
- #cosh(a : Tensor | Enumerable)
- #cosh(a : Number)
- #cosh(a : ClTensor(Float32))
- #cosh!(a : Tensor)
- #cosh!(a : ClTensor(Float32))
- #cospi(a : ClTensor(Float32))
- #cospi!(a : ClTensor(Float32))
- #cumsum(t : Tensor | Enumerable, axis : Int)
-
#cumsum(a : Tensor | Enumerable)
Accumulate a
Tensoras though it is flat. - #divide(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #divide(a : Tensor | Enumerable, b : Number)
- #divide(a : Number, b : Tensor | Enumerable)
- #divide(a : Number, b : Number)
- #divide(a : ClTensor(Float32), b : ClTensor(Float32))
- #divide!(a : Tensor, b : Tensor | Enumerable)
- #divide!(a : Tensor, b : Number)
- #divide!(a : ClTensor(Float32), b : ClTensor(Float32))
- #equal(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #equal(a : Tensor | Enumerable, b : Number)
- #equal(a : Number, b : Tensor | Enumerable)
- #equal(a : Number, b : Number)
- #equal!(a : Tensor, b : Tensor | Enumerable)
- #equal!(a : Tensor, b : Number)
- #erf(a : Tensor | Enumerable)
- #erf(a : Number)
- #erf(a : ClTensor(Float32))
- #erf!(a : Tensor)
- #erf!(a : ClTensor(Float32))
- #erfc(a : Tensor | Enumerable)
- #erfc(a : Number)
- #erfc(a : ClTensor(Float32))
- #erfc!(a : Tensor)
- #erfc!(a : ClTensor(Float32))
- #exp(a : Tensor | Enumerable)
- #exp(a : Number)
- #exp(a : ClTensor(Float32))
- #exp!(a : Tensor)
- #exp!(a : ClTensor(Float32))
- #exp10(a : ClTensor(Float32))
- #exp10!(a : ClTensor(Float32))
- #exp2(a : Tensor | Enumerable)
- #exp2(a : Number)
- #exp2(a : ClTensor(Float32))
- #exp2!(a : Tensor)
- #exp2!(a : ClTensor(Float32))
- #expm1(a : Tensor | Enumerable)
- #expm1(a : Number)
- #expm1(a : ClTensor(Float32))
- #expm1!(a : Tensor)
- #expm1!(a : ClTensor(Float32))
- #fabs(a : ClTensor(Float32))
- #fabs!(a : ClTensor(Float32))
-
#flip(a : Tensor | Enumerable, axis : Int)
Flips a
Tensoralong an axis, returning a view -
#flip(a : Tensor | Enumerable)
Flips a
Tensoralong all axes, returning a view - #floor(a : ClTensor(Float32))
- #floor!(a : ClTensor(Float32))
- #floordiv(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #floordiv(a : Tensor | Enumerable, b : Number)
- #floordiv(a : Number, b : Tensor | Enumerable)
- #floordiv(a : Number, b : Number)
- #floordiv!(a : Tensor, b : Tensor | Enumerable)
- #floordiv!(a : Tensor, b : Number)
- #gamma(a : Tensor | Enumerable)
- #gamma(a : Number)
- #gamma!(a : Tensor)
- #greater(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #greater(a : Tensor | Enumerable, b : Number)
- #greater(a : Number, b : Tensor | Enumerable)
- #greater(a : Number, b : Number)
- #greater!(a : Tensor, b : Tensor | Enumerable)
- #greater!(a : Tensor, b : Number)
- #greater_equal(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #greater_equal(a : Tensor | Enumerable, b : Number)
- #greater_equal(a : Number, b : Tensor | Enumerable)
- #greater_equal(a : Number, b : Number)
- #greater_equal!(a : Tensor, b : Tensor | Enumerable)
- #greater_equal!(a : Tensor, b : Number)
-
#h_concat(t_array : Array(Tensor | Enumerable))
Stack an array of
Tensors in sequence column-wise. -
#h_concat(*t_args : Tensor | Enumerable)
Stack an array of
Tensors in sequence column-wise. - #hypot(a : Tensor, b : Tensor | Enumerable)
- #hypot(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #hypot(a : Tensor | Enumerable, b : Number)
- #hypot(a : Number, b : Tensor | Enumerable)
- #hypot(a : Number, b : Number)
- #hypot!(a : Tensor, b : Number)
- #ilogb(a : Tensor | Enumerable)
- #ilogb(a : Number)
- #ilogb!(a : Tensor)
- #ldexp(a : Tensor, b : Tensor | Enumerable)
- #ldexp(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #ldexp(a : Tensor | Enumerable, b : Number)
- #ldexp(a : Number, b : Tensor | Enumerable)
- #ldexp(a : Number, b : Number)
- #ldexp!(a : Tensor, b : Number)
- #left_shift(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #left_shift(a : Tensor | Enumerable, b : Number)
- #left_shift(a : Number, b : Tensor | Enumerable)
- #left_shift(a : Number, b : Number)
- #left_shift!(a : Tensor, b : Tensor | Enumerable)
- #left_shift!(a : Tensor, b : Number)
- #less(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #less(a : Tensor | Enumerable, b : Number)
- #less(a : Number, b : Tensor | Enumerable)
- #less(a : Number, b : Number)
- #less!(a : Tensor, b : Tensor | Enumerable)
- #less!(a : Tensor, b : Number)
- #less_equal(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #less_equal(a : Tensor | Enumerable, b : Number)
- #less_equal(a : Number, b : Tensor | Enumerable)
- #less_equal(a : Number, b : Number)
- #less_equal!(a : Tensor, b : Tensor | Enumerable)
- #less_equal!(a : Tensor, b : Number)
- #lgamma(a : Tensor | Enumerable)
- #lgamma(a : Number)
- #lgamma(a : ClTensor(Float32))
- #lgamma!(a : Tensor)
- #lgamma!(a : ClTensor(Float32))
- #log(a : Tensor | Enumerable)
- #log(a : Number)
- #log(a : ClTensor(Float32))
- #log!(a : Tensor)
- #log!(a : ClTensor(Float32))
- #log10(a : Tensor | Enumerable)
- #log10(a : Number)
- #log10(a : ClTensor(Float32))
- #log10!(a : Tensor)
- #log10!(a : ClTensor(Float32))
- #log1p(a : Tensor | Enumerable)
- #log1p(a : Number)
- #log1p(a : ClTensor(Float32))
- #log1p!(a : Tensor)
- #log1p!(a : ClTensor(Float32))
- #log2(a : Tensor | Enumerable)
- #log2(a : Number)
- #log2(a : ClTensor(Float32))
- #log2!(a : Tensor)
- #log2!(a : ClTensor(Float32))
- #logb(a : Tensor | Enumerable)
- #logb(a : Number)
- #logb(a : ClTensor(Float32))
- #logb!(a : Tensor)
- #logb!(a : ClTensor(Float32))
- #max(a : Tensor, b : Tensor | Enumerable)
- #max(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #max(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
- #max(a : Tensor | Enumerable, b : Number)
- #max(a : Number, b : Tensor | Enumerable)
- #max(a : Number, b : Number)
-
#max(a : Tensor | Enumerable)
Reduces a
Tensorto a scalar by finding the maximum value - #max!(a : Tensor, b : Number)
- #mean(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
-
#mean(a : Tensor | Enumerable)
Reduces a
Tensorto a scalar by finding the average - #min(a : Tensor, b : Tensor | Enumerable)
- #min(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #min(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
- #min(a : Tensor | Enumerable, b : Number)
- #min(a : Number, b : Tensor | Enumerable)
- #min(a : Number, b : Number)
-
#min(a : Tensor | Enumerable)
Reduces a
Tensorto a scalar by finding the minimum value - #min!(a : Tensor, b : Number)
- #modulo(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #modulo(a : Tensor | Enumerable, b : Number)
- #modulo(a : Number, b : Tensor | Enumerable)
- #modulo(a : Number, b : Number)
- #modulo!(a : Tensor, b : Tensor | Enumerable)
- #modulo!(a : Tensor, b : Number)
- #multiply(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #multiply(a : Tensor | Enumerable, b : Number)
- #multiply(a : Number, b : Tensor | Enumerable)
- #multiply(a : Number, b : Number)
- #multiply(a : ClTensor(Float32), b : ClTensor(Float32))
- #multiply!(a : Tensor, b : Tensor | Enumerable)
- #multiply!(a : Tensor, b : Number)
- #multiply!(a : ClTensor(Float32), b : ClTensor(Float32))
- #not_equal(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #not_equal(a : Tensor | Enumerable, b : Number)
- #not_equal(a : Number, b : Tensor | Enumerable)
- #not_equal(a : Number, b : Number)
- #not_equal!(a : Tensor, b : Tensor | Enumerable)
- #not_equal!(a : Tensor, b : Number)
- #power(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #power(a : Tensor | Enumerable, b : Number)
- #power(a : Number, b : Tensor | Enumerable)
- #power(a : Number, b : Number)
- #power!(a : Tensor, b : Tensor | Enumerable)
- #power!(a : Tensor, b : Number)
- #prod(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
-
#prod(a : Tensor | Enumerable)
Reduces a
Tensorto a scalar by multiplying all of its elements -
#ptp(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
Finds the difference between the maximum and minimum elements of a
Tensoralong an axis -
#ptp(a : Tensor | Enumerable)
Finds the difference between the maximum and minimum elements of a
Tensor -
#repeat(a : Tensor | Enumerable, n : Int, axis : Int)
Repeat elements of a
Tensoralong an axis - #repeat(a : Tensor | Enumerable, n : Int)
- #right_shift(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #right_shift(a : Tensor | Enumerable, b : Number)
- #right_shift(a : Number, b : Tensor | Enumerable)
- #right_shift(a : Number, b : Number)
- #right_shift!(a : Tensor, b : Tensor | Enumerable)
- #right_shift!(a : Tensor, b : Number)
- #rint(a : ClTensor(Float32))
- #rint!(a : ClTensor(Float32))
- #round(a : ClTensor(Float32))
- #round!(a : ClTensor(Float32))
- #rsqrt(a : ClTensor(Float32))
- #rsqrt!(a : ClTensor(Float32))
- #sin(a : Tensor | Enumerable)
- #sin(a : Number)
- #sin(a : ClTensor(Float32))
- #sin!(a : Tensor)
- #sin!(a : ClTensor(Float32))
- #sinh(a : Tensor | Enumerable)
- #sinh(a : Number)
- #sinh(a : ClTensor(Float32))
- #sinh!(a : Tensor)
- #sinh!(a : ClTensor(Float32))
- #sinpi(a : ClTensor(Float32))
- #sinpi!(a : ClTensor(Float32))
- #sqrt(a : Tensor | Enumerable)
- #sqrt(a : Number)
- #sqrt(a : ClTensor(Float32))
- #sqrt!(a : Tensor)
- #sqrt!(a : ClTensor(Float32))
- #std(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
-
#std(a : Tensor | Enumerable)
Reduces a
Tensorto a scalar by finding the standard deviation - #subtract(a : Tensor | Enumerable, b : Tensor | Enumerable)
- #subtract(a : Tensor | Enumerable, b : Number)
- #subtract(a : Number, b : Tensor | Enumerable)
- #subtract(a : Number, b : Number)
- #subtract(a : ClTensor(Float32), b : ClTensor(Float32))
- #subtract!(a : Tensor, b : Tensor | Enumerable)
- #subtract!(a : Tensor, b : Number)
- #subtract!(a : ClTensor(Float32), b : ClTensor(Float32))
- #sum(a : Tensor | Enumerable, axis : Int, dims : Bool = false)
-
#sum(a : Tensor | Enumerable)
Reduces a
Tensorto a scalar by summing all of its elements - #tan(a : Tensor | Enumerable)
- #tan(a : Number)
- #tan(a : ClTensor(Float32))
- #tan!(a : Tensor)
- #tan!(a : ClTensor(Float32))
- #tanh(a : Tensor | Enumerable)
- #tanh(a : Number)
- #tanh(a : ClTensor(Float32))
- #tanh!(a : Tensor)
- #tanh!(a : ClTensor(Float32))
- #tanpi(a : ClTensor(Float32))
- #tanpi!(a : ClTensor(Float32))
- #tgamma(a : ClTensor(Float32))
- #tgamma!(a : ClTensor(Float32))
-
#tile(a : Tensor | Enumerable, n : Int)
Tile elements of a
Tensor -
#tile(a : Tensor | Enumerable, n : Array(Int))
Tile elements of a
Tensor - #trunc(a : ClTensor(Float32))
- #trunc!(a : ClTensor(Float32))
-
#v_concat(t_array : Array(Tensor | Enumerable))
Stack an array of
Tensors in sequence row-wise. -
#v_concat(*t_args : Tensor | Enumerable)
Stack an array of
Tensors in sequence row-wise. - #value_counts(a : Tensor(U)) forall U
Macro Summary
Instance Method Detail
Reduces a Tensor along an axis, asserting the truthiness of all values
in each view into the Tensor
Arguments
a : Tensor | Enumerable Argument to reduce axis : Int Axis of reduction dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.all(a, 0) # => [false, true]
Num.all(a, 1, dims: true)
# [[false],
# [ true]]
Reduces a Tensor to a boolean by asserting the truthiness of
all elements
Arguments
a : Tensor | Enumerable Argument to reduce
Examples
a = [0, 2, 3]
Num.all(a) # => false
Asserts that two Tensors are equal, allowing for small
margins of errors with floating point values using
an EPSILON value.
Arguments
a : Tensor | Enumerable
First Tensor to compare
b : Tensor | Enumerable
Second Tensor to compare
epsilon : Number
Allowed variance between numbers
Examples
a = [0.0, 0.0, 0.0000000001].to_tensor
b = [0.0, 0.0, 0.0].to_tensor
Num.all_close(a, b) # => true
Reduces a Tensor along an axis, asserting the truthiness of any values
in each view into the Tensor
Arguments
a : Tensor | Enumerable Argument to reduce axis : Int Axis of reduction dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.any(a, 0) # => [true, true]
Num.any(a, 1, dims: true)
# [[true],
# [ true]]
Reduces a Tensor to a boolean by asserting the truthiness of
any element
Arguments
a : Tensor | Enumerable Argument to reduce
Examples
a = [0, 2, 3]
Num.any(a) # => true
Join a sequence of Tensors along an existing axis. The Tensors
must have the same shape for all axes other than the axis of
concatenation
Arguments
t_array : Array(Tensor | Enumerable)
Array of items to concatenate. All elements
will be cast to Tensor, so arrays can be passed here, but
all inputs must have the same generic type. Union types
are not allowed
axis : Int
Axis of concatenation, negative axes are allowed
Examples
a = [1, 2, 3]
b = Tensor.from_array [4, 5, 6]
Num.concat([a, b], 0) # => [1, 2, 3, 4, 5, 6]
c = Tensor.new([3, 2, 2]) { |i| i / 2 }
Num.concat([c, c, c], -1)
# [[[0 , 0.5, 0 , 0.5, 0 , 0.5],
# [1 , 1.5, 1 , 1.5, 1 , 1.5]],
#
# [[2 , 2.5, 2 , 2.5, 2 , 2.5],
# [3 , 3.5, 3 , 3.5, 3 , 3.5]],
#
# [[4 , 4.5, 4 , 4.5, 4 , 4.5],
# [5 , 5.5, 5 , 5.5, 5 , 5.5]]]
Join a sequence of one dimensional Tensors along the first axis,
creating a one-dimensional output
Arguments
t_array : Array(Tensor | Enumerable)
Array of items to concatenate. All elements
will be cast to Tensor, so arrays can be passed here, but
all inputs must have the same generic type. Union types
are not allowed
Examples
a = [1, 2, 3]
b = Tensor.from_array [4, 5, 6]
Num.concat([a, b]) # => [1, 2, 3, 4, 5, 6]
Join a sequence of Tensors along an existing axis. The Tensors
must have the same shape for all axes other than the axis of
concatenation
Arguments
t_array : Array(Tensor | Enumerable)
Array of items to concatenate. All elements
will be cast to Tensor, so arrays can be passed here, but
all inputs must have the same generic type. Union types
are not allowed
axis : Int
Axis of concatenation, negative axes are allowed
Examples
a = [1, 2, 3]
b = Tensor.from_array [4, 5, 6]
Num.concat([a, b], 0) # => [1, 2, 3, 4, 5, 6]
c = Tensor.new([3, 2, 2]) { |i| i / 2 }
Num.concat([c, c, c], -1)
# [[[0 , 0.5, 0 , 0.5, 0 , 0.5],
# [1 , 1.5, 1 , 1.5, 1 , 1.5]],
#
# [[2 , 2.5, 2 , 2.5, 2 , 2.5],
# [3 , 3.5, 3 , 3.5, 3 , 3.5]],
#
# [[4 , 4.5, 4 , 4.5, 4 , 4.5],
# [5 , 5.5, 5 , 5.5, 5 , 5.5]]]
Join a sequence of one dimensional Tensors along the first axis,
creating a one-dimensional output
Arguments
t_array : Array(Tensor | Enumerable)
Array of items to concatenate. All elements
will be cast to Tensor, so arrays can be passed here, but
all inputs must have the same generic type. Union types
are not allowed
Examples
a = [1, 2, 3]
b = Tensor.from_array [4, 5, 6]
Num.concat([a, b]) # => [1, 2, 3, 4, 5, 6]
Accumulate's a Tensor along an axis, summing each view into
the Tensor
Arguments
a : Tensor | Enumerable Argument to sum axis : Int Axis of summation
Examples
a = Tensor.new([3, 3, 2]) { |i| i }
Num.cumsum(a, 0)
# [[[ 0, 1],
# [ 2, 3],
# [ 4, 5]],
#
# [[ 6, 8],
# [10, 12],
# [14, 16]],
#
# [[18, 21],
# [24, 27],
# [30, 33]]]
Accumulate a Tensor as though it is flat. Returning a one dimensional
result.
Arguments
a : Tensor | Enumerable Tensor to accumulate. Will be treated as one-dimensional
Examples
a = [1, 2, 3]
Num.cumsum(a) # => [1, 3, 6]
Flips a Tensor along an axis, returning a view
Arguments
a: Tensor | Enumerable Argument to flipaxis: Int Axis to flip
Examples
a = [[1, 2, 3], [4, 5, 6]]
puts Num.flip(a, 1)
# [[3, 2, 1],
# [6, 5, 4]]
Flips a Tensor along all axes, returning a view
Arguments
a: Tensor | Enumerable Argument to flip
Examples
a = [[1, 2, 3], [4, 5, 6]]
puts Num.flip(a)
# [[6, 5, 4],
# [3, 2, 1]]
Stack an array of Tensors in sequence column-wise. While this
method can take Tensors with any number of dimensions, it makes
the most sense with rank <= 3
For one dimensional Tensors, this will still stack along the
first axis
Arguments
t_array : Array(Tensor | Enumerable)
Tensors to concatenate
Examples
a = [1, 2, 3].to_tensor
Num.h_concat([a, a]) # => [1, 2, 3, 1, 2, 3]
b = [[1, 2], [3, 4]].to_tensor
Num.h_concat([b, b])
# [[1, 2, 1, 2],
# [3, 4, 3, 4]]
Stack an array of Tensors in sequence column-wise. While this
method can take Tensors with any number of dimensions, it makes
the most sense with rank <= 3
For one dimensional Tensors, this will still stack along the
first axis
Arguments
t_array : Array(Tensor | Enumerable)
Tensors to concatenate
Examples
a = [1, 2, 3].to_tensor
Num.h_concat([a, a]) # => [1, 2, 3, 1, 2, 3]
b = [[1, 2], [3, 4]].to_tensor
Num.h_concat([b, b])
# [[1, 2, 1, 2],
# [3, 4, 3, 4]]
Reduces a Tensor along an axis, finding the max of each
view into the Tensor
Arguments
a : Tensor | Enumerable Argument to reduce axis : Int Axis of reduction dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.max(a, 0) # => [2, 3]
Num.max(a, 1, dims: true)
# [[1],
# [3]]
Reduces a Tensor to a scalar by finding the maximum value
Arguments
a : Tensor | Enumerable Argument to reduce
Examples
a = [1, 2, 3]
Num.max(a) # => 3
Reduces a Tensor along an axis, finding the average of each
view into the Tensor
Arguments
a : Tensor | Enumerable Argument to reduce axis : Int Axis of reduction dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.mean(a, 0) # => [1, 2]
Num.mean(a, 1, dims: true)
# [[0],
# [2]]
Reduces a Tensor to a scalar by finding the average
Arguments
a : Tensor | Enumerable Argument to reduce
Examples
a = [1, 2, 3]
Num.mean(a) # => 2.0
Reduces a Tensor along an axis, finding the min of each
view into the Tensor
Arguments
a : Tensor | Enumerable Argument to reduce axis : Int Axis of reduction dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.min(a, 0) # => [0, 1]
Num.min(a, 1, dims: true)
# [[0],
# [2]]
Reduces a Tensor to a scalar by finding the minimum value
Arguments
a : Tensor | Enumerable Argument to reduce
Examples
a = [1, 2, 3]
Num.min(a) # => 3
Reduces a Tensor along an axis, multiplying each view into
the Tensor
Arguments
a : Tensor | Enumerable Argument to reduce axis : Int Axis of reduction dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.prod(a, 0) # => [0, 3]
Num.prod(a, 1, dims: true)
# [[0],
# [6]]
Reduces a Tensor to a scalar by multiplying all of its
elements
Arguments
a : Tensor | Enumerable Argument to reduce
Examples
a = [1, 2, 3]
Num.prod(a) # => 6
Finds the difference between the maximum and minimum
elements of a Tensor along an axis
Arguments
a : Tensor Argument to reduce axis : Tensor Axis of reduction dims : Bool Keep axis of reduction in output
Examples
a = [[3, 4], [1, 2], [6, 2]]
Num.ptp(a, 1) # [1, 1, 4]
Finds the difference between the maximum and minimum
elements of a Tensor
Arguments
a : Tensor to find peak to peak value
Examples
a = [1, 2, 3]
Num.ptp(a) # => 2
Repeat elements of a Tensor along an axis
Arguments
a: Tensor | Enumerable Object to repeatn: Int Number of times to repeataxis: Int Axis along which to repeat
Examples
a = [[1, 2, 3], [4, 5, 6]]
Num.repeat(a, 2, 1)
# [[1, 1, 2, 2, 3, 3],
# [4, 4, 5, 5, 6, 6]]
Repeat elements of a Tensor, treating the Tensor
as flat
Arguments
a: Tensor | Enumerable Object to repeatn: Int Number of times to repeat
Examples
a = [1, 2, 3]
Num.repeat(a, 2) # => [1, 1, 2, 2, 3, 3]
Reduces a Tensor along an axis, finding the std of each
view into the Tensor
Arguments
a : Tensor | Enumerable Argument to reduce axis : Int Axis of reduction dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.std(a, 0) # => [1, 1]
Num.std(a, 1, dims: true)
# [[0.707107],
# [0.707107]]
Reduces a Tensor to a scalar by finding the standard deviation
Arguments
a : Tensor | Enumerable Argument to reduce
Examples
a = [1, 2, 3]
Num.std(a) # => 0.816496580927726
Reduces a Tensor along an axis, summing each view into
the Tensor
Arguments
a : Tensor | Enumerable Argument to sum axis : Int Axis of summation dims : Bool Indicate if the axis of reduction should remain in the result
Examples
a = Tensor.new([2, 2]) { |i| i }
Num.sum(a, 0) # => [2, 4]
Num.sum(a, 1, dims: true)
# [[1],
# [5]]
Reduces a Tensor to a scalar by summing all of its
elements
Arguments
a : Tensor | Enumerable Argument to sum
Examples
a = [1, 2, 3]
Num.sum(a) # => 6
Tile elements of a Tensor
Arguments
a: Tensor | Enumerable Argument to tilen: Int Number of times to tile
Examples
a = [[1, 2, 3], [4, 5, 6]]
puts Num.tile(a, 2)
# [[1, 2, 3, 1, 2, 3],
# [4, 5, 6, 4, 5, 6]]
Tile elements of a Tensor
Arguments
a: Tensor | Enumerable Argument to tilen: Array(Int) Number of times to tile in each dimension
Examples
a = [[1, 2, 3], [4, 5, 6]]
puts Num.tile(a, [2, 2])
# [[1, 2, 3, 1, 2, 3],
# [4, 5, 6, 4, 5, 6],
# [1, 2, 3, 1, 2, 3],
# [4, 5, 6, 4, 5, 6]]
Stack an array of Tensors in sequence row-wise. While this
method can take Tensors with any number of dimensions, it makes
the most sense with rank <= 3
Arguments
t_array : Array(Tensor | Enumerable)
Tensors to concatenate
Examples
a = [1, 2, 3].to_tensor
Num.v_concat([a, a])
# [[1, 2, 3],
# [1, 2, 3]]
Stack an array of Tensors in sequence row-wise. While this
method can take Tensors with any number of dimensions, it makes
the most sense with rank <= 3
Arguments
t_array : Array(Tensor | Enumerable)
Tensors to concatenate
Examples
a = [1, 2, 3].to_tensor
Num.v_concat([a, a])
# [[1, 2, 3],
# [1, 2, 3]]