module Bottle::Creation
Overview
A module primarily responsible for Tensor
creation routines.
This module should be namespaced as part of the external API to provide user facing methods for creation.
Extended Modules
Direct including types
Defined in:
tensor/creation.crInstance Method Summary
-
#arange(start : Int32, stop : Int32, step : Number = 1, dtype : U.class = Int32) forall U
Return evenly spaced values within a given interval.
-
#arange(stop : Int32, step : Int32 = 1, dtype : U.class = Int32) forall U
Return evenly spaced values within a given interval.
-
#bincount(x : Tensor(Int32), weights : Tensor(U), min_count = 0) forall U
Count number of occurrences of each value in array of non-negative ints.
-
#bincount(x : Tensor(Int32), min_count = 0)
Count number of occurrences of each value in array of non-negative ints.
-
#diag(a : Tensor(U), k : Int32 = 0) forall U
Returns a Matrix with the given
Tensor
set along the diagonal. -
#empty(shape : Array(Int32), dtype : U.class = Float64) forall U
Initializes a
Tensor
with an uninitialized slice of data. - #empty_like(other : Tensor, dtype : U.class = Float64) forall U
-
#eye(m : Int32, n : Int32 | Nil = nil, k : Int32 = 0, dtype : U.class = Float64) forall U
Return a
Matrix
with ones on the diagonal and zeros elsewhere. -
#full(shape : Array(Int32), x : Number, dtype : U.class = Float64) forall U
Initializes a
Tensor
of the givensize
anddtype
, filled with the given value. - #full_like(other : NDTensor, x : Number, dtype : U.class = Float64) forall U
-
#geomspace(start, stop, num = 50, endpoint = true)
Return numbers spaced evenly on a log scale (a geometric progression).
-
#identity(n : Int32, dtype : U.class = Float64) forall U
Returns the identify matrix with dimensions m by m
-
#linspace(start : Number, stop : Number, num = 50, endpoint = true)
Return evenly spaced numbers over a specified interval.
-
#logspace(start, stop, num = 50, endpoint = true, base = 10.0)
Return numbers spaced evenly on a log scale.
-
#ones(shape : Array(Int32), dtype : U.class = Float64) forall U
Initializes a
Tensor
of the givensize
anddtype
, filled with ones. - #ones_like(other : Tensor, dtype : U.class = Float64) forall U
- #tri(n : Int32, m : Int32 | Nil = nil, k : Int32 = 0, dtype = U.class = Float64) forall U
- #tril(t : Tensor(U), k = 0) forall U
- #triu(t : Tensor(U), k = 0) forall U
- #vander(x : Tensor(U), n : Int32 | Nil = nil, increasing : Bool = false) forall U
-
#zeros(shape : Array(Int32), dtype : U.class = Float64) forall U
Initializes a
Tensor
of the givensize
anddtype
, filled with zeros. - #zeros_like(other : NDTensor, dtype : U.class = Float64) forall U
Macro Summary
Instance Method Detail
Return evenly spaced values within a given interval.
Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop).
B.arange(1, 5) # => Tensor[1, 2, 3, 4]
Return evenly spaced values within a given interval.
Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop).
B.arange(5) # => Tensor[0, 1, 2, 3, 4]
Count number of occurrences of each value in array of non-negative ints.
The number of bins (of size 1) is one larger than the largest value in x. If minlength is specified, there will be at least this number of bins in the output array (though it will be longer if necessary, depending on the contents of x). Each bin gives the number of occurrences of its index value in x. If weights is specified the input array is weighted by it, i.e. if a value n is found at position i, out[n] += weight[i] instead of out[n] += 1.
t = Tensor.random(0...10, [10])
t # => Tensor([7, 2, 2, 7, 0, 7, 6, 6, 0, 6])
bincount(t) # => Tensor([2, 0, 2, 0, 0, 0, 3, 3, 0, 0])
Count number of occurrences of each value in array of non-negative ints.
The number of bins (of size 1) is one larger than the largest value in x. If minlength is specified, there will be at least this number of bins in the output array (though it will be longer if necessary, depending on the contents of x). Each bin gives the number of occurrences of its index value in x. If weights is specified the input array is weighted by it, i.e. if a value n is found at position i, out[n] += weight[i] instead of out[n] += 1.
t = Tensor.random(0...10, [10])
t # => Tensor([7, 2, 2, 7, 0, 7, 6, 6, 0, 6])
bincount(t) # => Tensor([2, 0, 2, 0, 0, 0, 3, 3, 0, 0])
Returns a Matrix with the given
Tensor
set along the diagonal.
TODO Support k offsets
Initializes a Tensor
with an uninitialized slice
of data.
f = empty(5, dtype: Int32)
f # => Tensor[0, 0, 0, 0, 0]
Initializes a Tensor
with an uninitialized slice
of data that is the same size as a given
Tensor
.
t = Tensor.new [1, 2, 3]
f = empty_like(t, dtype: Int32)
f # => Tensor[0, 0, 0]
Return a Matrix
with ones on the diagonal and
zeros elsewhere.
m = eye(3, dtype: Int32)
m # => [[1, 0, 0], [0, 1, 0], 0, 0, 1]
Initializes a Tensor
of the given size
and dtype
,
filled with the given value.
f = full(5, 3, dtype: Int32)
f # => Tensor[3, 3, 3, 3, 3]
Initializes a Tensor
filled with the provided value, whose size
is inferred from a given Tensor
t = Tensor.new [1, 2, 3]
f = full_like(t, -1, dtype: Int32)
f # => Tensor[-1, -1, -1]
Return numbers spaced evenly on a log scale (a geometric progression).
This is similar to #logspace
, but with endpoints specified directly.
Each output sample is a constant multiple of the previous.
geomspace(1, 1000, 4) # => Tensor[1.0, 10.0, 100.0, 1000.0]
Returns the identify matrix with dimensions m by m
m = identity(3)
m # => [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
Return evenly spaced numbers over a specified interval.
Returns num
evenly spaced samples, calculated over the
interval [start
, stop
].
The endpoint of the interval can optionally be excluded.
B.linspace(0, 1, 5) # => Tensor[0.0, 0.25, 0.5, 0.75, 1.0]
B.linspace(0, 1, 5, endpoint: false) # => Tensor[0.0, 0.2, 0.4, 0.6, 0.8]
Return numbers spaced evenly on a log scale.
In linear space, the sequence starts at base ** start
(base
to the power of start
) and ends with base ** stop
(see endpoint
below).
B.logspace(2.0, 3.0, num = 4) # => Tensor[100.0, 215.44346900318845, 464.15888336127773, 1000.0]
Initializes a Tensor
of the given size
and dtype
,
filled with ones.
f = ones(5, dtype: Int32)
f # => Tensor[1, 1, 1, 1, 1]
Initializes a Tensor
filled with ones, whose size
is inferred from a given Tensor
t = Tensor.new [1, 2, 3]
f = ones_like(t, dtype: Int32)
f # => Tensor[1, 1, 1]
Initializes a Tensor
of the given size
and dtype
,
filled with zeros.
f = zeros(5, dtype: Int32)
f # => Tensor[0, 0, 0, 0, 0]
Initializes a Tensor
filled with zeros, whose size
is inferred from a given Tensor
t = Tensor.new [1, 2, 3]
f = zeros_like(t, dtype: Int32)
f # => Tensor[0, 0, 0]