add minimalvec#22
Conversation
|
Ok I think this is ready. Maybe some review is welcome, @lkdvos ? |
There was a problem hiding this comment.
In principle, this is quite an extensive testset for something that is simply wrapping Vector. We could simply have:
@testset "scale" begin
a = rand(2)
alfa = rand()
@test scale(a, alfa) == scale(MinimalMVec(a), alfa).vec
...
endAlong with some simple checks of type stability. I am also fine with just leaving this as is, but less code is easier to maintain 😉
There was a problem hiding this comment.
That is true, it's copy pasted code, with small adjustments for the specific case.
It did help me with finding some problem in our fallbacks though. Base has a mul!(::Any, :Any, :Any) method, so testing applicable(mul!, x, y, alpha) was kind of pointless. That Tuple{Any,Any,Any} method assumes this is a matrix multiplication call, and just adds 2 more arguments true and false playing the role of alpha and beta. But that is of course pointless if you want to do what we call scale! or add!, and alpha is already the third argument. I guess this just illustrates what I dislike about the current mul! method and why I started VectorInterface.jl in the first place.
It actually also helped me track down another error in our MinimalVec implementation, where our interface promises that scale!!(y, x, alpha) will always work. So even if y is mutable, but happens to have a scalar type that is not compatible with the scalar type of x * alpha, the method should not complain and return a new vector (which actually has scalar type that is the promotion of that of y, x and alpha)`. This was broken and resulting in an error in the original implementation.
So I would favor keeping it for now.
Co-authored-by: Lukas Devos <ldevos98@gmail.com>
No description provided.