Comments (5)
Hi.
I went with SWIG because it does a lot of the hard work of parsing and validating input for you. If you write your own wrapper, you have to write a lot of boilerplated code yourself. Given a large enough codebase (100K+ lines), custom wrappers become very hard to maintain.
The Python typemap lives here: https://github.com/wiseio/paratext/blob/master/src/python
. The interface file (python.i) is pretty rudimentary. It converts std::vector<int/double/string>
to NumPy vectors.
%typemap(out) std::vector<int> {
$result = (PyObject*)::build_array<std::vector<int>>($1);
}
%typemap(out) std::vector<double> {
$result = (PyObject*)::build_array<std::vector<double>>($1);
}
%typemap(out) std::vector<size_t> {
$result = (PyObject*)::build_array<std::vector<size_t>>($1);
}
%typemap(out) const std::vector<std::string> & {
{ auto range = std::make_pair($1->begin(), $1->end());
$result = (PyObject*)::build_array_from_range(range);
}
}
%typemap(out) std::vector<std::string> {
$result = (PyObject*)::build_array<std::vector<std::string>>($1);
}
%typemap(out) ParaText::CSV::ColBasedPopulator {
$result = (PyObject*)::build_populator<ParaText::CSV::ColBasedPopulator>($1);
}
You need to write template functions to convert from C++ containers to Ruby arrays.
Ruby::Value build_array<ContainerType>(const ContainerType &container)
You also need to write a function to convert CSV columns to Ruby arrays:
Ruby::Value build_populator<ParaText::CSV::ColBasedPopulator>(ParaText::CSV::ColBasedPopulator &populator)
This is needed to call the loader.get_column(column_index)
function.
Best,
Damian
from paratext.
I am not very familiar with the internals of Ruby, but I am happy to provide guidance for the effort.
from paratext.
Works :)
Should we use SWIG or is it ok to use the Ruby C API directly? Any specific reasons why you used SWIG for the python bindings?
from paratext.
SWIG will likely make your life easier if you have straightforward type mappings. I may write a Cython binding for paratext (mainly to simplify talking to other Python modules that use Cython -- you can define an internal C API via pxd files) but either way it makes for less work than a hand-coded C extension for Python at least.
from paratext.
Alright. I'll explore all the options and post them here soon. Thanks :)
from paratext.
Related Issues (20)
- Build fails on Windows 7 with Anaconda HOT 3
- Add support for reading large files in chunks HOT 1
- C++ rowbase stream processing?
- Unexpected content conversion for a hex string data HOT 3
- add support for .gz files HOT 1
- add support for opening multiple files HOT 1
- Paratext <-> Apache Arrow bridge HOT 1
- perf problems HOT 3
- can i access data by row HOT 3
- how to install paratext for python3? HOT 1
- Support for tab-delimited files? HOT 1
- Reading from stdin should use single thread or report an error HOT 1
- Feature request : Add support for conda HOT 1
- Feature request: Add `sep` argument for separator HOT 1
- Import fails on OSX 10.12.5 using Anaconda HOT 8
- C++11 compiler warning with clang on OS X
- Unable to read csv
- how to use it in c or c++?
- Issue with paratext.load_csv_to_pandas() HOT 4
- Tested on AWS Lambda - EFS ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paratext.