src/mathops.jl
changed.
src/mathfuns.jl
changed.
src/numerics.jl
changed.
Other files ignored by Codecov
1 | - | import Base: +, -, ^, /, //, \, *, == |
|
1 | + | import Base: +, -, ^, /, //, \, *, ==, sum |
|
2 | 2 | ||
3 | 3 | ## equality |
|
4 | 4 | function ==(b1::SymbolicType, b2::SymbolicType) |
34 | 34 | Base.:(//)(b1::Number, b2::SymbolicType) = //(promote(b1, b2)...) |
|
35 | 35 | ||
36 | 36 | ||
37 | + | function sum(v::CVecBasic) |
|
38 | + | a = Basic() |
|
39 | + | err_code = ccall((:basic_add_vec, libsymengine), Cuint, (Ref{Basic}, Ptr{Cvoid}), a, v.ptr) |
|
40 | + | throw_if_error(err_code, "add_vec") |
|
41 | + | return a |
|
42 | + | end |
|
43 | + | ||
44 | + | +(b1::Basic, b2::Basic, b3::Basic, bs...) = sum(convert(CVecBasic, [b1, b2, b3, bs...])) |
|
45 | + | +(b1::Basic, b2::Basic, b3, bs...) = +(Basic(b1), Basic(b2), Basic(b3), bs...) |
|
46 | + | +(b1, b2::Basic, b3::Basic, bs...) = +(Basic(b1), Basic(b2), Basic(b3), bs...) |
|
47 | + | +(b1::Basic, b2, b3::Basic, bs...) = +(Basic(b1), Basic(b2), Basic(b3), bs...) |
|
48 | + | ||
49 | + | +(b1::Basic, b2, b3, bs...) = +(Basic(b1), Basic(b2), Basic(b3), bs...) |
|
50 | + | +(b1, b2::Basic, b3, bs...) = +(Basic(b1), Basic(b2), Basic(b3), bs...) |
|
51 | + | +(b1, b2, b3::Basic, bs...) = +(Basic(b1), Basic(b2), Basic(b3), bs...) |
|
52 | + | ||
53 | + | ||
37 | 54 | ## ## constants |
|
38 | 55 | Base.zero(x::Basic) = Basic(0) |
|
39 | 56 | Base.zero(::Type{T}) where {T<:Basic} = Basic(0) |
5 | 5 | function ($meth)(b::SymbolicType) |
|
6 | 6 | a = Basic() |
|
7 | 7 | err_code = ccall(($(string(lib,symnm)), libsymengine), Cuint, (Ref{Basic}, Ref{Basic}), a, b) |
|
8 | - | throw_if_error(err_code, $meth) |
|
8 | + | throw_if_error(err_code, $(string(meth))) |
|
9 | 9 | return a |
|
10 | 10 | end |
|
11 | 11 | end |
17 | 17 | a = Basic() |
|
18 | 18 | b1, b2 = promote(b1, b2) |
|
19 | 19 | err_code = ccall(($(string(lib,symnm)), libsymengine), Cuint, (Ref{Basic}, Ref{Basic}, Ref{Basic}), a, b1, b2) |
|
20 | - | throw_if_error(err_code, $meth) |
|
20 | + | throw_if_error(err_code, $(string(meth))) |
|
21 | 21 | return a |
|
22 | 22 | end |
|
23 | 23 | end |
151 | 151 | out = evalf(b) |
|
152 | 152 | imag(out) == Basic(0.0) ? real(out) : out |
|
153 | 153 | end |
|
154 | - | ||
155 | 154 | ||
156 | - | ## Conversions SymEngine -> Julia |
|
155 | + | ||
156 | + | ## Conversions SymEngine -> Julia |
|
157 | 157 | function as_numer_denom(x::Basic) |
|
158 | 158 | a, b = Basic(), Basic() |
|
159 | 159 | ccall((:basic_as_numer_denom, libsymengine), Nothing, (Ref{Basic}, Ref{Basic}, Ref{Basic}), a, b, x) |
175 | 175 | imag(x::BasicType{Val{:Rational}}) = Basic(0) |
|
176 | 176 | imag(x::SymEngine.BasicType) = throw(InexactError()) |
|
177 | 177 | ||
178 | + | # Because of the definitions above, `real(x) == x` for `x::Basic` |
|
179 | + | # such as `x = symbols("x")`. Thus, it is consistent to define the |
|
180 | + | # fallback |
|
181 | + | Base.conj(x::Basic) = 2 * real(x) - x |
|
182 | + | ||
178 | 183 | ## define convert(T, x) methods leveraging N() |
|
179 | 184 | convert(::Type{Float64}, x::Basic) = convert(Float64, N(evalf(x, 53, true))) |
|
180 | 185 | convert(::Type{BigFloat}, x::Basic) = convert(BigFloat, N(evalf(x, precision(BigFloat), true))) |
203 | 208 | ||
204 | 209 | ||
205 | 210 | ## These should have support in symengine-wrapper, but currently don't |
|
206 | - | trunc(x::Basic, args...) = Basic(trunc(N(x), args...)) |
|
211 | + | trunc(x::Basic, args...) = Basic(trunc(N(x), args...)) |
|
207 | 212 | trunc(::Type{T},x::Basic, args...) where {T <: Integer} = convert(T, trunc(x,args...)) |
|
208 | 213 | ||
209 | 214 | ceil(x::Basic) = Basic(ceil(N(x))) |
Files | Coverage |
---|---|
src | 63.89% |
Project Totals (15 files) | 63.89% |