diff --git a/wrap/Argument.cpp b/wrap/Argument.cpp index b36094f60..1077e3df6 100644 --- a/wrap/Argument.cpp +++ b/wrap/Argument.cpp @@ -130,6 +130,13 @@ void Argument::emit_cython_pyx(FileWriter& file) const { file.oss << type.pyxArgumentType() << " " << name; } +/* ************************************************************************* */ +std::string Argument::pyx_convertEigenTypeAndStorageOrder() const { + if (!type.isEigen()) + return ""; + return name + " = " + name + ".astype(float, order=\'F\', copy=False)"; +} + /* ************************************************************************* */ std::string Argument::pyx_asParam() const { string cythonType = type.pxdClassName(); @@ -142,7 +149,7 @@ std::string Argument::pyx_asParam() const { } else { cythonVar = name; } - return cythonVar; + return cythonVar; } /* ************************************************************************* */ @@ -242,6 +249,14 @@ void ArgumentList::emit_cython_pyx(FileWriter& file) const { } } +/* ************************************************************************* */ +std::string ArgumentList::pyx_convertEigenTypeAndStorageOrder(const std::string& indent) const { + string ret; + for (size_t j = 0; j < size(); ++j) + ret += indent + at(j).pyx_convertEigenTypeAndStorageOrder() + "\n"; + return ret; +} + /* ************************************************************************* */ std::string ArgumentList::pyx_asParams() const { string ret; diff --git a/wrap/Argument.h b/wrap/Argument.h index 5cc5f7322..c06e4f797 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -73,6 +73,7 @@ struct Argument { const std::vector& templateArgs) const; void emit_cython_pyx(FileWriter& file) const; std::string pyx_asParam() const; + std::string pyx_convertEigenTypeAndStorageOrder() const; friend std::ostream& operator<<(std::ostream& os, const Argument& arg) { os << (arg.is_const ? "const " : "") << arg.type << (arg.is_ptr ? "*" : "") @@ -131,6 +132,7 @@ struct ArgumentList: public std::vector { std::string pyx_asParams() const; std::string pyx_paramsList() const; std::string pyx_castParamsToPythonType() const; + std::string pyx_convertEigenTypeAndStorageOrder(const std::string& indent) const; /** * emit checking arguments to MATLAB proxy diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index 69f63519b..b2ebbce4c 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -148,6 +148,7 @@ void Constructor::emit_cython_pyx(FileWriter& pyxFile, const Class& cls) const { pyxFile.oss << " def " + cls.pyxClassName() + "_" + to_string(i) + "(self, *args, **kwargs):\n"; pyxFile.oss << pyx_resolveOverloadParams(args, true); + pyxFile.oss << argumentList(i).pyx_convertEigenTypeAndStorageOrder(" "); pyxFile.oss << " self." << cls.shared_pxd_obj_in_pyx() << " = " << cls.shared_pxd_class_in_pyx() << "(new " << cls.pxd_class_in_pyx() diff --git a/wrap/GlobalFunction.cpp b/wrap/GlobalFunction.cpp index 62a652405..ff5c32d65 100644 --- a/wrap/GlobalFunction.cpp +++ b/wrap/GlobalFunction.cpp @@ -164,6 +164,7 @@ void GlobalFunction::emit_cython_pyx_no_overload(FileWriter& file) const { file.oss << "):\n"; /// Call cython corresponding function and return + file.oss << argumentList(0).pyx_convertEigenTypeAndStorageOrder(" "); string ret = pyx_functionCall("", pxdName(), 0); if (!returnVals_[0].isVoid()) { file.oss << " cdef " << returnVals_[0].pyx_returnType() @@ -200,6 +201,7 @@ void GlobalFunction::emit_cython_pyx(FileWriter& file) const { file.oss << pyx_resolveOverloadParams(args, false, 1); // lazy: always return None even if it's a void function /// Call cython corresponding function + file.oss << argumentList(i).pyx_convertEigenTypeAndStorageOrder(" "); string ret = pyx_functionCall("", pxdName(), i); if (!returnVals_[i].isVoid()) { file.oss << " cdef " << returnVals_[i].pyx_returnType() diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 306ea986d..9670fb090 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -115,6 +115,7 @@ void Method::emit_cython_pyx_no_overload(FileWriter& file, file.oss << "):\n"; /// Call cython corresponding function and return + file.oss << argumentList(0).pyx_convertEigenTypeAndStorageOrder(" "); string caller = "self." + cls.shared_pxd_obj_in_pyx() + ".get()"; string ret = pyx_functionCall(caller, funcName, 0); if (!returnVals_[0].isVoid()) { @@ -158,6 +159,7 @@ void Method::emit_cython_pyx(FileWriter& file, const Class& cls) const { file.oss << pyx_resolveOverloadParams(args, false); // lazy: always return None even if it's a void function /// Call cython corresponding function + file.oss << argumentList(i).pyx_convertEigenTypeAndStorageOrder(" "); string caller = "self." + cls.shared_pxd_obj_in_pyx() + ".get()"; string ret = pyx_functionCall(caller, funcName, i); diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index e2a5a31ff..e60228199 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -79,6 +79,7 @@ void StaticMethod::emit_cython_pyx_no_overload(FileWriter& file, file.oss << "):\n"; /// Call cython corresponding function and return + file.oss << argumentList(0).pyx_convertEigenTypeAndStorageOrder(" "); string ret = pyx_functionCall(cls.pxd_class_in_pyx(), name_, 0); file.oss << " "; if (!returnVals_[0].isVoid()) { @@ -117,6 +118,7 @@ void StaticMethod::emit_cython_pyx(FileWriter& file, const Class& cls) const { file.oss << pyx_resolveOverloadParams(args, false); // lazy: always return None even if it's a void function /// Call cython corresponding function and return + file.oss << argumentList(i).pyx_convertEigenTypeAndStorageOrder(" "); string ret = pyx_functionCall(cls.pxd_class_in_pyx(), pxdFuncName, i); if (!returnVals_[i].isVoid()) { file.oss << " cdef " << returnVals_[i].pyx_returnType()