Skip to content

Commit 006bd92

Browse files
author
AshleySetter
committed
succeeding in passing a numpy matrix to c++
1 parent 8b8857a commit 006bd92

9 files changed

Lines changed: 24151 additions & 0 deletions

‎KalmanFilterC/CythonExample.cpp‎

Lines changed: 2709 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎KalmanFilterC/CythonExample.pyx‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cdef extern from "cpp_test.h":
2+
cdef cppclass Test:
3+
Test()
4+
Test(int test1)
5+
int test1
6+
int returnFive()
7+
Test add "operator+"(Test other)
8+
Test sub "operator-"(Test other)
9+
10+
cdef class pyTest:
11+
cdef Test* thisptr # hold a C++ instance
12+
def __cinit__(self, int test1):
13+
self.thisptr = new Test(test1)
14+
def __dealloc__(self):
15+
del self.thisptr
16+
17+
def __add__(pyTest left, pyTest other):
18+
cdef Test t = left.thisptr.add(other.thisptr[0])
19+
cdef pyTest tt = pyTest(t.test1)
20+
return tt
21+
def __sub__(pyTest left, pyTest other):
22+
cdef Test t = left.thisptr.sub(other.thisptr[0])
23+
cdef pyTest tt = pyTest(t.test1)
24+
return tt
25+
26+
def __repr__(self):
27+
return "pyTest[%s]" % (self.thisptr.test1)
28+
29+
def returnFive(self):
30+
return self.thisptr.returnFive()
31+
32+
def printMe(self):
33+
return "hello world"

0 commit comments

Comments
 (0)