Skip to content

Commit

Permalink
Use where for some linalg functions
Browse files Browse the repository at this point in the history
  • Loading branch information
musm committed Apr 19, 2017
1 parent 08fc7aa commit 49a92ff
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 86 deletions.
10 changes: 5 additions & 5 deletions base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ _chrinstr(sbuff::String, chr::UInt8, startpos::Int, endpos::Int) =
(endpos >= startpos) && (C_NULL != ccall(:memchr, Ptr{UInt8},
(Ptr{UInt8}, Int32, Csize_t), pointer(sbuff)+startpos-1, chr, endpos-startpos+1))

function store_cell{T}(dlmstore::DLMStore{T}, row::Int, col::Int,
quoted::Bool, startpos::Int, endpos::Int)
function store_cell(dlmstore::DLMStore{T}, row::Int, col::Int,
quoted::Bool, startpos::Int, endpos::Int) where T
drow = row - dlmstore.hdr_offset

ncols = dlmstore.ncols
Expand Down Expand Up @@ -291,7 +291,7 @@ function store_cell{T}(dlmstore::DLMStore{T}, row::Int, col::Int,
nothing
end

function result{T}(dlmstore::DLMStore{T})
function result(dlmstore::DLMStore{T}) where T
nrows = dlmstore.nrows - dlmstore.hdr_offset
ncols = dlmstore.ncols
lastcol = dlmstore.lastcol
Expand Down Expand Up @@ -456,9 +456,9 @@ function colval(sbuff::String, startpos::Int, endpos::Int, cells::Array{<:Char,2
end
colval(sbuff::String, startpos::Int, endpos::Int, cells::Array, row::Int, col::Int) = true

function dlm_parse{D}(dbuff::String, eol::D, dlm::D, qchar::D, cchar::D,
function dlm_parse(dbuff::String, eol::D, dlm::D, qchar::D, cchar::D,
ign_adj_dlm::Bool, allow_quote::Bool, allow_comments::Bool,
skipstart::Int, skipblanks::Bool, dh::DLMHandler)
skipstart::Int, skipblanks::Bool, dh::DLMHandler) where D
ncols = nrows = col = 0
is_default_dlm = (dlm == invalid_dlm(D))
error_str = ""
Expand Down
4 changes: 2 additions & 2 deletions base/fft/FFTW.jl
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ for (f,direction) in ((:fft,FORWARD), (:bfft,BACKWARD))
end
end

function A_mul_B!{T}(y::StridedArray{T}, p::cFFTWPlan{T}, x::StridedArray{T})
function A_mul_B!(y::StridedArray{T}, p::cFFTWPlan{T}, x::StridedArray{T}) where T
assert_applicable(p, x, y)
unsafe_execute!(p, x, y)
return y
Expand Down Expand Up @@ -781,7 +781,7 @@ function plan_inv{T<:fftwNumber,K,inplace,N}(p::r2rFFTWPlan{T,K,inplace,N})
1:length(iK)))
end

function A_mul_B!{T}(y::StridedArray{T}, p::r2rFFTWPlan{T}, x::StridedArray{T})
function A_mul_B!(y::StridedArray{T}, p::r2rFFTWPlan{T}, x::StridedArray{T}) where T
assert_applicable(p, x, y)
unsafe_execute!(p, x, y)
return y
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function SVDOperator(A::AbstractMatrix{T}) where T
SVDOperator{Tnew,typeof(Anew)}(Anew)
end

function A_mul_B!{T}(u::StridedVector{T}, s::SVDOperator{T}, v::StridedVector{T})
function A_mul_B!(u::StridedVector{T}, s::SVDOperator{T}, v::StridedVector{T}) where T
a, b = s.m, length(v)
A_mul_B!(view(u,1:a), s.X, view(v,a+1:b)) # left singular vector
Ac_mul_B!(view(u,a+1:b), s.X, view(v,1:a)) # right singular vector
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/givens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function *(R::AbstractRotation{T}, A::AbstractVecOrMat{S}) where {T,S}
TS = typeof(zero(T)*zero(S) + zero(T)*zero(S))
A_mul_B!(convert(AbstractRotation{TS}, R), TS == S ? copy(A) : convert(AbstractArray{TS}, A))
end
function A_mul_Bc{T,S}(A::AbstractVecOrMat{T}, R::AbstractRotation{S})
function A_mul_Bc(A::AbstractVecOrMat{T}, R::AbstractRotation{S}) where {T,S}
TS = typeof(zero(T)*zero(S) + zero(T)*zero(S))
A_mul_Bc!(TS == T ? copy(A) : convert(AbstractArray{TS}, A), convert(AbstractRotation{TS}, R))
end
Expand Down
20 changes: 10 additions & 10 deletions base/linalg/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ end
size(A::LQPackedQ) = size(A.factors)

## Multiplication by LQ
A_mul_B!{T<:BlasFloat}(A::LQ{T}, B::StridedVecOrMat{T}) = A[:L]*LAPACK.ormlq!('L','N',A.factors,A.τ,B)
A_mul_B!{T<:BlasFloat}(A::LQ{T}, B::QR{T}) = A[:L]*LAPACK.ormlq!('L','N',A.factors,A.τ,full(B))
A_mul_B!{T<:BlasFloat}(A::QR{T}, B::LQ{T}) = A_mul_B!(zeros(full(A)), full(A), full(B))
A_mul_B!(A::LQ{T}, B::StridedVecOrMat{T}) where {T<:BlasFloat} = A[:L]*LAPACK.ormlq!('L','N',A.factors,A.τ,B)
A_mul_B!(A::LQ{T}, B::QR{T}) where {T<:BlasFloat} = A[:L]*LAPACK.ormlq!('L','N',A.factors,A.τ,full(B))
A_mul_B!(A::QR{T}, B::LQ{T}) where {T<:BlasFloat} = A_mul_B!(zeros(full(A)), full(A), full(B))
function *(A::LQ{TA},B::StridedVecOrMat{TB}) where {TA,TB}
TAB = promote_type(TA, TB)
A_mul_B!(convert(Factorization{TAB},A), copy_oftype(B, TAB))
Expand All @@ -137,15 +137,15 @@ end

## Multiplication by Q
### QB
A_mul_B!{T<:BlasFloat}(A::LQPackedQ{T}, B::StridedVecOrMat{T}) = LAPACK.ormlq!('L','N',A.factors,A.τ,B)
A_mul_B!(A::LQPackedQ{T}, B::StridedVecOrMat{T}) where {T<:BlasFloat} = LAPACK.ormlq!('L','N',A.factors,A.τ,B)
function (*)(A::LQPackedQ,B::StridedVecOrMat)
TAB = promote_type(eltype(A), eltype(B))
A_mul_B!(convert(AbstractMatrix{TAB}, A), copy_oftype(B, TAB))
end

### QcB
Ac_mul_B!{T<:BlasReal}(A::LQPackedQ{T}, B::StridedVecOrMat{T}) = LAPACK.ormlq!('L','T',A.factors,A.τ,B)
Ac_mul_B!{T<:BlasComplex}(A::LQPackedQ{T}, B::StridedVecOrMat{T}) = LAPACK.ormlq!('L','C',A.factors,A.τ,B)
Ac_mul_B!(A::LQPackedQ{T}, B::StridedVecOrMat{T}) where {T<:BlasReal} = LAPACK.ormlq!('L','T',A.factors,A.τ,B)
Ac_mul_B!(A::LQPackedQ{T}, B::StridedVecOrMat{T}) where {T<:BlasComplex} = LAPACK.ormlq!('L','C',A.factors,A.τ,B)
function Ac_mul_B(A::LQPackedQ, B::StridedVecOrMat)
TAB = promote_type(eltype(A), eltype(B))
if size(B,1) == size(A.factors,2)
Expand All @@ -171,7 +171,7 @@ for (f1, f2) in ((:A_mul_Bc, :A_mul_B!),
end

### AQ
A_mul_B!{T<:BlasFloat}(A::StridedMatrix{T}, B::LQPackedQ{T}) = LAPACK.ormlq!('R', 'N', B.factors, B.τ, A)
A_mul_B!(A::StridedMatrix{T}, B::LQPackedQ{T}) where {T<:BlasFloat} = LAPACK.ormlq!('R', 'N', B.factors, B.τ, A)
function *(A::StridedMatrix{TA},B::LQPackedQ{TB}) where {TA,TB}
TAB = promote_type(TA,TB)
if size(B.factors,2) == size(A,2)
Expand All @@ -184,9 +184,9 @@ function *(A::StridedMatrix{TA},B::LQPackedQ{TB}) where {TA,TB}
end

### AQc
A_mul_Bc!{T<:BlasReal}(A::StridedMatrix{T}, B::LQPackedQ{T}) = LAPACK.ormlq!('R','T',B.factors,B.τ,A)
A_mul_Bc!{T<:BlasComplex}(A::StridedMatrix{T}, B::LQPackedQ{T}) = LAPACK.ormlq!('R','C',B.factors,B.τ,A)
function A_mul_Bc{TA<:Number,TB<:Number}( A::StridedVecOrMat{TA}, B::LQPackedQ{TB})
A_mul_Bc!(A::StridedMatrix{T}, B::LQPackedQ{T}) where {T<:BlasReal} = LAPACK.ormlq!('R','T',B.factors,B.τ,A)
A_mul_Bc!(A::StridedMatrix{T}, B::LQPackedQ{T}) where {T<:BlasComplex} = LAPACK.ormlq!('R','C',B.factors,B.τ,A)
function A_mul_Bc( A::StridedVecOrMat{TA}, B::LQPackedQ{TB}) where {TA<:Number,TB<:Number}
TAB = promote_type(TA,TB)
A_mul_Bc!(copy_oftype(A, TAB), convert(AbstractMatrix{TAB},(B)))
end
Expand Down
Loading

0 comments on commit 49a92ff

Please sign in to comment.