Module: TorchModel::Tensor

Defined in:
lib/scout/model/python/torch/helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(obj) ⇒ Object



19
20
21
# File 'lib/scout/model/python/torch/helpers.rb', line 19

def self.setup(obj)
  obj.extend Tensor
end

Instance Method Details

#delObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scout/model/python/torch/helpers.rb', line 23

def del
  begin
    self.to("cpu")
    self.detach
    self.grad = nil
    self.untyped_storage.resize_ 0
  rescue Exception
    Log.exception $!
  end
  self
end

#lengthObject



15
16
17
# File 'lib/scout/model/python/torch/helpers.rb', line 15

def length
  PyCall.len(self)
end

#to_rubyObject



5
6
7
# File 'lib/scout/model/python/torch/helpers.rb', line 5

def to_ruby
  ScoutPython.numpy2ruby(self)
end

#to_ruby!Object



9
10
11
12
13
# File 'lib/scout/model/python/torch/helpers.rb', line 9

def to_ruby!
  r = self.to_ruby
  self.del
  r
end