Skip to content
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

Wrap matrix copyto! incorrect #144

Open
liamh opened this issue Dec 18, 2024 · 3 comments
Open

Wrap matrix copyto! incorrect #144

liamh opened this issue Dec 18, 2024 · 3 comments

Comments

@liamh
Copy link

liamh commented Dec 18, 2024

When using copyto! with wrap_gsl_matrix, the result looks correct but it is not.

using GSL
mat = reshape([Float64(10*j+i) for i=1:2 for j=1:4],4,2)
matgsl = GSL.matrix_alloc(4,2)
copyto!(GSL.wrap_gsl_matrix(matgsl), CartesianIndices((4,2)), mat, CartesianIndices((4,2)))

Which gives the expected results for mat and GSL.wrap_gsl_matrix(matgsl)

4×2 Matrix{Float64}:
 11.0  12.0
 21.0  22.0
 31.0  32.0
 41.0  42.0

but e.g. the first column that's actually in the GSL matrix is not correct

[GSL.matrix_get(matgsl,i,0) for i=0:3]
4-element Vector{Float64}:
 11.0
 31.0
 12.0
 32.0
@liamh
Copy link
Author

liamh commented Dec 18, 2024

Actually, it doesn't have to do with copyto!; I got rid of that and still I must fix up the wrap_gsl_matrix() result. With solngsl being the GSL matrix pointer,

solnjl = GSL.wrap_gsl_matrix(solngsl)
soln = reshape(reshape(solnjl,size(solnjl,1)*size(solnjl,2)),size(solnjl,2),size(solnjl,1))'

@giordano
Copy link
Member

Is that simply because GSL is row-major, while Julia is column-major? Having to transpose matrices when interacting with external libraries is pretty normal.

@liamh
Copy link
Author

liamh commented Dec 18, 2024

I believe it is. It would be nice if there were some kind of transpose-storage function, or at least a warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants