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

fold_list generalization of scan? inplace version? #592

Open
nilsbecker opened this issue Jul 22, 2021 · 0 comments
Open

fold_list generalization of scan? inplace version? #592

nilsbecker opened this issue Jul 22, 2021 · 0 comments

Comments

@nilsbecker
Copy link
Contributor

the signature

val scan:  ?axis:int ->
  ('a -> 'a -> 'a) ->
  ('a, 'b) Dense.Ndarray.Generic.t -> ('a, 'b) Dense.Ndarray.Generic.t

is not the most general. a more general one would be a list of intermediate fold results,

val fold_list:  ?axis:int -> 
  ('a -> 'b -> 'a) ->
  'a ->
  ('b, 'c) Dense.Ndarray.Generic.t -> ('a, 'c) Dense.Ndarray.Generic.t

but maybe the use case of producing a different bigarray compatible element type is not so common? an intermediate version would be to add an optional initializer to scan:

val scan:  ?axis:int ->
  ('a -> 'a -> 'a) ->
?init:'a ->
  ('a, 'b) Dense.Ndarray.Generic.t -> ('a, 'b) Dense.Ndarray.Generic.t

where the folding function is called with init and the first array element first, instead of just repeating the first element of the array as it is done now, and reverts to the current semantics if init is not given.

not sure this is worth it? but it might be worth it to add an in-place version (which it have not found)

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

No branches or pull requests

2 participants