GithubHelp home page GithubHelp logo

Python 3 binding about fmm HOT 8 CLOSED

cyang-kth avatar cyang-kth commented on July 17, 2024
Python 3 binding

from fmm.

Comments (8)

cyang-kth avatar cyang-kth commented on July 17, 2024 1

@zhuang-hao-ming
This is a good question. What I expect for a python interface is something that can be tested interactively on the fly. It would be convenient if different components of the program can be designed with Python interface.

The program is like

from fmm import ubodt, network, mm_app
app = mm_app()
table = ubodt.read("ubodt.txt")
net = network.read("network.shp")
app.register_ubodt(table)
app.register_network(net)
app.register_config({r:200,k:8,pf:100})
# Some functions
print table.query_dist(12,23)
print table.query_path(12,23)
print net.search_candidate(point, k = 5, r= 200)
print app.match_wkt("Linestring ...")

With the python interface above, it would also be easy to design a map matching web service in Python using lightweight server such as flask.

https://github.com/BVLC/caffe/tree/master/examples/web_demo

I have very few experience with writing Python interface for C program. Perhaps that would be quite a lot of work.

from fmm.

zhuang-hao-ming avatar zhuang-hao-ming commented on July 17, 2024

Hello @cyang-kth .

I am not very familiar with Caffe.
I want to know what your definition of python interface is.
I just implemented a python interface.
It look like this.

>>> import fmm
>>> fmm.fmm("fmm_config.xml")
------------ Fast map matching (FMM) ------------
------------     Author: Can Yang    ------------
------------   Version: 2018.03.09   ------------
------------     Applicaton: fmm     ------------
Validating configuration for map match application:
    Warning, overwrite existing result file.mr.txt

And the code look like this.

#include <boost/python.hpp>
#include <string>
using namespace std;

#include <app/fmm.cpp>

void fmm(string config_file_name) {

	char* argvs[] = { "fmm" , const_cast<char*>(config_file_name.c_str()) };
	main(2, argvs);
}


BOOST_PYTHON_MODULE(fmm)
{
	using namespace boost::python;

	def("fmm", fmm);
}

I think there is no difference between such a python interface and the command line.
So I think you might have some suggestions on the design of python interfaces.

Thank.

from fmm.

cyang-kth avatar cyang-kth commented on July 17, 2024

There seems to be several ways to write python wrapper for c++.

Other popular libraries

from fmm.

cyang-kth avatar cyang-kth commented on July 17, 2024

A Python API has been added in the latest commit.

from fmm.

cweber9843 avatar cweber9843 commented on July 17, 2024

Thanks @cyang-kth for the great work with this code!
Do you have plans to make the API available in python3?
Would be great, especially since python 2.7 reached end of life in 2020.

from fmm.

cyang-kth avatar cyang-kth commented on July 17, 2024

@cweber9843

The current Python API is built using Swig, which supports Python 3.0 according to the documentation.
http://www.swig.org/Doc3.0/SWIGDocumentation.html#Python_python3support

If you want to build the Python 3 API you can just add a line to this cmake file before this line

swig_link_libraries(fmm

set_property(TARGET fmm PROPERTY SWIG_COMPILE_OPTIONS -py3)

Then you should have the Python 3 binding installed.

Currently I have no time to test the Python 3 binding but in the future it can be added as one option to the cmake command line to enable python 3 support.

from fmm.

cweber9843 avatar cweber9843 commented on July 17, 2024

Thanks for the quick reply! And thanks for the hint, I now managed to compile to python3.8, and the fmm_test.py completes successfully. Also my first test on my own data looks promising.

I had to do some more modifications in the CMakeLists.txt:
Require right python version:
find_package(PythonLibs 3.8 REQUIRED)
And I think the target is called pyfmm, not fmm:
set_property(TARGET pyfmm PROPERTY SWIG_COMPILE_OPTIONS -py3)

from fmm.

cyang-kth avatar cyang-kth commented on July 17, 2024

@cweber9843

Thank you for correcting this problem. The current Swig built with cmake majorly copies from online resources so there exist some out of date commands and errors.
I will update the master branch when I have time.

from fmm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.