Hi,
I'm a newbie to nim and I'm trying it out as I've been finding python to be really slow for the kinds of problems I'm working on. The task i'm working on involves Hidden Markov Model estimation where I have to keep track of a lot of probabilities of different states at different intervals of time. The typical recursive equation in this kind of problem is of the type
I'm used to doing this in python where alpha is a dictionary hashed by tuples. What would the nim way of doing this? A table hashed by tuples?
Thanks Araq for replying. I went ahead and coded it in nim and it's much much faster than python, brings it down from 30 minutes to about 6. But my classmates who did this in C++ have a runtime of about 10-20 seconds. Could you let me know what I'm doing wrong? I'm assuming it's because I'm using assignment by value everywhere instead of references but I don't know how to do this. Thanks in advance.
Yes I did use -d:release.
The files can be found at this link http://www.clsp.jhu.edu/~sanjeev/520.666/proj1/textA.txt and http://www.clsp.jhu.edu/~sanjeev/520.666/proj1/textB.txt
But from how your code looks you could use seqs (or seqs of seqs) instead of tables. That should be much faster.
I'm used to doing this in python where alpha is a dictionary hashed by tuples.
Of course, this can be a general problem for people with Python, Ruby or other interpreted languages as first and only programming languages. For these languages a hash access is not much slower than an access of a plain variable or an array access. The reason is, that the code needed for the expensive hash operation is generally written is fast optimized C. But for compiled languages, access to plain variables or array (sequences) is very fast -- compared to this a hash access is much slower.