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

memoize and options #3491

Open
mahrud opened this issue Sep 20, 2024 · 1 comment
Open

memoize and options #3491

mahrud opened this issue Sep 20, 2024 · 1 comment

Comments

@mahrud
Copy link
Member

mahrud commented Sep 20, 2024

Should memoize be sensitive to options?

I can see arguments both ways:

  1. sometimes the options contain important parameters, like coefficient ring or variable name (e.g. see Update random(QQ) to use standard uniform distribution #3481 (comment));
  2. on the other hand, sometimes options are just verbosity level or strategy, and if the code has already run maybe we don't care about that.

I don't think using memoize (as opposed to other means of caching) should be recommended anyway, so maybe this is a moot point.

@pzinn
Copy link
Contributor

pzinn commented Sep 26, 2024

Note that it's not so easy to use memoize with say a method with options, as I think I pointed out in some other thread.
e.g., givin

f= method(Options=>new OptionTable from{a=>1})

neither

f ZZ := o -> memoize(x -> (print (x,o#a); x+o#a))

nor

f ZZ := memoize(o -> x -> (print (x,o#a); x+o#a))

will work, as can be checked by applying repeatedly.
this does work:

f ZZ := memoize(o -> memoize(x -> (print (x,o#a); x+o#a)))

but seems heavy.
If one wants to ignore the option for memoize purposes, I don't even know any simple option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants