Skip to content

Commit

Permalink
fix python for types, prepare for publish
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Jan 4, 2019
1 parent c1fdaaa commit 37c4273
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 50 deletions.
4 changes: 2 additions & 2 deletions python/Makefile
Expand Up @@ -2,8 +2,8 @@ build: ## build the package
python3 setup.py build

inplace: ## copy things inplace
cp `find build -name "libbinding.so"` perspective/
cp `find build -name "libpsp.so"` perspective/
cp `find build -name "libbinding.so"` perspective/table/
cp `find build -name "libpsp.so"` perspective/table/

tests: inplace ## Clean and Make unit tests
python3 -m nose2 -v perspective --with-coverage --coverage=perspective
Expand Down
10 changes: 5 additions & 5 deletions python/perspective/include/perspective/binding.h
Expand Up @@ -25,10 +25,10 @@ void test(const char* name);
perspective::t_schema* t_schema_init(py::list& columns, py::list& types);

template<typename T>
void _fill_col(std::vector<T>& dcol, perspective::t_col_sptr col);
void _fill_col(std::vector<T>& dcol, std::shared_ptr<perspective::t_column> col);

template<typename T>
void _fill_col_np(np::ndarray& dcol, perspective::t_col_sptr col);
void _fill_col_np(np::ndarray& dcol, std::shared_ptr<perspective::t_column> col);


void _fill_data_single_column(perspective::t_table& tbl,
Expand Down Expand Up @@ -80,7 +80,7 @@ BOOST_PYTHON_MODULE(libbinding)


py::class_<perspective::t_schema>("t_schema",
py::init<perspective::t_svec, perspective::t_dtypevec>())
py::init<std::vector<std::string>, std::vector<perspective::t_dtype> >())
.def(py::init<>())
.def(py::init<perspective::t_schema_recipe>())

Expand Down Expand Up @@ -132,8 +132,8 @@ BOOST_PYTHON_MODULE(libbinding)

.def("pprint", static_cast<void (perspective::t_table::*)() const>(&perspective::t_table::pprint))
.def("pprint", static_cast<void (perspective::t_table::*)(perspective::t_uindex, std::ostream*) const>(&perspective::t_table::pprint))
.def("pprint", static_cast<void (perspective::t_table::*)(const perspective::t_str&) const>(&perspective::t_table::pprint))
.def("pprint", static_cast<void (perspective::t_table::*)(const perspective::t_uidxvec&) const>(&perspective::t_table::pprint))
.def("pprint", static_cast<void (perspective::t_table::*)(const std::string&) const>(&perspective::t_table::pprint))
.def("pprint", static_cast<void (perspective::t_table::*)(const std::vector<perspective::t_uindex>&) const>(&perspective::t_table::pprint))


// custom add ins
Expand Down
61 changes: 31 additions & 30 deletions python/perspective/src/binding.cpp
Expand Up @@ -8,18 +8,19 @@
*/
#ifdef PSP_ENABLE_PYTHON
#include <perspective/binding.h>
#include <cstdint>

void test(const char* name) {
std::cout << "Hello " << name << "!" << std::endl;
}

perspective::t_schema* t_schema_init(py::list& columns, py::list& types)
{
perspective::t_svec cols;
perspective::t_dtypevec ts;
std::vector<std::string> cols;
std::vector<perspective::t_dtype> ts;

for(ssize_t i=0; i < py::len(columns); i++) {
cols.push_back(py::extract<perspective::t_str>(columns[i]));
cols.push_back(py::extract<std::string>(columns[i]));
}

for(ssize_t i=0; i < py::len(types); i++) {
Expand All @@ -30,7 +31,7 @@ perspective::t_schema* t_schema_init(py::list& columns, py::list& types)
}

template<typename T>
void _fill_col(std::vector<T>& dcol, perspective::t_col_sptr col)
void _fill_col(std::vector<T>& dcol, std::shared_ptr<perspective::t_column> col)
{
perspective::t_uindex nrows = col->size();

Expand All @@ -43,7 +44,7 @@ void _fill_col(std::vector<T>& dcol, perspective::t_col_sptr col)
}

template<typename T>
void _fill_col_np(np::ndarray& dcol, perspective::t_col_sptr col)
void _fill_col_np(np::ndarray& dcol, std::shared_ptr<perspective::t_column>col)
{
perspective::t_uindex nrows = col->size();
for (auto i = 0; i < nrows; ++i)
Expand All @@ -61,65 +62,65 @@ void _fill_data_single_column(perspective::t_table& tbl,
py::list& data_cols_i,
perspective::t_dtype col_type)
{
perspective::t_str name = colname_i;
perspective::t_col_sptr col = tbl.get_column(name);
std::string name = colname_i;
std::shared_ptr<perspective::t_column> col = tbl.get_column(name);

switch(col_type){
case perspective::DTYPE_INT64 : {
std::vector<perspective::t_int64> dcol;
std::vector<std::int64_t> dcol;

for(ssize_t i=0; i < py::len(data_cols_i); i++)
{
dcol.push_back(py::extract<perspective::t_int64>(data_cols_i[i]));
dcol.push_back(py::extract<std::int64_t>(data_cols_i[i]));
}

_fill_col<perspective::t_int64>(dcol, col);
_fill_col<std::int64_t>(dcol, col);
break;
}
case perspective::DTYPE_UINT64 : {
std::vector<perspective::t_uint64> dcol;
std::vector<std::uint64_t> dcol;

for(ssize_t i=0; i < py::len(data_cols_i); i++)
{
dcol.push_back(py::extract<perspective::t_uint64>(data_cols_i[i]));
dcol.push_back(py::extract<std::uint64_t>(data_cols_i[i]));
}

_fill_col<perspective::t_uint64>(dcol, col);
_fill_col<std::uint64_t>(dcol, col);
break;
}
case perspective::DTYPE_FLOAT64 : {
std::vector<perspective::t_float64> dcol;
std::vector<double> dcol;

for(ssize_t i=0; i < py::len(data_cols_i); i++)
{
dcol.push_back(py::extract<perspective::t_float64>(data_cols_i[i]));
dcol.push_back(py::extract<double>(data_cols_i[i]));
}

_fill_col<perspective::t_float64>(dcol, col);
_fill_col<double>(dcol, col);
break;
}
case perspective::DTYPE_BOOL : {
//FIXME segfault
std::vector<perspective::t_bool> dcol;
std::vector<bool> dcol;

for(ssize_t i=0; i < py::len(data_cols_i); i++)
{
dcol.push_back(py::extract<perspective::t_bool>(data_cols_i[i]));
dcol.push_back(py::extract<bool>(data_cols_i[i]));
}

_fill_col<perspective::t_bool>(dcol, col);
_fill_col<bool>(dcol, col);
break;
}
case perspective::DTYPE_STR : {

std::vector<perspective::t_str> dcol;
std::vector<std::string> dcol;

for(ssize_t i=0; i < py::len(data_cols_i); i++)
{
dcol.push_back(py::extract<perspective::t_str>(data_cols_i[i]));
dcol.push_back(py::extract<std::string>(data_cols_i[i]));
}

_fill_col<perspective::t_str>(dcol, col);
_fill_col<std::string>(dcol, col);
break;
}
default: {
Expand All @@ -134,20 +135,20 @@ _fill_data_single_column_np(perspective::t_table& tbl,
np::ndarray& dcol,
perspective::t_dtype col_type)
{
perspective::t_str name = colname_i;
perspective::t_col_sptr col = tbl.get_column(name);
std::string name = colname_i;
std::shared_ptr<perspective::t_column> col = tbl.get_column(name);

switch(col_type){
case perspective::DTYPE_INT64 : {
_fill_col_np<perspective::t_int64>(dcol, col);
_fill_col_np<std::int64_t>(dcol, col);
break;
}
case perspective::DTYPE_FLOAT64 : {
_fill_col_np<perspective::t_float64>(dcol, col);
_fill_col_np<double>(dcol, col);
break;
}
case perspective::DTYPE_STR : {
_fill_col_np<perspective::t_str>(dcol, col);
_fill_col_np<std::string>(dcol, col);
break;
}
default: {
Expand All @@ -159,11 +160,11 @@ _fill_data_single_column_np(perspective::t_table& tbl,

np::ndarray _get_as_numpy(perspective::t_table& tbl, const std::string& colname_i)
{
perspective::t_str name = colname_i;
perspective::t_col_sptr col = tbl.get_column(name);
std::string name = colname_i;
std::shared_ptr<perspective::t_column> col = tbl.get_column(name);
return col->_as_numpy();
}



#endif
#endif
22 changes: 11 additions & 11 deletions python/perspective/src/numpy.cpp
Expand Up @@ -39,43 +39,43 @@ get_numpy_typenum_from_dtype(t_dtype dtype)
{
case DTYPE_INT8:
{
return np::dtype::get_builtin<t_int8>();
return np::dtype::get_builtin<std::int8_t>();
}
case DTYPE_UINT8:
{
return np::dtype::get_builtin<t_uint8>();
return np::dtype::get_builtin<std::uint8_t>();
}
case DTYPE_INT16:
{
return np::dtype::get_builtin<t_int16>();
return np::dtype::get_builtin<std::int16_t>();
}
case DTYPE_UINT16:
{
return np::dtype::get_builtin<t_uint16>();
return np::dtype::get_builtin<std::uint16_t>();
}
case DTYPE_INT32:
{
return np::dtype::get_builtin<t_int32>();
return np::dtype::get_builtin<std::int32_t>();
}
case DTYPE_UINT32:
{
return np::dtype::get_builtin<t_uint32>();
return np::dtype::get_builtin<std::uint32_t>();
}
case DTYPE_UINT64:
{
return np::dtype::get_builtin<t_uint64>();
return np::dtype::get_builtin<std::uint64_t>();
}
case DTYPE_INT64:
{
return np::dtype::get_builtin<t_int64>();
return np::dtype::get_builtin<std::int64_t>();
}
case DTYPE_FLOAT32:
{
return np::dtype::get_builtin<t_float32>();
return np::dtype::get_builtin<float>();
}
case DTYPE_FLOAT64:
{
return np::dtype::get_builtin<t_float64>();
return np::dtype::get_builtin<double>();
}
// TODO
// case DTYPE_STR:
Expand All @@ -92,7 +92,7 @@ get_numpy_typenum_from_dtype(t_dtype dtype)
// }
case DTYPE_BOOL:
{
return np::dtype::get_builtin<t_bool>();
return np::dtype::get_builtin<bool>();
}
default:
{
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions python/setup.py
Expand Up @@ -68,7 +68,7 @@ def build_cmake(self, ext):


setup(
name='perspective',
name='perspective-python',
version='0.0.1',
description='Analytics library',
long_description=long_description,
Expand All @@ -89,7 +89,7 @@ def build_cmake(self, ext):

keywords='analytics tools plotting',
# packages=find_packages(exclude=['tests', ]),
packages=find_packages(),
packages=['perspective.table'],
include_package_data=True,
zip_safe=False,
ext_modules=[
Expand Down

0 comments on commit 37c4273

Please sign in to comment.