I have two large numpy matrices, X
and r
(appr. 5500x3500). I need to calculate digamma(X+r)
and digamma(r)
, which I do with scipy.special.psi
. The calculation happens in the gradient function that I am using for a fit by gradient descent. During optimization the gradient function is going to be called a lot of times, so it is imperative that it runs fast. Now, to the actual question:
digamma(r)
takes ~11s to rundigamma(X+r)
takes ~50s to run
out of curiosity I ran some other examples:
digamma(X.astype(np.float64))
, takes ~1min to rundigamma(X)
, takes ~5-6min to run
why is that happening, and what can I do to improve runtimes?
X
contains integers (numpy.int64
) from 0 to 164.r
contains floats (numpy.float64
) from 0. to ~4.6.- X is very sparse (about 75% of it is 0).
- r is not sparse (about 10% of it is 0)
EDIT: corrected X.as_float