Closed gregorgorjanc closed 1 year ago
Changing
@jit(nopython=True, nogil=True, locals={'e':float32, 'e4':float32, 'e16':float32, 'e1e':float32, 'childValues':float32[:,:]})
to
@jit(nopython=True, nogil=True, locals={'e': float32, 'e4':float32, 'e16':float32, 'e1e':float32})
makes the code run, and considerably faster
Numba docs say The locals dictionary may be used to force the [Types and signatures](https://numba.pydata.org/numba-doc/latest/reference/types.html#numba-types) of particular local variables, for example if you want to force the use of single precision floats at some point. In general, we recommend you let Numba’s compiler infer the types of local variables by itself.
https://numba.pydata.org/numba-doc/latest/reference/jit-compilation.html
I think that indeed we don't need to state that childValues
is float32[:,:]
in @jit()
in Peeling.py
since it's created from
...
penetrance = peelingInfo.penetrance
posterior = peelingInfo.posterior
...
childValues = posterior[child,:,:] * penetrance[child,:,:]
where peelingInfo
is created in class jit_peelingInformation(object):
(in PeelingInfo.py
) with these components defined as
...
self.posterior = np.full((self.nInd, 4, self.nLoci), baseValue, dtype = np.float32)
self.penetrance = np.full((self.nInd, 4, self.nLoci), baseValue, dtype = np.float32)
...
Also, other similar variables aren't specified in @jit()
in Peeling.py
, say:
probSire = anterior[sire,:,:]*penetrance[sire,:,:] * peelingInfo.posteriorSire_minusFam[fam,:,:]
After implementing these changes I get
% Rscript checkAccuracy.r
[1] " "
[1] "Assessing peeling file: multilocus.dosages"
[1] "Comparing accuracies: 0.98"
[1] " "
[1] "Assessing peeling file: hybrid.dosages"
[1] "Comparing accuracies: 0.716"
I am experiencing issue described by https://stackoverflow.com/questions/74681366/alphapeel-numba-fails-to-allocate-array-with-layout-a, which seems to be the same as https://stackoverflow.com/questions/64044846/python-slicing-2d-numpy-array-to-produce-order-c-arrays-while-using-numba
I tried using
childValues = posterior[child,:,:] * penetrance[child,:,:]
orchildValues = np.ascontiguousarray(posterior[child,:,:] * penetrance[child,:,:])
, but both give the same error:(Here is reproducible example code
which returns