My apologies in case this has been discussed before. @dkarrasch would you consider making LinearMap{T} a subtype of AbstractMatrix{T}?
I've really grow to love the flexibility of LinearMaps and the ability to use them as drop-in replacements for matrices in many applications. But sometimes that's not easy because generic code in packages frequently requires an AbstractMatrix as the argument type - a LinearMap would often work well since a lot of code only uses high-level linear algebra operations, but LinearMap and AbstractMatrix just have no common supertype that typical package code would dispatch on.
To me, a LinearMap feels like a matrix in almost every way already - is has a size, element type, etc. What it currently doesn't have is getindex - but I think it could. A[:,:] and A[:,j] would be efficient, and if A is transposable then A[i,:] would be efficient as well. Even views would be somewhat efficient I guess, just A[i,j] would be horribly inefficient of course. But the same is true for Julia GPU arrays like CuArray - one could adopt the same warning/error mechanism implemented there that alerts users that serial/element-wise access is inefficient (or even prevents it).
My apologies in case this has been discussed before. @dkarrasch would you consider making
LinearMap{T}a subtype ofAbstractMatrix{T}?I've really grow to love the flexibility of
LinearMaps and the ability to use them as drop-in replacements for matrices in many applications. But sometimes that's not easy because generic code in packages frequently requires anAbstractMatrixas the argument type - aLinearMapwould often work well since a lot of code only uses high-level linear algebra operations, butLinearMapandAbstractMatrixjust have no common supertype that typical package code would dispatch on.To me, a
LinearMapfeels like a matrix in almost every way already - is has a size, element type, etc. What it currently doesn't have isgetindex- but I think it could.A[:,:]andA[:,j]would be efficient, and ifAis transposable thenA[i,:]would be efficient as well. Even views would be somewhat efficient I guess, justA[i,j]would be horribly inefficient of course. But the same is true for Julia GPU arrays likeCuArray- one could adopt the same warning/error mechanism implemented there that alerts users that serial/element-wise access is inefficient (or even prevents it).