arrayfire / arrayfire-haskell

Haskell bindings to ArrayFire
http://hackage.haskell.org/package/arrayfire
BSD 3-Clause "New" or "Revised" License
59 stars 5 forks source link

Most reductions in ArrayFire.Algorithms should return array, not scalar #36

Closed gilgamec closed 4 years ago

gilgamec commented 4 years ago

The functions which take a dimension to reduce along should return a full matrix, with only that dimension flattened, rather than a single scalar. These are (at least) sum, sumNaN, product, productNaN, min, max, allTrue, anyTrue, and count. The correct array is being computed by the FFI, but the getScalar function is being applied and just extracts the first element, rather than returning the entire array. The current behaviour of (for instance) sum is

λ> A.mkArray @Int [2,3] [1..]
ArrayFire Array
[2 3 1 1]
         1          3          5 
         2          4          6 
λ> A.sum it 0
3
λ> A.sum it 1
9

as opposed to the expected output,

ArrayFire Array
[1 3 1 1]
         3          7         11 

and

ArrayFire Array
[2 1 1 1]
         9 
        12 
dmjio commented 4 years ago

I think a few of these functions should be extracting a scalar value, allTrue, anyTrue, countAll, but the rest probably not. I'll make a PR to remove this.

dmjio commented 4 years ago

@gilgamec this should solve all those issues, tests have been updated to reflect the changes.

https://github.com/arrayfire/arrayfire-haskell/pull/24