module Num

Extended Modules

Defined in:

linalg/work.cr
num.cr
tensor/backends/agnostic/impl_index.cr
tensor/backends/agnostic/impl_manipulate.cr
tensor/backends/arrow/impl_allocation.cr
tensor/backends/arrow/impl_convert.cr
tensor/backends/arrow/impl_data_structure.cr
tensor/backends/arrow/impl_index.cr
tensor/backends/arrow/impl_iteration.cr
tensor/backends/arrow/impl_manipulate.cr
tensor/backends/arrow/impl_math.cr
tensor/backends/arrow/impl_reduction.cr
tensor/backends/cpu/impl_allocation.cr
tensor/backends/cpu/impl_convert.cr
tensor/backends/cpu/impl_data_structure.cr
tensor/backends/cpu/impl_index.cr
tensor/backends/cpu/impl_iteration.cr
tensor/backends/cpu/impl_manipulate.cr
tensor/backends/cpu/impl_math.cr
tensor/backends/cpu/impl_reduction.cr
tensor/backends/opencl/impl_convert.cr
tensor/backends/opencl/impl_data_structure.cr
tensor/backends/opencl/impl_index.cr
tensor/backends/opencl/impl_iteration.cr
tensor/backends/opencl/impl_manipulate.cr
tensor/backends/opencl/impl_math.cr
tensor/backends/opencl/impl_reduction.cr
tensor/backends/opencl/kernels/base.cr
tensor/backends/opencl/kernels/templates.cr
tensor/internal/enums.cr
tensor/internal/shape.cr

Constant Summary

ColMajor = OrderType::ColMajor
RowMajor = OrderType::RowMajor
VERSION = "0.5.0"

Instance Method Summary

Instance Method Detail

def acos(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method acos on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acos(a)

[View source]
def acos(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function acos for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.acos(a)

[View source]
def acos(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method acos on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acos(a)

[View source]
def acos!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method acos on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acos(a)

[View source]
def acos!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function acos for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.acos!(a)

[View source]
def acos!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method acos on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acos(a)

[View source]
def acosh(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method acosh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acosh(a)

[View source]
def acosh(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function acosh for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.acosh(a)

[View source]
def acosh(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method acosh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acosh(a)

[View source]
def acosh!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method acosh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acosh(a)

[View source]
def acosh!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function acosh for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.acosh!(a)

[View source]
def acosh!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method acosh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.acosh(a)

[View source]
def acospi(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function acospi for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.acospi(a)

[View source]
def acospi!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function acospi for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.acospi!(a)

[View source]
def add(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :+ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.add(a, b)

[View source]
def add(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :+ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.add(a, b)

[View source]
def add(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :+ operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.add(b, a)

[View source]
def add(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Add two Tensors elementwise

Arguments

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.add(a, a)

[View source]
def add(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Add a Tensor and a Number elementwise

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to add
  • b : U - RHS argument to add

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.add(a, 3.5)

[View source]
def add(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Add a Number and a Tensor elementwise

Arguments

  • a : U - LHS argument to add
  • b : Tensor(U, OCL(U)) - RHS argument to add

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.add(a, 3.5)

[View source]
def add(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :+ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.add(a, b)

[View source]
def add(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :+ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.add(a, b)

[View source]
def add(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :+ operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.add(b, a)

[View source]
def add!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :+ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.add!(a, b) # a is modified

[View source]
def add!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :+ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.add!(a, b)

[View source]
def add!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

"Add" two Tensors elementwise, storing the result in the first Tensor

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to add, will be modified inplace
  • b : Tensor(U, OCL(U)) - RHS argument to add

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.add!(a, a)

[View source]
def add!(a : Tensor(U, OCL(U)), b : U) : Nil forall U #

Add a Tensor and a Number elementwise, modifying the Tensor inplace.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to add
  • b : U - RHS argument to add

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.add(a, 3.5)

[View source]
def add!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :+ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.add!(a, b) # a is modified

[View source]
def add!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :+ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.add!(a, b)

[View source]
def all(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, asserting the truthiness of all values in each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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]]

[View source]
def all(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, asserting the truthiness of all values in each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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]]

[View source]
def all(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a boolean by asserting the truthiness of all elements

Arguments

Examples

a = [0, 2, 3]
Num.all(a) # => false

[View source]
def all(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a boolean by asserting the truthiness of all elements

Arguments

Examples

a = [0, 2, 3]
Num.all(a) # => false

[View source]
def all_close(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V)), epsilon = 1e-6) : Bool forall U, V #

Asserts that two Tensors are equal, allowing for small margins of errors with floating point values using an EPSILON value.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to compare
  • b : Tensor(V, CPU(V)) - RHS argument 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

[View source]
def all_close(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V)), epsilon = 1e-6) : Bool forall U, V #

Asserts that two Tensors are equal, allowing for small margins of errors with floating point values using an EPSILON value.

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to compare
  • b : Tensor(V, ARROW(V)) - RHS argument 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

[View source]
def any(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, asserting the truthiness of any values in each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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]]

[View source]
def any(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, asserting the truthiness of any values in each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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]]

[View source]
def any(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a boolean by asserting the truthiness of any element

Arguments

Examples

a = [0, 2, 3]
Num.any(a) # => true

[View source]
def any(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a boolean by asserting the truthiness of any element

Arguments

Examples

a = [0, 2, 3]
Num.any(a) # => true

[View source]
def argmax(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Find the maximum index value of a Tensor along an axis

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to reduce
  • axis : Int - Axis of reduction
  • dims : Bool - Indicate if the axis of reduction should remain in the result

Examples

a = [[2, 1], [1, 2]].to_tensor
puts a.argmax(1) # => [0, 1]

[View source]
def argmax(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Find the maximum index value of a Tensor along an axis

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to reduce
  • axis : Int - Axis of reduction
  • dims : Bool - Indicate if the axis of reduction should remain in the result

Examples

a = [[2, 1], [1, 2]].to_tensor
puts a.argmax(1) # => [0, 1]

[View source]
def argmax(a : Tensor(U, CPU(U))) : Int32 forall U #

Find the maximum index value of a Tensor

Arguments

Examples

a = [1, 10, 1].to_tensor
a.argmax # => 1

[View source]
def argmax(a : Tensor(U, ARROW(U))) : Int32 forall U #

Find the maximum index value of a Tensor

Arguments

Examples

a = [1, 10, 1].to_tensor
a.argmax # => 1

[View source]
def argmin(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Find the minimum index value of a Tensor along an axis

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to reduce
  • axis : Int - Axis of reduction
  • dims : Bool - Indicate if the axis of reduction should remain in the result

Examples

a = [[2, 1], [1, 2]].to_tensor
puts a.argmin(1) # => [1, 0]

[View source]
def argmin(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Find the minimum index value of a Tensor along an axis

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to reduce
  • axis : Int - Axis of reduction
  • dims : Bool - Indicate if the axis of reduction should remain in the result

Examples

a = [[2, 1], [1, 2]].to_tensor
puts a.argmin(1) # => [1, 0]

[View source]
def argmin(a : Tensor(U, CPU(U))) : Int32 forall U #

Find the minimum index value of a Tensor

Arguments

Examples

a = [10, 1, 10].to_tensor
a.argmin # => 1

[View source]
def argmin(a : Tensor(U, ARROW(U))) : Int32 forall U #

Find the minimum index value of a Tensor

Arguments

Examples

a = [10, 1, 10].to_tensor
a.argmin # => 1

[View source]
def array_split(a : Tensor(U, CPU(U)), ind : Int, axis : Int = 0) : Array(Tensor(U, CPU(U))) forall U #

Split a Tensor into multiple sub-Tensors

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to split`
  • ind : Int - Number of sections of resulting Array
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(9)
puts Num.array_split(a, 2) # => [[0, 1, 2, 3, 4], [5, 6, 7, 8]]

[View source]
def array_split(a : Tensor(U, CPU(U)), ind : Array(Int), axis : Int = 0) : Array(Tensor(U, CPU(U))) forall U #

Split a Tensor into multiple sub-Tensors, using an explicit mapping of indices to split the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to split`
  • ind : Int - Array of indices to use when splitting the Tensor
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(9)
puts Num.array_split(a, [1, 3, 5]) # => [[0], [1, 2], [3, 4], [5, 6, 7, 8]]

[View source]
def array_split(a : Tensor(U, ARROW(U)), ind : Int, axis : Int = 0) : Array(Tensor(U, ARROW(U))) forall U #

Split a Tensor into multiple sub-Tensors

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to split`
  • ind : Int - Number of sections of resulting Array
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(9)
puts Num.array_split(a, 2) # => [[0, 1, 2, 3, 4], [5, 6, 7, 8]]

[View source]
def array_split(a : Tensor(U, ARROW(U)), ind : Array(Int), axis : Int = 0) : Array(Tensor(U, ARROW(U))) forall U #

Split a Tensor into multiple sub-Tensors, using an explicit mapping of indices to split the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to split`
  • ind : Int - Array of indices to use when splitting the Tensor
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(9)
puts Num.array_split(a, [1, 3, 5]) # => [[0], [1, 2], [3, 4], [5, 6, 7, 8]]

[View source]
def as_strided(arr : Tensor(U, V), shape : Array(Int), strides : Array(Int)) : Tensor(U, V) forall U, V #

#as_strided creates a view into the Tensor given the exact strides and shape. This means it manipulates the internal data structure of a Tensor and, if done incorrectly, the array elements can point to invalid memory and can corrupt results or crash your program.

It is advisable to always use the original strides when calculating new strides to avoid reliance on a contiguous memory layout.

Furthermore, Tensors created with this function often contain self overlapping memory, so that two elements are identical. Vectorized write operations on such Tensors will typically be unpredictable. They may even give different results for small, large, or transposed Tensors.

Arguments

Examples

a = Tensor.from_array [1, 2, 3]
a.as_strided([3, 3], [0, 1])

# [[1, 2, 3],
#  [1, 2, 3],
#  [1, 2, 3]]

[View source]
def as_tensor(value : Number, like : Tensor(U, V) | Tensor(U, V).class) forall U, V #

Convert a scalar value to a Tensor like the one specified, matching the data type and target compute.

Examples

t = Tensor(Float32, OCL(Float32)).from_array([0.5, 0.2])
x = Num.as_tensor(12, like: t)
x = Num.as_tensor(12, like: Tensor(Float32, OCL(Float32)))

[View source]
def as_type(arr : Tensor(U, CPU(U)), dtype : V.class) forall U, V #

Casts a Tensor to a new dtype, by making a copy. Information may be lost when converting between data types, for example Float to Int or Int to Bool.

Arguments

  • u : U.class - Data type the Tensor will be cast to

Examples

a = Tensor.from_array [1.5, 2.5, 3.5]

a.astype(Int32)   # => [1, 2, 3]
a.astype(Bool)    # => [true, true, true]
a.astype(Float32) # => [1.5, 2.5, 3.5]

[View source]
def as_type(arr : Tensor(U, ARROW(U)), dtype : V.class) forall U, V #

Casts a Tensor to a new dtype, by making a copy. Information may be lost when converting between data types, for example Float to Int or Int to Bool.

Arguments

  • u : U.class - Data type the Tensor will be cast to

Examples

a = Tensor.from_array [1.5, 2.5, 3.5]

a.astype(Int32)   # => [1, 2, 3]
a.astype(Bool)    # => [true, true, true]
a.astype(Float32) # => [1.5, 2.5, 3.5]

[View source]
def asin(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method asin on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asin(a)

[View source]
def asin(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function asin for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.asin(a)

[View source]
def asin(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method asin on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asin(a)

[View source]
def asin!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method asin on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asin(a)

[View source]
def asin!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function asin for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.asin!(a)

[View source]
def asin!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method asin on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asin(a)

[View source]
def asinh(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method asinh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asinh(a)

[View source]
def asinh(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function asinh for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.asinh(a)

[View source]
def asinh(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method asinh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asinh(a)

[View source]
def asinh!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method asinh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asinh(a)

[View source]
def asinh!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function asinh for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.asinh!(a)

[View source]
def asinh!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method asinh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.asinh(a)

[View source]
def asinpi(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function asinpi for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.asinpi(a)

[View source]
def asinpi!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function asinpi for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.asinpi!(a)

[View source]
def atan(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method atan on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atan(a)

[View source]
def atan(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function atan for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atan(a)

[View source]
def atan(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method atan on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atan(a)

[View source]
def atan!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method atan on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atan(a)

[View source]
def atan!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function atan for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atan!(a)

[View source]
def atan!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method atan on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atan(a)

[View source]
def atan2(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method atan2 on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.atan2(a, b)

[View source]
def atan2(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method atan2 on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.atan2(a, b)

[View source]
def atan2(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method atan2 on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.atan2(a, b)

[View source]
def atan2(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function atan2 between two Tensors

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.atan2(a, b)

[View source]
def atan2(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function atan2 between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atan2(a, 3_f64)

[View source]
def atan2(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function atan2 between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atan2(3_f64, a)

[View source]
def atan2(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method atan2 on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.atan2(a, b)

[View source]
def atan2(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method atan2 on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.atan2(a, b)

[View source]
def atan2(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method atan2 on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.atan2(a, b)

[View source]
def atan2!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method atan2 on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.atan2!(a, b)

[View source]
def atan2!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method atan2 on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.atan2!(a, b)

[View source]
def atan2!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function atan2 between two Tensors, mutating the first Tensor, modifying it to store the result of the operation

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.atan2!(a, b)

[View source]
def atan2!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method atan2 on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.atan2!(a, b)

[View source]
def atan2!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method atan2 on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.atan2!(a, b)

[View source]
def atanh(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method atanh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atanh(a)

[View source]
def atanh(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function atanh for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atanh(a)

[View source]
def atanh(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method atanh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atanh(a)

[View source]
def atanh!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method atanh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atanh(a)

[View source]
def atanh!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function atanh for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atanh!(a)

[View source]
def atanh!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method atanh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.atanh(a)

[View source]
def atanpi(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function atanpi for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atanpi(a)

[View source]
def atanpi!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function atanpi for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.atanpi!(a)

[View source]
def besselj(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method besselj on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.besselj(a, b)

[View source]
def besselj(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method besselj on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.besselj(a, b)

[View source]
def besselj(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method besselj on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.besselj(a, b)

[View source]
def besselj(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method besselj on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.besselj(a, b)

[View source]
def besselj(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method besselj on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.besselj(a, b)

[View source]
def besselj(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method besselj on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.besselj(a, b)

[View source]
def besselj!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method besselj on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.besselj!(a, b)

[View source]
def besselj!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method besselj on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.besselj!(a, b)

[View source]
def besselj!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method besselj on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.besselj!(a, b)

[View source]
def besselj!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method besselj on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.besselj!(a, b)

[View source]
def besselj0(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method besselj0 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj0(a)

[View source]
def besselj0(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method besselj0 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj0(a)

[View source]
def besselj0!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method besselj0 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj0(a)

[View source]
def besselj0!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method besselj0 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj0(a)

[View source]
def besselj1(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method besselj1 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj1(a)

[View source]
def besselj1(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method besselj1 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj1(a)

[View source]
def besselj1!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method besselj1 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj1(a)

[View source]
def besselj1!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method besselj1 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.besselj1(a)

[View source]
def bessely(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method bessely on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.bessely(a, b)

[View source]
def bessely(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method bessely on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.bessely(a, b)

[View source]
def bessely(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method bessely on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.bessely(a, b)

[View source]
def bessely(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method bessely on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.bessely(a, b)

[View source]
def bessely(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method bessely on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.bessely(a, b)

[View source]
def bessely(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method bessely on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.bessely(a, b)

[View source]
def bessely!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method bessely on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.bessely!(a, b)

[View source]
def bessely!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method bessely on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.bessely!(a, b)

[View source]
def bessely!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method bessely on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.bessely!(a, b)

[View source]
def bessely!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method bessely on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.bessely!(a, b)

[View source]
def bessely0(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method bessely0 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely0(a)

[View source]
def bessely0(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method bessely0 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely0(a)

[View source]
def bessely0!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method bessely0 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely0(a)

[View source]
def bessely0!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method bessely0 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely0(a)

[View source]
def bessely1(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method bessely1 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely1(a)

[View source]
def bessely1(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method bessely1 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely1(a)

[View source]
def bessely1!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method bessely1 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely1(a)

[View source]
def bessely1!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method bessely1 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.bessely1(a)

[View source]
def bitwise_and(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :& operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_and(a, b)

[View source]
def bitwise_and(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :& operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_and(a, b)

[View source]
def bitwise_and(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :& operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_and(b, a)

[View source]
def bitwise_and(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "&" between two Tensors. Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "&" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "&" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.bitwise_and(a, a)

[View source]
def bitwise_and(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "&" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "&" operator
  • b : U - RHS argument to the "&" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.bitwise_and(a, 3)

[View source]
def bitwise_and(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "&" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : U - LHS argument to the "&" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "&" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.bitwise_and(3, a)

[View source]
def bitwise_and(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :& operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_and(a, b)

[View source]
def bitwise_and(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :& operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_and(a, b)

[View source]
def bitwise_and(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :& operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_and(b, a)

[View source]
def bitwise_and!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :& operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_and!(a, b) # a is modified

[View source]
def bitwise_and!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :& operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_and!(a, b)

[View source]
def bitwise_and!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :& operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_and!(a, b) # a is modified

[View source]
def bitwise_and!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :& operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_and!(a, b)

[View source]
def bitwise_or(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :| operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_or(a, b)

[View source]
def bitwise_or(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :| operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_or(a, b)

[View source]
def bitwise_or(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :| operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_or(b, a)

[View source]
def bitwise_or(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "|" between two Tensors. Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "|" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "|" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.bitwise_or(a, a)

[View source]
def bitwise_or(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "|" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "|" operator
  • b : U - RHS argument to the "|" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.bitwise_or(a, 3)

[View source]
def bitwise_or(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "|" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : U - LHS argument to the "|" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "|" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.bitwise_or(3, a)

[View source]
def bitwise_or(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :| operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_or(a, b)

[View source]
def bitwise_or(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :| operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_or(a, b)

[View source]
def bitwise_or(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :| operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_or(b, a)

[View source]
def bitwise_or!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :| operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_or!(a, b) # a is modified

[View source]
def bitwise_or!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :| operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_or!(a, b)

[View source]
def bitwise_or!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :| operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_or!(a, b) # a is modified

[View source]
def bitwise_or!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :| operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_or!(a, b)

[View source]
def bitwise_xor(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :^ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_xor(a, b)

[View source]
def bitwise_xor(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :^ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_xor(a, b)

[View source]
def bitwise_xor(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :^ operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_xor(b, a)

[View source]
def bitwise_xor(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "^" between two Tensors. Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "^" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "^" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.bitwise_xor(a, a)

[View source]
def bitwise_xor(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "^" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "^" operator
  • b : U - RHS argument to the "^" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.bitwise_xor(a, 3)

[View source]
def bitwise_xor(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "^" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : U - LHS argument to the "^" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "^" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.bitwise_xor(3, a)

[View source]
def bitwise_xor(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :^ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_xor(a, b)

[View source]
def bitwise_xor(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :^ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_xor(a, b)

[View source]
def bitwise_xor(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :^ operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_xor(b, a)

[View source]
def bitwise_xor!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :^ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_xor!(a, b) # a is modified

[View source]
def bitwise_xor!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :^ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_xor!(a, b)

[View source]
def bitwise_xor!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :^ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.bitwise_xor!(a, b) # a is modified

[View source]
def bitwise_xor!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :^ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.bitwise_xor!(a, b)

[View source]
def broadcast(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V)), c : Tensor(W, CPU(W))) forall U, V, W #

Broadcasts two Tensor's' to a new shape. This allows for elementwise operations between the two Tensors with the new shape.

Broadcasting rules apply, and imcompatible shapes will raise an error.

Arguments

Examples

a = Tensor.from_array [1, 2, 3]
b = Tensor.new([3, 3]) { |i| i }
c = Tensor.new([3, 3, 3, 3]) { |i| i }

x, y, z = a.broadcast(b, c)
x.shape # => [3, 3, 3, 3]

[View source]
def broadcast(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V)), c : Tensor(W, ARROW(W))) forall U, V, W #

Broadcasts two Tensor's' to a new shape. This allows for elementwise operations between the two Tensors with the new shape.

Broadcasting rules apply, and imcompatible shapes will raise an error.

Arguments

Examples

a = Tensor.from_array [1, 2, 3]
b = Tensor.new([3, 3]) { |i| i }
c = Tensor.new([3, 3, 3, 3]) { |i| i }

x, y, z = a.broadcast(b, c)
x.shape # => [3, 3, 3, 3]

[View source]
def broadcast(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) forall U, V #

Broadcasts two Tensor's' to a new shape. This allows for elementwise operations between the two Tensors with the new shape.

Broadcasting rules apply, and imcompatible shapes will raise an error.

Arguments

Examples

a = Tensor.from_array [1, 2, 3]
b = Tensor.new([3, 3]) { |i| i }

x, y = a.broadcast(b)
x.shape # => [3, 3]

[View source]
def broadcast(a : Tensor(U, OCL(U)), b : Tensor(V, OCL(V))) forall U, V #

Broadcasts two Tensor's' to a new shape. This allows for elementwise operations between the two Tensors with the new shape.

Broadcasting rules apply, and imcompatible shapes will raise an error.

Examples

a = Tensor.from_array [1, 2, 3]
b = Tensor.new([3, 3]) { |i| i }

x, y = a.broadcast(b)
x.shape # => [3, 3]

[View source]
def broadcast(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) forall U, V #

Broadcasts two Tensor's' to a new shape. This allows for elementwise operations between the two Tensors with the new shape.

Broadcasting rules apply, and imcompatible shapes will raise an error.

Arguments

Examples

a = Tensor.from_array [1, 2, 3]
b = Tensor.new([3, 3]) { |i| i }

x, y = a.broadcast(b)
x.shape # => [3, 3]

[View source]
def broadcast_to(arr : Tensor(U, V), shape : Array(Int)) forall U, V #

Broadcasts a Tensor to a new shape. Returns a read-only view of the original Tensor. Many elements in the Tensor will refer to the same memory location, and the result is rarely contiguous.

Shapes must be broadcastable, and an error will be raised if broadcasting fails.

Arguments

Examples

a = [1, 2, 3].to_tensor
a.broadcast_to([3, 3])

# [[1, 2, 3],
#  [1, 2, 3],
#  [1, 2, 3]]

[View source]
def cbrt(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method cbrt on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cbrt(a)

[View source]
def cbrt(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function cbrt for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cbrt(a)

[View source]
def cbrt(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method cbrt on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cbrt(a)

[View source]
def cbrt!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method cbrt on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cbrt(a)

[View source]
def cbrt!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function cbrt for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cbrt!(a)

[View source]
def cbrt!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method cbrt on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cbrt(a)

[View source]
def ceil(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function ceil for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.ceil(a)

[View source]
def ceil!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function ceil for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.ceil!(a)

[View source]
def concatenate(arrs : Array(Tensor(U, V)), axis : Int) forall U, V #

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

  • arrs : Array(Tensor) - Tensors to concatenate
  • axis : Int - Axis of concatenation, negative axes are allowed

Examples

a = [1, 2, 3].to_tensor
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]]]

[View source]
def concatenate(*arrs : Tensor(U, V), axis : Int) forall U, V #

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

  • arrs : Tuple(Tensor) - Tensors to concatenate
  • axis : Int - Axis of concatenation, negative axes are allowed

Examples

a = [1, 2, 3].to_tensor
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]]]

[View source]
def copysign(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method copysign on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.copysign(a, b)

[View source]
def copysign(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method copysign on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.copysign(a, b)

[View source]
def copysign(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method copysign on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.copysign(a, b)

[View source]
def copysign(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method copysign on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.copysign(a, b)

[View source]
def copysign(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method copysign on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.copysign(a, b)

[View source]
def copysign(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method copysign on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.copysign(a, b)

[View source]
def copysign!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method copysign on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.copysign!(a, b)

[View source]
def copysign!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method copysign on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.copysign!(a, b)

[View source]
def copysign!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method copysign on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.copysign!(a, b)

[View source]
def copysign!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method copysign on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.copysign!(a, b)

[View source]
def cos(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method cos on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cos(a)

[View source]
def cos(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function cos for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cos(a)

[View source]
def cos(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method cos on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cos(a)

[View source]
def cos!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method cos on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cos(a)

[View source]
def cos!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function cos for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cos!(a)

[View source]
def cos!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method cos on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cos(a)

[View source]
def cosh(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method cosh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cosh(a)

[View source]
def cosh(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function cosh for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cosh(a)

[View source]
def cosh(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method cosh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cosh(a)

[View source]
def cosh!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method cosh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cosh(a)

[View source]
def cosh!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function cosh for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cosh!(a)

[View source]
def cosh!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method cosh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.cosh(a)

[View source]
def cospi(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function cospi for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cospi(a)

[View source]
def cospi!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function cospi for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.cospi!(a)

[View source]
def cpu(arr : Tensor(U, CPU(U))) forall U #

Converts a CPU Tensor to CPU. Returns the input array, no copy is performed.

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.opencl # => "<4> on OpenCL Backend"

[View source]
def cpu(arr : Tensor(U, OCL(U))) forall U #

Converts a Tensor stored on an OpenCL device to a Tensor stored on a CPU.

Arguments

Examples

a = Tensor.new([2, 2], device: OCL) { |i| i }
a.cpu # => [[0, 1], [2, 3]]

[View source]
def cpu(arr : Tensor(U, ARROW(U))) forall U #

Converts a ARROW Tensor to CPU. Returns the input array, no copy is performed.

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.opencl # => "<4> on OpenCL Backend"

[View source]
def diagonal(arr : Tensor(U, CPU(U))) forall U #

Returns a view of the diagonal of a Tensor. This method only works for two-dimensional arrays.

TODO Implement views for offset diagonals

Arguments

Examples

a = Tensor.new(3, 3) { |i, _| i }
a.diagonal # => [0, 1, 2]

[View source]
def diagonal(arr : Tensor(U, ARROW(U))) forall U #

Returns a view of the diagonal of a Tensor. This method only works for two-dimensional arrays.

TODO Implement views for offset diagonals

Arguments

Examples

a = Tensor.new(3, 3) { |i, _| i }
a.diagonal # => [0, 1, 2]

[View source]
def divide(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :/ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.divide(a, b)

[View source]
def divide(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :/ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.divide(a, b)

[View source]
def divide(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :/ operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.divide(b, a)

[View source]
def divide(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Divide two Tensors elementwise

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to divide
  • b : Tensor(U, OCL(U)) - RHS argument to divide

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.divide(a, a)

[View source]
def divide(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Divide a Tensor and a Number elementwise

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to divide
  • b : U - RHS argument to divide

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.divide(a, 3.5)

[View source]
def divide(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Divide a Number and a Tensor elementwise

Arguments

  • a : U - LHS argument to divide
  • b : Tensor(U, OCL(U)) - RHS argument to divide

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.divide(a, 3.5)

[View source]
def divide(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :/ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.divide(a, b)

[View source]
def divide(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :/ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.divide(a, b)

[View source]
def divide(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :/ operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.divide(b, a)

[View source]
def divide!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :/ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.divide!(a, b) # a is modified

[View source]
def divide!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :/ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.divide!(a, b)

[View source]
def divide!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

"Divide" two Tensors elementwise, storing the result in the first Tensor

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to divide, will be modified inplace
  • b : Tensor(U, OCL(U)) - RHS argument to divide

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.divide!(a, a)

[View source]
def divide!(a : Tensor(U, OCL(U)), b : U) : Nil forall U #

Divide a Tensor and a Number elementwise, modifying the Tensor inplace.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to divide
  • b : U - RHS argument to divide

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.divide(a, 3.5)

[View source]
def divide!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :/ operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.divide!(a, b) # a is modified

[View source]
def divide!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :/ operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.divide!(a, b)

[View source]
def dup(t : Tensor(U, CPU(U)), order : Num::OrderType = Num::RowMajor) forall U #

Deep-copies a Tensor. If an order is provided, the returned Tensor's memory layout will respect that order.

If no order is provided, the Tensor will retain it's same memory layout.

Arguments

Examples

a = Tensor.from_array [1, 2, 3]
a.dup # => [1, 2, 3]

[View source]
def dup(t : Tensor(U, ARROW(U)), order : Num::OrderType = Num::RowMajor) forall U #

Deep-copies a Tensor. If an order is provided, the returned Tensor's memory layout will respect that order.

If no order is provided, the Tensor will retain it's same memory layout.

Arguments

Examples

a = Tensor.from_array [1, 2, 3]
a.dup # => [1, 2, 3]

[View source]
def each(arr : Tensor(U, CPU(U)), &block : U -> _) forall U #

Yields the elements of a Tensor, always in RowMajor order, as if the Tensor was flat.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each do |el|
  puts el
end

# 0
# 1
# 2
# 3

[View source]
def each(arr : Tensor(U, CPU(U))) forall U #

Yields the elements of a Tensor lazily, always in RowMajor order, as if the Tensor was flat.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
iter = a.each
a.size.times do
  puts iter.next.value
end

# 0
# 1
# 2
# 3

[View source]
def each(arr : Tensor(U, ARROW(U)), &block : U -> _) forall U #

Yields the elements of a Tensor, always in RowMajor order, as if the Tensor was flat.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each do |el|
  puts el
end

# 0
# 1
# 2
# 3

[View source]
def each(arr : Tensor(U, ARROW(U))) forall U #

Yields the elements of a Tensor lazily, always in RowMajor order, as if the Tensor was flat.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
iter = a.each
a.size.times do
  puts iter.next.value
end

# 0
# 1
# 2
# 3

[View source]
def each_axis(a0 : Tensor(U, CPU(U)), axis : Int, dims : Bool = false, &block : Tensor(U, CPU(U)) -> _) forall U #

Yields a view of each lane of an axis. Changes made in the passed block will be reflected in the original Tensor

Arguments

  • a0 : Tensor(U, CPU(U)) - Tensor to iterate along
  • axis : Int - Axis of reduction
  • dims : Bool - Indicates if the axis of reduction should be removed from the result

Examples

a = Tensor.new([3, 3]) { |i| i }
a.each_axis(1) do |ax|
  puts ax
end

# [0, 3, 6]
# [1, 4, 7]
# [2, 5, 8]

[View source]
def each_axis(arr : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Returns an iterator along each element of an axis. Each element returned by the iterator is a view, not a copy

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to iterate along
  • axis : Int - Axis of reduction
  • dims : Bool - Indicates if the axis of reduction should be removed from the result

Examples

a = Tensor.new([3, 3]) { |i| i }
a.each_axis(1).next # => [0, 3, 6]

[View source]
def each_axis(a0 : Tensor(U, OCL(U)), axis : Int, dims : Bool = false, &block : Tensor(U, OCL(U)) -> _) forall U #

Yields a view of each lane of an axis. Changes made in the passed block will be reflected in the original Tensor

Arguments

  • a0 : Tensor(U, OCL(U)) - Tensor to iterate along
  • axis : Int - Axis of reduction
  • dims : Bool - Indicates if the axis of reduction should be removed from the result

Examples

a = Tensor.new([3, 3], device: OCL) { |i| i }
a.each_axis(1) do |ax|
  puts ax.cpu
end

# [0, 3, 6]
# [1, 4, 7]
# [2, 5, 8]

[View source]
def each_axis(a0 : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false, &block : Tensor(U, ARROW(U)) -> _) forall U #

Yields a view of each lane of an axis. Changes made in the passed block will be reflected in the original Tensor

Arguments

  • a0 : Tensor(U, ARROW(U)) - Tensor to iterate along
  • axis : Int - Axis of reduction
  • dims : Bool - Indicates if the axis of reduction should be removed from the result

Examples

a = Tensor.new([3, 3]) { |i| i }
a.each_axis(1) do |ax|
  puts ax
end

# [0, 3, 6]
# [1, 4, 7]
# [2, 5, 8]

[View source]
def each_axis(arr : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Returns an iterator along each element of an axis. Each element returned by the iterator is a view, not a copy

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to iterate along
  • axis : Int - Axis of reduction
  • dims : Bool - Indicates if the axis of reduction should be removed from the result

Examples

a = Tensor.new([3, 3]) { |i| i }
a.each_axis(1).next # => [0, 3, 6]

[View source]
def each_pointer(arr : Tensor(U, CPU(U)), &block : Pointer(U) -> _) forall U #

Yields the memory locations of each element of a Tensor, always in RowMajor oder, as if the Tensor was flat.

This should primarily be used by internal methods. Methods such as #map! provided more convenient access to editing the values of a Tensor

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each_pointer do |el|
  puts el.value
end

# 0
# 1
# 2
# 3

[View source]
def each_pointer(arr : Tensor(U, ARROW(U)), &block : Pointer(U) -> _) forall U #

Yields the memory locations of each element of a Tensor, always in RowMajor oder, as if the Tensor was flat.

This should primarily be used by internal methods. Methods such as #map! provided more convenient access to editing the values of a Tensor

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each_pointer do |el|
  puts el.value
end

# 0
# 1
# 2
# 3

[View source]
def each_pointer_with_index(arr : Tensor(U, CPU(U)), &block : Pointer(U), Int32 -> _) forall U #

Yields the memory locations of each element of a Tensor, always in RowMajor oder, as if the Tensor was flat.

This should primarily be used by internal methods. Methods such as #map! provided more convenient access to editing the values of a Tensor

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each_pointer do |el|
  puts el.value
end

# 0
# 1
# 2
# 3

[View source]
def each_pointer_with_index(arr : Tensor(U, ARROW(U)), &block : Pointer(U), Int32 -> _) forall U #

Yields the memory locations of each element of a Tensor, always in RowMajor oder, as if the Tensor was flat.

This should primarily be used by internal methods. Methods such as #map! provided more convenient access to editing the values of a Tensor

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each_pointer do |el|
  puts el.value
end

# 0
# 1
# 2
# 3

[View source]
def each_with_index(arr : Tensor(U, CPU(U)), &block : U, Int32 -> _) forall U #

Yields the elements of a Tensor, always in RowMajor order, as if the Tensor was flat. Also yields the flat index of each element.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each_with_index do |el, i|
  puts "#{el}_#{i}"
end

# 0_0
# 1_1
# 2_2
# 3_3

[View source]
def each_with_index(arr : Tensor(U, ARROW(U)), &block : U, Int32 -> _) forall U #

Yields the elements of a Tensor, always in RowMajor order, as if the Tensor was flat. Also yields the flat index of each element.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
a.each_with_index do |el, i|
  puts "#{el}_#{i}"
end

# 0_0
# 1_1
# 2_2
# 3_3

[View source]
def equal(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :== operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.equal(a, b)

[View source]
def equal(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :== operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.equal(a, b)

[View source]
def equal(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :== operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.equal(b, a)

[View source]
def equal(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "==" between two Tensors. The returned result of OpenCL relational operators will always be Tensor(Int32, OCL(Int32)).

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "==" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "==" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.equal(a, a)

[View source]
def equal(a : Tensor(U, OCL(U)), b : U) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "==" between a Tensor and a Number. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "==" operator
  • b : U - RHS argument to the "==" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.equal(a, 3)

[View source]
def equal(a : U, b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "==" between a Number and a Tensor. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : U - LHS argument to the "==" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "==" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.equal(3, a)

[View source]
def equal(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :== operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.equal(a, b)

[View source]
def equal(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :== operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.equal(a, b)

[View source]
def equal(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :== operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.equal(b, a)

[View source]
def equal!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :== operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.equal!(a, b) # a is modified

[View source]
def equal!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :== operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.equal!(a, b)

[View source]
def equal!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :== operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.equal!(a, b) # a is modified

[View source]
def equal!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :== operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.equal!(a, b)

[View source]
def erf(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method erf on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erf(a)

[View source]
def erf(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function erf for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.erf(a)

[View source]
def erf(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method erf on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erf(a)

[View source]
def erf!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method erf on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erf(a)

[View source]
def erf!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function erf for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.erf!(a)

[View source]
def erf!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method erf on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erf(a)

[View source]
def erfc(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method erfc on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erfc(a)

[View source]
def erfc(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function erfc for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.erfc(a)

[View source]
def erfc(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method erfc on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erfc(a)

[View source]
def erfc!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method erfc on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erfc(a)

[View source]
def erfc!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function erfc for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.erfc!(a)

[View source]
def erfc!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method erfc on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.erfc(a)

[View source]
def exp(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method exp on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp(a)

[View source]
def exp(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function exp for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.exp(a)

[View source]
def exp(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method exp on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp(a)

[View source]
def exp!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method exp on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp(a)

[View source]
def exp!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function exp for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.exp!(a)

[View source]
def exp!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method exp on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp(a)

[View source]
def exp10(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function exp10 for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.exp10(a)

[View source]
def exp10!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function exp10 for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.exp10!(a)

[View source]
def exp2(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method exp2 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp2(a)

[View source]
def exp2(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function exp2 for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.exp2(a)

[View source]
def exp2(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method exp2 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp2(a)

[View source]
def exp2!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method exp2 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp2(a)

[View source]
def exp2!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function exp2 for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.exp2!(a)

[View source]
def exp2!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method exp2 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.exp2(a)

[View source]
def expand_dims(arr : Tensor(U, V), axis : Int) : Tensor(U, V) forall U, V #

Expands a Tensor along an axis

Arguments

  • arr : Tensor - Tensor to expand
  • axis : Int - Axis along which to expand

Examples

a = [1, 2, 3].to_tensor
a.expand_dims(0) # => [[1, 2, 3]]

[View source]
def expm1(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method expm1 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.expm1(a)

[View source]
def expm1(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function expm1 for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.expm1(a)

[View source]
def expm1(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method expm1 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.expm1(a)

[View source]
def expm1!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method expm1 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.expm1(a)

[View source]
def expm1!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function expm1 for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.expm1!(a)

[View source]
def expm1!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method expm1 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.expm1(a)

[View source]
def fabs(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function fabs for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.fabs(a)

[View source]
def fabs!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function fabs for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.fabs!(a)

[View source]
def flat(arr : Tensor(U, CPU(U))) forall U #

Flattens a Tensor to a single dimension. If a view can be created, the reshape operation will not copy data.

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.flat # => [0, 1, 2, 3]

[View source]
def flat(arr : Tensor(U, ARROW(U))) forall U #

Flattens a Tensor to a single dimension. If a view can be created, the reshape operation will not copy data.

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.flat # => [0, 1, 2, 3]

[View source]
def flip(a : Tensor(U, CPU(U)), axis : Int) forall U #

Flips a Tensor along an axis, returning a view

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to flip
  • axis : Int - Axis along which to flip

Examples

a = [[1, 2, 3], [4, 5, 6]]
puts Num.flip(a, 1)

# [[3, 2, 1],
#  [6, 5, 4]]

[View source]
def flip(a : Tensor(U, ARROW(U)), axis : Int) forall U #

Flips a Tensor along an axis, returning a view

Arguments

Examples

a = [[1, 2, 3], [4, 5, 6]]
puts Num.flip(a, 1)

# [[3, 2, 1],
#  [6, 5, 4]]

[View source]
def flip(a : Tensor(U, CPU(U))) forall U #

Flips a Tensor along all axes, returning a view

Arguments

Examples

a = [[1, 2, 3], [4, 5, 6]]
puts Num.flip(a)

# [[6, 5, 4],
#  [3, 2, 1]]

[View source]
def flip(a : Tensor(U, ARROW(U))) forall U #

Flips a Tensor along all axes, returning a view

Arguments

Examples

a = [[1, 2, 3], [4, 5, 6]]
puts Num.flip(a)

# [[6, 5, 4],
#  [3, 2, 1]]

[View source]
def floor(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function floor for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.floor(a)

[View source]
def floor!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function floor for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.floor!(a)

[View source]
def floordiv(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :// operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.floordiv(a, b)

[View source]
def floordiv(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :// operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.floordiv(a, b)

[View source]
def floordiv(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :// operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.floordiv(b, a)

[View source]
def floordiv(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :// operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.floordiv(a, b)

[View source]
def floordiv(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :// operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.floordiv(a, b)

[View source]
def floordiv(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :// operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.floordiv(b, a)

[View source]
def floordiv!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :// operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.floordiv!(a, b) # a is modified

[View source]
def floordiv!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :// operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.floordiv!(a, b)

[View source]
def floordiv!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :// operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.floordiv!(a, b) # a is modified

[View source]
def floordiv!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :// operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.floordiv!(a, b)

[View source]
def gamma(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method gamma on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.gamma(a)

[View source]
def gamma(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method gamma on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.gamma(a)

[View source]
def gamma!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method gamma on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.gamma(a)

[View source]
def gamma!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method gamma on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.gamma(a)

[View source]
def greater(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater(a, b)

[View source]
def greater(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater(a, b)

[View source]
def greater(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :> operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater(b, a)

[View source]
def greater(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator ">" between two Tensors. The returned result of OpenCL relational operators will always be Tensor(Int32, OCL(Int32)).

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the ">" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the ">" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.greater(a, a)

[View source]
def greater(a : Tensor(U, OCL(U)), b : U) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator ">" between a Tensor and a Number. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the ">" operator
  • b : U - RHS argument to the ">" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.greater(a, 3)

[View source]
def greater(a : U, b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator ">" between a Number and a Tensor. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : U - LHS argument to the ">" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the ">" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.greater(3, a)

[View source]
def greater(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater(a, b)

[View source]
def greater(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater(a, b)

[View source]
def greater(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :> operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater(b, a)

[View source]
def greater!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater!(a, b) # a is modified

[View source]
def greater!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater!(a, b)

[View source]
def greater!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater!(a, b) # a is modified

[View source]
def greater!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater!(a, b)

[View source]
def greater_equal(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :>= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater_equal(a, b)

[View source]
def greater_equal(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :>= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater_equal(a, b)

[View source]
def greater_equal(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :>= operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater_equal(b, a)

[View source]
def greater_equal(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator ">=" between two Tensors. The returned result of OpenCL relational operators will always be Tensor(Int32, OCL(Int32)).

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the ">=" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the ">=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.greater_equal(a, a)

[View source]
def greater_equal(a : Tensor(U, OCL(U)), b : U) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator ">=" between a Tensor and a Number. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the ">=" operator
  • b : U - RHS argument to the ">=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.greater_equal(a, 3)

[View source]
def greater_equal(a : U, b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator ">=" between a Number and a Tensor. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : U - LHS argument to the ">=" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the ">=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.greater_equal(3, a)

[View source]
def greater_equal(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :>= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater_equal(a, b)

[View source]
def greater_equal(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :>= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater_equal(a, b)

[View source]
def greater_equal(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :>= operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater_equal(b, a)

[View source]
def greater_equal!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :>= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater_equal!(a, b) # a is modified

[View source]
def greater_equal!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :>= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater_equal!(a, b)

[View source]
def greater_equal!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :>= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.greater_equal!(a, b) # a is modified

[View source]
def greater_equal!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :>= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.greater_equal!(a, b)

[View source]
def hstack(arrs : Array(Tensor(U, V))) forall U, V #

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

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]]

[View source]
def hstack(*arrs : Tensor(U, V)) forall U, V #

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

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]]

[View source]
def hypot(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method hypot on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.hypot(a, b)

[View source]
def hypot(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method hypot on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.hypot(a, b)

[View source]
def hypot(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method hypot on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.hypot(a, b)

[View source]
def hypot(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method hypot on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.hypot(a, b)

[View source]
def hypot(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method hypot on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.hypot(a, b)

[View source]
def hypot(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method hypot on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.hypot(a, b)

[View source]
def hypot!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method hypot on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.hypot!(a, b)

[View source]
def hypot!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method hypot on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.hypot!(a, b)

[View source]
def hypot!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method hypot on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.hypot!(a, b)

[View source]
def hypot!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method hypot on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.hypot!(a, b)

[View source]
def ilogb(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method ilogb on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.ilogb(a)

[View source]
def ilogb(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method ilogb on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.ilogb(a)

[View source]
def ilogb!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method ilogb on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.ilogb(a)

[View source]
def ilogb!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method ilogb on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.ilogb(a)

[View source]
def ldexp(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method ldexp on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.ldexp(a, b)

[View source]
def ldexp(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method ldexp on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.ldexp(a, b)

[View source]
def ldexp(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method ldexp on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.ldexp(a, b)

[View source]
def ldexp(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method ldexp on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.ldexp(a, b)

[View source]
def ldexp(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method ldexp on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.ldexp(a, b)

[View source]
def ldexp(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method ldexp on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.ldexp(a, b)

[View source]
def ldexp!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method ldexp on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.ldexp!(a, b)

[View source]
def ldexp!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method ldexp on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.ldexp!(a, b)

[View source]
def ldexp!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method ldexp on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.ldexp!(a, b)

[View source]
def ldexp!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method ldexp on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.ldexp!(a, b)

[View source]
def left_shift(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :<< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.left_shift(a, b)

[View source]
def left_shift(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :<< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.left_shift(a, b)

[View source]
def left_shift(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :<< operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.left_shift(b, a)

[View source]
def left_shift(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "<<" between two Tensors. Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "<<" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "<<" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.left_shift(a, a)

[View source]
def left_shift(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "<<" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "<<" operator
  • b : U - RHS argument to the "<<" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.left_shift(a, 3)

[View source]
def left_shift(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator "<<" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : U - LHS argument to the "<<" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "<<" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.left_shift(3, a)

[View source]
def left_shift(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :<< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.left_shift(a, b)

[View source]
def left_shift(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :<< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.left_shift(a, b)

[View source]
def left_shift(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :<< operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.left_shift(b, a)

[View source]
def left_shift!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :<< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.left_shift!(a, b) # a is modified

[View source]
def left_shift!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :<< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.left_shift!(a, b)

[View source]
def left_shift!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :<< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.left_shift!(a, b) # a is modified

[View source]
def left_shift!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :<< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.left_shift!(a, b)

[View source]
def less(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less(a, b)

[View source]
def less(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less(a, b)

[View source]
def less(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :< operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less(b, a)

[View source]
def less(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "<" between two Tensors. The returned result of OpenCL relational operators will always be Tensor(Int32, OCL(Int32)).

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "<" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "<" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.less(a, a)

[View source]
def less(a : Tensor(U, OCL(U)), b : U) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "<" between a Tensor and a Number. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "<" operator
  • b : U - RHS argument to the "<" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.less(a, 3)

[View source]
def less(a : U, b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "<" between a Number and a Tensor. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : U - LHS argument to the "<" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "<" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.less(3, a)

[View source]
def less(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less(a, b)

[View source]
def less(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less(a, b)

[View source]
def less(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :< operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less(b, a)

[View source]
def less!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less!(a, b) # a is modified

[View source]
def less!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less!(a, b)

[View source]
def less!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :< operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less!(a, b) # a is modified

[View source]
def less!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :< operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less!(a, b)

[View source]
def less_equal(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :<= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less_equal(a, b)

[View source]
def less_equal(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :<= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less_equal(a, b)

[View source]
def less_equal(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :<= operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less_equal(b, a)

[View source]
def less_equal(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "<=" between two Tensors. The returned result of OpenCL relational operators will always be Tensor(Int32, OCL(Int32)).

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "<=" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "<=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.less_equal(a, a)

[View source]
def less_equal(a : Tensor(U, OCL(U)), b : U) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "<=" between a Tensor and a Number. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "<=" operator
  • b : U - RHS argument to the "<=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.less_equal(a, 3)

[View source]
def less_equal(a : U, b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "<=" between a Number and a Tensor. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : U - LHS argument to the "<=" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "<=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.less_equal(3, a)

[View source]
def less_equal(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :<= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less_equal(a, b)

[View source]
def less_equal(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :<= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less_equal(a, b)

[View source]
def less_equal(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :<= operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less_equal(b, a)

[View source]
def less_equal!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :<= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less_equal!(a, b) # a is modified

[View source]
def less_equal!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :<= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less_equal!(a, b)

[View source]
def less_equal!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :<= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.less_equal!(a, b) # a is modified

[View source]
def less_equal!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :<= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.less_equal!(a, b)

[View source]
def lgamma(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method lgamma on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.lgamma(a)

[View source]
def lgamma(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function lgamma for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.lgamma(a)

[View source]
def lgamma(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method lgamma on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.lgamma(a)

[View source]
def lgamma!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method lgamma on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.lgamma(a)

[View source]
def lgamma!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function lgamma for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.lgamma!(a)

[View source]
def lgamma!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method lgamma on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.lgamma(a)

[View source]
def log(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method log on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log(a)

[View source]
def log(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function log for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log(a)

[View source]
def log(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method log on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log(a)

[View source]
def log!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method log on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log(a)

[View source]
def log!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function log for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log!(a)

[View source]
def log!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method log on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log(a)

[View source]
def log10(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method log10 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log10(a)

[View source]
def log10(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function log10 for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log10(a)

[View source]
def log10(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method log10 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log10(a)

[View source]
def log10!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method log10 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log10(a)

[View source]
def log10!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function log10 for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log10!(a)

[View source]
def log10!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method log10 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log10(a)

[View source]
def log1p(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method log1p on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log1p(a)

[View source]
def log1p(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function log1p for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log1p(a)

[View source]
def log1p(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method log1p on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log1p(a)

[View source]
def log1p!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method log1p on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log1p(a)

[View source]
def log1p!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function log1p for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log1p!(a)

[View source]
def log1p!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method log1p on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log1p(a)

[View source]
def log2(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method log2 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log2(a)

[View source]
def log2(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function log2 for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log2(a)

[View source]
def log2(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method log2 on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log2(a)

[View source]
def log2!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method log2 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log2(a)

[View source]
def log2!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function log2 for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.log2!(a)

[View source]
def log2!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method log2 on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.log2(a)

[View source]
def logb(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method logb on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.logb(a)

[View source]
def logb(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function logb for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.logb(a)

[View source]
def logb(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method logb on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.logb(a)

[View source]
def logb!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method logb on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.logb(a)

[View source]
def logb!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function logb for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.logb!(a)

[View source]
def logb!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method logb on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.logb(a)

[View source]
def map(a0 : Tensor(U, CPU(U)), a1 : Tensor(V, CPU(V)), a2 : Tensor(W, CPU(W)), &block : U, V, W -> X) : Tensor(X, CPU(X)) forall U, V, W, X #

Maps a block across three Tensors. This is more efficient than zipping iterators since it iterates all Tensor's in a single call, avoiding overhead from tracking multiple iterators.

The generic type of the returned Tensor is inferred from a block

Arguments

  • a0 : Tensor(U, CPU(U)) - First Tensor for iteration, must be broadcastable against the shape of a1 and a2
  • a1 : Tensor(V, CPU(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0 and a2
  • a2 : Tensor(W, CPU(W)) - Third Tensor for iteration, must be broadcastable against the shape of a0 and a1
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }
c = Tensor.new([3]) { |i| i }

a.map(b, c) { |i, j, k| i + j + k } # => [0, 3, 6]

[View source]
def map(a0 : Tensor(U, ARROW(U)), a1 : Tensor(V, ARROW(V)), a2 : Tensor(W, ARROW(W)), &block : U, V, W -> X) : Tensor(X, ARROW(X)) forall U, V, W, X #

Maps a block across three Tensors. This is more efficient than zipping iterators since it iterates all Tensor's in a single call, avoiding overhead from tracking multiple iterators.

The generic type of the returned Tensor is inferred from a block

Arguments

  • a0 : Tensor(U, ARROW(U)) - First Tensor for iteration, must be broadcastable against the shape of a1 and a2
  • a1 : Tensor(V, ARROW(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0 and a2
  • a2 : Tensor(W, ARROW(W)) - Third Tensor for iteration, must be broadcastable against the shape of a0 and a1
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }
c = Tensor.new([3]) { |i| i }

a.map(b, c) { |i, j, k| i + j + k } # => [0, 3, 6]

[View source]
def map(a0 : Tensor(U, CPU(U)), a1 : Tensor(V, CPU(V)), &block : U, V -> W) forall U, V, W #

Maps a block across two Tensors. This is more efficient than zipping iterators since it iterates both Tensor's in a single call, avoiding overhead from tracking multiple iterators.

The generic type of the returned Tensor is inferred from a block

Arguments

  • a0 : Tensor(U, CPU(U)) - First Tensor for iteration, must be broadcastable against the shape of a1
  • a1 : Tensor(V, CPU(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }

a.map(b) { |i, j| i + j } # => [0, 2, 4]

[View source]
def map(a0 : Tensor(U, ARROW(U)), a1 : Tensor(V, ARROW(V)), &block : U, V -> W) forall U, V, W #

Maps a block across two Tensors. This is more efficient than zipping iterators since it iterates both Tensor's in a single call, avoiding overhead from tracking multiple iterators.

The generic type of the returned Tensor is inferred from a block

Arguments

  • a0 : Tensor(U, ARROW(U)) - First Tensor for iteration, must be broadcastable against the shape of a1
  • a1 : Tensor(V, ARROW(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }

a.map(b) { |i, j| i + j } # => [0, 2, 4]

[View source]
def map(arr : Tensor(U, CPU(U)), &block : U -> V) : Tensor(V, CPU(V)) forall U, V #

Maps a block across a Tensor. The Tensor is treated as flat during iteration, and iteration is always done in RowMajor order

The generic type of the returned Tensor is inferred from the block

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to map the Proc across
  • block : Proc(T, U) - Proc to map across the Tensor

Examples

a = Tensor.new([3]) { |i| i }
a.map { |e| e + 5 } # => [5, 6, 7]

[View source]
def map(arr : Tensor(U, ARROW(U)), &block : U -> V) : Tensor(V, ARROW(V)) forall U, V #

Maps a block across a Tensor. The Tensor is treated as flat during iteration, and iteration is always done in RowMajor order

The generic type of the returned Tensor is inferred from the block

Arguments

Examples

a = Tensor.new([3]) { |i| i }
a.map { |e| e + 5 } # => [5, 6, 7]

[View source]
def map!(a0 : Tensor(U, CPU(U)), a1 : Tensor(V, CPU(V)), a2 : Tensor(W, CPU(W)), &) forall U, V, W #

Maps a block across three Tensors. This is more efficient than zipping iterators since it iterates all Tensor's in a single call, avoiding overhead from tracking multiple iterators. The result of the block is stored in self.

Broadcasting rules still apply, but since this is an in place operation, the other Tensor's must broadcast to the shape of self

Arguments

  • a0 : Tensor(U, CPU(U)) - First Tensor for iteration
  • a1 : Tensor(V, CPU(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0
  • a2 : Tensor(W, CPU(W)) - Third Tensor for iteration, must be broadcastable against the shape of a0
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }
c = Tensor.new([3]) { |i| i }

a.map!(b, c) { |i, j, k| i + j + k }
a # => [0, 3, 6]

[View source]
def map!(a0 : Tensor(U, ARROW(U)), a1 : Tensor(V, ARROW(V)), a2 : Tensor(W, ARROW(W)), &) forall U, V, W #

Maps a block across three Tensors. This is more efficient than zipping iterators since it iterates all Tensor's in a single call, avoiding overhead from tracking multiple iterators. The result of the block is stored in self.

Broadcasting rules still apply, but since this is an in place operation, the other Tensor's must broadcast to the shape of self

Arguments

  • a0 : Tensor(U, ARROW(U)) - First Tensor for iteration
  • a1 : Tensor(V, ARROW(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0
  • a2 : Tensor(W, ARROW(W)) - Third Tensor for iteration, must be broadcastable against the shape of a0
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }
c = Tensor.new([3]) { |i| i }

a.map!(b, c) { |i, j, k| i + j + k }
a # => [0, 3, 6]

[View source]
def map!(a0 : Tensor(U, CPU(U)), a1 : Tensor(V, CPU(V)), &block : U, V -> _) forall U, V #

Maps a block across two Tensors. This is more efficient than zipping iterators since it iterates both Tensor's in a single call, avoiding overhead from tracking multiple iterators. The result of the block is stored in self.

Broadcasting rules still apply, but since this is an in place operation, the other Tensor must broadcast to the shape of self

Arguments

  • a0 : Tensor(U, CPU(U)) - First Tensor for iteration
  • a1 : Tensor(V, CPU(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }

a.map!(b) { |i, j| i + j }
a # => [0, 2, 4]

[View source]
def map!(a0 : Tensor(U, ARROW(U)), a1 : Tensor(V, ARROW(V)), &block : U, V -> _) forall U, V #

Maps a block across two Tensors. This is more efficient than zipping iterators since it iterates both Tensor's in a single call, avoiding overhead from tracking multiple iterators. The result of the block is stored in self.

Broadcasting rules still apply, but since this is an in place operation, the other Tensor must broadcast to the shape of self

Arguments

  • a0 : Tensor(U, ARROW(U)) - First Tensor for iteration
  • a1 : Tensor(V, ARROW(V)) - Second Tensor for iteration, must be broadcastable against the shape of a0
  • block : Proc(T, U, V) - The block to map across both Tensors

Examples

a = Tensor.new([3]) { |i| i }
b = Tensor.new([3]) { |i| i }

a.map!(b) { |i, j| i + j }
a # => [0, 2, 4]

[View source]
def map!(arr : Tensor(U, CPU(U)), &block : U -> _) forall U #

Maps a block across a Tensor in place. The Tensor is treated as flat during iteration, and iteration is always done in RowMajor order

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to map the Proc across
  • block : Proc(T, U) - Proc to map across the Tensor

Examples

a = Tensor.new([3]) { |i| i }
a.map! { |e| e + 5 }
a # => [5, 6, 7]

[View source]
def map!(arr : Tensor(U, ARROW(U)), &block : U -> _) forall U #

Maps a block across a Tensor in place. The Tensor is treated as flat during iteration, and iteration is always done in RowMajor order

Arguments

Examples

a = Tensor.new([3]) { |i| i }
a.map! { |e| e + 5 }
a # => [5, 6, 7]

[View source]
def max(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method max on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.max(a, b)

[View source]
def max(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the max of each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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]]

[View source]
def max(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method max on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.max(a, b)

[View source]
def max(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method max on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.max(a, b)

[View source]
def max(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function fmax between two Tensors

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.fmax(a, b)

[View source]
def max(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function fmax between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.fmax(a, 3_f64)

[View source]
def max(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function fmax between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.fmax(3_f64, a)

[View source]
def max(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method max on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.max(a, b)

[View source]
def max(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the max of each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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]]

[View source]
def max(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method max on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.max(a, b)

[View source]
def max(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method max on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.max(a, b)

[View source]
def max(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a scalar by finding the maximum value

Arguments

Examples

a = [1, 2, 3]
Num.max(a) # => 3

[View source]
def max(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a scalar by finding the maximum value

Arguments

Examples

a = [1, 2, 3]
Num.max(a) # => 3

[View source]
def max!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method max on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.max!(a, b)

[View source]
def max!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method max on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.max!(a, b)

[View source]
def max!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function fmax between two Tensors, mutating the first Tensor, modifying it to store the result of the operation

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.fmax!(a, b)

[View source]
def max!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method max on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.max!(a, b)

[View source]
def max!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method max on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.max!(a, b)

[View source]
def mean(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the average of each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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]]

[View source]
def mean(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the average of each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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]]

[View source]
def mean(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a scalar by finding the average

Arguments

Examples

a = [1, 2, 3]
Num.mean(a) # => 2.0

[View source]
def mean(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a scalar by finding the average

Arguments

Examples

a = [1, 2, 3]
Num.mean(a) # => 2.0

[View source]
def min(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the stdlib Math method min on two Tensors, broadcasting the Tensors together.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.min(a, b)

[View source]
def min(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the min of each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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]]

[View source]
def min(a : Tensor(U, CPU(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method min on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.min(a, b)

[View source]
def min(a : Number, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method min on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, CPU(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.min(a, b)

[View source]
def min(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function fmin between two Tensors

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.fmin(a, b)

[View source]
def min(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function fmin between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.fmin(a, 3_f64)

[View source]
def min(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function fmin between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.fmin(3_f64, a)

[View source]
def min(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the stdlib Math method min on two Tensors, broadcasting the Tensors together.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.min(a, b)

[View source]
def min(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the min of each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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]]

[View source]
def min(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the stdlib Math method min on a Tensor and a Number, broadcasting the method across all elements of a Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.min(a, b)

[View source]
def min(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method min on a Number and a Tensor, broadcasting the method across all elements of a Tensor

Arguments

  • a : Number - RHS argument to the method
  • b : Tensor(U, ARROW(U)) - LHS argument to the method

Examples

a = 1.5
b = [2.0, 3.65, 3.141].to_tensor
Num.min(a, b)

[View source]
def min(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a scalar by finding the minimum value

Arguments

Examples

a = [1, 2, 3]
Num.min(a) # => 3

[View source]
def min(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a scalar by finding the minimum value

Arguments

Examples

a = [1, 2, 3]
Num.min(a) # => 3

[View source]
def min!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the stdlib Math method min on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Tensor(V, CPU(V)) - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.min!(a, b)

[View source]
def min!(a : Tensor(U, CPU(U)), b : Number) : Nil forall U #

Implements the stdlib Math method min on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, CPU(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.min!(a, b)

[View source]
def min!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function fmin between two Tensors, mutating the first Tensor, modifying it to store the result of the operation

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.fmin!(a, b)

[View source]
def min!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the stdlib Math method min on a Tensor, broadcasting the Tensors together. The second Tensor must broadcast against the shape of the first, as the first Tensor is modified inplace.

Arguments

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = [1.45, 3.2, 1.18]
Num.min!(a, b)

[View source]
def min!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the stdlib Math method min on a Tensor and a Number, broadcasting the method across all elements of a Tensor. The Tensor is modified inplace

Arguments

  • a : Tensor(U, ARROW(U)) - LHS argument to the method
  • b : Number - RHS argument to the method

Examples

a = [2.0, 3.65, 3.141].to_tensor
b = 1.5
Num.min!(a, b)

[View source]
def modulo(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :% operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.modulo(a, b)

[View source]
def modulo(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :% operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.modulo(a, b)

[View source]
def modulo(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :% operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.modulo(b, a)

[View source]
def modulo(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :% operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.modulo(a, b)

[View source]
def modulo(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :% operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.modulo(a, b)

[View source]
def modulo(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :% operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.modulo(b, a)

[View source]
def modulo!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :% operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.modulo!(a, b) # a is modified

[View source]
def modulo!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :% operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.modulo!(a, b)

[View source]
def modulo!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :% operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.modulo!(a, b) # a is modified

[View source]
def modulo!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :% operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.modulo!(a, b)

[View source]
def move_axis(arr : Tensor(U, CPU(U)), source : Array(Int), destination : Array(Int)) forall U #

Move axes of a Tensor to new positions, other axes remain in their original order

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to permute
  • source : Array(Int) - Original positions of axes
  • destination : Array(Int) - Destination positions of axes

Examples

a = Tensor(Int8, CPU(Int8)).new([3, 4, 5])
Num.moveaxis(a, [0], [-1]).shape # => 4, 5, 3

[View source]
def move_axis(arr : Tensor(U, CPU(U)), source : Int, destination : Int) forall U #

Move axes of a Tensor to new positions, other axes remain in their original order

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to permute
  • source : Int - Original position of axis
  • destination : Int - Destination position of axis

Examples

a = Tensor(Int8, CPU(Int8)).new([3, 4, 5])
Num.moveaxis(a, 0, 1).shape # => 4, 5, 3

[View source]
def move_axis(arr : Tensor(U, ARROW(U)), source : Array(Int), destination : Array(Int)) forall U #

Move axes of a Tensor to new positions, other axes remain in their original order

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to permute
  • source : Array(Int) - Original positions of axes
  • destination : Array(Int) - Destination positions of axes

Examples

a = Tensor(Int8, ARROW(Int8)).new([3, 4, 5])
Num.moveaxis(a, [0], [-1]).shape # => 4, 5, 3

[View source]
def move_axis(arr : Tensor(U, ARROW(U)), source : Int, destination : Int) forall U #

Move axes of a Tensor to new positions, other axes remain in their original order

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to permute
  • source : Int - Original position of axis
  • destination : Int - Destination position of axis

Examples

a = Tensor(Int8, ARROW(Int8)).new([3, 4, 5])
Num.moveaxis(a, 0, 1).shape # => 4, 5, 3

[View source]
def multiply(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :* operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.multiply(a, b)

[View source]
def multiply(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :* operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.multiply(a, b)

[View source]
def multiply(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :* operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.multiply(b, a)

[View source]
def multiply(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Multiply two Tensors elementwise

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to multiply
  • b : Tensor(U, OCL(U)) - RHS argument to multiply

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.multiply(a, a)

[View source]
def multiply(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Multiply a Tensor and a Number elementwise

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to multiply
  • b : U - RHS argument to multiply

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.multiply(a, 3.5)

[View source]
def multiply(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Multiply a Number and a Tensor elementwise

Arguments

  • a : U - LHS argument to multiply
  • b : Tensor(U, OCL(U)) - RHS argument to multiply

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.multiply(a, 3.5)

[View source]
def multiply(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :* operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.multiply(a, b)

[View source]
def multiply(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :* operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.multiply(a, b)

[View source]
def multiply(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :* operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.multiply(b, a)

[View source]
def multiply!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :* operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.multiply!(a, b) # a is modified

[View source]
def multiply!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :* operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.multiply!(a, b)

[View source]
def multiply!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

"Multiply" two Tensors elementwise, storing the result in the first Tensor

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to multiply, will be modified inplace
  • b : Tensor(U, OCL(U)) - RHS argument to multiply

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.multiply!(a, a)

[View source]
def multiply!(a : Tensor(U, OCL(U)), b : U) : Nil forall U #

Multiply a Tensor and a Number elementwise, modifying the Tensor inplace.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to multiply
  • b : U - RHS argument to multiply

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.multiply(a, 3.5)

[View source]
def multiply!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :* operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.multiply!(a, b) # a is modified

[View source]
def multiply!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :* operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.multiply!(a, b)

[View source]
def negate(a : Tensor(U, CPU(U))) : Tensor(U, CPU(U)) forall U #

Implements the negation operator on a Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
Num.negate(a) # => [-1, -2, -3]

[View source]
def negate(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the negation operator on a Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
Num.negate(a) # => [-1, -2, -3]

[View source]
def negate(a : Tensor(U, ARROW(U))) : Tensor(U, ARROW(U)) forall U #

Implements the negation operator on a Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
Num.negate(a) # => [-1, -2, -3]

[View source]
def not_equal(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :!= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.not_equal(a, b)

[View source]
def not_equal(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :!= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.not_equal(a, b)

[View source]
def not_equal(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :!= operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.not_equal(b, a)

[View source]
def not_equal(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "!=" between two Tensors. The returned result of OpenCL relational operators will always be Tensor(Int32, OCL(Int32)).

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "!=" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "!=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.not_equal(a, a)

[View source]
def not_equal(a : Tensor(U, OCL(U)), b : U) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "!=" between a Tensor and a Number. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the "!=" operator
  • b : U - RHS argument to the "!=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.not_equal(a, 3)

[View source]
def not_equal(a : U, b : Tensor(U, OCL(U))) : Tensor(Int32, OCL(Int32)) forall U #

Implements the comparison operator "!=" between a Number and a Tensor. The returned result of OpenCL relational operators will always beTensor(Int32, OCL(Int32))`.

Arguments

  • a : U - LHS argument to the "!=" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the "!=" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.not_equal(3, a)

[View source]
def not_equal(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :!= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.not_equal(a, b)

[View source]
def not_equal(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :!= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.not_equal(a, b)

[View source]
def not_equal(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :!= operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.not_equal(b, a)

[View source]
def not_equal!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :!= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.not_equal!(a, b) # a is modified

[View source]
def not_equal!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :!= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.not_equal!(a, b)

[View source]
def not_equal!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :!= operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.not_equal!(a, b) # a is modified

[View source]
def not_equal!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :!= operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.not_equal!(a, b)

[View source]
def opencl(arr : Tensor(U, CPU(U))) : Tensor(U, OCL(U)) forall U #

Places a Tensor stored on a CPU onto an OpenCL Device.

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.opencl # => "<4> on OpenCL Backend"

[View source]
def opencl(arr : Tensor(U, ARROW(U))) : Tensor(U, OCL(U)) forall U #

Places a Tensor stored on a ARROW onto an OpenCL Device.

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.opencl # => "<4> on OpenCL Backend"

[View source]
def power(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :** operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.power(a, b)

[View source]
def power(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :** operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.power(a, b)

[View source]
def power(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :** operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.power(b, a)

[View source]
def power(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function pow between two Tensors

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.pow(a, b)

[View source]
def power(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function pow between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.pow(a, 3_f64)

[View source]
def power(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function pow between two a Tensor and a Number

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.pow(3_f64, a)

[View source]
def power(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :** operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.power(a, b)

[View source]
def power(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :** operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.power(a, b)

[View source]
def power(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :** operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.power(b, a)

[View source]
def power!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :** operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.power!(a, b) # a is modified

[View source]
def power!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :** operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.power!(a, b)

[View source]
def power!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function pow between two Tensors, mutating the first Tensor, modifying it to store the result of the operation

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
b = [0.2, 0.5, 0.1].to_tensor(OCL)
Num.pow!(a, b)

[View source]
def power!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :** operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.power!(a, b) # a is modified

[View source]
def power!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :** operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.power!(a, b)

[View source]
def prod(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, multiplying each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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]]

[View source]
def prod(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, multiplying each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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]]

[View source]
def prod(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a scalar by multiplying all of its elements

Arguments

Examples

a = [1, 2, 3]
Num.prod(a) # => 6

[View source]
def prod(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a scalar by multiplying all of its elements

Arguments

Examples

a = [1, 2, 3]
Num.prod(a) # => 6

[View source]
def ptp(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Finds the difference between the maximum and minimum elements of a Tensor along an axis

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to reduce
  • axis : Int - Axis of reduction
  • dims : Bool - Indicate if the axis of reduction should remain in the result

Examples

a = [[3, 4], [1, 2], [6, 2]]
Num.ptp(a, 1) # [1, 1, 4]

[View source]
def ptp(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Finds the difference between the maximum and minimum elements of a Tensor along an axis

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to reduce
  • axis : Int - Axis of reduction
  • dims : Bool - Indicate if the axis of reduction should remain in the result

Examples

a = [[3, 4], [1, 2], [6, 2]]
Num.ptp(a, 1) # [1, 1, 4]

[View source]
def ptp(a : Tensor(U, CPU(U))) forall U #

Finds the difference between the maximum and minimum elements of a Tensor

Arguments

Examples

a = [1, 2, 3]
Num.ptp(a) # => 2

[View source]
def ptp(a : Tensor(U, ARROW(U))) forall U #

Finds the difference between the maximum and minimum elements of a Tensor

Arguments

Examples

a = [1, 2, 3]
Num.ptp(a) # => 2

[View source]
def reduce_axis(a0 : Tensor(U, CPU(U)), axis : Int, dims : Bool = false, &block : U, U -> _) forall U #

Reduces a Tensor along an axis. Returns a Tensor, with the axis of reduction either removed, or reduced to 1 if dims is True, which allows the result to broadcast against its previous shape

Arguments

  • a0 : Tensor(U, CPU(U)) - Tensor to reduce along an axis
  • axis : Int - Axis of reduction
  • dims : Bool - Flag determining whether the axis of reduction should be kept in the result
  • block : Proc(U, U, _) - Proc to apply to values along an axis

Examples

a = Tensor.new([2, 2]) { |i| i }
a.reduce_axis(0) { |i, j| i + j } # => [2, 4]

[View source]
def reduce_axis(a0 : Tensor(U, OCL(U)), axis : Int, dims : Bool = false, &block : Tensor(U, OCL(U)), Tensor(U, OCL(U)) -> _) : Tensor(U, OCL(U)) forall U #

Reduces a Tensor along an axis. Returns a Tensor, with the axis of reduction either removed, or reduced to 1 if dims is True, which allows the result to broadcast against its previous shape

Arguments

  • a0 : Tensor(U, OCL(U)) - Tensor to reduce along an axis
  • axis : Int - Axis of reduction
  • dims : Bool - Flag determining whether the axis of reduction should be kept in the result
  • block : Proc(Tensor(U, OCL(U)), Tensor(U, OCL(U)), _) - Proc to apply to values along an axis

Examples

a = Tensor.new([2, 2]) { |i| i }
a.reduce_axis(0) { |i, j| Num.add!(i, j) } # => "<2> on OpenCL Backend"

[View source]
def reduce_axis(a0 : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false, &block : U, U -> _) forall U #

Reduces a Tensor along an axis. Returns a Tensor, with the axis of reduction either removed, or reduced to 1 if dims is True, which allows the result to broadcast against its previous shape

Arguments

  • a0 : Tensor(U, ARROW(U)) - Tensor to reduce along an axis
  • axis : Int - Axis of reduction
  • dims : Bool - Flag determining whether the axis of reduction should be kept in the result
  • block : Proc(U, U, _) - Proc to apply to values along an axis

Examples

a = Tensor.new([2, 2]) { |i| i }
a.reduce_axis(0) { |i, j| i + j } # => [2, 4]

[View source]
def repeat(a : Tensor(U, CPU(U)), n : Int, axis : Int) forall U #

Repeat elements of a Tensor along an axis

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to repeat
  • n : Int - Number of times to repeat
  • axis : 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]]

[View source]
def repeat(a : Tensor(U, ARROW(U)), n : Int, axis : Int) forall U #

Repeat elements of a Tensor along an axis

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to repeat
  • n : Int - Number of times to repeat
  • axis : 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]]

[View source]
def repeat(a : Tensor(U, CPU(U)), n : Int) forall U #

Repeat elements of a Tensor, treating the Tensor as flat

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to repeat
  • n : Int - Number of times to repeat

Examples

a = [1, 2, 3]
Num.repeat(a, 2) # => [1, 1, 2, 2, 3, 3]

[View source]
def repeat(a : Tensor(U, ARROW(U)), n : Int) forall U #

Repeat elements of a Tensor, treating the Tensor as flat

Arguments

Examples

a = [1, 2, 3]
Num.repeat(a, 2) # => [1, 1, 2, 2, 3, 3]

[View source]
def reshape(arr : Tensor(U, CPU(U)), shape : Array(Int)) forall U #

Transform's a Tensor's shape. If a view can be created, the reshape will not copy data. The number of elements in the Tensor must remain the same.

Arguments

Examples

a = Tensor.from_array [1, 2, 3, 4]
a.reshape([2, 2])

# [[1, 2],
#  [3, 4]]

[View source]
def reshape(arr : Tensor(U, ARROW(U)), shape : Array(Int)) forall U #

Transform's a Tensor's shape. If a view can be created, the reshape will not copy data. The number of elements in the Tensor must remain the same.

Arguments

Examples

a = Tensor.from_array [1, 2, 3, 4]
a.reshape([2, 2])

# [[1, 2],
#  [3, 4]]

[View source]
def reshape(arr : Tensor(U, CPU(U)), *shape : Int) forall U #

Transform's a Tensor's shape. If a view can be created, the reshape will not copy data. The number of elements in the Tensor must remain the same.

Arguments

Examples

a = Tensor.from_array [1, 2, 3, 4]
a.reshape([2, 2])

# [[1, 2],
#  [3, 4]]

[View source]
def reshape(arr : Tensor(U, ARROW(U)), *shape : Int) forall U #

Transform's a Tensor's shape. If a view can be created, the reshape will not copy data. The number of elements in the Tensor must remain the same.

Arguments

Examples

a = Tensor.from_array [1, 2, 3, 4]
a.reshape([2, 2])

# [[1, 2],
#  [3, 4]]

[View source]
def right_shift(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :>> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.right_shift(a, b)

[View source]
def right_shift(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :>> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.right_shift(a, b)

[View source]
def right_shift(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :>> operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.right_shift(b, a)

[View source]
def right_shift(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator ">>" between two Tensors. Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the ">>" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the ">>" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
b = [1, 8, 5.to_tensor(OCL)
Num.right_shift(a, a)

[View source]
def right_shift(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator ">>" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to the ">>" operator
  • b : U - RHS argument to the ">>" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.right_shift(a, 3)

[View source]
def right_shift(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the bitwise operator ">>" between a Tensor and a Number

Only Int32 and UInt32 Tensors are supported

Arguments

  • a : U - LHS argument to the ">>" operator
  • b : Tensor(U, OCL(U)) - RHS argument to the ">>" operator

Examples

a = [12, 3, 5].to_tensor(OCL)
Num.right_shift(3, a)

[View source]
def right_shift(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :>> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.right_shift(a, b)

[View source]
def right_shift(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :>> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.right_shift(a, b)

[View source]
def right_shift(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :>> operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.right_shift(b, a)

[View source]
def right_shift!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :>> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.right_shift!(a, b) # a is modified

[View source]
def right_shift!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :>> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.right_shift!(a, b)

[View source]
def right_shift!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :>> operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.right_shift!(a, b) # a is modified

[View source]
def right_shift!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :>> operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.right_shift!(a, b)

[View source]
def rint(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function rint for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.rint(a)

[View source]
def rint!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function rint for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.rint!(a)

[View source]
def round(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function round for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.round(a)

[View source]
def round!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function round for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.round!(a)

[View source]
def rsqrt(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function rsqrt for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.rsqrt(a)

[View source]
def rsqrt!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function rsqrt for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.rsqrt!(a)

[View source]
def set(arr : Tensor(U, CPU(U)), args : Array, t : Tensor(V, CPU(V))) forall U, V #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to which values will be assigned
  • args : Array - Array of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : Tensor(V, CPU(V)) - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2]) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, CPU(U)), args : Array, t : V) forall U, V #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to which values will be assigned
  • args : Array - Tuple of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : V - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2]) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, OCL(U)), args : Array, t : Tensor(U, OCL(U))) forall U #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, OCL(U)) - Tensor to which values will be assigned
  • args : Array - Array of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : Tensor(U, OCL(U)) - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2], device: OCL) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, OCL(U)), args : Array, t : U) forall U #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, OCL(U)) - Tensor to which values will be assigned
  • args : Array - Array of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : U - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2], device: OCL) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, ARROW(U)), args : Array, t : Tensor(V, ARROW(V))) forall U, V #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to which values will be assigned
  • args : Array - Array of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : Tensor(V, ARROW(V)) - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2]) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, ARROW(U)), args : Array, t : V) forall U, V #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to which values will be assigned
  • args : Array - Tuple of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : V - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2]) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, CPU(U)), *args, value) forall U #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to which values will be assigned
  • args : Tuple - Tuple of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : Tensor | Number - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2]) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, OCL(U)), *args, value) forall U #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, OCL(U)) - Tensor to which values will be assigned
  • args : Tuple - Tuple of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : Tensor | Number - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2], device: OCL) { |i| i }
a[1.., 1..] = 99
a.cpu

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def set(arr : Tensor(U, ARROW(U)), *args, value) forall U #

The primary method of setting Tensor values. The slicing behavior for this method is identical to the [] method.

If a Tensor is passed as the value to set, it will be broadcast to the shape of the slice if possible. If a scalar is passed, it will be tiled across the slice.

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to which values will be assigned
  • args : Tuple - Tuple of arguments. All arguments must be valid indexers, so a Range, Int, or Tuple(Range, Int).
  • value : Tensor | Number - Argument to assign to the Tensor

Examples

a = Tensor.new([2, 2]) { |i| i }
a[1.., 1..] = 99
a

# [[ 0,  1],
#  [ 2, 99]]

[View source]
def sin(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method sin on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sin(a)

[View source]
def sin(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function sin for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sin(a)

[View source]
def sin(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method sin on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sin(a)

[View source]
def sin!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method sin on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sin(a)

[View source]
def sin!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function sin for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sin!(a)

[View source]
def sin!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method sin on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sin(a)

[View source]
def sinh(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method sinh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sinh(a)

[View source]
def sinh(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function sinh for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sinh(a)

[View source]
def sinh(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method sinh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sinh(a)

[View source]
def sinh!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method sinh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sinh(a)

[View source]
def sinh!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function sinh for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sinh!(a)

[View source]
def sinh!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method sinh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sinh(a)

[View source]
def sinpi(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function sinpi for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sinpi(a)

[View source]
def sinpi!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function sinpi for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sinpi!(a)

[View source]
def slice(arr : Tensor(U, V), args : Array) forall U, V #

Returns a view of a Tensor from any valid indexers. This view must be able to be represented as valid strided/shaped view, slicing as a copy is not supported.

When an Integer argument is passed, an axis will be removed from the Tensor, and a view at that index will be returned.

a = Tensor.new([2, 2]) { |i| i }
a[0] # => [0, 1]

When a Range argument is passed, an axis will be sliced based on the endpoints of the range.

a = Tensor.new([2, 2, 2]) { |i| i }
a[1...]

# [[[4, 5],
#   [6, 7]]]

When a Tuple containing a Range and an Integer step is passed, an axis is sliced based on the endpoints of the range, and the strides of the axis are updated to reflect the step. Negative steps will reflect the array along an axis.

a = Tensor.new([2, 2]) { |i| i }
a[{..., -1}]

# [[2, 3],
#  [0, 1]]

[View source]
def slice(arr : Tensor(U, V), *args) forall U, V #

Returns a view of a Tensor from any valid indexers. This view must be able to be represented as valid strided/shaped view, slicing as a copy is not supported.

When an Integer argument is passed, an axis will be removed from the Tensor, and a view at that index will be returned.

a = Tensor.new([2, 2]) { |i| i }
a[0] # => [0, 1]

When a Range argument is passed, an axis will be sliced based on the endpoints of the range.

a = Tensor.new([2, 2, 2]) { |i| i }
a[1...]

# [[[4, 5],
#   [6, 7]]]

When a Tuple containing a Range and an Integer step is passed, an axis is sliced based on the endpoints of the range, and the strides of the axis are updated to reflect the step. Negative steps will reflect the array along an axis.

a = Tensor.new([2, 2]) { |i| i }
a[{..., -1}]

# [[2, 3],
#  [0, 1]]

[View source]
def sort(a : Tensor(U, CPU(U)), axis : Int) forall U #

Sorts a Tensor along an axis.

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to sort
  • axis : Int - Axis along which to sort

Examples

t = Tensor.random(0...10, [3, 3, 2])
puts Num.sort(t, axis: 1)

# [[[1, 1],
#   [4, 5],
#   [5, 7]],
#
#  [[0, 0],
#   [2, 3],
#   [8, 4]],
#
#  [[2, 5],
#   [5, 7],
#   [5, 7]]]

[View source]
def sort(a : Tensor(U, ARROW(U)), axis : Int) forall U #

Sorts a Tensor along an axis.

Arguments

Examples

t = Tensor.random(0...10, [3, 3, 2])
puts Num.sort(t, axis: 1)

# [[[1, 1],
#   [4, 5],
#   [5, 7]],
#
#  [[0, 0],
#   [2, 3],
#   [8, 4]],
#
#  [[2, 5],
#   [5, 7],
#   [5, 7]]]

[View source]
def sort(a : Tensor(U, CPU(U))) forall U #

Sorts a Tensor, treating it's elements like the Tensor is flat.

Arguments

Examples

a = [3, 2, 1].to_tensor
Num.sort(a) # => [1, 2, 3]

[View source]
def sort(a : Tensor(U, CPU(U)), axis : Int, &block : U, U -> _) forall U #

Sorts a Tensor along an axis.

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to sort
  • axis : Int - Axis along which to sort
  • block : Proc(U, U, _) - Proc to use to sort

Examples

t = Tensor.random(0...10, [3, 3, 2])
puts Num.sort(t, axis: 1) { |i, j| i <=> j }
# [[[3, 1],
#   [4, 3],
#   [6, 8]],
#
#  [[4, 2],
#   [5, 3],
#   [9, 7]],
#
#  [[0, 1],
#   [2, 2],
#   [4, 9]]]

[View source]
def sort(a : Tensor(U, ARROW(U)), axis : Int, &block : U, U -> _) forall U #

Sorts a Tensor along an axis.

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to sort
  • axis : Int - Axis along which to sort
  • block : Proc(U, U, _) - Proc to use to sort

Examples

t = Tensor.random(0...10, [3, 3, 2])
puts Num.sort(t, axis: 1) { |i, j| i <=> j }
# [[[3, 1],
#   [4, 3],
#   [6, 8]],
#
#  [[4, 2],
#   [5, 3],
#   [9, 7]],
#
#  [[0, 1],
#   [2, 2],
#   [4, 9]]]

[View source]
def sort(a : Tensor(U, CPU(U)), &block : U, U -> _) forall U #

Sorts a Tensor, treating it's elements like the Tensor is flat.

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to sort
  • block : Proc(U, U, _) - Proc to use to compare values

Examples

a = [3, 2, 1].to_tensor
Num.sort(a) # => [1, 2, 3]

[View source]
def sort(a : Tensor(U, ARROW(U))) forall U #

Sorts a Tensor, treating it's elements like the Tensor is flat.

Arguments

Examples

a = [3, 2, 1].to_tensor
Num.sort(a) # => [1, 2, 3]

[View source]
def sort(a : Tensor(U, ARROW(U)), &block : U, U -> _) forall U #

Sorts a Tensor, treating it's elements like the Tensor is flat.

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to sort
  • block : Proc(U, U, _) - Proc to use to compare values

Examples

a = [3, 2, 1].to_tensor
Num.sort(a) # => [1, 2, 3]

[View source]
def split(a : Tensor(U, CPU(U)), ind : Int, axis : Int = 0) : Array(Tensor(U, CPU(U))) forall U #

Split a Tensor into multiple sub-Tensors. The number of sections must divide the Tensor equally.

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to split`
  • ind : Int - Number of sections of resulting Array
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(1, 9)
puts Num.array_split(a, 2) # => [[1, 2, 3, 4], [5, 6, 7, 8]]

[View source]
def split(a : Tensor(U, CPU(U)), ind : Array(Int), axis : Int = 0) : Array(Tensor(U, CPU(U))) forall U #

Split a Tensor into multiple sub-Tensors, using an explicit mapping of indices to split the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to split`
  • ind : Int - Array of indices to use when splitting the Tensor
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(9)
puts Num.array_split(a, [1, 3, 5]) # => [[0], [1, 2], [3, 4], [5, 6, 7, 8]]

[View source]
def split(a : Tensor(U, ARROW(U)), ind : Int, axis : Int = 0) : Array(Tensor(U, ARROW(U))) forall U #

Split a Tensor into multiple sub-Tensors. The number of sections must divide the Tensor equally.

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to split`
  • ind : Int - Number of sections of resulting Array
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(1, 9)
puts Num.array_split(a, 2) # => [[1, 2, 3, 4], [5, 6, 7, 8]]

[View source]
def split(a : Tensor(U, ARROW(U)), ind : Array(Int), axis : Int = 0) : Array(Tensor(U, ARROW(U))) forall U #

Split a Tensor into multiple sub-Tensors, using an explicit mapping of indices to split the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor to split`
  • ind : Int - Array of indices to use when splitting the Tensor
  • axis : Int - Axis along which to split

Examples

a = Tensor.range(9)
puts Num.array_split(a, [1, 3, 5]) # => [[0], [1, 2], [3, 4], [5, 6, 7, 8]]

[View source]
def sqrt(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method sqrt on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sqrt(a)

[View source]
def sqrt(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function sqrt for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sqrt(a)

[View source]
def sqrt(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method sqrt on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sqrt(a)

[View source]
def sqrt!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method sqrt on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sqrt(a)

[View source]
def sqrt!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function sqrt for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.sqrt!(a)

[View source]
def sqrt!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method sqrt on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.sqrt(a)

[View source]
def std(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the std of each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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]]

[View source]
def std(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, finding the std of each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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]]

[View source]
def std(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a scalar by finding the standard deviation

Arguments

Examples

a = [1, 2, 3]
Num.std(a) # => 0.816496580927726

[View source]
def std(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a scalar by finding the standard deviation

Arguments

Examples

a = [1, 2, 3]
Num.std(a) # => 0.816496580927726

[View source]
def subtract(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Tensor forall U, V #

Implements the :- operator between two Tensors. Broadcasting rules apply, the method is applied elementwise.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.subtract(a, b)

[View source]
def subtract(a : Tensor(U, CPU(U)), b : Number | Complex) : Tensor forall U #

Implements the :- operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.subtract(a, b)

[View source]
def subtract(a : Number | Complex, b : Tensor(U, CPU(U))) : Tensor forall U #

Implements the :- operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

  • a : Number | Complex - RHS to the operation
  • b : Tensor(U, CPU(U)) - LHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.subtract(b, a)

[View source]
def subtract(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Subtract two Tensors elementwise

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to subtract
  • b : Tensor(U, OCL(U)) - RHS argument to subtract

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.subtract(a, a)

[View source]
def subtract(a : Tensor(U, OCL(U)), b : U) : Tensor(U, OCL(U)) forall U #

Subtract a Tensor and a Number elementwise

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to subtract
  • b : U - RHS argument to subtract

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.subtract(a, 3.5)

[View source]
def subtract(a : U, b : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Subtract a Number and a Tensor elementwise

Arguments

  • a : U - LHS argument to subtract
  • b : Tensor(U, OCL(U)) - RHS argument to subtract

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.subtract(a, 3.5)

[View source]
def subtract(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Tensor forall U, V #

Implements the :- operator between two Tensors. Broadcasting rules apply, the method is applied elementwise_arrow.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.subtract(a, b)

[View source]
def subtract(a : Tensor(U, ARROW(U)), b : Number) : Tensor forall U #

Implements the :- operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.subtract(a, b)

[View source]
def subtract(a : Number, b : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the :- operator between a scalar and Tensor. The scalar is broadcasted across all elements of the Tensor

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.subtract(b, a)

[View source]
def subtract!(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V))) : Nil forall U, V #

Implements the :- operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Tensor(U, CPU(U)) - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.subtract!(a, b) # a is modified

[View source]
def subtract!(a : Tensor(U, CPU(U)), b : Number | Complex) : Nil forall U #

Implements the :- operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

  • a : Tensor(U, CPU(U)) - LHS to the operation
  • b : Number | Complex - RHS to the operation

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.subtract!(a, b)

[View source]
def subtract!(a : Tensor(U, OCL(U)), b : Tensor(U, OCL(U))) : Nil forall U #

"Subtract" two Tensors elementwise, storing the result in the first Tensor

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to subtract, will be modified inplace
  • b : Tensor(U, OCL(U)) - RHS argument to subtract

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.subtract!(a, a)

[View source]
def subtract!(a : Tensor(U, OCL(U)), b : U) : Nil forall U #

Subtract a Tensor and a Number elementwise, modifying the Tensor inplace.

Arguments

  • a : Tensor(U, OCL(U)) - LHS argument to subtract
  • b : U - RHS argument to subtract

Examples

a = [1.5, 2.2, 3.2].to_tensor(OCL)
Num.subtract(a, 3.5)

[View source]
def subtract!(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V))) : Nil forall U, V #

Implements the :- operator between two Tensors. Broadcasting rules apply, the method is applied elementwise. This method applies the operation inplace, storing the result in the LHS argument. Broadcasting cannot occur for the LHS operand, so the second argument must broadcast to the first operand's shape.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = [4, 5, 6].to_tensor
Num.subtract!(a, b) # a is modified

[View source]
def subtract!(a : Tensor(U, ARROW(U)), b : Number) : Nil forall U #

Implements the :- operator between a Tensor and scalar. The scalar is broadcasted across all elements of the Tensor, and the Tensor is modified inplace.

Arguments

Examples

a = [1, 2, 3].to_tensor
b = 4
Num.subtract!(a, b)

[View source]
def sum(a : Tensor(U, CPU(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, summing each view into the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor 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.sum(a, 0) # => [2, 4]
Num.sum(a, 1, dims: true)
# [[1],
#  [5]]

[View source]
def sum(a : Tensor(U, OCL(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, summing each view into the Tensor

Arguments

  • a : Tensor(U, OCL(U)) - Tensor 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], device: OCL) { |i| i }
Num.sum(a, 0).cpu # => [2, 4]
Num.sum(a, 1, dims: true).cpu
# [[1],
#  [5]]

[View source]
def sum(a : Tensor(U, ARROW(U)), axis : Int, dims : Bool = false) forall U #

Reduces a Tensor along an axis, summing each view into the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Tensor 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.sum(a, 0) # => [2, 4]
Num.sum(a, 1, dims: true)
# [[1],
#  [5]]

[View source]
def sum(a : Tensor(U, CPU(U))) forall U #

Reduces a Tensor to a scalar by summing all of its elements

Arguments

Examples

a = [1, 2, 3]
Num.sum(a) # => 6

[View source]
def sum(a : Tensor(U, ARROW(U))) forall U #

Reduces a Tensor to a scalar by summing all of its elements

Arguments

Examples

a = [1, 2, 3]
Num.sum(a) # => 6

[View source]
def swap_axes(arr : Tensor(U, CPU(U)), a : Int, b : Int) forall U #

Permutes two axes of a Tensor. This will always create a view of the permuted Tensor

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to permute
  • source : Int - First axis to swap
  • destination : Int - Second axis to swap

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.swap_axes(2, 0)

# [[[ 0,  6, 12, 18]
#   [ 2,  8, 14, 20]
#   [ 4, 10, 16, 22]]
#
#  [[ 1,  7, 13, 19]
#   [ 3,  9, 15, 21]
#   [ 5, 11, 17, 23]]]

[View source]
def swap_axes(arr : Tensor(U, ARROW(U)), a : Int, b : Int) forall U #

Permutes two axes of a Tensor. This will always create a view of the permuted Tensor

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to permute
  • source : Int - First axis to swap
  • destination : Int - Second axis to swap

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.swap_axes(2, 0)

# [[[ 0,  6, 12, 18]
#   [ 2,  8, 14, 20]
#   [ 4, 10, 16, 22]]
#
#  [[ 1,  7, 13, 19]
#   [ 3,  9, 15, 21]
#   [ 5, 11, 17, 23]]]

[View source]
def tan(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method tan on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tan(a)

[View source]
def tan(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function tan for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tan(a)

[View source]
def tan(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method tan on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tan(a)

[View source]
def tan!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method tan on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tan(a)

[View source]
def tan!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function tan for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tan!(a)

[View source]
def tan!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method tan on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tan(a)

[View source]
def tanh(a : Tensor(U, CPU(U))) : Tensor forall U #

Implements the stdlib Math method tanh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tanh(a)

[View source]
def tanh(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function tanh for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tanh(a)

[View source]
def tanh(a : Tensor(U, ARROW(U))) : Tensor forall U #

Implements the stdlib Math method tanh on a Tensor, broadcasting the operation across all elements of the Tensor

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tanh(a)

[View source]
def tanh!(a : Tensor(U, CPU(U))) : Nil forall U #

Implements the stdlib Math method tanh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, CPU(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tanh(a)

[View source]
def tanh!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function tanh for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tanh!(a)

[View source]
def tanh!(a : Tensor(U, ARROW(U))) : Nil forall U #

Implements the stdlib Math method tanh on a Tensor, broadcasting the operation across all elements of the Tensor. The Tensor is modified inplace to store the result

Arguments

  • a : Tensor(U, ARROW(U)) - Argument to be operated upon

Examples

a = [2.0, 3.65, 3.141].to_tensor
Num.tanh(a)

[View source]
def tanpi(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function tanpi for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tanpi(a)

[View source]
def tanpi!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function tanpi for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tanpi!(a)

[View source]
def tgamma(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function tgamma for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tgamma(a)

[View source]
def tgamma!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function tgamma for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.tgamma!(a)

[View source]
def tile(a : Tensor(U, CPU(U)), n : Int) forall U #

Tile elements of a Tensor

Arguments

  • a : Tensor(U, CPU(U)) - Tensor to repeat
  • n : 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]]

[View source]
def tile(a : Tensor(U, CPU(U)), n : Array(Int)) forall U #

Tile elements of a Tensor

Arguments

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]]

[View source]
def tile(a : Tensor(U, ARROW(U)), n : Int) forall U #

Tile elements of a Tensor

Arguments

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]]

[View source]
def tile(a : Tensor(U, ARROW(U)), n : Array(Int)) forall U #

Tile elements of a Tensor

Arguments

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]]

[View source]
def to_a(arr : Tensor(U, CPU(U))) forall U #

Converts a Tensor to a standard library array. The returned array will always be one-dimensional to avoid return type ambiguity

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.to_a # => [0, 1, 2, 3]

[View source]
def to_a(arr : Tensor(U, OCL(U))) forall U #

Converts a Tensor to a standard library array. The returned array will always be one-dimensional to avoid return type ambiguity

Arguments

Examples

a = Tensor.new([2, 2], device: OCL) { |i| i }
a.to_a # => [0, 1, 2, 3]

[View source]
def to_a(arr : Tensor(U, ARROW(U))) forall U #

Converts a Tensor to a standard library array. The returned array will always be one-dimensional to avoid return type ambiguity

Arguments

Examples

a = Tensor.new([2, 2]) { |i| i }
a.to_a # => [0, 1, 2, 3]

[View source]
def transpose(arr : Tensor(U, CPU(U)), axes : Array(Int) = [] of Int32) forall U #

Permutes a Tensor's axes to a different order. This will always create a view of the permuted Tensor.

Arguments

Arguments

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.transpose([2, 0, 1])

# [[[ 0,  2,  4],
#   [ 6,  8, 10],
#   [12, 14, 16],
#   [18, 20, 22]],
#
#  [[ 1,  3,  5],
#   [ 7,  9, 11],
#   [13, 15, 17],
#   [19, 21, 23]]]

[View source]
def transpose(arr : Tensor(U, OCL(U)), axes : Array(Int) = [] of Int32) forall U #

Permutes a Tensor's axes to a different order. This will always create a view of the permuted Tensor.

Arguments

axes : Array(Int) New ordering of axes for the permuted Tensor. If empty, a full transpose will occur

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.transpose([2, 0, 1])

# [[[ 0,  2,  4],
#   [ 6,  8, 10],
#   [12, 14, 16],
#   [18, 20, 22]],
#
#  [[ 1,  3,  5],
#   [ 7,  9, 11],
#   [13, 15, 17],
#   [19, 21, 23]]]

[View source]
def transpose(arr : Tensor(U, ARROW(U)), axes : Array(Int) = [] of Int32) forall U #

Permutes a Tensor's axes to a different order. This will always create a view of the permuted Tensor.

Arguments

Arguments

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.transpose([2, 0, 1])

# [[[ 0,  2,  4],
#   [ 6,  8, 10],
#   [12, 14, 16],
#   [18, 20, 22]],
#
#  [[ 1,  3,  5],
#   [ 7,  9, 11],
#   [13, 15, 17],
#   [19, 21, 23]]]

[View source]
def transpose(arr : Tensor(U, CPU(U)), *args : Int) forall U #

Permutes a Tensor's axes to a different order. This will always create a view of the permuted Tensor.

Arguments

Arguments

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.transpose([2, 0, 1])

# [[[ 0,  2,  4],
#   [ 6,  8, 10],
#   [12, 14, 16],
#   [18, 20, 22]],
#
#  [[ 1,  3,  5],
#   [ 7,  9, 11],
#   [13, 15, 17],
#   [19, 21, 23]]]

[View source]
def transpose(arr : Tensor(U, OCL(U)), *args : Int) forall U #

Permutes a Tensor's axes to a different order. This will always create a view of the permuted Tensor.

Arguments

axes : Array(Int) New ordering of axes for the permuted Tensor. If empty, a full transpose will occur

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.transpose([2, 0, 1])

# [[[ 0,  2,  4],
#   [ 6,  8, 10],
#   [12, 14, 16],
#   [18, 20, 22]],
#
#  [[ 1,  3,  5],
#   [ 7,  9, 11],
#   [13, 15, 17],
#   [19, 21, 23]]]

[View source]
def transpose(arr : Tensor(U, ARROW(U)), *args : Int) forall U #

Permutes a Tensor's axes to a different order. This will always create a view of the permuted Tensor.

Arguments

Arguments

Examples

a = Tensor.new([4, 3, 2]) { |i| i }
a.transpose([2, 0, 1])

# [[[ 0,  2,  4],
#   [ 6,  8, 10],
#   [12, 14, 16],
#   [18, 20, 22]],
#
#  [[ 1,  3,  5],
#   [ 7,  9, 11],
#   [13, 15, 17],
#   [19, 21, 23]]]

[View source]
def trunc(a : Tensor(U, OCL(U))) : Tensor(U, OCL(U)) forall U #

Implements the OpenCL builtin function trunc for a single Tensor. Only Float32 and Float64 Tensors are supported.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.trunc(a)

[View source]
def trunc!(a : Tensor(U, OCL(U))) : Nil forall U #

Implements the OpenCL builtin function trunc for a single Tensor. Only Float32 and Float64 Tensors are supported. This method mutates the original Tensor, modifying it in place.

Arguments

Examples

a = [0.45, 0.3, 2.4].to_tensor(OCL)
Num.trunc!(a)

[View source]
def view(arr : Tensor(U, CPU(U)), dtype : V.class) forall U, V #

Return a shallow copy of a Tensor with a new dtype. The underlying data buffer is shared, but the Tensor owns its other attributes. The size of the new dtype must be a multiple of the current dtype

Arguments

  • arr : Tensor(U, CPU(U)) - Tensor to view as a different data type
  • u : V.class - The data type used to reintepret the underlying data buffer of a Tensor

Examples

a = Tensor.new([3]) { |i| i }
a.view(Int8) # => [0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0]

[View source]
def view(arr : Tensor(U, ARROW(U)), dtype : V.class) forall U, V #

Return a shallow copy of a Tensor with a new dtype. The underlying data buffer is shared, but the Tensor owns its other attributes. The size of the new dtype must be a multiple of the current dtype

Arguments

  • arr : Tensor(U, ARROW(U)) - Tensor to view as a different data type
  • u : V.class - The data type used to reintepret the underlying data buffer of a Tensor

Examples

a = Tensor.new([3]) { |i| i }
a.view(Int8) # => [0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0]

[View source]
def vstack(arrs : Array(Tensor(U, V))) forall U, V #

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

Examples

a = [1, 2, 3].to_tensor
Num.vstack([a, a])

# [[1, 2, 3],
#  [1, 2, 3]]

[View source]
def vstack(*arrs : Tensor(U, V)) forall U, V #

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

Examples

a = [1, 2, 3].to_tensor
Num.vstack([a, a])

# [[1, 2, 3],
#  [1, 2, 3]]

[View source]
def with_broadcast(arr : Tensor(U, V), n : Int) : Tensor(U, V) forall U, V #

Expands a Tensors dimensions n times by broadcasting the shape and strides. No data is copied, and the result is a read-only view of the original Tensor

Arguments

  • arr : Tensor - Tensor to broadcast
  • n : Int - Number of dimensions to broadcast

Examples

a = [1, 2, 3].to_tensor
a.with_broadcast(2)

# [[[1]],
#
#  [[2]],
#
#  [[3]]]

[View source]
def yield_along_axis(a0 : Tensor(U, CPU(U)), axis : Int, &) forall U #

Similar to #each_axis, but instead of yielding slices of an axis, it yields slices along an axis, useful for methods that require an entire view of an axis slice for a reduction operation, such as #std, rather than being able to incrementally reduce.

Arguments

  • a0 : Tensor(U, CPU(U)) - Tensor along which to iterate
  • axis : Int - Axis of reduction

Examples

a = Tensor.new([3, 3, 3]) { |i| i }
a.yield_along_axis(0) do |ax|
  puts ax
end

# [ 0,  9, 18]
# [ 1, 10, 19]
# [ 2, 11, 20]
# [ 3, 12, 21]
# [ 4, 13, 22]
# [ 5, 14, 23]
# [ 6, 15, 24]
# [ 7, 16, 25]
# [ 8, 17, 26]

[View source]
def yield_along_axis(a0 : Tensor(U, ARROW(U)), axis : Int, &) forall U #

Similar to #each_axis, but instead of yielding slices of an axis, it yields slices along an axis, useful for methods that require an entire view of an axis slice for a reduction operation, such as #std, rather than being able to incrementally reduce.

Arguments

  • a0 : Tensor(U, ARROW(U)) - Tensor along which to iterate
  • axis : Int - Axis of reduction

Examples

a = Tensor.new([3, 3, 3]) { |i| i }
a.yield_along_axis(0) do |ax|
  puts ax
end

# [ 0,  9, 18]
# [ 1, 10, 19]
# [ 2, 11, 20]
# [ 3, 12, 21]
# [ 4, 13, 22]
# [ 5, 14, 23]
# [ 6, 15, 24]
# [ 7, 16, 25]
# [ 8, 17, 26]

[View source]
def zip(a : Tensor(U, CPU(U)), b : Tensor(V, CPU(V)), &block : U, V -> _) forall U, V #

Yields the elements of two Tensors, always in RowMajor order, as if the Tensors were flat.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
b = Tensor.new(2, 2) { |i| i + 2 }
a.zip(b) do |el|
  puts el
end

# { 0, 2}
# { 1, 3}
# { 2, 4}
# { 3, 5}

[View source]
def zip(a : Tensor(U, ARROW(U)), b : Tensor(V, ARROW(V)), &block : U, V -> _) forall U, V #

Yields the elements of two Tensors, always in RowMajor order, as if the Tensors were flat.

Arguments

Examples

a = Tensor.new(2, 2) { |i| i }
b = Tensor.new(2, 2) { |i| i + 2 }
a.zip(b) do |el|
  puts el
end

# { 0, 2}
# { 1, 3}
# { 2, 4}
# { 3, 5}

[View source]