Skip to content

Commit

Permalink
More performant solution for transpose! with Vectors (see JuliaLang#8726
Browse files Browse the repository at this point in the history
)
  • Loading branch information
timholy committed Oct 27, 2014
1 parent 7a7110b commit 7f91ee1
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ end

## Transpose ##
const transposebaselength=64
function transpose!(B::StridedVecOrMat,A::StridedMatrix)
function transpose!(B::StridedMatrix,A::StridedMatrix)
m, n = size(A)
size(B,1) == n && size(B,2) == m || throw(DimensionMismatch("transpose"))

Expand All @@ -1254,7 +1254,15 @@ function transpose!(B::StridedVecOrMat,A::StridedMatrix)
end
return B
end
function transposeblock!(B::StridedVecOrMat,A::StridedMatrix,m::Int,n::Int,offseti::Int,offsetj::Int)
function transpose!(B::StridedVector, A::StridedMatrix)
length(B) == length(A) && size(A,1) == 1 || throw(DimensionMismatch("transpose"))
copy!(B, A)
end
function transpose!(B::StridedMatrix, A::StridedVector)
length(B) == length(A) && size(B,1) == 1 || throw(DimensionMismatch("transpose"))
copy!(B, A)
end
function transposeblock!(B::StridedMatrix,A::StridedMatrix,m::Int,n::Int,offseti::Int,offsetj::Int)
if m*n<=transposebaselength
@inbounds begin
for j = offsetj+(1:n)
Expand All @@ -1274,7 +1282,7 @@ function transposeblock!(B::StridedVecOrMat,A::StridedMatrix,m::Int,n::Int,offse
end
return B
end
function ctranspose!(B::StridedVecOrMat,A::StridedMatrix)
function ctranspose!(B::StridedMatrix,A::StridedMatrix)
m, n = size(A)
size(B,1) == n && size(B,2) == m || throw(DimensionMismatch("transpose"))

Expand All @@ -1291,7 +1299,15 @@ function ctranspose!(B::StridedVecOrMat,A::StridedMatrix)
end
return B
end
function ctransposeblock!(B::StridedVecOrMat,A::StridedMatrix,m::Int,n::Int,offseti::Int,offsetj::Int)
function ctranspose!(B::StridedVector, A::StridedMatrix)
length(B) == length(A) && size(A,1) == 1 || throw(DimensionMismatch("transpose"))
ccopy!(B, A)
end
function ctranspose!(B::StridedMatrix, A::StridedVector)
length(B) == length(A) && size(B,1) == 1 || throw(DimensionMismatch("transpose"))
ccopy!(B, A)
end
function ctransposeblock!(B::StridedMatrix,A::StridedMatrix,m::Int,n::Int,offseti::Int,offsetj::Int)
if m*n<=transposebaselength
@inbounds begin
for j = offsetj+(1:n)
Expand All @@ -1311,6 +1327,11 @@ function ctransposeblock!(B::StridedVecOrMat,A::StridedMatrix,m::Int,n::Int,offs
end
return B
end
function ccopy!(B, A)
for i = 1:length(A)
B[i] = ctranspose(A[i])
end
end

function transpose(A::StridedMatrix)
B = similar(A, size(A, 2), size(A, 1))
Expand Down

0 comments on commit 7f91ee1

Please sign in to comment.