Skip to main content
9 events
when toggle format what by license comment
Sep 2, 2016 at 3:18 comment added Andy Ross @matheorem that is correct. It is an odd inconsistency
Sep 2, 2016 at 1:17 comment added matheorem @AndyRoss Yeah, I mean MainEvaluate. In mathematica.stackexchange.com/a/1028/4742 , Oleksandr R. did explicitly mentioned we can not stuffbag tensor directly into a bag. So bag in Compile is quite different from bag outside Compile. It seems that Bag in Compile must be flat while there is no such constraint outside Compile
Sep 1, 2016 at 16:19 comment added Andy Ross @matheorem By "can not be compiled" I assume you mean it makes a call to MainEvaluate because this compiles just fine for me otherwise. By adding the second argument indicating the dimension (I was sloppy with the work "rank") of the input it tells the compiler to expect a vector and does not require calling MainEvaluate
Sep 1, 2016 at 15:47 comment added matheorem Hi, @AndyRoss. I still can not understand "indicates the rank of the elements going in". When outside Compile, we can directly stuff 1d list into a bag, and got a 2d list. For example, myBag = Internal`Bag[];Do[Internal`StuffBag[myBag, {i, i, i}], {i, 3}];Internal`BagPart[myBag, All]. Then why is it not working in Compile? In Compile[{}, Module[{myBag = Internal`Bag[]}, Do[Internal`StuffBag[myBag, {i, i, i}], {i, 3}]; Internal`BagPart[myBag, All]]]`, `Internal`StuffBag[myBag, {i, i, i}] can not be compiled.
Feb 18, 2012 at 17:53 comment added Andy Ross @Szabolcs there may well be another way but I'm unaware of it. I typically initialize the bag as you have if I want to avoid coercion to reals.
Feb 18, 2012 at 8:25 vote accept Szabolcs
Feb 18, 2012 at 8:10 comment added Szabolcs Notice that this returns reals rather than integers. What is the best way to get it to work with integers (and also run faster)? @halirutan's trick of initializing the Bag as bag = Internal`Bag[Most[{0}]] does work, but I find it both ugly and confusing, so I was wondering if there is a better way (maybe through Compile's 3rd argument).
Feb 18, 2012 at 0:07 comment added acl very useful information, +1. Cheating a bit though :)
Feb 17, 2012 at 23:32 history answered Andy Ross CC BY-SA 3.0