Hello everybody,
I just came across some unexpected performance behavior of NGSolve that might be interesting. When building a matrix from two existing matrices, it makes a huge difference if one multiplies with a Python float or a numpy.float64.
I created a minimal working example (MWE) to test on your machine.
MWE_AddMat.py (1.2 KB)
On mine, the code
Mstar.AsVector().data = np_float * blf.mat.AsVector() + blf.mat.AsVector()
takes approximately 300 times longer than
Mstar.AsVector().data = python_float * blf.mat.AsVector() + blf.mat.AsVector()
where python_float
and np_float
describe the same value and just differ in data type. Furthermore, adding the second matrix (without any scalar multiplication with it) also takes significantly longer when the first matrix is multiplied by the numpy float.
To overcome the issue, one can simply convert the numpy float to a Python float using float(np_float)
.
I don’t know if this issue is solvable on the C++ side of NGSolve.
Greetings,
Paul