mrkn / mxnet.rb

MXNet binding for Ruby
MIT License
48 stars 10 forks source link

Guidance on method definition #20

Open ljulliar opened 6 years ago

ljulliar commented 6 years ago

I was about to write the spec for NDArray#sqrt when I realized that as it is today I can only call:

z = MXNet::NDArray.sqrt(x) which means NDArray.sqrt (class method)

I guess for #sqrt to work I need to implement

def sqrt
....
end

in NDArray Ruby class, right ?

ljulliar commented 6 years ago

In other words int he MXNet Ruby interface are we happy with the class call or do we want to also systematically define the instance method call as well.

If I define NDArray#sqrt as

    def sqrt(*args, **kwargs)
      Ops.sqrt(self, *args, **kwargs)
    end

We can chose to use either z = MXNet::NDArray.sqrt(x) or z = x.sqrt Shall we systematize such definition of instance methods ?

mrkn commented 6 years ago

@ljulliar please follow the implementation of Python binding.

On MXNet::NDArray#sqrt, the corresponding python's implementation is:

def sqrt(self, *args, **kwargs)
  return op.sqrt(self, *args, **kwargs)

So you can write in Ruby as:

def sqrt(*args, **kwargs)
  Ops.sqrt(self, *args, **kwargs)
end