Open perazz opened 2 years ago
Thanks @perazz. For comparison and inspiration, how would this be done in NumPy (if it has this feature)?
If we take the pack
intrinsic as example, NumPy's has two equivalent functions:
pack
, i.e. by internally unrolling the multidimensional array and the mask to same-sized 1D ones. For efficient implementation in a compiler, do you think these can still be implemented as regular Fortran functions (and thus go to stdlib
as a start), or does the compiler have to have special knowledge of them in order to be able to optimize them?
One limitation in current Fortran's array handling I find pretty annoying is the inability to employ
logical
masks which only represent one dimension of the array, instead of the whole one. I think this limitation makes all intrinsic functions de facto useless when handling multidimensional arrays.Here's an example. I have a table storing a list of quantities over two dimensions:
Now, assume I want to do some non-trivial operations with masking, like counting all fruits of some class over the summer months (OK the conditions in this example could be replaced by index-based slicing, but let's assume they're not)
Everything would be far simpler if the array intrinsics had an option to allow the logical
mask
to correspond to one of the array dimensions (potentially even more than one mask could be specified). For example