Closed Kahlir closed 9 years ago
For reduce, you can either flatten the array first and then apply a single reduction or you can use a nested reduction operation. In either case, you will end up with a single result value. We have opted not to provide a version of reduce that allows the programmer to specify a depth as doing so does not give any more expressiveness than using flatten/reduce or nested reduce. You could even define reduce with a depth argument as a library.
For scan, it depends on what you want to compute. You can either compute a nested scan operation, where first a scan of each row is performed and then the results are used to compute a scan across the rows. Note that for the former, the elemental function operates on single elements whereas for the latter it operates on vectors of elements. If you flatten the array first, you will get a different result as the scan will be computed on the concatenated rows. We do not provide an overloading of scan with a depth parameter as we could not agree which if the two semantics would be more intuitive for a 2D scan. By forcing the programmer to explicitly write flatten or a nested scan, we make the choice of semantics visible in the code. As with reduce, a library could introduce an additional overloading with optional depth if it turns out to be common.
Is it possible to apply reduce and scan on 2-D arrays directly? Or do we need to first flatten the 2-D or higher dimension arrays? as nothing regarding the way to apply it on multidimensional arrays is mentioned in the documentation.