Skip to content

Commit

Permalink
Merge pull request JuliaLang#9141 from nwh/blas-scal-cleanup
Browse files Browse the repository at this point in the history
Blas scal cleanup
  • Loading branch information
Viral B. Shah committed Nov 25, 2014
2 parents a02fdc7 + a384f0a commit f0dd6c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 12 additions & 12 deletions base/linalg/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ for (fname, elty) in ((:dscal_,:Float64),
(:cscal_,:Complex64))
@eval begin
# SUBROUTINE DSCAL(N,DA,DX,INCX)
function scal!(n::Integer, DA::$elty, DX::Union(Ptr{$elty},StridedArray{$elty}), incx::Integer)
function scal!(n::Integer, DA::$elty, DX::Union(Ptr{$elty},DenseArray{$elty}), incx::Integer)
ccall(($(blasfunc(fname)), libblas), Void,
(Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
&n, &DA, DX, &incx)
Expand All @@ -89,17 +89,17 @@ for (fname, elty) in ((:dscal_,:Float64),
end
scal(n, DA, DX, incx) = scal!(n, DA, copy(DX), incx)
# In case DX is complex, and DA is real, use dscal/sscal to save flops
for (fname, elty, celty) in ((:sscal_, :Float32, :Complex64),
(:dscal_, :Float64, :Complex128))
@eval begin
function scal!(n::Integer, DA::$elty, DX::Union(Ptr{$celty},StridedArray{$celty}), incx::Integer)
ccall(($(blasfunc(fname)), libblas), Void,
(Ptr{BlasInt}, Ptr{$elty}, Ptr{$celty}, Ptr{BlasInt}),
&(2*n), &DA, DX, &incx)
DX
end
end
end
#for (fname, elty, celty) in ((:sscal_, :Float32, :Complex64),
# (:dscal_, :Float64, :Complex128))
# @eval begin
# function scal!(n::Integer, DA::$elty, DX::Union(Ptr{$celty},StridedArray{$celty}), incx::Integer)
# ccall(($(blasfunc(fname)), libblas), Void,
# (Ptr{BlasInt}, Ptr{$elty}, Ptr{$celty}, Ptr{BlasInt}),
# &(2*n), &DA, DX, &incx)
# DX
# end
# end
#end

## dot
for (fname, elty) in ((:ddot_,:Float64),
Expand Down
6 changes: 5 additions & 1 deletion base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ function scale!{T<:BlasFloat}(X::Array{T}, s::T)
end

scale!{T<:BlasFloat}(X::Array{T}, s::Number) = scale!(X, convert(T, s))
scale!{T<:BlasComplex}(X::Array{T}, s::Real) = BLAS.scal!(length(X), oftype(real(zero(T)),s), X, 1)
function scale!{T<:BlasComplex}(X::Array{T}, s::Real)
R = typeof(real(zero(T)))
BLAS.scal!(2*length(X), convert(R,s), convert(Ptr{R},pointer(X)), 1)
X
end

#Test whether a matrix is positive-definite
isposdef!{T<:BlasFloat}(A::StridedMatrix{T}, UL::Symbol) = LAPACK.potrf!(char_uplo(UL), A)[2] == 0
Expand Down

0 comments on commit f0dd6c3

Please sign in to comment.