Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • $\begingroup$ @Xavier Thanks. Glad you liked it. You can search the site for dynP function of Mr.Wizard, which has comparable performance to Internal`PartitionRagged, while being implemented purely in top-level code. $\endgroup$ Commented Aug 29, 2015 at 1:45
  • $\begingroup$ Neat, but fails when negatives present. +1 though. Interestingly, dramatic slowdown with reals. $\endgroup$ Commented Aug 29, 2015 at 4:09
  • $\begingroup$ @ciao Thanks. It does work with negative numbers, for me. Can you provide an example where it fails for you? Re: slowdown - indeed. Probably related to the auto-compilation, although I still don't understand why - by default the arguments of compiled function are anyway reals. $\endgroup$ Commented Aug 29, 2015 at 13:35
  • $\begingroup$ @ciao One guess would be that, for integers, the list of 4 elements produced at each iteration of Fold, can still be packed, and is packed since Fold auto-compiles. For reals, the list contains 2 integers and 2 reals, and so can't be packed. Not sure if I am right, but I can't see any better explanation at the moment. One thing that kind of confirms my guess is that if you use N@{0, 0, 0, 0} as a starting value in FoldList, instead of {0, 0, 0, 0}, then the performance on integers also degrades just like it does for reals. $\endgroup$ Commented Aug 29, 2015 at 13:41
  • $\begingroup$ @LeonidShifrin: Range[-3,3] trivial example - s/b 7 distinct sets, but output is just the range... $\endgroup$ Commented Aug 29, 2015 at 19:20