-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_numpy_array.cpp
50 lines (38 loc) · 2.13 KB
/
copy_numpy_array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <python_interpreter.hpp>
#include <vector>
#include <string>
#include <iostream>
int main()
{
const PythonInterpreter& python = PythonInterpreter::instance();
int intResult = python.import("functions")->function("produce_int").call().returnObject()->asInt();
std::cout << "int should be 9: " << intResult << std::endl;
double doubleResult = python.import("functions")->function("produce_double").call().returnObject()->asDouble();
std::cout << "double should be 8: " << doubleResult << std::endl;
bool boolResult = python.import("functions")->function("produce_bool").call().returnObject()->asBool();
std::cout << "bool should be 1: " << boolResult << std::endl;
std::string stringResult = python.import("functions")->function("produce_string").call().returnObject()->asString();
std::cout << "string should be 'Test string': " << stringResult << std::endl;
auto result = python.import("functions")->function("produce_array").call().returnObject()->as1dArray();
for(double& r: *result)
std::cout << r << ", ";
std::cout << std::endl;
result = python.import("functions")->function("produce_list").call().returnObject()->as1dArray();
for(double& r: *result)
std::cout << r << ", ";
std::cout << std::endl;
result = python.import("functions")->function("produce_tuple").call().returnObject()->as1dArray();
for(double& r: *result)
std::cout << r << ", ";
std::cout << std::endl;
python.import("functions")->function("take_int").pass(INT).call(intResult);
python.import("functions")->function("take_double").pass(DOUBLE).call(doubleResult);
python.import("functions")->function("take_bool").pass(BOOL).call(boolResult);
python.import("functions")->function("take_string").pass(STRING).call(&stringResult);
std::vector<double> array{1.2, 2.3, 3.4};
python.import("functions")->function("take_array").pass(ONEDARRAY).call(&array);
result = python.import("functions")->function("multiple_io").pass(DOUBLE).pass(INT).call(2.0, 1).returnObject()->as1dArray();
for(double& r: *result)
std::cout << r << ", ";
std::cout << std::endl;
}