You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
typeMaybeTensor[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.
The text was updated successfully, but these errors were encountered:
cmacmackin
changed the title
Automatically overload methods for tensors and scalars
Automatically overload custom procedures to take tensors and scalars
Dec 29, 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
andapply_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:
Then a user can simply define a procedure with arguments of this implicitly generic type.
The text was updated successfully, but these errors were encountered: