Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ndarray sum keep_dims:true does not always keep dimensions #621

Open
mooreryan opened this issue Jun 8, 2022 · 0 comments
Open

Ndarray sum keep_dims:true does not always keep dimensions #621

mooreryan opened this issue Jun 8, 2022 · 0 comments

Comments

@mooreryan
Copy link
Contributor

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:

sum.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant