How to work with Symbolic Expression Calculation in C++ drake? - drake

I used to work with pydrake and recently I want to use drake in C++. I am not experienced with C++. I find that the symbolic expression calculation in C++ drake has some strange behaviors. For example,
in pydrake, I can have
prog = MathematicalProgram()
v = prog.NewContinuousVariables(7, 'v')
prog.AddCost((J_G.dot(v) - V_G_desired).dot(J_G.dot(v) - V_G_desired) + 0.01* v.dot(v))
which works fine. However, in C++, if I write similarly,
drake::solvers::MathematicalProgram prog;
auto v = prog.NewContinuousVariables(7, "v");
prog.AddCost((J_V_WS*v - V_WS).dot(J_V_WS*v - V_WS) + 0.01*v.dot(v));
I would get a long error message:
In file included from external/eigen/include/_usr_include_eigen3/Eigen/Core:372,
from bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/common/autodiff.h:12,
from bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/common/default_scalars.h:3,
from bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/systems/framework/leaf_system.h:14,
from ./kuka/diffIK_controller.h:3,
from kuka/diffIK_controller.cc:3:
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/GenericPacketMath.h: In instantiation of 'Packet Eigen::internal::pmul(const Packet&, const Packet&) [with Packet = drake::symbolic::Variable]':
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/util/BlasUtil.h:75:116: required from 'Scalar Eigen::internal::conj_helper<Scalar, Scalar, false, false>::pmul(const Scalar&, const Scalar&) const [with Scalar = drake::symbolic::Variable]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/functors/BinaryFunctors.h:120:66: required from 'const result_type Eigen::internal::scalar_conj_product_op<LhsScalar, RhsScalar>::operator()(const LhsScalar&, const RhsScalar&) const [with LhsScalar = drake::symbolic::Variable; RhsScalar = drake::symbolic::Variable; Eigen::internal::scalar_conj_product_op<LhsScalar, RhsScalar>::result_type = drake::symbolic::Expression]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/CoreEvaluators.h:713:74: required from 'Eigen::internal::binary_evaluator<Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>, Eigen::internal::IndexBased, Eigen::internal::IndexBased>::CoeffReturnType Eigen::internal::binary_evaluator<Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>, Eigen::internal::IndexBased, Eigen::internal::IndexBased>::coeff(Eigen::Index, Eigen::Index) const [with BinaryOp = Eigen::internal::scalar_conj_product_op<drake::symbolic::Variable, drake::symbolic::Variable>; Lhs = const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>; Rhs = const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>; typename Eigen::internal::traits<typename Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::Rhs>::Scalar = drake::symbolic::Variable; typename Eigen::internal::traits<typename Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::Lhs>::Scalar = drake::symbolic::Variable; Eigen::internal::binary_evaluator<Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>, Eigen::internal::IndexBased, Eigen::internal::IndexBased>::CoeffReturnType = const drake::symbolic::Expression; Eigen::Index = long int]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/Redux.h:381:84: required from 'Eigen::internal::redux_evaluator<_XprType>::CoeffReturnType Eigen::internal::redux_evaluator<_XprType>::coeffByOuterInner(Eigen::Index, Eigen::Index) const [with _XprType = Eigen::CwiseBinaryOp<Eigen::internal::scalar_conj_product_op<drake::symbolic::Variable, drake::symbolic::Variable>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1> >; Eigen::internal::redux_evaluator<_XprType>::CoeffReturnType = const drake::symbolic::Expression; Eigen::Index = long int]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/Redux.h:194:9: required from 'static Eigen::internal::redux_impl<Func, Derived, 0, 0>::Scalar Eigen::internal::redux_impl<Func, Derived, 0, 0>::run(const Derived&, const Func&) [with Func = Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>; Derived = Eigen::internal::redux_evaluator<Eigen::CwiseBinaryOp<Eigen::internal::scalar_conj_product_op<drake::symbolic::Variable, drake::symbolic::Variable>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1> > >; Eigen::internal::redux_impl<Func, Derived, 0, 0>::Scalar = drake::symbolic::Expression]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/Redux.h:418:56: required from 'typename Eigen::internal::traits<T>::Scalar Eigen::DenseBase<Derived>::redux(const Func&) const [with BinaryOp = Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>; Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_conj_product_op<drake::symbolic::Variable, drake::symbolic::Variable>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1> >; typename Eigen::internal::traits<T>::Scalar = drake::symbolic::Expression]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/Redux.h:453:73: required from 'typename Eigen::internal::traits<T>::Scalar Eigen::DenseBase<Derived>::sum() const [with Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_conj_product_op<drake::symbolic::Variable, drake::symbolic::Variable>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>, const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1> >; typename Eigen::internal::traits<T>::Scalar = drake::symbolic::Expression]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/Dot.h:37:52: required from 'static Eigen::internal::dot_nocheck<T, U, NeedToTranspose>::ResScalar Eigen::internal::dot_nocheck<T, U, NeedToTranspose>::run(const Eigen::MatrixBase<Derived>&, const Eigen::MatrixBase<U>&) [with T = Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>; U = Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>; bool NeedToTranspose = false; Eigen::internal::dot_nocheck<T, U, NeedToTranspose>::ResScalar = drake::symbolic::Expression]'
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/Dot.h:84:58: required from 'typename Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, typename Eigen::internal::traits<OtherDerived>::Scalar>::ReturnType Eigen::MatrixBase<Derived>::dot(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>; Derived = Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1>; typename Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, typename Eigen::internal::traits<OtherDerived>::Scalar>::ReturnType = drake::symbolic::Expression]'
kuka/diffIK_controller.cc:52:67: required from 'drake::VectorX<T> DiffIKController<T>::CalcDiffIK(drake::MatrixX<double>, drake::VectorX<double>) const [with T = double; drake::VectorX<T> = Eigen::Matrix<double, -1, 1>; drake::MatrixX<double> = Eigen::Matrix<double, -1, -1>; drake::VectorX<double> = Eigen::Matrix<double, -1, 1>]'
kuka/diffIK_controller.cc:67:16: required from here
external/eigen/include/_usr_include_eigen3/Eigen/src/Core/GenericPacketMath.h:171:37: error: could not convert 'drake::symbolic::operator*(drake::symbolic::Expression, const drake::symbolic::Expression&)(drake::symbolic::Expression((* & b)))' from 'drake::symbolic::Expression' to 'drake::symbolic::Variable'
171 | const Packet& b) { return a*b; }
| ^
| |
| drake::symbolic::Expression
Target //kuka:diffIK_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 5.876s, Critical Path: 5.72s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
I find that by simply adding a paraenthesis around 0.01*v would solve this error:
prog.AddCost((J_V_WS*v - V_WS).dot(J_V_WS*v - V_WS) + (0.01*v).dot(v));
However, use the transpose method to do the inner product would still have issues:
prog.AddCost((J_V_WS*v - V_WS).transpose()*(J_V_WS*v - V_WS) + (0.01*v).transpose()*(v));
The error info is:
kuka/diffIK_controller.cc failed: (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 319 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox
kuka/diffIK_controller.cc: In member function 'drake::VectorX<T> DiffIKController<T>::CalcDiffIK(drake::MatrixX<double>, drake::VectorX<double>) const':
kuka/diffIK_controller.cc:53:90: error: no matching function for call to 'drake::solvers::MathematicalProgram::AddCost(const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >)'
53 | prog.AddCost((J_V_WS*v - V_WS).transpose()*(J_V_WS*v - V_WS) + (0.01*v).transpose()*(v));
| ^
In file included from kuka/diffIK_controller.cc:5:
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:863:17: note: candidate: 'drake::solvers::Binding<drake::solvers::Cost> drake::solvers::MathematicalProgram::AddCost(const drake::solvers::Binding<drake::solvers::Cost>&)'
863 | Binding<Cost> AddCost(const Binding<Cost>& binding);
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:863:46: note: no known conversion for argument 1 from 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >' to 'const drake::solvers::Binding<drake::solvers::Cost>&'
863 | Binding<Cost> AddCost(const Binding<Cost>& binding);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:873:8: note: candidate: 'template<class C> auto drake::solvers::MathematicalProgram::AddCost(const std::shared_ptr<_Tp>&, const Eigen::Ref<const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1> >&)'
873 | auto AddCost(const std::shared_ptr<C>& obj,
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:873:8: note: template argument deduction/substitution failed:
kuka/diffIK_controller.cc:53:90: note: 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >' is not derived from 'const std::shared_ptr<_Tp>'
53 | prog.AddCost((J_V_WS*v - V_WS).transpose()*(J_V_WS*v - V_WS) + (0.01*v).transpose()*(v));
| ^
In file included from kuka/diffIK_controller.cc:5:
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:888:8: note: candidate: 'template<class C> auto drake::solvers::MathematicalProgram::AddCost(const std::shared_ptr<_Tp>&, const VariableRefList&)'
888 | auto AddCost(const std::shared_ptr<C>& obj, const VariableRefList& vars) {
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:888:8: note: template argument deduction/substitution failed:
kuka/diffIK_controller.cc:53:90: note: 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >' is not derived from 'const std::shared_ptr<_Tp>'
53 | prog.AddCost((J_V_WS*v - V_WS).transpose()*(J_V_WS*v - V_WS) + (0.01*v).transpose()*(v));
| ^
In file included from kuka/diffIK_controller.cc:5:
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:911:3: note: candidate: 'template<class F> std::enable_if_t<drake::solvers::internal::is_cost_functor_candidate<F>::value, drake::solvers::Binding<drake::solvers::Cost> > drake::solvers::MathematicalProgram::AddCost(F&&, const VariableRefList&)'
911 | AddCost(F&& f, const VariableRefList& vars) {
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:911:3: note: template argument deduction/substitution failed:
kuka/diffIK_controller.cc:53:90: note: candidate expects 2 arguments, 1 provided
53 | prog.AddCost((J_V_WS*v - V_WS).transpose()*(J_V_WS*v - V_WS) + (0.01*v).transpose()*(v));
| ^
In file included from kuka/diffIK_controller.cc:5:
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:925:3: note: candidate: 'template<class F> std::enable_if_t<drake::solvers::internal::is_cost_functor_candidate<F>::value, drake::solvers::Binding<drake::solvers::Cost> > drake::solvers::MathematicalProgram::AddCost(F&&, const Eigen::Ref<const Eigen::Matrix<drake::symbolic::Variable, -1, 1, 0, -1, 1> >&)'
925 | AddCost(F&& f, const Eigen::Ref<const VectorXDecisionVariable>& vars) {
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:925:3: note: template argument deduction/substitution failed:
kuka/diffIK_controller.cc:53:90: note: candidate expects 2 arguments, 1 provided
53 | prog.AddCost((J_V_WS*v - V_WS).transpose()*(J_V_WS*v - V_WS) + (0.01*v).transpose()*(v));
| ^
In file included from kuka/diffIK_controller.cc:5:
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:940:3: note: candidate: 'template<class F, class Vars> std::enable_if_t<drake::solvers::internal::assert_if_is_constraint<F>::value, drake::solvers::Binding<drake::solvers::Cost> > drake::solvers::MathematicalProgram::AddCost(F&&, Vars&&)'
940 | AddCost(F&&, Vars&&) {
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:940:3: note: template argument deduction/substitution failed:
kuka/diffIK_controller.cc:53:90: note: candidate expects 2 arguments, 1 provided
53 | prog.AddCost((J_V_WS*v - V_WS).transpose()*(J_V_WS*v - V_WS) + (0.01*v).transpose()*(v));
| ^
In file included from kuka/diffIK_controller.cc:5:
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:951:23: note: candidate: 'drake::solvers::Binding<drake::solvers::LinearCost> drake::solvers::MathematicalProgram::AddCost(const drake::solvers::Binding<drake::solvers::LinearCost>&)'
951 | Binding<LinearCost> AddCost(const Binding<LinearCost>& binding);
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:951:58: note: no known conversion for argument 1 from 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >' to 'const drake::solvers::Binding<drake::solvers::LinearCost>&'
951 | Binding<LinearCost> AddCost(const Binding<LinearCost>& binding);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:1001:26: note: candidate: 'drake::solvers::Binding<drake::solvers::QuadraticCost> drake::solvers::MathematicalProgram::AddCost(const drake::solvers::Binding<drake::solvers::QuadraticCost>&)'
1001 | Binding<QuadraticCost> AddCost(const Binding<QuadraticCost>& binding);
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:1001:64: note: no known conversion for argument 1 from 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >' to 'const drake::solvers::Binding<drake::solvers::QuadraticCost>&'
1001 | Binding<QuadraticCost> AddCost(const Binding<QuadraticCost>& binding);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:1107:23: note: candidate: 'drake::solvers::Binding<drake::solvers::L2NormCost> drake::solvers::MathematicalProgram::AddCost(const drake::solvers::Binding<drake::solvers::L2NormCost>&)'
1107 | Binding<L2NormCost> AddCost(const Binding<L2NormCost>& binding);
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:1107:58: note: no known conversion for argument 1 from 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >' to 'const drake::solvers::Binding<drake::solvers::L2NormCost>&'
1107 | Binding<L2NormCost> AddCost(const Binding<L2NormCost>& binding);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:1170:17: note: candidate: 'drake::solvers::Binding<drake::solvers::Cost> drake::solvers::MathematicalProgram::AddCost(const drake::symbolic::Expression&)'
1170 | Binding<Cost> AddCost(const symbolic::Expression& e);
| ^~~~~~~
bazel-out/k8-opt/bin/external/drake/tools/install/libdrake/_virtual_includes/drake_shared_library/drake/solvers/mathematical_program.h:1170:53: note: no known conversion for argument 1 from 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<drake::symbolic::Expression, drake::symbolic::Expression>, const Eigen::Product<Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> > >, Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<drake::symbolic::Expression, double>, const Eigen::Matrix<drake::symbolic::Expression, -1, 1, 0, -1, 1>, const Eigen::Matrix<double, -1, 1> >, 0>, const Eigen::Matrix<drake::symbolic::Expression, 1, 1, 0, 1, 1> >' to 'const drake::symbolic::Expression&'
1170 | Binding<Cost> AddCost(const symbolic::Expression& e);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Target //kuka:diffIK_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 5.757s, Critical Path: 5.61s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
What's more, I find that
prog.AddCost(v.dot(v))
would cause error while
prog.AddCost(v.transpose() * v);
would work fine.
Why would the symbolic calculations in C++ drake have above behaviors? Is there some guidance on how to do symbolic calculations with drake in C++? Thank you very much for your help.

We have two different class, symbolic::Variable and symbolic::Expression. We first create symbolic::Variable (for example using prog.NewContinuousVariables()), and then do some algebraic operation on these symbolic::Variable objects to get a symbolic::Expression.
In pydrake, we can convert symbolic::Variable to symbolic::Expression automatically. But in C++, the user has to explicitly do that conversion. I modified your code here
prog.AddCost((J_V_WS*v - V_WS).dot(J_V_WS*v - V_WS) + 0.01*v.cast<symbolic::Expression>().dot(v));
Note that I did v.cast<symbolic::Expression>().dot(v) to explicitly change v from a vector of symbolic::Variable to a vector of symbolic::Expression.
As you said, doing (0.01* v) also solves the problem, that is because when we have a double scalar multiply a symbolic::Variable, we end up with a symbolic::Expression.

Related

How to convert binary code to a number in Dart

Given an array of ones and zeroes, convert the equivalent binary value to an integer.
Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1.
Testing: [0, 0, 0, 1] ==> 1
Testing: [0, 0, 1, 0] ==> 2
Testing: [0, 1, 0, 1] ==> 5
Testing: [1, 0, 0, 1] ==> 9
Testing: [0, 0, 1, 0] ==> 2
Testing: [0, 1, 1, 0] ==> 6
Testing: [1, 1, 1, 1] ==> 15
Testing: [1, 0, 1, 1] ==> 11
With Prime numbers I solved everything code from below
int binaryArrayToNumber(List<int> arr) {
return
(arr[0] * 8) +
(arr[1] * 4) +
(arr[2] * 2) +
(arr[3] * 1);
}
How do I make this automatic for larger numbers
A traditional approach would be to iterate over the binary digits and to perform bitshifts and ORs:
int binaryArrayToNumber(List<int> digits) {
var result = 0;
for (var digit in digits) {
result <<= 1;
result |= digit;
}
return result;
}
A more concise, less error-prone (but less efficient) approach would be to convert the list of digits to a String and then parse it:
int binaryArrayToNumber(List<int> digits) =>
int.parse(digits.join(""), radix: 2);
It's good to learn the protocols for the core data types, like List.fold.
int binaryArrayToNumber(List<int> digits) =>
digits.fold(0,(prev, cur) => 2*prev + cur);

How to use pcl::transformPoint() in PCL 1.8 Compile Error, working in PCL 1.7

I'm trying to transform a Point using pcl::transformPoint(my_point, my_affine) to transform the point my_point. However when trying to compile the following code using catkin_make I get a compile error under lubuntu 18.04, ros melodic (which uses pcl 1.8.1). When trying to compile the exact same code under ubuntu 16.04 with ros kinetic (which uses pcl 1.7.2) my code example compiles and can be executed without any problem.
I don't know why the code is not working under melodic/PCL 1.8 and what I have to change.
This is the code I am trying to use:
#include <iostream>
#include <pcl/common/transforms.h>
#include <matrixHandling.h>
int main(){
pcl::PointXYZ my_point;
Eigen::Affine3d my_affine;
Matrix4d my_matrix;
my_point= pcl::PointXYZ(1,2,3);
std::cout << my_point << std::endl;
my_matrix << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0, 1;
my_affine.matrix() = my_matrix;
std::cout << my_affine.matrix()<< std::endl;
my_point = transformPoint(my_point, my_affine);
std::cout << my_point << std::endl;
return 0;
}
And I get the following compile error under ros melodic/ PCL 1.8.1:
In file included from /usr/include/eigen3/Eigen/Core:419:0,
from /usr/include/eigen3/Eigen/StdVector:14,
from /usr/include/pcl-1.8/pcl/point_cloud.h:46,
from /usr/include/pcl-1.8/pcl/common/transforms.h:42,
from /home/admin/catkin_ws/src/project/cpp/tools/transforming.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Product.h: In instantiation of ‘struct Eigen::internal::traits<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >’:
/usr/include/eigen3/Eigen/src/Core/Product.h:115:7: required from ‘class Eigen::internal::dense_product_base<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0, 3>’
/usr/include/eigen3/Eigen/src/Core/Product.h:147:7: required from ‘class Eigen::ProductImpl<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0, Eigen::Dense>’
/usr/include/eigen3/Eigen/src/Core/Product.h:71:7: required from ‘class Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>’
/usr/include/eigen3/Eigen/src/Geometry/Transform.h:1390:72: required from ‘static Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::ResultType Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::run(const TransformType&, const MatrixType&) [with TransformType = Eigen::Transform<double, 3, 2>; MatrixType = Eigen::Map<const Eigen::Matrix<float, 3, 1>, 0, Eigen::Stride<0, 0> >; Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::ResultType = Eigen::Matrix<float, 3, 1>]’
/usr/include/eigen3/Eigen/src/Geometry/Transform.h:442:80: required from ‘const typename Eigen::internal::transform_right_product_impl<Eigen::Transform<Scalar, Dim, Mode, _Options>, OtherDerived>::ResultType Eigen::Transform<Scalar, Dim, Mode, _Options>::operator*(const Eigen::EigenBase<OtherDerived>&) const [with OtherDerived = Eigen::Map<const Eigen::Matrix<float, 3, 1>, 0, Eigen::Stride<0, 0> >; _Scalar = double; int _Dim = 3; int _Mode = 2; int _Options = 0; typename Eigen::internal::transform_right_product_impl<Eigen::Transform<Scalar, Dim, Mode, _Options>, OtherDerived>::ResultType = Eigen::Matrix<float, 3, 1>]’
/usr/include/pcl-1.8/pcl/common/impl/transforms.hpp:319:37: required from ‘PointT pcl::transformPoint(const PointT&, const Eigen::Transform<Scalar, 3, 2>&) [with PointT = pcl::PointXYZ; Scalar = double]’
/home/admin/catkin_ws/src/project/cpp/tools/transforming.cpp:17:55: required from here
/usr/include/eigen3/Eigen/src/Core/Product.h:29:127: error: no type named ‘ReturnType’ in ‘struct Eigen::ScalarBinaryOpTraits<double, float, Eigen::internal::scalar_product_op<double, float> >’
typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
^~~~~~
In file included from /usr/include/eigen3/Eigen/Core:415:0,
from /usr/include/eigen3/Eigen/StdVector:14,
from /usr/include/pcl-1.8/pcl/point_cloud.h:46,
from /usr/include/pcl-1.8/pcl/common/transforms.h:42,
from /home/admin/catkin_ws/src/project/cpp/tools/transforming.cpp:2:
/usr/include/eigen3/Eigen/src/Core/DenseBase.h: In instantiation of ‘class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >’:
/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:48:34: required from ‘class Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >’
/usr/include/eigen3/Eigen/src/Core/Product.h:115:7: required from ‘class Eigen::internal::dense_product_base<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0, 3>’
/usr/include/eigen3/Eigen/src/Core/Product.h:147:7: required from ‘class Eigen::ProductImpl<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0, Eigen::Dense>’
/usr/include/eigen3/Eigen/src/Core/Product.h:71:7: required from ‘class Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>’
/usr/include/eigen3/Eigen/src/Geometry/Transform.h:1390:72: required from ‘static Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::ResultType Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::run(const TransformType&, const MatrixType&) [with TransformType = Eigen::Transform<double, 3, 2>; MatrixType = Eigen::Map<const Eigen::Matrix<float, 3, 1>, 0, Eigen::Stride<0, 0> >; Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::ResultType = Eigen::Matrix<float, 3, 1>]’
/usr/include/eigen3/Eigen/src/Geometry/Transform.h:442:80: required from ‘const typename Eigen::internal::transform_right_product_impl<Eigen::Transform<Scalar, Dim, Mode, _Options>, OtherDerived>::ResultType Eigen::Transform<Scalar, Dim, Mode, _Options>::operator*(const Eigen::EigenBase<OtherDerived>&) const [with OtherDerived = Eigen::Map<const Eigen::Matrix<float, 3, 1>, 0, Eigen::Stride<0, 0> >; _Scalar = double; int _Dim = 3; int _Mode = 2; int _Options = 0; typename Eigen::internal::transform_right_product_impl<Eigen::Transform<Scalar, Dim, Mode, _Options>, OtherDerived>::ResultType = Eigen::Matrix<float, 3, 1>]’
/usr/include/pcl-1.8/pcl/common/impl/transforms.hpp:319:37: required from ‘PointT pcl::transformPoint(const PointT&, const Eigen::Transform<Scalar, 3, 2>&) [with PointT = pcl::PointXYZ; Scalar = double]’
/home/admin/catkin_ws/src/project/cpp/tools/transforming.cpp:17:55: required from here
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:83:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::coeff’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::coeff;
^~~~~
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:84:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::coeffByOuterInner’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::coeffByOuterInner;
^~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:85:26: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::operator()’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::operator();
^
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:86:26: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::operator[]’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::operator[];
^
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:87:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::x’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::x;
^
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:88:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::y’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::y;
^
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:89:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::z’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::z;
^
/usr/include/eigen3/Eigen/src/Core/DenseBase.h:90:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}::w’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>, 0>}’
using Base::w;
^
In file included from /usr/include/eigen3/Eigen/Core:416:0,
from /usr/include/eigen3/Eigen/StdVector:14,
from /usr/include/pcl-1.8/pcl/point_cloud.h:46,
from /usr/include/pcl-1.8/pcl/common/transforms.h:42,
from /home/admin/catkin_ws/src/project/cpp/tools/transforming.cpp:2:
/usr/include/eigen3/Eigen/src/Core/MatrixBase.h: In instantiation of ‘class Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >’:
/usr/include/eigen3/Eigen/src/Core/Product.h:115:7: required from ‘class Eigen::internal::dense_product_base<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0, 3>’
/usr/include/eigen3/Eigen/src/Core/Product.h:147:7: required from ‘class Eigen::ProductImpl<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0, Eigen::Dense>’
/usr/include/eigen3/Eigen/src/Core/Product.h:71:7: required from ‘class Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0>’
/usr/include/eigen3/Eigen/src/Geometry/Transform.h:1390:72: required from ‘static Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::ResultType Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::run(const TransformType&, const MatrixType&) [with TransformType = Eigen::Transform<double, 3, 2>; MatrixType = Eigen::Map<const Eigen::Matrix<float, 3, 1>, 0, Eigen::Stride<0, 0> >; Eigen::internal::transform_right_product_impl<TransformType, MatrixType, 2, 1>::ResultType = Eigen::Matrix<float, 3, 1>]’
/usr/include/eigen3/Eigen/src/Geometry/Transform.h:442:80: required from ‘const typename Eigen::internal::transform_right_product_impl<Eigen::Transform<Scalar, Dim, Mode, _Options>, OtherDerived>::ResultType Eigen::Transform<Scalar, Dim, Mode, _Options>::operator*(const Eigen::EigenBase<OtherDerived>&) const [with OtherDerived = Eigen::Map<const Eigen::Matrix<float, 3, 1>, 0, Eigen::Stride<0, 0> >; _Scalar = double; int _Dim = 3; int _Mode = 2; int _Options = 0; typename Eigen::internal::transform_right_product_impl<Eigen::Transform<Scalar, Dim, Mode, _Options>, OtherDerived>::ResultType = Eigen::Matrix<float, 3, 1>]’
/usr/include/pcl-1.8/pcl/common/impl/transforms.hpp:319:37: required from ‘PointT pcl::transformPoint(const PointT&, const Eigen::Transform<Scalar, 3, 2>&) [with PointT = pcl::PointXYZ; Scalar = double]’
/home/admin/catkin_ws/src/project/cpp/tools/transforming.cpp:17:55: required from here
/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:75:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}::coeff’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}’
using Base::coeff;
^~~~~
/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:78:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}::eval’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}’
using Base::eval;
^~~~
/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:81:25: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}::operator*=’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}’
using Base::operator*=;
^~
/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:82:25: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}::operator/=’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 4, 4>, Eigen::Matrix<float, 4, 1>, 0> >}’
using Base::operator/=;
^~
project/cpp/CMakeFiles/transforming.dir/build.make:62: recipe for target 'project/cpp/CMakeFiles/transforming.dir/tools/transforming.cpp.o' failed
make[2]: *** [project/cpp/CMakeFiles/transforming.dir/tools/transforming.cpp.o] Error 1
CMakeFiles/Makefile2:549: recipe for target 'project/cpp/CMakeFiles/transforming.dir/all' failed
make[1]: *** [project/cpp/CMakeFiles/transforming.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j2 -l2" failed
Is your pointcloud double precision? Try Matrix4f

Error when trying to generate simple apk on Kivy Complete VM

Windows 10 x64
VirtualBox 6.1
Kivy Complete VM 0.7
I'm trying to generate a simple apk file and it always returns errors, I've tried to delete the virtual machine and create it again, thinking it was the result of some configuration done previously by me. I'm new to programming, I don't find that same mistake on the internet and I don't know how to solve it.
The code in "/home/kivy/Desktop/teste/main.py":
from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
def build(self):
return Button(text='Hello World')
MyApp().run()
The commands in "/home/kivy/Desktop/teste":
buildozer init
buildozer -v android debug
Some things that return:
[INFO]: Trying first build of pyjnius to get cython files: this is expected to fail
[INFO]: -> running python3 setup.py build_ext -v
Exception in thread background thread for pid 3232:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 1540, in wrap
fn(*args, **kwargs)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 2459, in background_thread
handle_exit_code(exit_code)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 2157, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py build_ext -v
STDOUT:
warning: [options] bootstrap class path not set in conjunction with -source 7
1 warning
running build_ext
building 'jnius' extension
creating build
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/jnius
/home/kivy/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target armv7a-linux-androideabi21 -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -target armv7a-linux-androideabi21 -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include -DANDROID -D__ANDROID_API__=21 -I/home/kivy/.buildozer/android/platform/android-ndk-r19b/sysroot/usr/include/arm-linux-androideabi -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/include/python3.8 -fPIC -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build -c jnius/jnius.c -o build/temp.linux-x86_64-3.8/jnius/jnius.o
clang: error: no such file or directory: 'jnius/jnius.c'
clang: error: no input files
error: command '/home/kivy/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang' failed with exit status 1
STDERR:
[INFO]: pyjnius first build failed (as expected)
[INFO]: Running cython where appropriate
[INFO]: Cythonize jnius/jnius.pyx
[INFO]: -> running python3 -m Cython.Build.Cythonize ./jnius/jnius.pyx
[INFO]: -> running python3 setup.py build_ext -v
working: error: command '/home/kivy/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang' failed with exit status 1 Exception in thread background thread for pid 3263:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 1540, in wrap
fn(*args, **kwargs)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 2459, in background_thread
handle_exit_code(exit_code)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 2157, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/kivy/.local/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py build_ext -v
STDOUT:
warning: [options] bootstrap class path not set in conjunction with -source 7
1 warning
running build_ext
building 'jnius' extension
/home/kivy/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target armv7a-linux-androideabi21 -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -target armv7a-linux-androideabi21 -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include -DANDROID -D__ANDROID_API__=21 -I/home/kivy/.buildozer/android/platform/android-ndk-r19b/sysroot/usr/include/arm-linux-androideabi -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/include/python3.8 -fPIC -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include -I/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build -c jnius/jnius.c -o build/temp.linux-x86_64-3.8/jnius/jnius.o
jnius/jnius.c:3738:89: warning: incompatible pointer types passing 'JNIEnv **'
(aka 'const struct JNINativeInterface_ ***') to parameter of type
'void **' [-Wincompatible-pointer-types]
...(&__pyx_v_env), NULL));
^~~~~~~~~~~~~~
jnius/jnius.c:10723:19: warning: assigning to 'jchar *' (aka 'unsigned short *')
from 'const jchar *' (aka 'const unsigned short *') discards qualifiers
[-Wincompatible-pointer-types-discards-qualifiers]
...= (__pyx_v_j_env[0])->GetStringChars(__pyx_v_j_env, __pyx_v_j_string, NULL);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jnius/jnius.c:20421:30: warning: incompatible pointer types assigning to
'jobject' (aka 'struct _jobject *') from 'jobject *' (aka
'struct _jobject **'); dereference with * [-Wincompatible-pointer-types]
(__pyx_v_jargs[0]) = ((jobject *)__pyx_v_classLoader);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*( )
jnius/jnius.c:20430:30: warning: incompatible pointer types assigning to
'jobject' (aka 'struct _jobject *') from 'jclass *' (aka
'struct _jobject **'); dereference with * [-Wincompatible-pointer-types]
(__pyx_v_jargs[1]) = __pyx_v_interfaces;
^ ~~~~~~~~~~~~~~~~~~
*
jnius/jnius.c:35645:36: warning: assigning to 'char *' from 'const char *'
discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
(__pyx_v_invoke_methods[0]).name = ((char const *)"invoke0");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~
jnius/jnius.c:35654:41: warning: assigning to 'char *' from 'const char *'
discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
...= ((char const *)"(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jnius/jnius.c:51997:258: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_env_pxi, __pyx_n_s_detach, 23, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52009:261: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(2, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__62, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_func_pxi, __pyx_n_s_cast, 4, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52021:272: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(1, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__64, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_func_pxi, __pyx_n_s_find_javaclass, 17, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52033:263: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(5, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__66, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_init, 11, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52048:273: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(2, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_instancecheck, 43, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52060:263: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(4, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__71, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_new, 113, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52072:273: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(2, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_subclasscheck, 119, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52084:273: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__75, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_get_javaclass, 148, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52096:274: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(2, 0, 21, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__77, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_resolve_class, 152, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52108:280: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__79, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_init, 1051, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52120:280: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__81, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_export_class_pxi, __pyx_n_s_init, 1057, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52140:255: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__84, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_proxy_pxi, __pyx_n_s_init, 2, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52155:256: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__87, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_proxy_pxi, __pyx_n_s_get_2, 7, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52167:256: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__89, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jnius_jnius_proxy_pxi, __pyx_n_s_call, 10, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:52232:259: error: too many arguments to function call, expected
15, have 16
...__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__96, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Enum, 1, __pyx_empty_bytes)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:57497:9: error: too many arguments to function call, expected 15,
have 16
__pyx_empty_bytes /*PyObject *lnotab*/
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
6 warnings and 16 errors generated.
error: command '/home/kivy/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang' failed with exit status 1
STDERR:
[INFO]: STDOUT (last 20 lines of 213):
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
jnius/jnius.c:57497:9: error: too many arguments to function call, expected 15,
have 16
__pyx_empty_bytes /*PyObject *lnotab*/
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jnius/jnius.c:331:82: note: expanded from macro '__Pyx_PyCode_New'
...PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
~~~~~~~~~~ ^~~~
/home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Include/code.h:122:12: note:
'PyCode_New' declared here
PyAPI_FUNC(PyCodeObject *) PyCode_New(
^
6 warnings and 16 errors generated.
error: command '/home/kivy/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang' failed with exit status 1
[INFO]: STDERR:
[INFO]: COMMAND:
cd /home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/pyjnius-python3-sdl2/armeabi-v7a__ndk_target_21/pyjnius && /home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py build_ext -v
[WARNING]: ERROR: /home/kivy/Desktop/teste/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 failed!
Thanks in advance.
EDIT: Problem solved with another VM
Had the same issue on my Ubuntu 16.04 machine. Settings:
Virtual Environment with python=3.6.3
Kivy=1.11.1
Setup buildozer from master (b566125f71edc82b53ac0249ca710ff8fd4fea54)
Installed compatible Cython=0.29.9 as mentioned here
Solved the problem by updating to the latest Cython version (0.29.16 for me):
pip install --upgrade Cython
It seems like you don't have cython or something is wrong with cython. Consider installing it with the command mentioned from alexmazurik

multiplication of two list using list -erlang

how to multiple two numbers represented in a list for example 123 * 12 = 1476
I want to do this operation using list in this example it should be like this
mul([1,2,3],[1,2]) result will be [1,4,7,6] without converting list to number by using list_to_integer function. I did this so far but its just working if the length of one of the list is equal to one
mul([],A) ->[];
mul(A,[]) ->[];
mul([H|T],B) ->
if
(length([H|T]) ==1) or (length(B)== 1)
->
[X*Y||X<-[H],Y<-B]++mul(T,B);
(length([H|T]) >1) or (length(B) > 1)
->
[X*Y||X<-[H],Y<-B]++mul(T,B)
end.
For example, so:
multi(List, N) when is_number(N) ->
element(1,
lists:foldr(
fun(X, {Sum, Index}) -> {Sum + X * N * pow10(Index), Index + 1} end,
{0, 0}, List));
multi(L1, L2) when is_list(L2) ->
List = [fun() -> multi(L1, X) end() || X <- L2],
element(1,
lists:foldr(
fun(X, {Sum, Index}) -> {Sum + X * pow10(Index), Index + 1} end,
{0, 0}, List)).
pow10(N) when N =:= 0 -> 1;
pow10(N) -> 10 * pow10(N - 1).
If a notice that foldr expressions similar , it is possible to simplify the code:
multi(List, N) when is_number(N) ->
element(1,
lists:foldr(
fun(X, {Sum, Index}) -> {Sum + X * N * pow10(Index), Index + 1} end,
{0, 0}, List));
multi(L1, L2) when is_list(L2) ->
multi([fun() -> multi(L1, X) end() || X <- L2], 1).
pow10(N) when N =:= 0 -> 1;
pow10(N) -> 10 * pow10(N - 1).
for getting list, use integer_to_list:
...
multi(L1, L2) when is_list(L2) ->
create_list(multi([fun() -> multi(L1, X) end() || X <- L2],1)).
create_list(Number)->
[X-48 || X<-integer_to_list(Number)].
...
Here is solution that doesn't use list_to_integer or integer_to_list. Algorithm is called long multiplication and is usually used when language does not support multiplication/sum of big (larger than INT.MAX) numbers. Below is basic implementation that can be optimized in various ways, but will work just fine for education purposes.
Keep in mind that Erlang supports long multiplication and long sum out of the box (as opposed to, say, C), so implementing multiplication is useless in real life applications.
sum(A, B) when is_list(A) andalso is_list(B) ->
lists:reverse(sum_impl(lists:reverse(A), lists:reverse(B), {[], 0})).
mult(A, B) when is_list(A) andalso is_list(B) ->
lists:reverse(mult_impl(lists:reverse(A), lists:reverse(B), {[], []})).
sum_impl([], [], {Res, 0}) -> Res;
sum_impl([], [], {Res, C}) -> sum_impl([C], [0], {Res, 0});
sum_impl(A, [], Acc) -> sum_impl(A, [0], Acc);
sum_impl([], B, Acc) -> sum_impl([0], B, Acc);
sum_impl([HA | TA], [HB | TB], {Res, C}) ->
sum_impl(TA, TB, {Res ++ [(HA + HB + C) rem 10], (HA + HB + C) div 10}).
mult_impl(_A, [], {Res, _C}) -> Res;
mult_impl(A, [HB | TB], {Res, C}) ->
mult_impl(A, TB, {sum_impl(Res, C ++ [X * HB || X <- A], {[], 0}), [0 | C]}).
Here's a version that allows you to specify a base (2-10):
In the shell:
167> c(my).
{ok,my}
168> Base10 = 10.
10
169> Base2 = 2.
2
170> my:list_mult([1,1], [1,1,1], Base10).
[1,2,2,1]
171> 11 * 111.
1221
172> my:list_mult([1,1], [1,1,1], Base2).
[1,0,1,0,1]
173> io:format("~.2B~n", [2#11 * 2#111]).
10101
ok
-module(my).
%%-compile(export_all).
-export([list_mult/3]).
-include_lib("eunit/include/eunit.hrl").
list_mult(List1, List2, Base) ->
Number = digits_to_int(List1, Base) * digits_to_int(List2, Base),
list_of_digits(Number, Base).
list_mult_test() ->
Base10 = 10,
?assertEqual(
list_of_digits(123 * 12, Base10),
list_mult([1,2,3], [1,2], Base10)
),
?assertEqual(
list_of_digits(2 * 5, Base10),
list_mult([2], [5], Base10)
),
?assertEqual(
list_of_digits(0 * 0, Base10),
list_mult([], [], Base10)
),
?assertEqual(
list_of_digits(0 * 23, Base10),
list_mult([], [2,3], Base10)
),
?assertEqual(
list_of_digits(30 * 4, Base10),
list_mult([0,3,0], [0,4], Base10)
),
?assertEqual(
list_of_digits(1 * 3, Base10),
list_mult([0,0,1], [0,3], Base10)
),
Base2 = 2,
?assertEqual(
list_of_digits(2#11 * 2#1000, Base2),
list_mult([1,1], [1,0,0,0], Base2)
),
?assertEqual(
list_of_digits(2#1001 * 2#10, Base2),
list_mult([1,0,0,1], [1,0], Base2)
),
%%Errors:
?assertThrow(
"illegal_number: Some elements are >= to Base",
list_mult([1,3], [1,0,0,0,0], Base2)
),
?assertThrow(
"illegal_number: Some elements are >= to Base",
list_mult([a, 3], [f,1], Base10) %%hex notation
).
%--------------
digits_to_int_test() ->
Base10 = 10,
?assertEqual(
123,
digits_to_int([1,2,3], Base10)
),
?assertEqual(
10,
digits_to_int([1,0], Base10)
),
?assertEqual(
3,
digits_to_int([3], Base10)
),
?assertEqual(
0,
digits_to_int([0], Base10)
),
?assertEqual(
0,
digits_to_int([], Base10)
),
Base2 = 2,
?assertEqual(
2#11,
digits_to_int([1,1], Base2)
),
?assertEqual(
2#1101,
digits_to_int([1,1,0,1], Base2)
),
?assertEqual(
2#11110000,
digits_to_int([1,1,1,1, 0,0,0,0], Base2)
),
?assertEqual(
2#1,
digits_to_int([1], Base2)
),
?assertEqual(
0,
digits_to_int([0], Base2)
),
?assertEqual(
0,
digits_to_int([], Base2)
),
%%Errors:
?assertThrow(
"illegal_number: Some elements are >= to Base",
digits_to_int([1,2,3], Base2)
),
?assertThrow(
"illegal_number: Some elements are >= to Base",
list_mult([a, 3], [f,1], Base10) %%hex notation
).
digits_to_int(List, Base) ->
HighestPower = length(List) - 1,
digits_to_int(List, Base, HighestPower, 0).
digits_to_int([], _, _, Sum) ->
Sum;
digits_to_int([X|Xs], Base, Power, Sum) when X<Base ->
Term = round( math:pow(Base, Power) * X ), %%round() converts float to integer.
digits_to_int(Xs, Base, Power-1, Sum+Term);
digits_to_int(_, _, _, _) ->
throw("illegal_number: Some elements are >= to Base").
%--------------
list_of_digits_test() ->
Base10 = 10,
?assertEqual(
[1,1],
list_of_digits(11, Base10)
),
?assertEqual(
[1,0,0],
list_of_digits(100, Base10)
),
?assertEqual(
[1],
list_of_digits(1, Base10)
),
?assertEqual(
[],
list_of_digits(0, Base10)
),
Base2 = 2,
?assertEqual(
[1,0,1,1],
list_of_digits(2#1011, Base2)
),
?assertEqual(
[1,1,1],
list_of_digits(2#111, Base2)
),
?assertEqual(
[1],
list_of_digits(1, Base2)
).
list_of_digits(0, _Base) ->
[];
list_of_digits(Number, Base) -> %% 193
HighestPower = get_highest_power(Number, Base),
list_of_digits(Number, Base, HighestPower, []).
list_of_digits(Number, _, 0, Digits) ->
lists:reverse([Number|Digits]);
list_of_digits(Number, Base, Power, Digits) ->
X = round(math:pow(Base, Power) ),
Digit = Number div X,
Remainder = Number rem X,
list_of_digits(Remainder, Base, Power-1, [Digit|Digits]).
%---------------
get_highest_power_test() ->
Base10 = 10,
?assertEqual(
2,
get_highest_power(199, Base10)
),
?assertEqual(
3,
get_highest_power(1999, Base10)
),
?assertEqual(
3,
get_highest_power(1000, Base10)
),
?assertEqual(
1,
get_highest_power(19, Base10)
),
?assertEqual(
0,
get_highest_power(5, Base10)
).
get_highest_power(Number, Base) ->
Power = 0,
KeepGoing = (Number div round(math:pow(Base,Power)) ) > 0,
get_highest_power(Number, Base, Power, KeepGoing).
get_highest_power(Number, Base, Power, KeepGoing) when KeepGoing =:= true ->
NewPower = Power+1,
StillKeepGoing = (Number div round(math:pow(Base, NewPower)) ) > 0,
get_highest_power(Number, Base, NewPower, StillKeepGoing);
get_highest_power(_, _, Power, KeepGoing) when KeepGoing =:= false ->
max(0, Power - 1).

Disk structuring element in opencv

I know a disk structuring element can be created in MATLAB as following:
se=strel('disk',4);
0 0 1 1 1 0 0
0 1 1 1 1 1 0
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
0 1 1 1 1 1 0
0 0 1 1 1 0 0
Is there any function or method or any other way of creating the structuring element same as above in opencv. I know we can manually create it using loops but I just want to know if some function exist for that.
The closest one (not the exact same) you can get in OpenCV is by calling getStructuringElement():
int sz = 4;
cv::Mat se = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2*sz-1, 2*sz-1));
, which gives the matrix with values
[0, 0, 0, 1, 0, 0, 0;
0, 1, 1, 1, 1, 1, 0;
1, 1, 1, 1, 1, 1, 1;
1, 1, 1, 1, 1, 1, 1;
1, 1, 1, 1, 1, 1, 1;
0, 1, 1, 1, 1, 1, 0;
0, 0, 0, 1, 0, 0, 0]
def estructurant(radius):
kernel = np.zeros((2*radius+1, 2*radius+1) ,np.uint8)
y,x = np.ogrid[-radius:radius+1, -radius:radius+1]
mask = x**2 + y**2 <= radius**2
kernel[mask] = 1
kernel[0,radius-1:kernel.shape[1]-radius+1] = 1
kernel[kernel.shape[0]-1,radius-1:kernel.shape[1]-radius+1]= 1
kernel[radius-1:kernel.shape[0]-radius+1,0] = 1
kernel[radius-1:kernel.shape[0]-radius+1,kernel.shape[1]-1] = 1
return kernel
try this
You could also use skimage.morphology.disk, which produces a symmetric result (unlike cv2.getStructuringElement):
>>> disk(4)
array([[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0]], dtype=uint8)

Resources