first range wrappers work

This commit is contained in:
Christian Zimmermann 2023-02-22 01:04:45 +01:00
parent 7a53982fdd
commit aefb45070d
6 changed files with 5222 additions and 7 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.eggs/
build/
cnorxz.egg-info/
*.so

7
cnorxz/base/range.pxd Normal file
View file

@ -0,0 +1,7 @@
from libcpp.memory cimport shared_ptr
cdef extern from "ranges/ranges.h" namespace "CNORXZ":
cdef cppclass cpp_RangeBase "CNORXZ::RangeBase":
size_t size() except +
size_t dim() except +

View file

@ -0,0 +1,12 @@
from libcpp.memory cimport shared_ptr
from range cimport cpp_RangeBase
cdef extern from "ranges/ranges.h" namespace "CNORXZ":
cdef cppclass cpp_RangeFactoryBase "CNORXZ::RangeFactoryBase":
shared_ptr[cpp_RangeBase] create() except +
cdef extern from "ranges/ranges.h" namespace "CNORXZ":
cdef cppclass cpp_CRangeFactory "CNORXZ::CRangeFactory" (cpp_RangeFactoryBase):
cpp_CRangeFactory(size_t size) except +
shared_ptr[cpp_RangeBase] create() except +

5140
cnorxz/base/ranges.cpp Normal file

File diff suppressed because it is too large Load diff

32
cnorxz/base/ranges.pyx Normal file
View file

@ -0,0 +1,32 @@
from libcpp.memory cimport shared_ptr, make_shared, dynamic_pointer_cast
from range cimport cpp_RangeBase
from range_factory cimport cpp_RangeFactoryBase, cpp_CRangeFactory
cdef class Range:
cdef shared_ptr[cpp_RangeBase] cpp_range
def size(self):
return self.cpp_range.get().size()
def dim(self):
return self.cpp_range.get().dim()
cdef class RangeFactory:
cdef shared_ptr[cpp_RangeFactoryBase] cpp_rfactory
def __cinit__(self,rangetype,**kvargs):
cdef size_t size = 0
if rangetype == 'C':
size = kvargs['size']
self.cpp_rfactory = dynamic_pointer_cast[cpp_RangeFactoryBase,cpp_CRangeFactory](
make_shared[cpp_CRangeFactory](size))
else:
raise Exception('unknown range type:'+ rangetype)
def create(self):
r = Range()
r.cpp_range = self.cpp_rfactory.get().create()
return r

View file

@ -3,19 +3,40 @@
import Cython.Build
import setuptools
import sysconfig
import subprocess
libname = "cnorxz"
author = "Christian Zimmermann"
author_email = "chizeta@f3l.de"
expected_cnorxz_version = "1.0.0" # dummy for now; in the future this is supposed to be the c++ version which is guaranteed to be compatible with py cnorxz
git_hash = subprocess.run(['git','rev-parse','HEAD'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
git_tags = subprocess.run(['git', 'tag', '-l', '--sort=refname', 'v*'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
version = git_hash[:7]
if len(git_tags) != 0:
git_tag = git_tags[-1]
git_hash_tag = subprocess.run(['git','rev-parse',git_tag],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
if git_hash_tag == git_hash:
version = git_tag[1:]
else:
version += git_tag[1:]
# if expected_cnorxz_version != cnorxz_version
# version += '-cxz' + cnorxz_version
path_to_cnorxz = "/home/chizeta/repos/cnorxz/install"
inc_dirs = list()
#inc_dirs.append( "@INSTALL_PATH@/include" )
# ^ specify cnorxz path in command line by typing 'pip install --install-option="--library-dirs=..."'
if path_to_cnorxz != "":
inc_dirs.append( path_to_cnorxz + "/include/cnorxz" )
lib_dirs = list()
lib_dirs.append( "/usr/lib" )
lib_dirs.append( "/usr/local/lib" )
#lib_dirs.append( "@INSTALL_PATH@/lib" )
if path_to_cnorxz != "":
inc_dirs.append( path_to_cnorxz + "/lib" )
lib_dirs.append( "/home/chizeta/repos/cnorxz/install/lib" )
extra_compile_args = sysconfig.get_config_var('CFLAGS').split()
extra_compile_args += ["-std=c++17", "-Wall", "-Wextra", "-Wpedantic"] # get this automatically from cnorxz itself??
@ -41,8 +62,8 @@ if __name__ == "__main__":
setuptools.Extension(
name = libname + ".base",
sources = [
"base/ranges.pys",
"base/array.pys",
"cnorxz/base/ranges.pyx",
#"cnorxz/base/array.pyx",
],
**default_extension_args
)
@ -52,8 +73,7 @@ if __name__ == "__main__":
setuptools.setup(
name = libname,
packages = setuptools.find_packages(),
version_format='{tag}.dev{commitcount}+{gitsha}',
setup_requires=['setuptools-git-version']
version = version,
include_dirs = inc_dirs,
ext_modules = Cython.Build.cythonize(extensions),
author = author,