-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make (c)transpose less error-prone #13171
Comments
Possible solutions formulated in #13157 (not mutually exclusive):
The kicker seems to be:
|
An additional complication for new non-scalar types: the |
Since this is part of the ARRAYPOCALYPSE mega-issue, I'm adding it to the milestone that issue carries. |
Current thinking: remove fallback transpose and ctranspose definitions, and add a better error message suggesting the use of |
A thought here is to have this signature be the central transpose(f::Function, M::AbstractMatrix) With these fallbacks: transpose(M::Matrix) = transpose(identity, M)
transpose{T<:Matrix}(M::AbstractMatrix{M}) = transpose(transpose, M)
ctranspose{T<:Number}(M::AbstractMatrix{T}) = transpose(conj, M)
ctranspose{T<:Matrix}(M::AbstractMatrix{M}) = transpose(ctranspose, M) Note: this addresses an orthogonal issue, which is defining one |
In #4774, the current plan seems to be to get away from the whole Naturally, this plan opens up the whole view-vs-copy debate all over again. |
I think we're should at this point stick to array as data structure changes in 0.5 and leave linear algebra changes, including 4774 to the future. |
Do I understand correctly that the concrete path forward is to
? Thanks! |
Fixed by #17075 |
Still needs to be loosened from an error to a deprecation, immediately erroring means half a dozen packages are broken when they should just be throwing a warning. |
I agree. Do you have a link to the package evaluator? I'd like to see the damages. |
pkg.julialang.org/pulse.html. If it doesn't get fixed soon I'll be reverting this, we're effectively feature frozen and it's not the time to add new breaking changes |
Apologies for being relatively off-grid this weekend. PR converting the error to a deprecation inbound. Thanks and best! |
Is there any hope that the transpose fallback will be un-deprecated? I suppose I could always add the missing definitions to my
|
Can you provide some details about your use case and why you can't use the solution from the warning, i.e. probably |
Or a minimal test case that triggers the warning through the same last few steps of the call chain. What is the function that's being mapped over an |
This is also problematic for me since the julia> [:a, :b, :c]'
WARNING: the no-op `transpose` fallback is deprecated, and no more specific `transpose` method for Symbol exists. Consider `permutedims(x, [2, 1])` or writing a specific `transpose(x::Symbol)` method if appropriate.
in depwarn(::String, ::Symbol) at ./deprecated.jl:64
in transpose(::Symbol) at ./deprecated.jl:771
in ctranspose at ./operators.jl:300 [inlined]
in (::Base.##143#144)(::Tuple{Int64,Symbol}) at ./<missing>:0
in copy!(::Array{Symbol,2}, ::Base.Generator{Base.Prod2{UnitRange{Int64},Array{Symbol,1}},Base.##143#144}) at ./abstractarray.jl:392
in ctranspose(::Array{Symbol,1}) at ./arraymath.jl:276
in eval(::Module, ::Any) at ./boot.jl:234
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:62
in macro expansion at ./REPL.jl:92 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:46
while loading no file, in expression starting on line 0
1×3 Array{Symbol,2}:
:a :b :c I often deal with Arrays of Any and not having the convenient transpose operator is annoying. This use case is quite common when working with DataFrames. |
Also, the suggested solution doesn't work here: julia> permutedims([:a, :b, :c], [2, 1])
ERROR: ArgumentError: no valid permutation of dimensions
in permutedims(::Array{Symbol,1}, ::Array{Int64,1}) at ./multidimensional.jl:777 |
True but this is the price to pay for safer behavior for It might also be possible to get around the verbosity by changing the coding style. In your case, you could write
It is a little tricky to get the warning message right. In this case, you want |
Indeed, it was just a small example.
When I fixed the deprecation warnings in my code, I did end up using julia> a = [:a, :b, :c]
3-element Array{Symbol,1}:
:a
:b
:c
julia> reshape(a, 1, length(a))
1×3 Array{Symbol,2}:
:a :b :c could be replaced by |
Can we agree to disagree on this? Having a fallback doesn't make it more dangerous. The fallback will never be called if there is some other, more correct, definition for a type.
The same reason I can't use Java... it's too verbose. Compare:
|
I guess the question is how often one really needs to transpose a non-numeric matrix / vector. This change was made on the premise that this is not a terribly common operations. Perhaps that's incorrect. |
I would say that it is quite common when data-mangling. I glue together (hcat and vcat are very handy) and transpose relational data on a regular basis. It's very convenient. |
The @tbreloff I tried to understand the example you posted. It seems to me that the list of labels could just be a vector. Why is it necessary to have the labels as a |
Currently, (c)transpose is implemented with two primary fallbacks:
Unfortunately, this does not cover the full spectrum of tensor-like objects that need to implement (c)transpose. For example,
QRCompactWYQ
does not satisfy the requirements ofAbstractArray
, but needs to implement (c)transpose. Having these fallbacks for::Any
means that any such tensor-like object gets the scalar no-op method implemented by default, which is easy to miss and silently introduces errors.An ideal solution here would ensure that all types implement the correct (c)transpose… hopefully with minimal gnashing of teeth.
The text was updated successfully, but these errors were encountered: