I am wondering about Julia conventions - is there a function or kwarg for skipping an intermediate type when taking an array through getindex and then vec?
More concretely, suppose we are doing a getindex call on a SparseMatrixCSC and convert the result into a vector:
using SparseArrays
sa = sparse([1 0 1; 0 1 0])
x = vec(sa[1:2, 1:2])
What is returned by getindex is a SparseMatrixCSC:
typeof(sa[1:2, 1:2]) <: SparseMatrixCSC
I want to skip the intermediate allocation to a SparseMatrixCSC, but I want to do it in a way that accords with Julia conventions. Note that getindex(args…; kwargs…) does not allow using kwargs with the bracket syntactic sugar.
The reason why I am asking is because I have defined my own array type such that it would be computationally cheaper if I could skip the intermediate getindex type. I would like something like:
typeof(my_arr) <: MyArrayType
typeof(getindex_as_vec(my_arr, 1:2, 1:2)) <: Vector
But I don’t want to write the function name getindex_as_vec if there is some convention I should be adhering to.