dfalbel / torch

torch from R!
http://dfalbel.github.io/torch
Other
50 stars 5 forks source link

prefix or s3 method? #3

Closed dfalbel closed 5 years ago

dfalbel commented 5 years ago

At this moment I am writing all tensor methods as S3 methods. The problem with this approach is that not all names can be used as S3 methods.

For example atan2 is not a generic in base.

I am wondering if it would be better to write everything like:

It's more verbose, but maybe make clearer that we are dealing with torch tensors and removes the problem of s3 methods.

nakamichiworks commented 5 years ago

Sorry for comment on the closed issue, but have you considered overriding base functions with generics and setting base functions as default methods ?

This approach would not be a bad option because it is suggested in the Writing R Extensions manual.

dfalbel commented 5 years ago

Thanks @nakamichiworks ! I have considered this. The problem is that when loading the package there would be a long list of:

The following objects are masked from ‘package:base’:

    atan2, fun2 ,fun3,

Also I think it's nice to have a prefix to help find all methods faster.

nakamichiworks commented 5 years ago

I understand the tradeoff and your decision. Thanks.

I'm really excited about the possibility for R users to have a native interface to pytorch. Keep up the great work !