Skip to content

Commit

Permalink
Remove Base method extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
lopezm94 committed Nov 4, 2016
1 parent e6faff0 commit 2fb04be
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/SugarBLAS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ export @blas!
include("Match/Match.jl")
using .Match

import Base: copy, -

copy(s::Symbol) = s #Generic fallback deprecated in 0.5

"""
Negate a symbol or expression
Negate a number, symbol or expression
"""
function -(ast)
neg(ast::Number) = -ast
function neg(ast::Union{Symbol, Expr})
if @match(ast, -ast) | (ast == 0)
ast
else
Expand Down Expand Up @@ -127,7 +124,7 @@ macro blas!(expr::Expr)
@case begin
@match(expr, X *= a) => @call scale!(a,X)
@match(expr, X = a*X) => @call scale!(a,X)
@match(expr, Y = Y - a*X) => @call Base.LinAlg.axpy!(-a,X,Y)
@match(expr, Y = Y - a*X) => @call Base.LinAlg.axpy!(neg(a),X,Y)
@match(expr, Y = Y - X) => @call Base.LinAlg.axpy!(-1.0,X,Y)
@match(expr, Y = a*X + Y) => @call Base.LinAlg.axpy!(a,X,Y)
@match(expr, Y = X + Y) => @call Base.LinAlg.axpy!(1.0,X,Y)
Expand Down Expand Up @@ -186,7 +183,7 @@ macro axpy!(expr::Expr)
unkeyword!(expr)
expr = expand(expr)
@case begin
@match(expr, Y = Y - a*X) => @call(Base.LinAlg.axpy!(-a,X,Y))
@match(expr, Y = Y - a*X) => @call(Base.LinAlg.axpy!(neg(a),X,Y))
@match(expr, Y = Y - X) => @call Base.LinAlg.axpy!(-1.0,X,Y)
@match(expr, Y = a*X + Y) => @call Base.LinAlg.axpy!(a,X,Y)
@match(expr, Y = X + Y) => @call Base.LinAlg.axpy!(1.0,X,Y)
Expand All @@ -208,7 +205,7 @@ macro ger!(expr::Expr)
expr = expand(expr)
f = @case begin
@match(expr, A = alpha*x*y' + A) => identity
@match(expr, A = A - alpha*x*y') => (-)
@match(expr, A = A - alpha*x*y') => neg
otherwise => error("No match found")
end
@call Base.LinAlg.BLAS.ger!(f(alpha),x,y,A)
Expand All @@ -231,7 +228,7 @@ macro syr!(expr::Expr)
@match(expr, A[uplo] = right) || error("No match found")
f = @case begin
@match(right, alpha*x*x.' + Y) => identity
@match(right, Y - alpha*x*x.') => (-)
@match(right, Y - alpha*x*x.') => neg
otherwise => error("No match found")
end
(@match(Y, Y[uplo]) && (Y == A)) || (Y == A) || error("No match found")
Expand Down Expand Up @@ -282,7 +279,7 @@ macro syrk!(expr::Expr)
@match(expr, C[uplo] = right) || error("No match found")
f = @case begin
@match(right, alpha*X*Y + D) => identity
@match(right, D - alpha*X*Y) => (-)
@match(right, D - alpha*X*Y) => neg
otherwise => error("No match found")
end
trans = @case begin
Expand Down Expand Up @@ -312,7 +309,7 @@ macro her!(expr::Expr)
@match(expr, A[uplo] = right) || error("No match found")
f = @case begin
@match(right, alpha*x*x' + Y) => identity
@match(right, Y - alpha*x*x') => (-)
@match(right, Y - alpha*x*x') => neg
otherwise => error("No match found")
end
(@match(Y, Y[uplo]) && (Y == A)) || (Y == A) || error("No match found")
Expand Down Expand Up @@ -361,7 +358,7 @@ macro herk!(expr::Expr)
@match(expr, C[uplo] = right) || error("No match found")
f = @case begin
@match(right, alpha*X*Y + D) => identity
@match(right, D - alpha*X*Y) => (-)
@match(right, D - alpha*X*Y) => neg
otherwise => error("No match found")
end
trans = @case begin
Expand Down Expand Up @@ -389,7 +386,7 @@ macro gbmv(expr::Expr)
@match(expr, alpha*Y*x) || error("No match found")
trans = @match(Y, Y') ? 'T' : 'N'
@match(Y, A[kl:ku,h=m])
@call Base.LinAlg.BLAS.gbmv(trans,m,-kl,ku,alpha,A,x)
@call Base.LinAlg.BLAS.gbmv(trans,m,neg(kl),ku,alpha,A,x)
end

"""
Expand All @@ -410,14 +407,14 @@ macro gbmv!(expr::Expr)
@match(expr, y = right) || error("No match found")
f = @case begin
@match(right, alpha*Y*x + w) => identity
@match(right, w - alpha*Y*x) => (-)
@match(right, w - alpha*Y*x) => neg
otherwise => error("No match found")
end
trans = @match(Y, Y') ? 'T' : 'N'
@match(Y, A[kl:ku,h=m])
@match(w, beta*w) || (beta = 1.0)
(y == w) || error("No match found")
@call Base.LinAlg.BLAS.gbmv!(trans,m,-kl,ku,f(alpha),A,x,beta,y)
@call Base.LinAlg.BLAS.gbmv!(trans,m,neg(kl),ku,f(alpha),A,x,beta,y)
end

"""
Expand Down Expand Up @@ -458,7 +455,7 @@ macro sbmv!(expr::Expr)
@match(expr, y = right) || error("No match found")
f = @case begin
@match(right, alpha*A[0:k,uplo]*x + w) => identity
@match(right, w - alpha*A[0:k,uplo]*x) => (-)
@match(right, w - alpha*A[0:k,uplo]*x) => neg
otherwise => error("No match found")
end
@match(w, beta*w) || (beta = 1.0)
Expand Down Expand Up @@ -519,7 +516,7 @@ macro gemm!(expr::Expr)
@match(expr, C = right) || error("No match found")
f = @case begin
@match(right, alpha*A*B + D) => identity
@match(right, D - alpha*A*B) => (-)
@match(right, D - alpha*A*B) => neg
otherwise => error("No match found")
end
tA = @match(A, A') ? 'T' : 'N'
Expand Down Expand Up @@ -571,9 +568,9 @@ macro gemv!(expr::Expr)
expr = expand(expr)
@match(expr, y = right) || error("No match found")
f = @case begin
@match(right, alpha*A*x + w) => identity
@match(right, w - alpha*A*x) => (-)
otherwise => error("No match found")
@match(right, alpha*A*x + w) => identity
@match(right, w - alpha*A*x) => neg
otherwise => error("No match found")
end
tA = @match(A, A') ? 'T' : 'N'
@match(w, beta*w) || (beta = 1.0)
Expand Down Expand Up @@ -634,7 +631,7 @@ macro symm!(expr::Expr)
@match(expr, C = right) || error("No match found")
f = @case begin
@match(right, alpha*A*B + D) => identity
@match(right, D - alpha*A*B) => (-)
@match(right, D - alpha*A*B) => neg
otherwise => error("No match found")
end
side = @case begin
Expand Down Expand Up @@ -684,7 +681,7 @@ macro symv!(expr::Expr)
@match(expr, y = right) || error("No match found")
f = @case begin
@match(right, alpha*A[uplo]*x + w) => identity
@match(right, w - alpha*A[uplo]*x) => (-)
@match(right, w - alpha*A[uplo]*x) => neg
otherwise => error("No match found")
end
@match(w, beta*w) || (beta = 1.0)
Expand Down

0 comments on commit 2fb04be

Please sign in to comment.