Why aren’t F and V below of the same type? How can I write a function that will handle both of them (but not also any generic vector)?
using SparseArrays
F = Vector{SparseVector}()
push!(F, sparse([1, -1, 5, -5]))
push!(F, sparse([4, -4, -3, 3]))
push!(F, sparse([3, -3, 1, -4]))
push!(F, sparse([8, -8, 1, -1]))
V = [
sparse([1, -1, 5, -5]),
sparse([4, -4, -3, 3]),
sparse([3, -3, 1, -4]),
sparse([8, -8, 1, -1])
]
typeof(F) # Vector{SparseVector}
typeof(V) # Vector{SparseVector{Int64, Int64}}
So, for example, this function
function foo(V::Vector{SparseVector})
println("My function 'tis of thee.")
end
only works on F
, and this function
function foo(V::Vector{SparseVector{Int,Int}})
println("Sweet Int of Int I see.")
end
only works on V
. I’d like to write a function that will work on both.