class Bottle::Tensor(T)
- Bottle::Tensor(T)
- Bottle::BaseArray(T)
- Reference
- Object
Defined in:
tensor/tensor.crConstructors
-
.new(buffer : Pointer(T), shape, strides, flags, base, update_flags = true)
Internal method to create tensors from low level libraries.
- .new(_shape : Array(Int32), order : ArrayFlags = ArrayFlags::Contiguous, ptr : Pointer(T) | Nil = nil)
-
.new(shape : Array(Int32), order : ArrayFlags = ArrayFlags::Contiguous, &block : Int32 -> T)
Yields a
BaseArray
from a provided shape and a block. -
.new(nrows : Int32, ncols : Int32, &block : Int32, Int32 -> T)
Yields a
Tensor
from a provided number of rows and columns.
Class Method Summary
- .from_array(_shape : Array(Int32), _data : Array)
-
.random(r : Range(U, U), _shape : Array(Int32)) forall U
A flexible method to create
Tensor
's of arbitrary shapes filled with random values of arbitrary types.
Instance Method Summary
-
#%(other)
Elementwise modulus of a Tensor} to another equally sized Tensor} or scalar
-
#&(other)
Elementwise bitwise and of a Tensor} to another equally sized Tensor} or scalar
-
#*(other)
Elementwise multiplication of a Tensor} to another equally sized Tensor} or scalar
- #**(other)
-
#+(other)
Elementwise addition of a Tensor} to another equally sized Tensor} or scalar
-
#-(other)
Elementwise subtraction of a Tensor} to another equally sized Tensor} or scalar
-
#/(other)
Elementwise division of a Tensor} to another equally sized Tensor} or scalar
-
#<(other)
Elementwise less than of a Tensor} to another equally sized Tensor} or scalar
-
#<<(other)
Elementwise left shift of a Tensor} to another equally sized Tensor} or scalar
-
#<=(other)
Elementwise less equals of a Tensor} to another equally sized Tensor} or scalar
-
#==(other)
Elementwise equals of a Tensor} to another equally sized Tensor} or scalar
-
#>(other)
Elementwise greater than of a Tensor} to another equally sized Tensor} or scalar
-
#>=(other)
Elementwise greater equal than of a Tensor} to another equally sized Tensor} or scalar
-
#>>(other)
Elementwise right shift of a Tensor} to another equally sized Tensor} or scalar
-
#^(other)
Elementwise bitwise xor of a Tensor} to another equally sized Tensor} or scalar
-
#|(other)
Elementwise bitwise or of a Tensor} to another equally sized Tensor} or scalar
- #basetype(t : U.class) forall U
- #basetype
- #cumsum(axis : Int32)
- #imag
- #matrix_iter
-
#max(axis : Int32)
Computes the maximum value of a Tensor
-
#max
Computes the maximum value of a Tensor
-
#mean(axis : Int32)
Computes the average of all Tensor values
-
#mean
Computes the average of all Tensor values
-
#median
Computes the median value of a Tensor
-
#min(axis : Int32)
Computes the minimum value of a Tensor
-
#min
Computes the minimum value of a Tensor
-
#ptp(axis : Int32)
Computes the "peak to peak" of a Tensor (max - min)
-
#ptp
Computes the "peak to peak" of a Tensor (max - min)
- #real
-
#std
Computes the standard deviation of a Tensor
-
#sum(axis : Int32)
Computes the total sum of a Tensor
-
#sum
Computes the total sum of a Tensor
-
#to_s(io)
Creates a string representation of a
Tensor
.
Instance methods inherited from class Bottle::BaseArray(T)
[](mask : Tensor(Bool))[](*args) [], []=(idx : Array, assign : BaseArray(T))
[]=(*args : *U) forall U []=, accumulate_along_axis(axis, &) accumulate_along_axis, aref_set(*args, value : Tensor(T))
aref_set(*args, value : Number) aref_set, as_strided(shape, strides, writeable = false) as_strided, astype(dtype : U.class) forall U astype, base base, basetype basetype, bc?(axis : Int32) bc?, broadcast_to(newshape) broadcast_to, broadcastable(other : BaseArray) broadcastable, buffer buffer, bytesize bytesize, check_type check_type, diag_view diag_view, dtype dtype, dup(order : Char | Nil = nil) forall U dup, dup_view dup_view, flags flags, flat_iter flat_iter, index_iter index_iter, is_contiguous is_contiguous, is_fortran_contiguous is_fortran_contiguous, nbytes nbytes, ndims ndims, ravel ravel, reduce_along_axis(axis, &) reduce_along_axis, reshape(newshape : Array(Int32)) reshape, shape shape, shape=(shape : Array(Int32)) shape=, size size, slice(idx : Array(Int32 | Range(Int32, Int32))) slice, strides strides, strides=(strides : Array(Int32)) strides=, to_s(io) to_s, transpose(order : Array(Int32) = [] of Int32) transpose, unsafe_iter unsafe_iter, value value, view(dtype : U.class) forall U view
Constructor methods inherited from class Bottle::BaseArray(T)
new(buffer : Pointer(T), shape : Array(Int32), strides : Array(Int32), flags : Bottle::Internal::ArrayFlags, base : Pointer(T) | Nil, update_flags = true)new(_shape : Array(Int32), order : ArrayFlags = ArrayFlags::Contiguous, ptr : Pointer(T) | Nil = nil)
new(shape : Array(Int32), order : ArrayFlags = ArrayFlags::Contiguous, &block : Int32 -> T)
new(nrows : Int32, ncols : Int32, &block : Int32, Int32 -> T) new
Class methods inherited from class Bottle::BaseArray(T)
from_array(array : Array)
from_array
Constructor Detail
Internal method to create tensors from low level libraries. This does no validation on inputs and is very unsafe unless called by the library.
Should not be used by the external API.
Yields a BaseArray
from a provided shape and a block. The block only
provides the absolute index, not an index dependent on the shape,
so if a user wants to handle an arbitrary shape inside the block
they need to do that themselves.
t = BaseArray.new([2, 2, 3]) { |i| i / 2 }
t # =>
Base([[[ 0, 1],
[ 2, 3]],
[[ 4, 5],
[ 6, 7]],
[[ 8, 9],
[10, 11]]])
Yields a Tensor
from a provided number of rows and columns.
This can quickly create matrices, useful for several Tensor
creattion
methods such as the underlying implementation of eye
, and diag
.
This method does provide i and j variables for the passed block, so no offset calculations need to be done by the user.
t = Tensor.new(3, 3) { |i, j| i == j ? 1 : 0 }
t # =>
Tensor([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
Class Method Detail
A flexible method to create Tensor
's of arbitrary shapes
filled with random values of arbitrary types. Since
Ranges can contain any dtype, the type of tensor is
inferred from the passed range, and a new Tensor
is
sampled using the provided shape.
t = Tensor.random(0...10, [2, 2])
t # =>
Tensor([[5, 9],
[3, 9]])
Instance Method Detail
Elementwise greater equal than of a Tensor} to another equally sized Tensor} or scalar
Compile time checking of data types of a Tensor
to ensure
mixing data types is not allowed, not are bad data types
allowed into the Tensor
Computes the maximum value of a Tensor
v = Tensor.new [1, 2, 3, 4]
max(v) # => 4
Computes the average of all Tensor values
v = Tensor.new [1, 2, 3, 4]
mean(v) # => 2.5
Computes the minimum value of a Tensor
v = Tensor.new [1, 2, 3, 4]
min(v) # => 1
Computes the "peak to peak" of a Tensor (max - min)
v = Tensor.new [1, 2, 3, 4]
v.ptp # => 3
Computes the "peak to peak" of a Tensor (max - min)
v = Tensor.new [1, 2, 3, 4]
v.ptp # => 3
Computes the total sum of a Tensor
v = Tensor.new [1, 2, 3, 4]
sum(v) # => 10