Skip to content
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

transposition operator for string arrays #6395

Closed
aviks opened this issue Apr 3, 2014 · 25 comments
Closed

transposition operator for string arrays #6395

aviks opened this issue Apr 3, 2014 · 25 comments

Comments

@aviks
Copy link
Member

aviks commented Apr 3, 2014

julia> a=["X" "Y"; "A" "B"]
2x2 Array{ASCIIString,2}:
 "X"  "Y"
 "A"  "B"

julia> a'
ERROR: no method conj(ASCIIString)
 in ctranspose at array.jl:1332

julia> transpose(a)
2x2 Array{ASCIIString,2}:
 "X"  "A"
 "Y"  "B"

It is not that big a deal to explicitly call the transpose function from non numeric matrices, but since this is a change from 0.2, I thought I'd ask. Is this intended?

Version 0.3.0-prerelease+2306 (2014-03-31 07:12 UTC)

@carlobaldassi
Copy link
Member

Actually, ' is the conjugate transpose operator; the transpose operator is .':

julia> a=["X" "Y"; "A" "B"]
2x2 Array{ASCIIString,2}:
 "X"  "Y"
 "A"  "B"

julia> a.'
2x2 Array{ASCIIString,2}:
 "X"  "A"
 "Y"  "B"

@aviks
Copy link
Member Author

aviks commented Apr 3, 2014

@aviks aviks closed this as completed Apr 3, 2014
@StefanKarpinski
Copy link
Member

The conjugate of a non-numeric value should fall back on the identity. In transit or I would do it.

@JeffBezanson
Copy link
Member

I'm not sure if this should be part of the behavior of conj or of ctranspose.

@simonster
Copy link
Member

See also #5449.

@StefanKarpinski
Copy link
Member

Yeah, probably the ctranspose come to think of it.

@JeffBezanson
Copy link
Member

The only thing I can think of doing is defining

ctrans_conj(x) = x
ctrans_conj(x::Number) = conj(x)

and using this instead of conj in ctranspose, but it seems strange to me.
I also don't think it should depend on the container type, since ctransposing a Matrix{Any} with various types of numbers in it should still apply conj.

@JeffBezanson
Copy link
Member

I think conj just doesn't make sense on arbitrary types, and conjugate transpose is defined correctly. This should just stay as-is.

@StefanKarpinski
Copy link
Member

This is annoying every time I trip over it. I really don't see the problem with making conj the identity on non-numbers.

@JeffBezanson
Copy link
Member

I think what's going on here is that people don't want to type the extra
dot, but that is just an unavoidable consequence of making single quote a
conjugate transpose operator. If, for example, the functions were called
trans and ctrans, I don't think anybody would argue that ctrans should work
on non-numbers.
On Apr 4, 2014 9:02 PM, "Stefan Karpinski" [email protected] wrote:

This is annoying every time I trip over it. I really don't see the problem
with making conj the identity on non-numbers.

Reply to this email directly or view it on GitHubhttps://github.com//issues/6395#issuecomment-39624751
.

@pygy
Copy link
Contributor

pygy commented Apr 25, 2014

I'm with Stefan on this one, but if Jeff prevails, it would be nice to add conj(x::Any) to deprecated.jl, and remove it in v0.4.

@JeffBezanson
Copy link
Member

Could you explain your reasoning? Do you think conj(x::Any) = x is actually correct?

@timholy
Copy link
Member

timholy commented Apr 25, 2014

Can we define

conj(x) = error("conj not defined for ", typeof(x), ". Did you mean to take the transpose (.')?")

@StefanKarpinski
Copy link
Member

My reasoning is that conj is the identity on anything that doesn't have an imaginary part – and strings clearly don't have an imaginary part. Obviously it's silly to take the conjugate of a string, but it seems pedantic to force using .' – what's the harm that could come from just ignoring the conjugation of a non-number?

@JeffBezanson
Copy link
Member

Well, a string can't be negative either, so maybe abs(x)=x should be defined too.

@StefanKarpinski
Copy link
Member

Touché. I'd be fine with making this part of the behavior of ctranspose, but I think it's obnoxious to make people use .'. The key thing is that the conjugate transpose is the right generic transpose most of the time for complex numbers – it's the unconjugated transpose that is weird for complexes.

@pygy
Copy link
Contributor

pygy commented Apr 25, 2014

It's a matter of practicality and user friendliness. There's no syntactic construct that involves abs.

Julia is not about correctness and consistency above everything else, and, in this case, I think it's worth it to define conj as the identity for non-complex types, even if it does not make sense mathematically.

@StefanKarpinski
Copy link
Member

I'm actually convinced now that this should be a behavior of ctranspose. The realization I had is that transpose is, despite the name, not the generic array transposition operator – ctranspose is. It just happens that the correct generic transposition for complex arrays also conjugates elements. If you want to do a transpose that doesn't conjugate, that is really a more special operation, as you can tell from the fact that A.' is a longer, less obvious syntax than A'. As Jeff pointed out, conjugating a string or other non-number still doesn't make sense and should be an error.

@pygy
Copy link
Contributor

pygy commented Apr 25, 2014

Indeed. To be honest I hadn't checked the nitty gritty of the transposition implementation, as long as A' works for all types, I'm fine :-).

How would you handle {0.0+1.0im}'? Define ctranspose(a::Array{Any}) based on maybeconj?

maybeconj(x) = x
maybeconj(z::Complex) = conj(z)

@JeffBezanson
Copy link
Member

No; all methods of ctranspose would use maybeconj. And the one that calls conj should apply for all Numbers.

@JeffBezanson
Copy link
Member

What worries me here is we're introducing a name for the concept "what you do to an element during generic transposition". In math, as far as I know, that's conj. Is there some other name that would make sense? Would you sometimes overload maybeconj (or whatever it should be called) instead of conj?

@StefanKarpinski
Copy link
Member

Well, this is what led me to the notion that conj should just be the identity on non-numbers.

@JeffBezanson
Copy link
Member

It's still possible I could be convinced that that is the correct generic meaning of conj. Wikipedia says "Usually one includes α itself in the set of conjugates." (http://en.wikipedia.org/wiki/Conjugate_element_(field_theory)).

@cmey
Copy link
Contributor

cmey commented May 4, 2014

Isn't the .op syntax meant to be an element-wise application of the op ?
I wouldn't expect .' to transpose the matrix (moving elements). Instead I would expect it to apply ' on each element of the matrix (without moving them).

@StefanKarpinski
Copy link
Member

That's the general trend, but happens not to be what this operator means. This is a traditional meaning inherited from Matlab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants