These are chat archives for symengine/symengine

22nd
Mar 2017
BHAVISHYA
@bhavishyagopesh
Mar 22 2017 11:52
@isuruf I'm looking for "Efficient Equation of Motion Generation", project, and I wanted to discuss the amount of time that implementing wrappers (in python)would require(I choose for around 2 weeks, after considering the wrappers implemented for other functions till now)
Isuru Fernando
@isuruf
Mar 22 2017 11:53
@bhavishyagopesh, I'm not sure what there is to be done in that project. Did you talk to @moorepants about it?
BHAVISHYA
@bhavishyagopesh
Mar 22 2017 11:55
@isuruf ok
Prateek Singh
@prateeksingh0001
Mar 22 2017 14:31
@isuruf this is with reference to symengine/symengine#1225. Actually there was a typo, I used the exp() function in pow.cpp, and on running exp(2) I got an answer of 7.38906. Please tell me how to reproduce the error or which files I should refer to for the above issue.
Isuru Fernando
@isuruf
Mar 22 2017 14:32
Can you post your source code?
Prateek Singh
@prateeksingh0001
Mar 22 2017 14:36
Sure,
#include <iostream>
#include <limits>
#include <symengine/basic.h>
#include <symengine/symbol.h>
#include <symengine/dict.h>
#include <symengine/integer.h>
#include <symengine/pow.h>
#include <symengine/printer.h>

using SymEngine::Basic;
using SymEngine::Mul;
using SymEngine::Pow;
using SymEngine::Symbol;
using SymEngine::symbol;
using SymEngine::umap_basic_num;
using SymEngine::map_vec_int;
using SymEngine::Integer;
using SymEngine::integer;
using SymEngine::multinomial_coefficients;
using SymEngine::RCP;
using SymEngine::rcp_dynamic_cast;

int main(){
    RCP<const Basic> e, f, r;
    std::cout<<exp(2) ;
    return 0 ;
}
The expressions e, f, r play no role in the code.....
Isuru Fernando
@isuruf
Mar 22 2017 14:37
that's the function from C stdlib
std::cout << *exp(integer(2))
Prateek Singh
@prateeksingh0001
Mar 22 2017 14:41
Ok, but wouldn't using Symengine::Pow automatically use the exp() from pow.cpp or should I specify the namespace also ?
Isuru Fernando
@isuruf
Mar 22 2017 14:41
you need to use using SymEngine::exp
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 17:49
function expr_arr_to_block(exprs)
  block = :(begin end)
  foreach(expr -> push!(block.args, expr), exprs)
  block
end

macro build_ops()
  exprs = Vector{Expr}(0)
  for (op, libnm) in ((:+, :add), (:-, :sub), (:*, :mul), (:/, :div), (://, :div), (:^, :pow))
      tup = (Base.Symbol("basic_$libnm"), libsymengine)
      function ($op)(b1::Basic, b2::Basic)
          a = Basic()
          ccall($tup, Void, (Ptr{Basic}, Ptr{Basic}, Ptr{Basic}), &a, &b1, &b2)
          return a
      end
      push!(exprs,:(($op)(b1::BasicType, b2::BasicType) = ($op)(Basic(b1), Basic(b2))))
  end
  expr_arr_to_block(exprs)
end
@build_ops
I think that should work in place of the @evals?
Isuru Fernando
@isuruf
Mar 22 2017 17:52
Are @evals that are run on pre-compilation stage a problem?
I thought only the ones run on __init__ are an issue
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 17:52
not sure
but it's probably best to get rid of them anyways
Isuru Fernando
@isuruf
Mar 22 2017 17:53
why?
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 17:54
macro build_ops()
  exprs = Vector{Expr}(0)
  for (op, libnm) in ((:+, :add), (:-, :sub), (:*, :mul), (:/, :div), (://, :div), (:^, :pow))
      tup = (Base.Symbol("basic_$libnm"), libsymengine)
      ex = :(
      function ($op)(b1::Basic, b2::Basic)
          a = Basic()
          ccall($tup, Void, (Ptr{Basic}, Ptr{Basic}, Ptr{Basic}), &a, &b1, &b2)
          return a
      end
      ($op)(b1::BasicType, b2::BasicType) = ($op)(Basic(b1), Basic(b2))
      )
      push!(exprs,ex)
  end
  expr_arr_to_block(exprs)
end
might be this
Scott P. Jones
@ScottPJones
Mar 22 2017 17:54
I haven't had any problems with @eval creating functions, for example, in a for loop etc. within a module, but I've not ever had it work correctly when in a function, __init__ or otherwise.
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 17:54
well, first of all it gets rid of the warning
Expr(:block, Expr(:line, 60, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, Expr(:tuple, :basic_new_stack, :libsymengine)::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :IM)::Any)::Any, Expr(:line, 61, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, (:basic_const_I, "/home/crackauc/.julia/v0.5/SymEngine/deps/usr/lib/libsymengine.so"), :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :IM)::Any)::Any, Expr(:line, 62, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:call, :finalizer, :IM, :basic_free)::Any)::Any
  ** incremental compilation may be broken for this module **
@ScottPJones @eval works at the module scope, so if you generate variables you have to bring the global that it creates back into scope
Secondly, I am not sure if that kind of @eval will still allow static compilation :smile:
Scott P. Jones
@ScottPJones
Mar 22 2017 17:56
I'm not worried about static compilation, but we do depend on precompilation a lot.
Yes, I hadn't thought of that, when extending a method. Not sure how I'd to it though (bring it into the correct scope)
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 17:59
function test_eval()
  @eval :(a=2)
  global a
  println(a)
end
but yeah, my main thing is, @isuruf that warning is scary :smile:
Scott P. Jones
@ScottPJones
Mar 22 2017 18:00
I was making a scheme to decouple our many service modules, that want to define serialization/deserialization functions for their own types, that the central serializer/deserializer code can dispatch on.
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 18:00
I'd like to get rid of it before tagging a release that allows precompilation
Isuru Fernando
@isuruf
Mar 22 2017 18:00
@ChrisRackauckas, yes. that warning is for init_constants method right?
Scott P. Jones
@ScottPJones
Mar 22 2017 18:01
Yes, I know how to deal with globals with eval, just hadn't thought I'd have to do something when extending a function - but I guess maybe it wasn't extending it, it was making a local function.
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 18:01
using ParameterizedFunctions
INFO: Recompiling stale cache file /home/crackauc/.julia/lib/v0.5/ParameterizedFunctions.ji for module ParameterizedFunctions.
WARNING: eval from module SymEngine to ParameterizedFunctions:    
Expr(:block, Expr(:line, 60, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, Expr(:tuple, :basic_new_stack, :libsymengine)::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :IM)::Any)::Any, Expr(:line, 61, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, (:basic_const_I, "/home/crackauc/.julia/v0.5/SymEngine/deps/usr/lib/libsymengine.so"), :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :IM)::Any)::Any, Expr(:line, 62, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:call, :finalizer, :IM, :basic_free)::Any)::Any
  ** incremental compilation may be broken for this module **

WARNING: eval from module SymEngine to ParameterizedFunctions:    
Expr(:block, Expr(:line, 60, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, Expr(:tuple, :basic_new_stack, :libsymengine)::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :PI)::Any)::Any, Expr(:line, 61, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, (:basic_const_pi, "/home/crackauc/.julia/v0.5/SymEngine/deps/usr/lib/libsymengine.so"), :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :PI)::Any)::Any, Expr(:line, 62, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:call, :finalizer, :PI, :basic_free)::Any)::Any
  ** incremental compilation may be broken for this module **

WARNING: eval from module SymEngine to ParameterizedFunctions:    
Expr(:block, Expr(:line, 60, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, Expr(:tuple, :basic_new_stack, :libsymengine)::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :E)::Any)::Any, Expr(:line, 61, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, (:basic_const_E, "/home/crackauc/.julia/v0.5/SymEngine/deps/usr/lib/libsymengine.so"), :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :E)::Any)::Any, Expr(:line, 62, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:call, :finalizer, :E, :basic_free)::Any)::Any
  ** incremental compilation may be broken for this module **

WARNING: eval from module SymEngine to ParameterizedFunctions:    
Expr(:block, Expr(:line, 60, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, Expr(:tuple, :basic_new_stack, :libsymengine)::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :EulerGamma)::Any)::Any, Expr(:line, 61, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:ccall, (:basic_const_EulerGamma, "/home/crackauc/.julia/v0.5/SymEngine/deps/usr/lib/libsymengine.so"), :Void, Expr(:tuple, Expr(:curly, :Ptr, :Basic)::Any)::Any, Expr(:&, :EulerGamma)::Any)::Any, Expr(:line, 62, :/home/crackauc/.julia/v0.5/SymEngine/src/mathops.jl)::Any, Expr(:call, :finalizer, :EulerGamma, :basic_free)::Any)::Any
  ** incremental compilation may be broken for this module **
Scott P. Jones
@ScottPJones
Mar 22 2017 18:02
Yechhh!
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 18:02
I guess it may just be the constants?
Isuru Fernando
@isuruf
Mar 22 2017 18:04
yes. I'll implement it for the constants for now. There are lots of @evals but only the constants are given issues
Isuru Fernando
@isuruf
Mar 22 2017 18:09

I've tried the following,


macro init_constant(op, libnm)
    tup = (Base.Symbol("basic_const_$libnm"), libsymengine)
    alloc_tup = (:basic_new_stack, libsymengine)
    :(
        ccall($alloc_tup, Void, (Ptr{Basic}, ), &($op))
        ccall($tup, Void, (Ptr{Basic}, ), &($op))
        finalizer($op, basic_free)
    )
end

function init_constants()
    @init_constant IM I
    @init_constant PI pi
    @init_constant E E
    @init_constant EulerGamma EulerGamma
end

doesn't work

Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 18:10
btw
you probably shouldn't overwrite Julia's I
Isuru Fernando
@isuruf
Mar 22 2017 18:11
Yes, that's why IM is used
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 18:11
oh I see
it's the other way around
Christopher Rackauckas
@ChrisRackauckas
Mar 22 2017 18:17
do you need to escape the values?
Isuru Fernando
@isuruf
Mar 22 2017 18:18
got it. needs a begin and an end for multiple statements
Isuru Fernando
@isuruf
Mar 22 2017 18:25
symengine/SymEngine.jl#78