SpecialMatrices.jl
SpecialMatrices.jl copied to clipboard
Overload Base.map
I think it would make sense for some types, like Vandermonde
and Companion
, to overload Base.map
. The goal is to make things like map(Float32, Vandermonde([0.5, 3])) isa Vandermonde{Float32}
hold.
Any objections?
Thanks for the suggestion. I have a couple questions.
For A = Vandermonde(1:4)
, currently map(x -> x+1, A)
returns a dense matrix, as it should. So does map(Float32, A)
and I can see why you'd prefer it to return a Vandermonde{Float32}
.
- How would you determine which functions
f
formap(f, A)
would be "Vandermonde preserving"? - Out of curiosity, what is the advantage of changing the type after construction, rather than simply using
Vandermonde(Float32[0.5,3]))
in the first place?
BTW, since you have some interest in this package, would you mind taking a look at #17 and offering a code review? I would like another pair of eyes on it before merging and no one has responded to my request.
How would you determine which functions
f
formap(f, A)
would be "Vandermonde preserving"?
We can't know anything about a Function
, but the overload for Base.map
could have a signature like this, to restrict the first argument only to some known-good types:
Base.map(::Type{T}, m::Vandermonde) where {T <: Number}
This would be similar to the Base.map
overload for UnitRange
s:
julia> map(Float64, 3:5)
3.0:1.0:5.0
julia> @which map(Float64, 3:5)
map(::Type{T}, r::UnitRange) where T<:Real in Base at abstractarray.jl:1176
what is the advantage of changing the type after construction
Just convenience.
would you mind taking a look at #17 and offering a code review
I don't actually know anything about Cauchy matrices, so I'm not sure of how much help I would be, sorry.
restrict the first argument only to some known-good types
Ah, that seems fine then. Should be an easy PR. Please include a test for any type where you add this extension.