memoize

How do I write a generic memoize function?

I'm writing a function to find triangle numbers and the natural way to write it is recursively: function triangle (x) if x == 0 then return 0 end return x+triangle(x-1) end But attempting to calculate the first 100,000 triangle numbers fails with a stack overflow after a while. This is an ideal function to memoize, but I want a...

How do you make a generic memoize function in Haskell?

I've seen the other post about this, but is there a clean way of doing this in Haskell? As a 2nd part, can it also be done without making the function monadic? ...

Loading a model into a half-edge data structure from a .PLY file

I am attempting to build a .PLY parser to load 3d models stored as .ply files into a half edge data structure mesh. Sorry for the huge question, I'm very verbose and I wanted to make sure I laid out all the details. Because of this, I'll restate my ultimate goals immediately, just so users can see can get an idea of what i want before ...

Two argument Memoization

In C# how do I memoize a function with two arguments? Do I have to curry before memoization? Wes Dyer wrote the Memoization code I typically use, but now I need two arguments ...

Is the pickling process deterministic?

Does Pickle always produce the same output for a certain input value? I suppose there could be a gotcha when pickling dictionaries that have the same contents but different insert/delete histories. My goal is to create a "signature" of function arguments, using Pickle and SHA1, for a memoize implementation. ...

Python func_dict used to memoize; other useful tricks?

A Python function object has an attribute dictionary called func_dict which is visible from outside the function and is mutable, but which is not modified when the function is called. (I learned this from answers to a question I asked yesterday (#1753232): thanks!) I was reading code (at http://pythonprogramming.jottit.com/functional%...

How to cache objects store them for multiple requests?

I am using Ruby on Rails and I need to store a search result set obtained by connecting to another server. The problem is I don't want to store the result set in the session and I want something where I can store the result set object over multiple requests. The querying takes time so I don't want to repeat it. Is there a way I could s...

Ruby: how to decorate a method with memoization?

Suppose I have a class in Ruby: class Test def method(arg1, arg2) return arg1+arg2 end memoize :method end And I want to memoize it's results. So for debug purposes I modified the class like this: class Test def method(arg1, arg2) puts 'sth to make sure the method was executed' return arg1+arg2 end ... end ...

Dynamic Image Caching

I have a CherryPy app that dynamically generates images, and those images are re-used a lot but generated each time. The image is generated from a querystring containing the variables, so the same query string will always return the same image (until I rewrite the generation code) and the images are not user-specific. It occurred to me ...

What does the term "memoize" imply?

Comparing the terms "memoize" and "cache" and in reading Wikipedia's memoization entry, do people agree that using the term "memoize" implies The memoized result is kept in the process' memory; in other words, it isn't stored in memcached . One only "memoizes" functions, as in mathematical functions, e.g. Fibonacci, not values that may...

Memoizing tail call optimized recursive functions in F#

Possible Duplicate: Combine memoization and tail-recursion So the following is the code that I wrote, tail call optimized using an accumulation variable let rec counter init count = if init = 1 then count + 1 else match init with | Even value -> (counter (value/2) (1 + count)) | Odd value -> (counter ((3 * value) + 1) (coun...

When is memoization automatic in GHC Haskell?

I can't figure out why m1 is apparently memoized while m2 is not in the following: m1 = ((filter odd [1..]) !!) m2 n = ((filter odd [1..]) !! n) m1 10000000 takes about 1.5 seconds on the first call, and a fraction of that on subsequent calls (presumably it caches the list), whereas m2 10000000 always takes the same amount of...