SparseMatrixCSC allocation

question
embedding

#1

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


#2

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


#3

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


#4

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.


#5

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.


#6

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


#7

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


#8

The type is accessible using the same C API.


#9

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.


#10

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")))

#11

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


#12

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.


#13

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?