|
|
Re: Compile function and AppendTo for lists (vrs. 8.0.4)
Posted:
Jan 31, 2012 5:43 AM
|
|
Hi Fred,
some short notes:
> appendBag2a = Compile[{{k, _Integer, 0}}, Module[{p = Bag[Most[{0}]]}, > Do[StuffBag[p, Bag[{1, i}]], {i, 1, k}]; > Table[BagPart[BagPart[p, i], All], {i, 1, k}]]]; > > That works fine and fast,
But look that your type p is clearly wrong. p is a bag of bags of Integer and has to be initialized with
Internal`Bag[Most[{Internal`Bag[{1}]}]]
We can only guess about the reasons why it works anyway. If it is implemented with pointers, than it seems the integers of your p-Bag are used to store the pointers.
> The problem seems to be the initialization of the > locale variable p. I tried compilation with the definitions p=Bag[], > p=Bag[{}], p=Bag[Rest[{0}]], p=Bag[Rest[{{0,0}}]], or e.g.
Now you know how.
Cheers Patrick
|
|