-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Reference: #17374
julia> x = ["x" for x = 1:5];
julia> x'
WARNING: the no-op `transpose` fallback is deprecated, and no more specific `transpose` method for String exists. Consider `permutedims(x, [2, 1])` or writing a specific `transpose(x::String)` method if appropriate.
at depwarn(::String, ::Symbol) at deprecated.jl:64
at transpose(::String) at deprecated.jl:771
at ctranspose at operators.jl:310 [inlined]
at (::Base.##211#212)(::Tuple{Int64,String}) at <missing>:0
at copy!(::Array{String,2}, ::Base.Generator{Base.Prod2{Base.OneTo{Int64},Array{String,1}},Base.##211#212}) at abstractarray.jl:394
at ctranspose(::Array{String,1}) at arraymath.jl:417
at eval(::Module, ::Any) at boot.jl:234
at eval_user_input(::Any, ::Base.REPL.REPLBackend) at REPL.jl:64
at macro expansion at REPL.jl:95 [inlined]
at (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at event.jl:68
while loading no file, in expression starting on line 0
1×5 Array{String,2}:
"x" "x" "x" "x" "x"
julia> permutedims(x, [2, 1])
------------------------------------------------------------------------------------------
ArgumentError Stacktrace (most recent call last)
[#1] — permutedims(::Array{String,1}, ::Array{Int64,1})
⌙ at multidimensional.jl:825
ArgumentError: no valid permutation of dimensionsI'd love to read the whole discussion of why this behavior changed, but I can't, I guess it's because some kind of mathematical purity consideration, I just wanted to do x' and move on, I had to read the source code of the referenced issue, to understand both what it meant by no-op and how to fix this issue:
julia> Base.transpose(s::AbstractString) = s
julia> x'
1×5 Array{String,2}:
"x" "x" "x" "x" "x"
I don't get why it's worth removing these definitions, and force people to implement them for their own types too. Even if permutedims is the answer, I just wanted to use x', as soon as I saw this I was like: ok ...I don't get this, but anyway I can (or so I thought) do this to make it work with all vectors again, it's just one line:
# this is what someone who whants to do `x'` could try:
julia> Base.transpose(xs::Vector) = permutedims(xs, [2, 1])
julia> type Foo end
julia> [Foo() for i in 1:3]' # lol ...yeah right! -_- But of course not, that was too naive.
I'm sure you guys know what you are doing and I trust you, but if we deprecate something, the warning should include the solution by today standards, not a tip, or consider and it have to be tested, I don't want to have to read 3+ year long discussions to figure out this or have to look at the Base code to understand what this means.
If I do:
julia> Base.transpose(x) = x
WARNING: Method definition transpose(Any) in module Base at deprecated.jl:771 overwritten in module Main at REPL[1]:1.I'll get a warning because now I'm redefining the method (but it works), do I really have to define transpose(x::T) for any new type if I may want to transpose a vector of those separately?
I also think it is a good idea to explain concisely why a feature is added, deprecated or removed in NEWS.md:
The no-op transpose fallback has been deprecated. Consider introducing suitable transpose methods or calling permutedims(x, [2,1]) (#13171, #17075, #17374).
This tells me nothing and suggests (forces) me to read 3 threads.