Repository navigation
Numba improvements - #144
Conversation
…here numba is not installed
`numba_installed` flag introduced
This reverts commit 8ea1206.
Following the issue and fix numba/numba#1103 and numba/numba#1104 Test should fail for this commit
…version that works in 0.18.2
Test should fail for this commit
For use with Numba <= 0.18.2
… a[n-1] <= v Docstring and test added
|
@spencerlyon2 Thanks for issuing the PR! Summary of changes and issues to discuss:
|
|
@oyamad Excellent summary. I think most of these discussions points are captured in other open issues now - so I don't see any reason not to merge this in. Do you? Point 7 (i). I have opened an issue to track this (#146) based on content in #137 Point 8. Interesting issue - I agree not entirely important at this stage - but good to be aware of. Thanks for pointing this out. |
|
@mmcky thanks. I still have a concern about the duplication in def mc_sample_path(P, init=0, sample_size=1000):
"""
See Section: DocStrings below
"""
n = len(P)
# CDFs, one for each row of P
cdfs = np.empty((n, n), order='C') # see issue #137#issuecomment-96128186
np.cumsum(P, axis=-1, out=cdfs)
# Random values, uniformly sampled from [0, 1)
u = np.random.random(size=sample_size)
# === set up array to store output === #
X = np.empty(sample_size, dtype=int)
if isinstance(init, int):
X[0] = init
else:
cdf0 = np.cumsum(init)
X[0] = searchsorted(cdf0, u[0])
# === generate the sample path === #
for t in range(sample_size-1):
X[t+1] = searchsorted(cdfs[X[t]], u[t+1])
return X
if numba_installed:
mc_sample_path = jit(mc_sample_path)If not numba_installed, |
|
@oyamad I see what you are saying now - thanks. I think this is a good idea. Effectively it boils down to moving the The only downside I see is in this implementation we won't be able to check the function @jstac I will leave the final decision with you. But @oyamad suggestion does reduce duplication in this special case. Performance: |
|
@mmcky Thank you for the performance comparison. It is very interesting. |
|
@oyamad Yeah I think you are right. Last night I had a quick look in our library for a simple utility for producing a |
|
@oyamad Indeed. I added a really simple test which is just using a random matrix |
|
@oyamad @mmcky You've done a lot of work. It's looking really good. I like the look of the code and I'm keen to merge this. I agree with @oyamad 's suggestion about cutting So I propose that we adopt @oyamad 's suggestion, cut this function, and then merge. |
|
I deleted |
|
Thanks for all this work. I'll merge now and at the same time open an issue to add a test for |

I'm just opening this as a PR so that it is easy to see what has been changed. We can still push to the branch to make more changes to the PR.
I have no intention of merging this myself.