Skip to content

Commit

Permalink
Remove dot operators
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira authored and dpo committed Apr 12, 2018
1 parent 1dc03e8 commit 2c29006
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
18 changes: 4 additions & 14 deletions src/LinearOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,8 @@ end
+(op :: AbstractLinearOperator, M :: AbstractMatrix) = op + LinearOperator(M)

# Operator .+ scalar.
@static if VERSION < v"0.6.0-"
.+(op :: AbstractLinearOperator, x :: Number) = op + x * opOnes(op.nrow, op.ncol)
.+(x :: Number, op :: AbstractLinearOperator) = x * opOnes(op.nrow, op.ncol) + op
else
+(op :: AbstractLinearOperator, x :: Number) = op + x * opOnes(op.nrow, op.ncol)
+(x :: Number, op :: AbstractLinearOperator) = x * opOnes(op.nrow, op.ncol) + op
end
+(op :: AbstractLinearOperator, x :: Number) = op + x * opOnes(op.nrow, op.ncol)
+(x :: Number, op :: AbstractLinearOperator) = x * opOnes(op.nrow, op.ncol) + op

# Operator - operator
-(op1 :: AbstractLinearOperator, op2 :: AbstractLinearOperator) = op1 + (-op2)
Expand All @@ -381,13 +376,8 @@ end
-(op :: AbstractLinearOperator, M :: AbstractMatrix) = op - LinearOperator(M)

# Operator - scalar.
@static if VERSION < v"0.6.0-"
.-(op :: AbstractLinearOperator, x :: Number) = op .+ (-x)
.-(x :: Number, op :: AbstractLinearOperator) = x .+ (-op)
else
-(op :: AbstractLinearOperator, x :: Number) = op + (-x)
-(x :: Number, op :: AbstractLinearOperator) = x + (-op)
end
-(op :: AbstractLinearOperator, x :: Number) = op + (-x)
-(x :: Number, op :: AbstractLinearOperator) = x + (-op)


# Utility functions.
Expand Down
14 changes: 4 additions & 10 deletions test/test_linop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ function test_linop()

B2 = rand(ncol, ncol+1) + rand(ncol, ncol+1) * im;
@testset "Operator ± scalar" begin
opC = LinearOperator(A1) .+ 2.12345;
opC = LinearOperator(A1) + 2.12345;
@test(vecnorm(A1 .+ 2.12345 - full(opC)) <= rtol * vecnorm(A1 .+ 2.12345));

opC = 2.12345 .+ LinearOperator(A1);
opC = 2.12345 + LinearOperator(A1);
@test(vecnorm(A1 .+ 2.12345 - full(opC)) <= rtol * vecnorm(A1 .+ 2.12345));

opC = LinearOperator(A1) .- 2.12345;
opC = LinearOperator(A1) - 2.12345;
@test(vecnorm((A1 .- 2.12345) - full(opC)) <= rtol * vecnorm(A1 .- 2.12345));

opC = 2.12345 .- LinearOperator(A1);
opC = 2.12345 - LinearOperator(A1);
@test(vecnorm((2.12345 .- A1) - full(opC)) <= rtol * vecnorm(2.12345 .- A1));

C = A1 * B2;
Expand Down Expand Up @@ -126,17 +126,11 @@ function test_linop()
@testset "Scalar × operator" begin
opC = 2.12345 * LinearOperator(A1);
@test(vecnorm(AA1 - full(opC)) <= rtol * vecnorm(AA1));

opC = 2.12345 .* LinearOperator(A1);
@test(vecnorm(AA1 - full(opC)) <= rtol * vecnorm(AA1));
end

@testset "Operator × scalar" begin
opC = LinearOperator(A1) * 2.12345;
@test(vecnorm(AA1 - full(opC)) <= rtol * vecnorm(AA1));

opC = LinearOperator(A1) .* 2.12345;
@test(vecnorm(AA1 - full(opC)) <= rtol * vecnorm(AA1));
end
end

Expand Down

0 comments on commit 2c29006

Please sign in to comment.