Skip to content

Commit d5155c7

Browse files
committed
Fix fallback methods
1 parent d4b734b commit d5155c7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/LinearMaps.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,25 @@ end
3939
# the following for multiplying with transpose and adjoint map are optional:
4040
# subtypes can overwrite nonmutating methods, implement mutating methods or do nothing
4141
function Base.At_mul_B(A::LinearMap, x::AbstractVector)
42-
if length(methods(Base.At_mul_B!,Tuple{AbstractVector, typeof(A), AbstractVector})) > 1
42+
l = methods(Base.At_mul_B!,Tuple{AbstractVector, typeof(A), AbstractVector})
43+
if length(l) > 0 && first(l.ms).sig.parameters[3] != LinearMap
4344
Base.At_mul_B!(similar(x, promote_type(eltype(A), eltype(x)), size(A,2)), A, x)
4445
else
4546
throw(MethodError(Base.At_mul_B, (A, x)))
4647
end
4748
end
4849
function Base.At_mul_B!(y::AbstractVector, A::LinearMap, x::AbstractVector)
4950
length(y) == size(A, 2) || throw(DimensionMismatch("At_mul_B!"))
50-
if length(methods(Base.At_mul_B,Tuple{typeof(A), AbstractVector})) > 1
51+
l = methods(Base.At_mul_B,Tuple{typeof(A), AbstractVector})
52+
if length(l) > 0 && first(l.ms).sig.parameters[2] != LinearMap
5153
copy!(y, Base.At_mul_B(A, x))
5254
else
5355
throw(MethodError(Base.At_mul_B!, (y, A, x)))
5456
end
5557
end
5658
function Base.Ac_mul_B(A::LinearMap,x::AbstractVector)
57-
if length(methods(Base.Ac_mul_B!,Tuple{AbstractVector, typeof(A), AbstractVector})) > 1
59+
l = methods(Base.Ac_mul_B!,Tuple{AbstractVector, typeof(A), AbstractVector})
60+
if length(l) > 0 && first(l.ms).sig.parameters[3] != LinearMap
5861
Base.Ac_mul_B!(similar(x, promote_type(eltype(A), eltype(x)), size(A,2)), A, x)
5962
else
6063
throw(MethodError(Base.Ac_mul_B, (A, x)))
@@ -63,7 +66,8 @@ end
6366
function
6467
Base.Ac_mul_B!(y::AbstractVector, A::LinearMap, x::AbstractVector)
6568
length(y)==size(A,2) || throw(DimensionMismatch("At_mul_B!"))
66-
if length(methods(Base.Ac_mul_B,Tuple{typeof(A), AbstractVector})) > 1
69+
l = methods(Base.Ac_mul_B,Tuple{typeof(A), AbstractVector})
70+
if length(l) > 0 && first(l.ms).sig.parameters[2] != LinearMap
6771
copy!(y, Base.Ac_mul_B(A, x))
6872
else
6973
throw(MethodError(Base.Ac_mul_B!, (y, A, x)))

test/runtests.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
if VERSION < v"0.7.0-DEV.2005"
2+
const Test = Base.Test
3+
end
4+
5+
using Test
16
using LinearMaps
2-
using Base.Test
37

48
import Base: *
59

@@ -45,6 +49,11 @@ F = LinearMap(cumsum,10)
4549
@test F*v == cumsum(v)
4650
@test_throws ErrorException F'*v
4751

52+
# Test fallback methods:
53+
L = LinearMap(x->x,x->x,10)
54+
v = randn(10);
55+
@test (2*L)'*v 2*v
56+
4857
# test linear combinations
4958
A = 2*rand(Complex128,(10,10)).-1
5059
M = LinearMap(A)

0 commit comments

Comments
 (0)