-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Add AbstractComplex type #26666
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
Add AbstractComplex type #26666
Conversation
Allows for other complex number types, e.g. PolarComplex representations or Duals for Wirtinger derivatives.
base/complex.jl
Outdated
| Abstract supertype for complex numbers. | ||
| """ | ||
| abstract type AbstractComplex <: Number | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put it on the line above? Having it on a separate line seems as if we might add fields which we can't.
|
Would it make sense to have |
|
I think we decided against it, as we decided it wasn't really a subset thing (but again can't remember the details). |
|
|
|
I'd like to see a bit more development here before we merge this — particularly if it's going to land this late in a release cycle. This exports a new abstract type that folks are going to want to use, but it provides no guidance on what it means beyond the name. What methods should I implement? What methods are provided? How does it promote? How does it convert? What does this provide beyond just subtyping Every time I’ve gone to actually implement an abstract supertype things are more challenging than they seem. It often requires re-jiggering the base dispatch trees. I'm imagining that iterating on this in a non-breaking manner may prove to be difficult. |
|
Those are good points. |
|
Also related to discussion in #26550. |
|
@StefanKarpinski While I don't disagree in principle, are there any functions that would work on complex numbers that don't make sense or behave differently on real numbers? Real numbers certainly implement the interface needed for In other words, while strictly speaking implementations of the reals are not a subset of implementations of the complex numbers, all implementations of real numbers should be able to behave like complex numbers. So why not |
|
@TotalVerb sqrt is a function that behaves differently on julia> sqrt(-1)
ERROR: DomainError:
sqrt will only return a complex result if called with a complex argument. Try sqrt(complex(x)).
Stacktrace:
[1] sqrt(::Int64) at ./math.jl:434
julia> sqrt(Complex(-1))
0.0 + 1.0im |
|
@jw3126 That's a good point. Yet we have and still |
|
@TotalVerb Fair enough. Here is another issue: We can canonically embed the reals into many things, why not |
|
The difference is that |
|
Shouldn't it be that |
|
@oscardssmith This is not correct; for example |
|
Well, I think the point is proven that we should not do this hastily or without further consideration. |
|
@StefanKarpinski Did you mean to close the PR? It just adds |
|
Yes, it still needs tests, news, etc. and as I said, I don't think we should do this now. We can always reopen it later when we decide that we want to do this. |
Allows for other complex number types, e.g. PolarComplex representations or Duals for Wirtinger derivatives.