Skip to content

Commit 05ca4ae

Browse files
authored
Merge pull request #42 from JuliaArrays/teh/transpose
Support (c)transpose
2 parents 447bbda + 01732f6 commit 05ca4ae

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/core.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ function Base.permutedims(A::AxisArray, perm)
264264
p = permutation(perm, axisnames(A))
265265
AxisArray(permutedims(A.data, p), axes(A)[[p...]])
266266
end
267+
268+
Base.transpose{T}(A::AxisArray{T,2}) = AxisArray(transpose(A.data), A.axes[2], A.axes[1])
269+
Base.ctranspose{T}(A::AxisArray{T,2}) = AxisArray(ctranspose(A.data), A.axes[2], A.axes[1])
270+
Base.transpose{T}(A::AxisArray{T,1}) = AxisArray(transpose(A.data), Axis{:transpose}(Base.OneTo(1)), A.axes[1])
271+
Base.ctranspose{T}(A::AxisArray{T,1}) = AxisArray(ctranspose(A.data), Axis{:transpose}(Base.OneTo(1)), A.axes[1])
272+
267273
permutation(to::Union{AbstractVector{Int},Tuple{Int,Vararg{Int}}}, from::Symbols) = to
268274

269275
"""

test/core.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ C = similar(A, 0)
2626
D = similar(A)
2727
@test size(A) == size(D)
2828
@test eltype(A) == eltype(D)
29+
30+
# permutedims and transpose
2931
@test axisnames(permutedims(A, (2,1,3))) == (:col, :row, :page)
3032
@test axisnames(permutedims(A, (2,3,1))) == (:col, :page, :row)
3133
@test axisnames(permutedims(A, (3,2,1))) == (:page, :col, :row)
@@ -35,6 +37,17 @@ for perm in ((:col, :row, :page), (:col, :page, :row),
3537
(:row, :page, :col), (:row, :col, :page))
3638
@test axisnames(permutedims(A, perm)) == perm
3739
end
40+
@test axisnames(permutedims(A, (:col,))) == (:col, :row, :page)
41+
@test axisnames(permutedims(A, (:page,))) == (:page, :row, :col)
42+
A2 = AxisArray(reshape(1:15, 3, 5))
43+
A1 = AxisArray(1:5, :t)
44+
for f in (transpose, ctranspose)
45+
@test f(A2).data == f(A2.data)
46+
@test axisnames(f(A2)) == (:col, :row)
47+
@test f(A1).data == f(A1.data)
48+
@test axisnames(f(A1)) == (:transpose, :t)
49+
end
50+
3851
# Test modifying a particular axis
3952
E = similar(A, Float64, Axis{:col}(1:2))
4053
@test size(E) == (2,2,4)

0 commit comments

Comments
 (0)