diff --git a/src/linear_algebra.jl b/src/linear_algebra.jl index 6c2efedb..22b87e14 100644 --- a/src/linear_algebra.jl +++ b/src/linear_algebra.jl @@ -57,3 +57,6 @@ function LinearAlgebra.axpby!(α::Number, x::ComponentArray, β::Number, y::Comp axpby!(α, getdata(x), β, getdata(y)) return ComponentArray(y, getaxes(y)) end + +lmul!(a::Number, B::ComponentArray) = ComponentArray(lmul!(a, getdata(B)), getaxes(B)) + diff --git a/test/runtests.jl b/test/runtests.jl index 4f4d4167..8d9279af 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,6 @@ caa = ComponentArray(a = ca, b = sq_mat) _a, _b, _c = Val.((:a, :b, :c)) - ## Tests @testset "Allocations and Inference" begin @test @ballocated($ca.c.a.a) == 0 @@ -690,6 +689,19 @@ end @test_throws ArgumentError axpby!(2, x, 3, y) end +@testset "lmul!" begin + a = rand() + x = ComponentArray(a = rand(4), b = rand(4)) + + xdata = copy(getdata(x)) + xaxes = getaxes(x) + + y = lmul!(a, x) + @test y == x + @test getdata(x) ≈ a * xdata + @test getaxes(x) == xaxes +end + @testset "Autodiff" begin include("autodiff_tests.jl") end