Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Merging JS and Python binding code - Part 2 #389

Merged
merged 12 commits into from
Jan 23, 2019
Prev Previous commit
Next Next commit
starting work on binding merging
  • Loading branch information
timkpaine committed Jan 18, 2019
commit 91fa42535cba87fe12bf832201ace6178f3e2417
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ set (SOURCE_FILES
src/cpp/base_impl_linux.cpp
src/cpp/base_impl_osx.cpp
src/cpp/base_impl_win.cpp
src/cpp/binding.cpp
src/cpp/build_filter.cpp
#src/cpp/calc_agg_dtype.cpp
src/cpp/column.cpp
Expand Down Expand Up @@ -265,21 +266,21 @@ if (PSP_WASM_BUILD)
add_library(psp ${SOURCE_FILES})
set_target_properties(psp PROPERTIES COMPILE_FLAGS "${ASYNC_MODE_FLAGS}")

add_executable(perspective.async src/cpp/main.cpp)
add_executable(perspective.async src/cpp/emscripten.cpp)
target_link_libraries(perspective.async psp "${ASYNC_MODE_FLAGS}")
set_target_properties(perspective.async PROPERTIES COMPILE_FLAGS "${ASYNC_MODE_FLAGS}")
set_target_properties(perspective.async PROPERTIES RUNTIME_OUTPUT_DIRECTORY "./build/")
set_target_properties(perspective.async PROPERTIES OUTPUT_NAME "psp.async")

add_executable(perspective.sync src/cpp/main.cpp)
add_executable(perspective.sync src/cpp/emscripten.cpp)
target_link_libraries(perspective.sync psp "${SYNC_MODE_FLAGS}")
set_target_properties(perspective.sync PROPERTIES COMPILE_FLAGS "${SYNC_MODE_FLAGS}")
set_target_properties(perspective.sync PROPERTIES RUNTIME_OUTPUT_DIRECTORY "./build/")
set_target_properties(perspective.sync PROPERTIES OUTPUT_NAME "psp.sync")
add_dependencies(perspective.sync perspective.async)

if (NOT DEFINED ENV{PSP_DEBUG})
add_executable(perspective.asm src/cpp/main.cpp)
add_executable(perspective.asm src/cpp/emscripten.cpp)
target_link_libraries(perspective.asm psp "${ASMJS_MODE_FLAGS}")
set_target_properties(perspective.asm PROPERTIES COMPILE_FLAGS "${ASMJS_MODE_FLAGS}")
set_target_properties(perspective.asm PROPERTIES RUNTIME_OUTPUT_DIRECTORY "./build/")
Expand All @@ -297,7 +298,7 @@ else()
target_link_libraries(psp ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
set(CMAKE_SHARED_LIBRARY_SUFFIX .so)

add_library(binding SHARED ${CMAKE_SOURCE_DIR}/python/perspective/src/binding.cpp)
add_library(binding SHARED ${CMAKE_SOURCE_DIR}/python/perspective/src/python.cpp)
target_link_libraries(binding psp)
target_link_libraries(binding tbb)
target_link_libraries(binding ${BOOST_PYTHON})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#include <perspective/first.h>
#include <perspective/base.h>
#include <perspective/table.h>
#include <perspective/column.h>
#include <perspective/gnode.h>


#ifndef __PSP_BINDING_HPP__
#define __PSP_BINDING_HPP__
#ifndef __PSP_PYTHON_HPP__
#define __PSP_PYTHON_HPP__


void test(const char* name);


perspective::t_schema* t_schema_init(py::list& columns, py::list& types);
Expand Down Expand Up @@ -48,6 +49,8 @@ BOOST_PYTHON_MODULE(libbinding)
np::initialize(true);
_import_array();

py::def("test", test);

py::enum_<perspective::t_dtype>("t_dtype")
.value("NONE", perspective::DTYPE_NONE)
.value("INT64", perspective::DTYPE_INT64)
Expand Down Expand Up @@ -98,27 +101,12 @@ BOOST_PYTHON_MODULE(libbinding)
// when returning const, need return_value_policy<copy_const_reference>
.def("columns", &perspective::t_schema::columns, py::return_value_policy<py::copy_const_reference>())
// .def("types", &perspective::t_schema::types, return_value_policy<copy_const_reference>())
.def("str", &perspective::t_schema::str)
;


//TODO
py::class_<perspective::t_column>("t_column",
py::init<>())
.def("pprint", &perspective::t_column::pprint)
.def("size", &perspective::t_column::size)
.def("get_dtype", &perspective::t_column::get_dtype)
;

py::class_<perspective::t_gnode>("t_gnode",
py::init<perspective::t_schema, perspective::t_schema>())
.def("init", &perspective::t_gnode::init)
.def("pprint", &perspective::t_gnode::pprint)
// when returning const, need return_value_policy<copy_const_reference>
// .def("get_table", static_cast<const perspective::t_table* (perspective::t_gnode::*)() const>(&perspective::t_gnode::get_table), py::return_value_policy<py::copy_const_reference>())
// when multiple overloading methods, need to static_cast to specify
// .def("get_table", static_cast<perspective::t_table* (perspective::t_gnode::*)()>(&perspective::t_gnode::get_table))
.def("get_tblschema", &perspective::t_gnode::get_tblschema)
.def("get_pivots", &perspective::t_gnode::get_pivots)
;

// need boost:noncopyable for PSP_NON_COPYABLE
Expand All @@ -138,7 +126,6 @@ BOOST_PYTHON_MODULE(libbinding)
// when returning const, need return_value_policy<copy_const_reference>
.def("name", &perspective::t_table::name, py::return_value_policy<py::copy_const_reference>())
.def("get_schema", &perspective::t_table::get_schema, py::return_value_policy<py::copy_const_reference>())
.def("make_column", &perspective::t_table::make_column)

// when multiple overloading methods, need to static_cast to specify
.def("num_rows", static_cast<perspective::t_uindex (perspective::t_table::*)() const> (&perspective::t_table::num_rows))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
*/
#ifdef PSP_ENABLE_PYTHON
#include <perspective/binding.h>
#include <perspective/python.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)
{
std::vector<std::string> cols;
Expand All @@ -26,7 +31,7 @@ perspective::t_schema* t_schema_init(py::list& columns, py::list& types)
return new perspective::t_schema(cols, ts);
}

template<typename T>
template<typename T>
void _fill_col(std::vector<T>& dcol, std::shared_ptr<perspective::t_column> col)
{
perspective::t_uindex nrows = col->size();
Expand Down
16 changes: 16 additions & 0 deletions src/cpp/binding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/******************************************************************************
*
* Copyright (c) 2019, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
#include <perspective/binding.h>
#include <cstdint>

namespace perspective {
namespace binding {

}
}
Loading