Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically overload custom procedures to take tensors and scalars #483

Open
cmacmackin opened this issue Dec 27, 2020 · 1 comment
Open

Comments

@cmacmackin
Copy link

cmacmackin commented Dec 27, 2020

In Fortran it is possible to declare a procedure "elemental", meaning that though it is defined in terms of scalar arguments and return types, it can also be applied element-wise for arrays. What is particularly nice about this is the compiler will let you mix array and scalar arguments in a function call. The "vectorize" decorator in NumPy behaves similarly (although is horrendously slow). Currently the closest available functions in Arraymancer are map and apply_ufunc, but neither is quite as powerful as what I'm describing. It would be nice to have a feature like this with Arraymancer, perhaps as a pragma we could use when defining our own procedures. I'm not sure how hard this would be to implement.

A simpler approach might be to overload all of your element-wise operators to work when all arguments are scalars and then define some sort of implicitly generic type which can be either a scalar or an array. E.g:

type
    MaybeTensor[T] = T | Tensor[T]
    MaybeCudaTensor[T] = T | CudaTensor[T]
    MaybeClTensor[T] = T | ClTensor[T]
    MaybeAnyTensor[T] = T | AnyTensor[T]

Then a user can simply define a procedure with arguments of this implicitly generic type.

@cmacmackin cmacmackin changed the title Automatically overload methods for tensors and scalars Automatically overload custom procedures to take tensors and scalars Dec 29, 2020
@mratsim
Copy link
Owner

mratsim commented Jan 1, 2021

linked to #87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants