Skip to content

Example matrix uses 1-based indexing in documentation for C interface #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rwl opened this issue Apr 8, 2025 · 3 comments · Fixed by #247
Closed

Example matrix uses 1-based indexing in documentation for C interface #246

rwl opened this issue Apr 8, 2025 · 3 comments · Fixed by #247
Assignees
Labels

Comments

@rwl
Copy link

rwl commented Apr 8, 2025

The examples provided for CSC and Coordinate matrix format use 1-based indexing in the documentation for the C interface:

int n = 5;
int ptr[] = { 1, 4, 5, 7, 9, 10 };
int row[] = { 1, 2, 4, 3, 3, 5, 4, 5, 5 };
double val[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };

int n = 5;
int ne = 9;
int row[] = { 1, 2, 3, 4, 3, 5, 4, 5, 5 };
int col[] = { 1, 1, 2, 1, 3, 3, 4, 4, 5 };
double val[] = { 1.1, 2.2, 4.4, 3.3, 5.5, 6.6, 7.7, 8.8, 9.9 };

The C examples use 0-based indexing:

/* Data for unsymmetric matrix:
* ( 2 5 )
* ( 1 4 7 )
* ( 1 2 )
* ( 3 )
* ( 8 2 ) */
int m = 5, n = 5;
int ptr[] = { 0, 2, 6, 7, 8, 10 };
int row[] = { 0, 1, 0, 1, 2, 4, 3, 2, 1, 4 };
double val[] = { 2.0, 1.0, 5.0, 4.0, 1.0, 8.0, 3.0, 2.0, 7.0, 2.0 };

@rwl
Copy link
Author

rwl commented Apr 8, 2025

The scaling examples in C produce a matching result that has 0-based indexing:

spral/docs/C/scaling.rst

Lines 196 to 211 in d217ecd

Initial matrix:
Real symmetric indefinite matrix, dimension 5x5 with 8 entries.
0: 2.0000E+00 1.0000E+00
1: 1.0000E+00 4.0000E+00 1.0000E+00 8.0000E+00
2: 1.0000E+00 3.0000E+00 2.0000E+00
3: 2.0000E+00
4: 8.0000E+00 2.0000E+00
Matching: 0 4 3 2 1
Scaling: 7.07E-01 1.62E-01 2.78E-01 1.80E+00 7.72E-01
Scaled matrix:
Real symmetric indefinite matrix, dimension 5x5 with 8 entries.
0: 1.0000E+00 1.1443E-01
1: 1.1443E-01 1.0476E-01 4.5008E-02 1.0000E+00
2: 4.5008E-02 2.3204E-01 1.0000E+00
3: 1.0000E+00
4: 1.0000E+00 1.1932E+00

Presumably, this then means that an unmatched row is indicated by -1 when using C. The documentation for the match parameters is the same as for Fortran e.g:

spral/docs/C/scaling.rst

Lines 73 to 75 in d217ecd

:param match: may be `NULL`; otherwise, an array of size `n` to output the
matching found by routine. Row `i` is matched to column `match[i]`, or is
unmatched if `match[i]=0`.

@jfowkes jfowkes added the docs label Apr 8, 2025
@jfowkes jfowkes self-assigned this Apr 8, 2025
@jfowkes
Copy link
Contributor

jfowkes commented Apr 8, 2025

Thank you for reporting, this is a copy-paste issue with the C documentation.

@jfowkes
Copy link
Contributor

jfowkes commented Apr 8, 2025

The C should indeed return -1 for unmatched rows by default (when the array_base option is set to 0 which is the default).

@jfowkes jfowkes linked a pull request Apr 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants