SparseMatrixCSC allocation

How to allocate an uninitialised SparseMatrixCSC in the C Embedding API? I mean I couldn’t find/create the type variable for SparseMatrixCSC.

Does the docs at https://docs.julialang.org/en/release-0.6/manual/arrays/#Compressed-Sparse-Column-(CSC)-Storage-1 help?

No, sorry, I wasn’t clear in my question, it is to allocate in the C Embedding API.

Apart from a few special types (ones that users might be interested in includes DataType, Module, Tuple, Array, String, Symbol) all types are defined in julia so there isn’t and won’t be C-API for them. You should write your own julia functions or make use of existing ones (using jl_get_global, jl_eval_string etc) to call julia code that does the allocation.

2 Likes

You seem to want to make your life difficult by writing Julia in C++. You should write Julia in Julia instead. What are you trying to do? There should be a simpler way to go about it.

No, I’m writing an interface for Scilab, another language, to call any function from Julia.

Then, how do I check whether, given a variable, it is of type SparseMatrixCSC?

The type is accessible using the same C API.

I didn’t quite get you and if you’re telling me to check with type in the C API, I couldn’t find the type.
I’d appreciate if you give me an example.
Thank you so much.

If what you want is equivalent to julia code isa(v, SparseMatrixCSC) then you can just do sth like

jl_typeis(v, jl_get_global(jl_base_module, jl_symbol("SparseMatrixCSC")))
2 Likes

I tried this

jl_value_t *empty = jl_eval_string("sparse([0 4325; 23 0; 0 0; 245 2352])");
jl_typeis(empty, jl_get_global(jl_base_module, jl_symbol("SparseMatrixCSC")));
jl_typeis(empty, jl_get_global(jl_base_module, jl_symbol("SparseMatrixCSC{Int64}")));
jl_typeis(empty, jl_get_global(jl_base_module, jl_symbol("SparseMatrixCSC{Int64,Int64}")));

And none of them gave positive. Why is this?

Thank you

Seems that jl_typeis is typeof(...) == ... not isa, so replace that with jl_isa.

Note that SparseMatrixCSC{Int64} isn’t the name of a global. You should either evaluate it as a string or apply the type.

I forgot to mention I’m using julia-0.5, and I couldn’t find jl_isa in 0.5. I see it is in 0.6. Is there an equivalent function in 0.5?