From 217d0af4fdc545b17a4af851f51d70153533edbd Mon Sep 17 00:00:00 2001 From: SatoshiTerasaki Date: Fri, 14 Jun 2024 23:38:01 +0900 Subject: [PATCH] fix cxxwrap4 --- cxxwrap4/deps/src/hello.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cxxwrap4/deps/src/hello.cpp b/cxxwrap4/deps/src/hello.cpp index d3cd9b0..8e35c1a 100644 --- a/cxxwrap4/deps/src/hello.cpp +++ b/cxxwrap4/deps/src/hello.cpp @@ -2,14 +2,26 @@ #include "jlcxx/jlcxx.hpp" #include "jlcxx/stl.hpp" #include -#include +#include + +auto print_address(jlcxx::ArrayRef jlx) { + std::cout << jlx.data() << std::endl; + static jlcxx::ArrayRef y = jlcxx::make_julia_array(jlx.data(), jlx.size()); + auto x = jlcxx::make_julia_array(jlx.data(), jlx.size()); + std::cout << x.data() << std::endl; + // do something with x and pass results to y + for (size_t i = 0; i < jlx.size(); i++) { + y[i] = 2*x[i]; + } + std::cout << y.data() << std::endl; + return y; +} auto twice(jlcxx::ArrayRef jlx) { static Eigen::VectorXd y; - auto x = Eigen::Map(&jlx[0], jlx.size()); + auto x = Eigen::Map(jlx.data(), jlx.size()); // do something with x and pass results to y y = 2 * x; - return jlcxx::make_julia_array(y.data(), y.size()); } @@ -21,14 +33,14 @@ void inplace_twice(jlcxx::ArrayRef jlx) { auto triple(jlcxx::ArrayRef v) { static Eigen::VectorXd y; - auto x = Eigen::Map(&v[0], v.size()); + auto x = Eigen::Map(v.data(), v.size()); // Do something y = 2 * x + x; return jlcxx::make_julia_array(y.data(), y.size()); } auto inplace_triple(jlcxx::ArrayRef jlx) { - auto x = Eigen::Map(&jlx[0], jlx.size()); + auto x = Eigen::Map(jlx.data(), jlx.size()); x = 3 * x; for (size_t i = 0; i < jlx.size(); i++) { jlx[i] = x[i]; @@ -36,6 +48,7 @@ auto inplace_triple(jlcxx::ArrayRef jlx) { } JLCXX_MODULE define_julia_module(jlcxx::Module &mod) { + mod.method("print_address", &print_address); mod.method("twice", &twice); mod.method("twice!", &inplace_twice);