owl
owl copied to clipboard
Ndarray sum keep_dims:true does not always keep dimensions
I'm not sure if this was a design decision or a bug, but when you run the sum
function with no axis
argument, and keep_dims:true
, the results are not what I would expect given the way keep_dims
works in other cases, as well as given how the keepdims
argument in numpy's sum function works.
# #require "owl, owl-top";;
# module A = Owl.Dense.Ndarray.D;;
# let a = A.of_arrays [| [| 1.; 2.; 3. |];
[| 4.; 5.; 6. |] |];;
val a : A.arr =
C0 C1 C2
R0 1 2 3
R1 4 5 6
# A.sum ~keep_dims:true a;;
- : A.arr =
C0
R 21
# A.sum ~keep_dims:true a |> A.shape;;
- : int array = [|1|]
Given the way the keep_dims:true
arg works when providing dimensions, (and the way numpy) works, I would expect this result:
# A.sum ~keep_dims:true a;;
- : A.arr =
C0
R0 21
# A.sum ~keep_dims:true a |> A.shape;;
- : int array = [|1, 1|]
Here's a summary of the function's current behavior
in shape | axis | keep_dims | out shape |
---|---|---|---|
2, 3 | NA | false | 1 |
2, 3 | NA | true | 1* |
2, 3 | 0 | false | 3 |
2, 3 | 0 | true | 1, 3 |
2, 3 | 1 | false | 2 |
2, 3 | 1 | true | 2,1 |
This makes sense except for the case I showed above (the row with the star in this little table).
And here is the whole utop session if you want to view it: