Why the sparse pattern of a sparse matrix changed

I'm building a sparse matrix through the mex function. Both the Ir and Jc properties are appointed in the mex function A. Later, this sparse matrix is returned to matlab, and is further transferred to another mex function B together with other parameters to assemble a large matrix.
For one test case, part of the Jc property of the created sparse matrix in the mex function A is as follows:
368
392
416
440
464
488
512
But when this sparse matrix is further transferred to mex function B, this part is altered and is as follows:
368
392
416
440
463
487
511
Actually, after this sparse matrix is established, I did no alternation about it. I want to know what may case this.

4 Kommentare

Matt J
Matt J am 11 Apr. 2021
Bearbeitet: Matt J am 11 Apr. 2021
I did no alternation about it
But you did (no one else could have - I certainly didn't). The question is where.
Rylan
Rylan am 11 Apr. 2021
What if some data in the sparse matrix is zero, whther or not the structure of the sparse matrix would be altered when the matrix returned to matlab
You MUST NOT store 0 elements internally. Use spok I indicate bellow to check if your mex-build result is valid.
Rylan
Rylan am 11 Apr. 2021
(9,22) -0.0000
(10,22) 0
(11,22) 0.0000
(12,22) -0.0000
(13,22) -0.2500
(14,22) 0.5000
It seems problem was caused by (10,22), and use of spok indicate that "0 jumbled row indices, 3 explicit zeros". To remove this problem, may be a vary small number, for example, 1e-16, should be added to all the data member.
Thanks for your suggestion!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Bruno Luong
Bruno Luong am 11 Apr. 2021

1 Stimme

The mex probably creates a non-valid sparse matrix, use spok to check validity

Weitere Antworten (0)

Kategorien

Mehr zu Sparse Matrices finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 11 Apr. 2021

Kommentiert:

am 28 Jan. 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by