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

foldMono, ifoldMono over the outermost dimension #56

Closed
kozross opened this issue Nov 26, 2018 · 2 comments
Closed

foldMono, ifoldMono over the outermost dimension #56

kozross opened this issue Nov 26, 2018 · 2 comments
Assignees
Projects

Comments

@kozross
Copy link

kozross commented Nov 26, 2018

By this, I mean functions with signatures like:

foldMonoOuter :: (OuterSlice r ix e, Source r ix e, Monoid m) => (Elt r ix e -> m) -> Array r ix e -> m
ifoldMonoOuter :: (OuterSlice r ix e, Source r ix e, Monoid m) => (Int -> Elt r ix e -> m) -> Array r ix e -> m

This would be very convenient for the work I'm trying to do at the moment.

@lehins lehins self-assigned this Nov 26, 2018
@lehins
Copy link
Owner

lehins commented Nov 26, 2018

These functions can already be easily implemented with functions at hand. I like the idea of folding over slices, so I'll probably add a more general version in next release, plus the other ones you requested, but for now you can just use that:

ifoldMonoOuter
  :: (OuterSlice r ix e, Monoid m, Size r ix e) =>
     (Int -> Elt r ix e -> m) -> Array r ix e -> m
ifoldMonoOuter f arr = foldMono g $ range (getComp arr) 0 (headDim (size arr))
  where
    g i = f i (arr !> i)

Which seems to be doing what you want, right?

λ> a = makeArrayR U Seq (2 :. 3) (toLinearIndex (2 :. 3))
λ> ifoldMonoOuter (\i s -> [(i, s)]) a
[(0,(Array M Seq (3)
  [ 0,1,2 ])),(1,(Array M Seq (3)
  [ 3,4,5 ]))]

@kozross
Copy link
Author

kozross commented Nov 26, 2018

Yeah, that is definitely it.

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

No branches or pull requests

2 participants