Sha256: 79696715dbd89c223de984a345ae3d819b422233fe3670567e668191e9eb3823

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

class Integer
  alias dnn__add +
  def +(other)
    if other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param)
      DNN::Layers::Add.(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.(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.(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.(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.(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.(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.(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.(self, other)
    else
      dnn__div(other)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-dnn-0.16.2 lib/dnn/core/monkey_patch.rb
ruby-dnn-0.16.1 lib/dnn/core/monkey_patch.rb