@@ -183,6 +183,7 @@ cdef class MKLPardisoSolver:
183183 cdef int_t mat_type
184184 cdef int_t _factored
185185 cdef size_t shape[2 ]
186+ cdef int_t _initialized
186187
187188 cdef void * a
188189
@@ -246,6 +247,7 @@ cdef class MKLPardisoSolver:
246247 >>> np.allclose(x, x_solved)
247248 True
248249 '''
250+ self ._initialized = False
249251 n_row, n_col = A.shape
250252 if n_row != n_col:
251253 raise ValueError (" Matrix is not square" )
@@ -276,13 +278,11 @@ cdef class MKLPardisoSolver:
276278 " matrix dtype and matrix_type not consistent, expected a complex matrix"
277279 )
278280
279-
280281 if self .mat_type in [- 2 , 2 , - 4 , 4 , 6 ]:
281282 A = sp.triu(A, format = ' csr' )
282283 A = _ensure_csr(A)
283284 A.sort_indices()
284285
285-
286286 # set integer length
287287 integer_len = A.indices.itemsize
288288 self ._is_32 = integer_len == sizeof(int_t)
@@ -294,6 +294,7 @@ cdef class MKLPardisoSolver:
294294 self ._initialize(self ._par64, A, matrix_type, verbose)
295295 else :
296296 raise PardisoError(" Unrecognized integer length" )
297+ self ._initialized = True
297298
298299 if (verbose):
299300 # for reporting factorization progress via python's `print`
@@ -488,21 +489,22 @@ cdef class MKLPardisoSolver:
488489 cdef int_t phase= - 1 , nrhs= 0 , error= 0
489490 cdef long_t phase64= - 1 , nrhs64= 0 , error64= 0
490491
491- if self ._is_32:
492- pardiso(
493- self .handle, & self ._par.maxfct, & self ._par.mnum, & self ._par.mtype,
494- & phase, & self ._par.n, self .a, NULL , NULL , NULL , & nrhs, self ._par.iparm,
495- & self ._par.msglvl, NULL , NULL , & error
496- )
497- else :
498- pardiso_64(
499- self .handle, & self ._par64.maxfct, & self ._par64.mnum, & self ._par64.mtype,
500- & phase64, & self ._par64.n, self .a, NULL , NULL , NULL , & nrhs64,
501- self ._par64.iparm, & self ._par64.msglvl, NULL , NULL , & error64
502- )
503- err = error or error64
504- if err!= 0 :
505- raise PardisoError(" Memmory release error " + _err_messages[err])
492+ if self ._initialized:
493+ if self ._is_32:
494+ pardiso(
495+ self .handle, & self ._par.maxfct, & self ._par.mnum, & self ._par.mtype,
496+ & phase, & self ._par.n, self .a, NULL , NULL , NULL , & nrhs, self ._par.iparm,
497+ & self ._par.msglvl, NULL , NULL , & error
498+ )
499+ else :
500+ pardiso_64(
501+ self .handle, & self ._par64.maxfct, & self ._par64.mnum, & self ._par64.mtype,
502+ & phase64, & self ._par64.n, self .a, NULL , NULL , NULL , & nrhs64,
503+ self ._par64.iparm, & self ._par64.msglvl, NULL , NULL , & error64
504+ )
505+ err = error or error64
506+ if err!= 0 :
507+ raise PardisoError(" Memmory release error " + _err_messages[err])
506508
507509 cdef _analyze(self ):
508510 # phase = 11
0 commit comments