This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Numpy conversion error

0 votes

Hi,

I am encountering a numpy conversion error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/ubc/cs/research/scl/people/mwathen/Dropbox/PHDResearch/MHD/FEniCS/MHD/Stabilised/SaddlePointForm/Test/SplitMatrix/ScottTest/MHDfluid.py in <module>()
    362`enter code here`
    363     interactive()
--> 364 foo()

/ubc/cs/research/scl/people/mwathen/Dropbox/PHDResearch/MHD/FEniCS/MHD/Stabilised/SaddlePointForm/Test/SplitMatrix/ScottTest/MHDfluid.py in foo()
    224                 else:
    225                     AA, bb = assemble_system(maxwell+ns+CoupleTerm, (Lmaxwell + Lns) - RHSform,  bcs)
--> 226                     A,b = CP.Assemble(AA,bb)
    227             # if iter == 1:
    228             MO.StrTimePrint("MHD total assemble, time: ", time.time()-AssembleTime)

/ubc/cs/research/scl/people/mwathen/Dropbox/PHDResearch/MHD/FEniCS/Classes/CheckPetsc4py.pyc in Assemble(AA, bb)
     25         if AA.size(1) == AA.size(0):
     26 #            As = AA.sparray()
---> 27             As = AA.sparray()
     28             As.eliminate_zeros()
     29             row, col, value = As.indptr, As.indices, As.data

/ubc/cs/research/scl/people/mwathen/.hastdist/bld/profile/3kneeoad7jpp/lib/python2.7/site-packages/dolfin/cpp/la.py in sparray(self)
    648         "Return a scipy.sparse representation of Matrix"
    649         from scipy.sparse import csr_matrix
--> 650         data = self.data(deepcopy=True)
    651         C = csr_matrix((data[2], data[1], data[0]))
    652         return C

/ubc/cs/research/scl/people/mwathen/.hastdist/bld/profile/3kneeoad7jpp/lib/python2.7/site-packages/dolfin/cpp/la.py in data(self, deepcopy)
    665                 destroyed together with the destruction of the Matrix
    666         """
--> 667         rows, cols, values = self._data()
    668         if deepcopy:
    669             rows, cols, values = rows.astype(int), cols.astype(int), values.copy()

TypeError: NumPy conversion error

how do I get around this?

asked Sep 14, 2015 by mwathen FEniCS Novice (710 points)

Can you post the full source code?

To run the the script that produces this error?

Yes...? That would help a lot...

Unfortunately I'm not able to provide the source code, there is too much of it....

When I fun the same code for smaller systems (<50 million) this code works fine, it just seems to have a problem for large scale problems

Hi, what version of FEniCS are you on? You should be able to reproduce your error by assembling any large matrix and then calling its sparray method. Check length of the column indices vector in comparison to the largest int (np.iinfo(int).max).

Is there a way to remove the 0's from the sparsity pattern before calling sparray?

...