Comments (8)
I think we can accept a PR for:
Base.complex(x::AbstractJuMPScalar, y::AbstractJuMPScalar) = x + im * y
Base.complex(x, y::AbstractJuMPScalar) = x + im * y
Base.complex(x::AbstractJuMPScalar, y) = x + im * y
but I'm not going to support Base.Complex
. That's a constructor and we can't return an instance of the type.
from jump.jl.
I think defining Complex(a, b)
to return something other than ::Complex
is legal, but bad form in Julia, so I would prefer not to do this.
Do you mean complex(r, i)
?
help?> complex
search: complex Complex ComplexF64 ComplexF32 ComplexF16 ComplexPlane ComplexVariable precompile __precompile__ Highs_compilationDate
complex(r, [i])
Convert real numbers or arrays to complex. i defaults to zero.
Examples
≡≡≡≡≡≡≡≡
julia> complex(7)
7 + 0im
julia> complex([1, 2, 3])
3-element Vector{Complex{Int64}}:
1 + 0im
2 + 0im
3 + 0im
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
complex(T::Type)
Return an appropriate type which can represent a value of type T as a complex number. Equivalent to typeof(complex(zero(T))).
Examples
≡≡≡≡≡≡≡≡
julia> complex(Complex{Int})
Complex{Int64}
julia> complex(Int)
Complex{Int64}
julia> complex(1, 2)
1 + 2im
Is this really an improvement on a + im * b
? Do you have a benchmark on a realistic instance? I don't really see how this could make a difference.
from jump.jl.
I really do mean Complex(a,b)
. No, I don't have a benchmark, but this is a function used deep inside almost every cone in Hypatia, so every microsecond matters.
@chriscoey I believe you're the one who wrote the original function with Complex(a,b)
instead of a + im*b
, care to comment?
from jump.jl.
Why does code in Hypatia need to work for JuMP variables?
In your own code, can't you just do:
my_complex(a, b) = Complex(a, b)
my_complex(a::AbstractJuMPScalar, b::AbstractJuMPScalar) = a + im * b
Complex(a,b) instead of a + im*b
a + im*b
does
tmp = (im * b)::ComplexF64
(a + tmp)::ComplexF64
so it introduces an additional temporary.
from jump.jl.
Because several of the examples use JuMP.
And no, I'm not defining a my_complex
function in order to add a method to JuMP. That's hideous and makes the code harder to read. Moreover, Complex
is a really basic function, I'm certain that such a method will also be useful for other people.
from jump.jl.
I did Complex(a, b)
in my original code for the reason Oscar mentioned (avoid a temp), and personally I think it's just as readable. Hypatia doesn't use JuMP internally, but some of the Hypatia examples do in order to help build the MOI models.
from jump.jl.
Great, that works for me, I'll do a PR. Shouldn't it be Union{GenericVariableRef{<:Real}, GenericAffExpr{<:Real}, GenericQuadExpr{<:Real}}
instead of AbstractJuMPScalar
, though?
from jump.jl.
I guess so. I assumed complex
would just do the equivalent, but it throws a MethodError, so I guess we should match.
julia> complex(1+2im, 3)
ERROR: MethodError: no method matching complex(::Complex{Int64}, ::Int64)
Closest candidates are:
complex(::Real, ::Real)
@ Base complex.jl:175
complex(::Complex)
@ Base complex.jl:173
Stacktrace:
[1] top-level scope
@ REPL[150]:1
julia> complex(1+2im, 0)
ERROR: MethodError: no method matching complex(::Complex{Int64}, ::Int64)
Closest candidates are:
complex(::Real, ::Real)
@ Base complex.jl:175
complex(::Complex)
@ Base complex.jl:173
Stacktrace:
[1] top-level scope
@ REPL[151]:1
julia> complex(1+2im, 0im)
ERROR: MethodError: no method matching complex(::Complex{Int64}, ::Complex{Int64})
Closest candidates are:
complex(::Complex)
@ Base complex.jl:173
Stacktrace:
[1] top-level scope
@ REPL[152]:1
from jump.jl.
Related Issues (20)
- Documentation Request: List whether a solver supports Indicator Constraints HOT 4
- Bullet point alignment in bibliography HOT 9
- Multiplication of matrix expression and variables leads to stack overflow and matmul error HOT 4
- Multiple Ranges for variables HOT 3
- Y' when Y is of type ::Matrix{NonlinearExpr} HOT 1
- Poor performance in complementarity models HOT 23
- MethodError with empty summations HOT 1
- Nonlinear subexpressions HOT 4
- Should error when trying to mix `NonlinearExpression` and `GenericNonlinearExpr` HOT 1
- Support normalized_coefficient for vector-valued constraints
- Precompilation in CI fails on v1.22 HOT 7
- Fuzzy search on unrecognized keyword arguments to give suggestions HOT 2
- Track failures on nightly HOT 3
- Possibly missing diagnostics for vector of vector of variables HOT 3
- Printing of large vectorized constraints should probably cause output eliding? HOT 5
- Deleting part of containerized constraints makes whole constraint unprintable HOT 2
- function_string of Symmetric matrix includes the entire matrix HOT 7
- Inequality constraints over symmetric matrices are cumbersome HOT 9
- Set inequality syntax suggestion HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jump.jl.