merge
This commit is contained in:
commit
153d82223a
5 changed files with 60 additions and 43 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
.eggs/
|
.eggs/
|
||||||
build/
|
build/
|
||||||
|
dist/
|
||||||
cnorxz.egg-info/
|
cnorxz.egg-info/
|
||||||
*.so
|
*.so
|
||||||
|
|
|
@ -24,10 +24,16 @@ namespace CNORXZ
|
||||||
virtual void readFile(cer::Format f, const String& fname) const = 0;
|
virtual void readFile(cer::Format f, const String& fname) const = 0;
|
||||||
#endif
|
#endif
|
||||||
virtual int typenum() const = 0;
|
virtual int typenum() const = 0;
|
||||||
virtual void* data() const = 0;
|
virtual const void* data() const = 0;
|
||||||
virtual SizeT datasize() const = 0;
|
virtual SizeT datasize() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ArrayWrapperBase : public CArrayWrapperBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void* data() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Typenum
|
struct Typenum
|
||||||
{
|
{
|
||||||
|
@ -59,7 +65,7 @@ namespace CNORXZ
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class ArrayWrapper : public CArrayWrapperBase
|
class ArrayWrapper : public ArrayWrapperBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Sptr<ArrayBase<T>> mArr;
|
Sptr<ArrayBase<T>> mArr;
|
||||||
|
@ -67,6 +73,7 @@ namespace CNORXZ
|
||||||
public:
|
public:
|
||||||
ArrayWrapper() : mArr( std::make_shared<MArray<T>>() ) {}
|
ArrayWrapper() : mArr( std::make_shared<MArray<T>>() ) {}
|
||||||
ArrayWrapper(const RangePtr& r) : mArr( std::make_shared<MArray<T>>(r) ) {}
|
ArrayWrapper(const RangePtr& r) : mArr( std::make_shared<MArray<T>>(r) ) {}
|
||||||
|
ArrayWrapper(const Sptr<ArrayBase<T>>& arr) : mArr(arr) {}
|
||||||
|
|
||||||
virtual RangePtr range() const override final { return mArr->range(); }
|
virtual RangePtr range() const override final { return mArr->range(); }
|
||||||
virtual SizeT size() const override final { return mArr->size(); }
|
virtual SizeT size() const override final { return mArr->size(); }
|
||||||
|
@ -92,7 +99,9 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
virtual int typenum() const override final { return Typenum<T>::value; }
|
virtual int typenum() const override final { return Typenum<T>::value; }
|
||||||
virtual void* data() const override final
|
virtual const void* data() const override final
|
||||||
|
{ return reinterpret_cast<const void*>( mArr->data() ); }
|
||||||
|
virtual void* data() override final
|
||||||
{ return reinterpret_cast<void*>( mArr->data() ); }
|
{ return reinterpret_cast<void*>( mArr->data() ); }
|
||||||
virtual SizeT datasize() const override final { return size() * sizeof(T); }
|
virtual SizeT datasize() const override final { return size() * sizeof(T); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,8 @@ namespace CNORXZ
|
||||||
inline SizeT dim() const { return mR->dim(); }
|
inline SizeT dim() const { return mR->dim(); }
|
||||||
inline RangePtr sub(SizeT pos) { return mR->sub(pos); }
|
inline RangePtr sub(SizeT pos) { return mR->sub(pos); }
|
||||||
inline String stringMeta(SizeT pos) const { return mR->stringMeta(pos); }
|
inline String stringMeta(SizeT pos) const { return mR->stringMeta(pos); }
|
||||||
|
inline MArray<RangePtr> sub() const { return mR->sub(); }
|
||||||
|
inline RangePtr sub(SizeT pos) const { return mR->sub(pos); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RangePtr mR;
|
RangePtr mR;
|
||||||
|
@ -35,6 +37,7 @@ PyObject* PyCxRange_size(PyCxRange* self);
|
||||||
PyObject* PyCxRange_dim(PyCxRange* self);
|
PyObject* PyCxRange_dim(PyCxRange* self);
|
||||||
PyObject* PyCxRange_sub(PyCxRange* self, PyObject* args, PyObject* kwds);
|
PyObject* PyCxRange_sub(PyCxRange* self, PyObject* args, PyObject* kwds);
|
||||||
PyObject* PyCxRange_stringMeta(PyCxRange* self, PyObject* args, PyObject* kwds);
|
PyObject* PyCxRange_stringMeta(PyCxRange* self, PyObject* args, PyObject* kwds);
|
||||||
|
PyObject* PyCxRange_sub(PyCxRange* self, PyObject* args, PyObject* kwds);
|
||||||
PyTypeObject* PyCxRangeType_init();
|
PyTypeObject* PyCxRangeType_init();
|
||||||
|
|
||||||
extern PyMethodDef PyCxRange_methods[];
|
extern PyMethodDef PyCxRange_methods[];
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
#include "array_wrapper.h"
|
||||||
#include "range_wrapper.h"
|
#include "range_wrapper.h"
|
||||||
|
|
||||||
using namespace CNORXZ;
|
using namespace CNORXZ;
|
||||||
|
@ -7,6 +8,7 @@ int PyCxRange_init(PyCxRange* self, PyObject* args, PyObject* kwds)
|
||||||
{
|
{
|
||||||
|
|
||||||
//!!!
|
//!!!
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyCxRange_dealloc(PyCxRange* self)
|
void PyCxRange_dealloc(PyCxRange* self)
|
||||||
|
@ -49,6 +51,14 @@ PyObject* PyCxRange_sub(PyCxRange* self, PyObject* args, PyObject* kwds)
|
||||||
return PyErr_Format(PyExc_RuntimeError, "requested sub-range position (%d) exceeds range dimension (%d)", pos, dim);
|
return PyErr_Format(PyExc_RuntimeError, "requested sub-range position (%d) exceeds range dimension (%d)", pos, dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// entire set of sub-ranges:
|
||||||
|
/*
|
||||||
|
PyCxArrayB* o;
|
||||||
|
o = PyObject_New(PyCxArrayB, &PyCxArrayBType);
|
||||||
|
o->ptrObj = new ArrayWrapper<RangePtr>( std::make_shared<MArray<RangePtr>>(self->ptrObj->sub()) );
|
||||||
|
return Py_BuildValue("O", o);
|
||||||
|
*/
|
||||||
|
|
||||||
const RangePtr r = self->ptrObj->sub(pos);
|
const RangePtr r = self->ptrObj->sub(pos);
|
||||||
PyCxRange* o = PyObject_New(PyCxRange, &PyCxRangeType);
|
PyCxRange* o = PyObject_New(PyCxRange, &PyCxRangeType);
|
||||||
o->ptrObj = new RangeWrapper(r);
|
o->ptrObj = new RangeWrapper(r);
|
||||||
|
|
74
setup.py
74
setup.py
|
@ -1,47 +1,57 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
#import numpy
|
# imports:
|
||||||
|
|
||||||
import setuptools
|
import setuptools
|
||||||
from distutils.core import setup, Extension
|
from distutils.core import setup, Extension
|
||||||
|
import os
|
||||||
import sysconfig
|
import sysconfig
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
# basic variables:
|
||||||
|
|
||||||
libname = "cnorxz"
|
libname = "cnorxz"
|
||||||
author = "Christian Zimmermann"
|
author = "Christian Zimmermann"
|
||||||
author_email = "chizeta@f3l.de"
|
author_email = "chizeta@f3l.de"
|
||||||
path_to_cnorxz = "/home/chizeta/repos/cnorxz/install"
|
path_to_cnorxz = ""
|
||||||
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
|
if 'CNORXZ' in os.environ:
|
||||||
|
path_to_cnorxz = os.environ['CNORXZ']
|
||||||
|
version = "0.0.0"
|
||||||
|
have_numpy = True
|
||||||
|
|
||||||
git_hash = subprocess.run(['git','rev-parse','HEAD'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
|
# flags:
|
||||||
git_tags = subprocess.run(['git', 'tag', '-l', '--sort=refname', 'v*'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
|
|
||||||
cnorxz_version = subprocess.run([path_to_cnorxz+"/bin/cnorxz-config",'--version'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
|
config_bin = path_to_cnorxz+"/bin/cnorxz-config"
|
||||||
|
extra_compile_args = sysconfig.get_config_var('CFLAGS').split()
|
||||||
|
cnorxz_version = subprocess.run([config_bin,'--version'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
|
||||||
|
cnorxz_flags = subprocess.run([config_bin,'--flags'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
|
||||||
|
cnorxz_definitions = subprocess.run([config_bin,'--definitions'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
|
||||||
|
cnorxz_flags.remove("-Werror")
|
||||||
|
cnorxz_flags.append("-Wno-write-strings")
|
||||||
|
extra_compile_args += cnorxz_flags
|
||||||
|
|
||||||
|
# includes:
|
||||||
|
|
||||||
assert len(git_tags) != 0, "no version tags found"
|
|
||||||
git_tag = git_tags[-1]
|
|
||||||
version = git_tag[1:] + 'dev'
|
|
||||||
git_hash_tag = subprocess.run(['git','rev-list','-n','1',git_tag],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
|
|
||||||
if git_hash_tag == git_hash and expected_cnorxz_version != cnorxz_version:
|
|
||||||
version = git_tag[1:]
|
|
||||||
|
|
||||||
inc_dirs = list()
|
inc_dirs = list()
|
||||||
if path_to_cnorxz != "":
|
if path_to_cnorxz != "":
|
||||||
inc_dirs.append( path_to_cnorxz + "/include/cnorxz" )
|
inc_dirs.append( path_to_cnorxz + "/include/cnorxz" )
|
||||||
inc_dirs.append( "cnorxz/core/include" )
|
inc_dirs.append( "cnorxz/core/include" )
|
||||||
#inc_dirs.append( numpy.get_include() )
|
|
||||||
inc_dirs.append( "/home/chizeta/my_env/lib/python3.11/site-packages/numpy/core/include" )
|
# library dirs:
|
||||||
|
|
||||||
lib_dirs = list()
|
lib_dirs = list()
|
||||||
lib_dirs.append( "/usr/lib" )
|
lib_dirs.append( "/usr/lib" )
|
||||||
lib_dirs.append( "/usr/local/lib" )
|
lib_dirs.append( "/usr/local/lib" )
|
||||||
if path_to_cnorxz != "":
|
if path_to_cnorxz != "":
|
||||||
inc_dirs.append( path_to_cnorxz + "/lib" )
|
lib_dirs.append( path_to_cnorxz + "/lib" )
|
||||||
lib_dirs.append( "/home/chizeta/repos/cnorxz/install/lib" )
|
|
||||||
|
|
||||||
extra_compile_args = sysconfig.get_config_var('CFLAGS').split()
|
# optional dependencies:
|
||||||
cnorxz_flags = subprocess.run([path_to_cnorxz+"/bin/cnorxz-config",'--flags'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
|
|
||||||
cnorxz_flags.remove("-Werror")
|
if have_numpy:
|
||||||
cnorxz_flags.append("-Wno-write-strings")
|
import numpy
|
||||||
extra_compile_args += cnorxz_flags
|
inc_dirs.append( numpy.get_include() )
|
||||||
|
|
||||||
|
# main
|
||||||
|
|
||||||
default_extension_args = dict(
|
default_extension_args = dict(
|
||||||
language = "c++",
|
language = "c++",
|
||||||
|
@ -49,6 +59,7 @@ default_extension_args = dict(
|
||||||
libraries = [libname],
|
libraries = [libname],
|
||||||
library_dirs = lib_dirs,
|
library_dirs = lib_dirs,
|
||||||
extra_compile_args = extra_compile_args,
|
extra_compile_args = extra_compile_args,
|
||||||
|
define_macros = [(mac,None) for mac in cnorxz_definitions]
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -59,21 +70,6 @@ if __name__ == "__main__":
|
||||||
for d in lib_dirs:
|
for d in lib_dirs:
|
||||||
print("\t",d)
|
print("\t",d)
|
||||||
|
|
||||||
#extensions = list()
|
|
||||||
#extensions.append(
|
|
||||||
# setuptools.Extension(
|
|
||||||
# #name = libname + ".core",
|
|
||||||
# name = libname,
|
|
||||||
# sources = [
|
|
||||||
# "cnorxz/core/core.cpp",
|
|
||||||
# "cnorxz/core/lib/array_wrapper.cpp"
|
|
||||||
# ],
|
|
||||||
# define_macros=[('HAVE_CEREAL',None)],
|
|
||||||
# **default_extension_args
|
|
||||||
# )
|
|
||||||
#)
|
|
||||||
# append further extensions (cereal, hdf5, mpi ...) here
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = libname,
|
name = libname,
|
||||||
packages = setuptools.find_packages(),
|
packages = setuptools.find_packages(),
|
||||||
|
@ -81,10 +77,8 @@ if __name__ == "__main__":
|
||||||
include_dirs = inc_dirs,
|
include_dirs = inc_dirs,
|
||||||
ext_modules = [Extension(
|
ext_modules = [Extension(
|
||||||
'cnorxz', ['cnorxz/core/core.cpp','cnorxz/core/lib/array_wrapper.cpp','cnorxz/core/lib/range_wrapper.cpp'],
|
'cnorxz', ['cnorxz/core/core.cpp','cnorxz/core/lib/array_wrapper.cpp','cnorxz/core/lib/range_wrapper.cpp'],
|
||||||
define_macros=[('HAVE_CEREAL',None)],
|
|
||||||
**default_extension_args
|
**default_extension_args
|
||||||
)],
|
)],
|
||||||
#ext_modules = Cython.Build.cythonize(extensions),
|
|
||||||
author = author,
|
author = author,
|
||||||
author_email = author_email,
|
author_email = author_email,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue