Module: GRX
- Defined in:
- lib/grx.rb,
lib/grx/nn.rb,
lib/grx/data.rb,
lib/grx/loss.rb,
lib/grx/c_api.rb,
lib/grx/optim.rb,
lib/grx/utils.rb,
lib/grx/errors.rb,
lib/grx/tensor.rb,
lib/grx/storage.rb,
lib/grx/version.rb,
lib/grx/serialization.rb
Defined Under Namespace
Modules: CAPI, Data, Loss, NN, Optim, Serialization, Utils
Classes: DimensionError, Error, ShapeError, Storage, StorageError, Tensor
Constant Summary
collapse
- VERSION =
"0.2.0"
Class Method Summary
collapse
Class Method Details
.c_loaded? ⇒ Boolean
53
54
55
|
# File 'lib/grx.rb', line 53
def self.c_loaded?
CAPI::LOADED
end
|
.mode ⇒ Object
57
58
59
|
# File 'lib/grx.rb', line 57
def self.mode
CAPI::LOADED ? :c : :ruby
end
|
.ones(shape, requires_grad: false) ⇒ Object
30
31
32
|
# File 'lib/grx.rb', line 30
def self.ones(shape, requires_grad: false)
Tensor.ones(shape, requires_grad: requires_grad)
end
|
.rand(shape, requires_grad: false) ⇒ Object
34
35
36
37
|
# File 'lib/grx.rb', line 34
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
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/grx.rb', line 39
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
22
23
24
|
# File 'lib/grx.rb', line 22
def self.tensor(data, shape, requires_grad: false)
Tensor.create(data, shape, requires_grad: requires_grad)
end
|
.zeros(shape, requires_grad: false) ⇒ Object
26
27
28
|
# File 'lib/grx.rb', line 26
def self.zeros(shape, requires_grad: false)
Tensor.zeros(shape, requires_grad: requires_grad)
end
|