Sha256: 3769ce1c1ff43d5e0300ac5224d41ab6a22b034b1bd9fd0f884799f9ad1a5e5e

Contents?: true

Size: 1.72 KB

Versions: 11

Compression:

Stored size: 1.72 KB

Contents

class Integer
  alias dnn__add +
  def +(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Add.(DNN::Tensor.convert(self), other)
    else
      dnn__add(other)
    end
  end

  alias dnn__sub -
  def -(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Sub.(DNN::Tensor.convert(self), other)
    else
      dnn__sub(other)
    end
  end

  alias dnn__mul *
  def *(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Mul.(DNN::Tensor.convert(self), other)
    else
      dnn__mul(other)
    end
  end

  alias dnn__div /
  def /(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Div.(DNN::Tensor.convert(self), other)
    else
      dnn__div(other)
    end
  end
end

class Float
  alias dnn__add +
  def +(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Add.(DNN::Tensor.convert(self), other)
    else
      dnn__add(other)
    end
  end

  alias dnn__sub -
  def -(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Sub.(DNN::Tensor.convert(self), other)
    else
      dnn__sub(other)
    end
  end

  alias dnn__mul *
  def *(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Mul.(DNN::Tensor.convert(self), other)
    else
      dnn__mul(other)
    end
  end

  alias dnn__div /
  def /(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Div.(DNN::Tensor.convert(self), other)
    else
      dnn__div(other)
    end
  end
end

if RUBY_VERSION < "2.6.0"
  class Hash
    alias dnn__to_h to_h
    def to_h(&block)
      dnn__to_h unless block
      map(&block).to_h
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ruby-dnn-1.3.0 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.2.3 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.2.2 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.2.1 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.2.0 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.1.6 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.1.5 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.1.4 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.1.3 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.1.2 lib/dnn/core/monkey_patch.rb
ruby-dnn-1.1.1 lib/dnn/core/monkey_patch.rb