Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Cython does not include definitions for
The blog post https://molpopgen.github.io/fwdpy/docs/examples/cython/WritingExtensions includes the following example
Is this the "best practice" way? If so, would it make sense to include the make_pair definition in
Yes, for sure. PRs welcome.…
On Fri, Nov 9, 2018, 5:17 AM Leonard Lausen ***@***.*** wrote: Cython does not include definitions for std::make_pair The blog post https://molpopgen.github.io/fwdpy/docs/examples/cython/WritingExtensions includes the following example %%cython --cplus --compile-args=-std=c++11 -I $fwdpy_includes -I $fwdpp_includes -l sequence -l gsl -l gslcblas from fwdpy.fwdpy cimport * from libcpp.utility cimport pair import numpy as np ctypedef vector[double] vd ctypedef pair[vd,vd] pvdvd #Annoyingly, Cython currently does not #expose std::make_pair, so we will #do it here ourselves! #If we don't have std::make_pair, #we end up making extra temporary copies #of our return values in memory. That's #not cool, as we're doing this because #we care about efficiency! cdef extern from "<utility>" namespace "std" nogil: pair[T,U] make_pair[T,U](T&,U&) cdef pvdvd freq_esize_cpp(const singlepop_t * pop): cdef vd freq,esize cdef double twoN = 2.0*float(pop.N) cdef size_t i = 0 cdef size_t nm=0 for i in range(pop.mcounts.size()): if pop.mcounts[i]>0: if pop.mutations[i].neutral is False: freq.push_back(float(pop.mcounts[i])/twoN) #s records the effect size/selection coefficient esize.push_back(pop.mutations[i].s) #For some reason, we need to provide casts #so that Cython can get the types right for the call to #make_pair: return make_pair(<vd>freq,<vd>esize) def freq_esize(Spop pop): return freq_esize_cpp(pop.pop.get()) Is this the "best practice" way? If so, would it make sense to include the make_pair definition in Includes/libcpp/? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#2706>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAdqgdEq4NjnD9Gt0IV6ctDBGN0Z3vb4ks5utQHAgaJpZM4YV702> .