@@ -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
@@ -283,6 +284,7 @@ cdef class MKLPardisoSolver:
283284 A.sort_indices()
284285
285286
287+ self ._initialized = False
286288 # set integer length
287289 integer_len = A.indices.itemsize
288290 self ._is_32 = integer_len == sizeof(int_t)
@@ -294,6 +296,7 @@ cdef class MKLPardisoSolver:
294296 self ._initialize(self ._par64, A, matrix_type, verbose)
295297 else :
296298 raise PardisoError(" Unrecognized integer length" )
299+ self ._initialized = True
297300
298301 if (verbose):
299302 # for reporting factorization progress via python's `print`
@@ -488,21 +491,22 @@ cdef class MKLPardisoSolver:
488491 cdef int_t phase= - 1 , nrhs= 0 , error= 0
489492 cdef long_t phase64= - 1 , nrhs64= 0 , error64= 0
490493
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])
494+ if self ._initialized:
495+ if self ._is_32:
496+ pardiso(
497+ self .handle, & self ._par.maxfct, & self ._par.mnum, & self ._par.mtype,
498+ & phase, & self ._par.n, self .a, NULL , NULL , NULL , & nrhs, self ._par.iparm,
499+ & self ._par.msglvl, NULL , NULL , & error
500+ )
501+ else :
502+ pardiso_64(
503+ self .handle, & self ._par64.maxfct, & self ._par64.mnum, & self ._par64.mtype,
504+ & phase64, & self ._par64.n, self .a, NULL , NULL , NULL , & nrhs64,
505+ self ._par64.iparm, & self ._par64.msglvl, NULL , NULL , & error64
506+ )
507+ err = error or error64
508+ if err!= 0 :
509+ raise PardisoError(" Memmory release error " + _err_messages[err])
506510
507511 cdef _analyze(self ):
508512 # phase = 11
0 commit comments