Skip to content

Commit d5dc7d2

Browse files
committed
add mean of LinearCombination
1 parent a3dca0a commit d5dc7d2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/linearcombination.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Base.mapreduce(::typeof(identity), ::typeof(Base.add_sum), maps::AbstractVector{
2222
LinearCombination{T}(maps)
2323

2424
mean(f::F, maps::LinearMapTupleOrVector) where {F} = sum(f, maps) / length(maps)
25-
mean(maps::LinearMapTupleOrVector) = sum(maps) / length(maps)
25+
mean(maps::LinearMapTupleOrVector) = mean(identity, maps)
26+
mean(A::LinearCombination) = mean(A.maps)
2627

2728
MulStyle(A::LinearCombination) = MulStyle(A.maps...)
2829

test/linearcombination.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using LinearMaps: FiveArg, LinearMapTuple, LinearMapVector
1717
@test isa((@inferred mean(Lv.maps)),
1818
LinearMaps.ScaledMap{ComplexF64,Float64,<:LinearMaps.LinearCombination{ComplexF64,<:LinearMapVector}})
1919
@test (@inferred mean(L.maps)) == (@inferred mean(Lv.maps)) == (@inferred sum(Lv.maps))/n
20+
@test (@inferred mean(L)) == (@inferred mean(Lv))
2021
@test (@inferred mean(x -> x*x, L.maps)) == (@inferred sum(x -> x*x, L.maps))/n
2122
@test mean(x -> x*x, Lv.maps) == (sum(x -> x*x, Lv.maps))/n
2223
@test L == Lv

0 commit comments

Comments
 (0)