probmods / webppl

Probabilistic programming for the web
http://webppl.org
Other
615 stars 89 forks source link

Deep copy for globalStore #60

Open dritchie opened 9 years ago

dritchie commented 9 years ago

It looks like everywhere the globalStore is copied during inference, either util.copyObj or _.clone are used, both of which just perform shallow copies.

I just added a generic deepcopy function to the procedural-modeling branch: https://github.com/probmods/webppl/commit/860cf78a48c117c57948a1668dbec6c07c6c7c74

It'd be good to integrate and test this at some point.

stuhlmueller commented 9 years ago

If we need deep copies, consider switching from underscore to lodash so that we can use _.cloneDeep? Better than having custom code that needs to be maintained.

Also, do we actually need deep copies? If I remember correctly, we only support mutation by re-assigning global store keys, but not mutation of individual arrays/objects.

ngoodman commented 9 years ago

right, so if we can rely on primitives to copy any data structures that they mutate, then we don't need deep copy for the global store. (because the new data structure has to get reassigned to that global variable anyhow.) this doesn't seem like a terrible contract, but we may also want to have a flag that sets the copy style (deep or shallow) for flexibility and debugging purposes....

-N

On Wed, Mar 18, 2015 at 6:30 PM, Andreas Stuhlmüller < notifications@github.com> wrote:

If we need deep copies, consider switching from underscore to lodash so that we can use _.cloneDeep https://lodash.com/docs#cloneDeep? Better than having custom code that needs to be maintained.

Also, do we actually need deep copies? If I remember correctly, we only support mutation by re-assigning global store keys, but not mutation of individual arrays/objects.

— Reply to this email directly or view it on GitHub https://github.com/probmods/webppl/issues/60#issuecomment-83249810.