From 755b4ed3d6f642232ca8653323982ccd7fff7e26 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Thu, 23 Jun 2016 11:26:38 -0700 Subject: [PATCH 1/3] Remove `transpose(x) = x` fallback, instead `error`'ing. Patch up a few missing `transpose` methods and correct a test that failed for lack of a `transpose` method. --- base/char.jl | 2 ++ base/operators.jl | 2 +- base/strings/basic.jl | 2 ++ test/linalg/matmul.jl | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/base/char.jl b/base/char.jl index 52aa1492e2f86..e28217dc8c10a 100644 --- a/base/char.jl +++ b/base/char.jl @@ -32,6 +32,8 @@ in(x::Char, y::Char) = x == y ==(x::Char, y::Char) = UInt32(x) == UInt32(y) isless(x::Char, y::Char) = UInt32(x) < UInt32(y) +transpose(c::Char) = c + const hashchar_seed = 0xd4d64234 hash(x::Char, h::UInt) = hash_uint64(((UInt64(x)+hashchar_seed)<<32) $ UInt64(h)) diff --git a/base/operators.jl b/base/operators.jl index 6570a14e3e612..6f1849f60d911 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -293,7 +293,7 @@ fldmod1{T<:Real}(x::T, y::T) = (fld1(x,y), mod1(x,y)) fldmod1{T<:Integer}(x::T, y::T) = (fld1(x,y), mod1(x,y)) # transpose -transpose(x) = x +transpose(x) = throw(ArgumentError("transpose not implemented for $(typeof(x)). Consider permutedims.")) ctranspose(x) = conj(transpose(x)) conj(x) = x diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 167bef7bcbd44..caa60795b8c0c 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -101,6 +101,8 @@ function length(s::AbstractString) end end +transpose(s::AbstractString) = s + ## string comparison functions ## function cmp(a::AbstractString, b::AbstractString) diff --git a/test/linalg/matmul.jl b/test/linalg/matmul.jl index 0f44b8cf8479c..f3fbb5f3d92a7 100644 --- a/test/linalg/matmul.jl +++ b/test/linalg/matmul.jl @@ -320,8 +320,9 @@ end immutable RootInt i::Int end -import Base: *, promote_op +import Base: *, transpose, promote_op (*)(x::RootInt, y::RootInt) = x.i*y.i +transpose(x::RootInt) = x promote_op(::typeof(*), ::Type{RootInt}, ::Type{RootInt}) = Int a = [RootInt(3)] From 060a51ca6026033c3459a49fa1d48ae1e66a1774 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Thu, 7 Jul 2016 21:26:06 -0700 Subject: [PATCH 2/3] Remove (c)transpose no-op for Chars and remove associated test. --- base/char.jl | 2 -- test/operators.jl | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/base/char.jl b/base/char.jl index e28217dc8c10a..52aa1492e2f86 100644 --- a/base/char.jl +++ b/base/char.jl @@ -32,8 +32,6 @@ in(x::Char, y::Char) = x == y ==(x::Char, y::Char) = UInt32(x) == UInt32(y) isless(x::Char, y::Char) = UInt32(x) < UInt32(y) -transpose(c::Char) = c - const hashchar_seed = 0xd4d64234 hash(x::Char, h::UInt) = hash_uint64(((UInt64(x)+hashchar_seed)<<32) $ UInt64(h)) diff --git a/test/operators.jl b/test/operators.jl index 36f80a6033ddf..07031ed2ff81e 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -33,7 +33,7 @@ p = 1=>:foo @test (|)(2) == 2 @test ($)(2) == 2 -@test ctranspose('a') == 'a' +# @test ctranspose('a') == 'a' # (c)transpose of Chars no longer supported @test_throws ArgumentError Base.scalarmin(['a','b'],['c','d']) @test_throws ArgumentError Base.scalarmin('a',['c','d']) From dd55ba51388bd22bf7358166eec76112ff87e10e Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Thu, 7 Jul 2016 21:36:11 -0700 Subject: [PATCH 3/3] Remove (c)transpose no-op for Strings and revise associated tests. --- base/strings/basic.jl | 2 -- test/datafmt.jl | 2 +- test/strings/basic.jl | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/base/strings/basic.jl b/base/strings/basic.jl index caa60795b8c0c..167bef7bcbd44 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -101,8 +101,6 @@ function length(s::AbstractString) end end -transpose(s::AbstractString) = s - ## string comparison functions ## function cmp(a::AbstractString, b::AbstractString) diff --git a/test/datafmt.jl b/test/datafmt.jl index 7116a2af614dc..4b97da3a32ef3 100644 --- a/test/datafmt.jl +++ b/test/datafmt.jl @@ -210,7 +210,7 @@ let i18n_data = ["Origin (English)", "Name (English)", "Origin (Native)", "Name "Yugoslavia (Cyrillic)", "Djordje Balasevic", "Југославија", "Ђорђе Балашевић", "Yugoslavia (Latin)", "Djordje Balasevic", "Jugoslavija", "Đorđe Balašević"] - i18n_arr = transpose(reshape(i18n_data, 4, Int(floor(length(i18n_data)/4)))) + i18n_arr = permutedims(reshape(i18n_data, 4, Int(floor(length(i18n_data)/4))), [2, 1]) i18n_buff = PipeBuffer() writedlm(i18n_buff, i18n_arr, ',') @test i18n_arr == readcsv(i18n_buff) diff --git a/test/strings/basic.jl b/test/strings/basic.jl index f8a63850a0253..183ec1ea74933 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -464,7 +464,7 @@ foobaz(ch) = reinterpret(Char, typemax(UInt32)) @test "a".*["b","c"] == ["ab","ac"] @test ["b","c"].*"a" == ["ba","ca"] -@test ["a","b"].*["c","d"]' == ["ac" "ad"; "bc" "bd"] +@test ["a","b"].*["c" "d"] == ["ac" "ad"; "bc" "bd"] # Make sure NULL pointers are handled consistently by String @test_throws ArgumentError unsafe_string(Ptr{UInt8}(0))