lib/torch/tensor.rb in torch-rb-0.2.6 vs lib/torch/tensor.rb in torch-rb-0.2.7

- old
+ new

@@ -1,8 +1,9 @@ module Torch class Tensor include Comparable + include Enumerable include Inspector alias_method :requires_grad?, :requires_grad alias_method :ndim, :dim alias_method :ndimension, :dim @@ -23,10 +24,18 @@ def to_s inspect end + def each + return enum_for(:each) unless block_given? + + size(0).times do |i| + yield self[i] + end + end + # TODO make more performant def to_a arr = _flat_data if shape.empty? arr @@ -149,9 +158,21 @@ pow(other) end def -@ neg + end + + def &(other) + logical_and(other) + end + + def |(other) + logical_or(other) + end + + def ^(other) + logical_xor(other) end # TODO better compare? def <=>(other) item <=> other