Closed VisualCoder123 closed 2 years ago
Currently there's no way to do it in Julia, because the C++ function is not wrapped in C.
There's a C++ function at https://github.com/symengine/symengine/blob/master/symengine/add.h#L161-L171, but there's no equivalent C function at https://github.com/symengine/symengine/blob/master/symengine/cwrapper.cpp#L525.
Can you open an issue in https://github.com/symengine/symengine?
Currently there's no way to do it in Julia, because the C++ function is not wrapped in C.
There's a C++ function at https://github.com/symengine/symengine/blob/master/symengine/add.h#L161-L171, but there's no equivalent C function at https://github.com/symengine/symengine/blob/master/symengine/cwrapper.cpp#L525.
Can you open an issue in https://github.com/symengine/symengine?
Thank you for the answer! I created an issue.
@VisualCoder123 or @jverzani, what's the signature of the method that julia dispatches a + b + c
to?
There's a basic_add_vec
function in 0.8 that we can use.
using SymEngine
@vars a b c
@which a + b + c
+(a, b, c, xs...) in Base at operators.jl:560
which leads to https://github.com/JuliaLang/julia/blob/eb0ab3c406bdbb13457935d1f5d3b0f90a91e570/base/operators.jl#L650
+(a, b, c, xs...) in Base at operators.jl:560, i.e.
(:+)(a, b, c, xs...)
Hi!
For benchmarking purposes I have this code:
Unfortunately, this code runs too long for my tasks (1.63 sec for n = 10000).
While working with symengine in Python I constructed the sum by hand using the Add class.
This function calculates the result in 0.062 sec (26 times faster).
If I will use "traditional" approach to calculating sum in python:
the result will calculate in 2.486 sec (1.5 times slower than Julia version).
I am not sure, but I think that the reason of achieved results is the following. When I'm using
return +(operands...)
, it sums operands one by one (reducing operands) which means creation of new objects and garbage collection (just like in the slow python version). But when I generate Add object manually I create a sum object without generating intermediate objects.Is there any way to create Add object and paste array of terms manually like I did it in Symengine.py?