3
votes

I am currently working on converting R code into Julia (0.6), and I was wondering if there was any Julia function that would allow me to create an object comparable to R sparse matrices of class ngCMatrix. They are very efficient since they just bear the location of non-zeros numbers without having to actually store a non-zero number.

sparseMatrix(1:10,1:10)
10 x 10 sparse Matrix of class "ngCMatrix"

 [1,] | . . . . . . . . .
 [2,] . | . . . . . . . .
 [3,] . . | . . . . . . .
 [4,] . . . | . . . . . .
 [5,] . . . . | . . . . .
 [6,] . . . . . | . . . .
 [7,] . . . . . . | . . .
 [8,] . . . . . . . | . .
 [9,] . . . . . . . . | .
[10,] . . . . . . . . . |

Since I am working with big matrices, it would make my code faster. I have not found in Julia sparse matrices documentation a similar function. Is there one way to reproduce that type of matrice in Julia ?

Thanks

Julie

1

1 Answers

1
votes

You can always search Julia documentation, and also use the help mode in the Julia prompt by typing ? followed by some keyword you are interested in. In this case, ?sparse showed me the answer:

sparse([],[],[],10,10) # creates a 10x10 sparse matrix

Or if you want to fill some entries:

Is = [1;2;3]
Js = [1;2;3]
Vs = [1;2;3]

sparse(Is, Js, Vs) # creates a diagonal sparse matrix