segfault when creating empty DenseMatrix
The following python code segfaults in ipython using the latest version of symengine from PyPI.
import symengine
symengine.DenseMatrix(4, 4)
Please let me know if I should have filed this issue to the python bindings instead.
I think that the constructor with just the rows and cols should be made private. I assume that you want a zero matrix right? There's a zeros method for that.
I think it's useful to be able to create an empty matrix also, like NumPy's empty. But either way it should not segfault, thanks @rikardn for reporting it.
You can create an empty matrix, but you can't print it.
Adding a check to all function calls to check if it's empty can be done in the python wrapper. Doing it in C++ to each function might be too costly.
Yes, we should not be doing it in C++.
The constructor for the empty DenseMatrix is as follows:
DenseMatrix::DenseMatrix(unsigned row, unsigned col) : row_(row), col_(col)
{
m_ = std::vector<RCP<const Basic>>(row * col);
}
It creates the vector and the RCPs, but they don't point to anything. We can assign to them in python with:
import symengine
A = symengine.DenseMatrix(2, 2)
A[0, 1] = 2
but we cannot print the entire matrix until all elements have been assigned. I assume RCP will default to nullptr so I guess checking for nullptrs before printing in the python wrapper is the solution here.