Module: GRX
- Defined in:
- lib/grx.rb,
lib/grx/nn.rb,
lib/grx/loss.rb,
lib/grx/c_api.rb,
lib/grx/optim.rb,
lib/grx/errors.rb,
lib/grx/tensor.rb,
lib/grx/storage.rb,
lib/grx/version.rb
Defined Under Namespace
Modules: CAPI, Loss, NN, Optim
Classes: DimensionError, Error, ShapeError, Storage, StorageError, Tensor
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.ones(shape, requires_grad: false) ⇒ Object
27
28
29
|
# File 'lib/grx.rb', line 27
def self.ones(shape, requires_grad: false)
Tensor.ones(shape, requires_grad: requires_grad)
end
|
.rand(shape, requires_grad: false) ⇒ Object
31
32
33
34
|
# File 'lib/grx.rb', line 31
def self.rand(shape, requires_grad: false)
n = shape.reduce(1, :*)
Tensor.create(Array.new(n) { ::Kernel.rand }, shape, requires_grad: requires_grad)
end
|
.randn(shape, requires_grad: false) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/grx.rb', line 36
def self.randn(shape, requires_grad: false)
n = shape.reduce(1, :*)
data = []
(n / 2.0).ceil.times do
u1 = ::Kernel.rand; u1 = ::Kernel.rand while u1 < 1e-15
u2 = ::Kernel.rand
r = Math.sqrt(-2.0 * Math.log(u1))
data << r * Math.cos(2 * Math::PI * u2)
data << r * Math.sin(2 * Math::PI * u2)
end
Tensor.create(data.first(n), shape, requires_grad: requires_grad)
end
|
.tensor(data, shape, requires_grad: false) ⇒ Object
19
20
21
|
# File 'lib/grx.rb', line 19
def self.tensor(data, shape, requires_grad: false)
Tensor.create(data, shape, requires_grad: requires_grad)
end
|
.zeros(shape, requires_grad: false) ⇒ Object
23
24
25
|
# File 'lib/grx.rb', line 23
def self.zeros(shape, requires_grad: false)
Tensor.zeros(shape, requires_grad: requires_grad)
end
|