Types error: invalid operands to binary expression ('double' and 'state_type')

Open
#38 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
backend

Research direction

Reproduce the provided C++ example and inspect boost/numeric/odeint/algebra/default_operations.hpp around line 443, especially the controlled-step error expression. Trace the types of m_eps_abs, m_eps_rel, and get_unit_value(...) to determine whether the formula supports vector_space_algebra. Done means the example no longer requires scalar-plus-state_type solely to satisfy the error estimate, with the behavior verified.

Written by the indexing model from the issue text.

Description

I defined new state type as

struct state_type { double x; };

and vector space operators

state_type operator * (const state_type &a, double k) { return {a.x * k}; }
state_type operator * (double k, const state_type &a) { return {a.x * k}; }
state_type operator + (const state_type &a, const state_type &b) { return {a.x + b.x}; }
state_type operator - (const state_type &a, const state_type &b) { return {a.x - b.x}; }
state_type operator / (const state_type &a, const state_type &b) { return {a.x / b.x}; }
state_type abs(state_type const& v) { return {fabs(v.x)}; }

The main function is

int main()
{
    state_type x0 {1.};
    double t0 = 0, t1 = 1, dt = 1e-3;
    using Stepper = runge_kutta_dopri5<state_type, double, state_type, double, vector_space_algebra>;
    auto f = [](state_type const& x, state_type& dx, double t) {
        dx = x;
    };
    integrate_adaptive(make_controlled<Stepper>(1e-10, 1e-10), f, x0, t0, t1, dt);
}

During compilation I am getting the error

/usr/include/boost/numeric/odeint/algebra/default_operations.hpp:443:76: error: invalid operands to binary expression ('double' and 'state_type')
[build] set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( t1 ) ) + m_a_dxdt * abs( get_unit_value( t2 ) ) ) ) );

If I add the requested operator

state_type operator + (double k, const state_type &a) { return {a.x + k}; }

the compilation works well. It seems that the formula

set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( t1 ) ) + m_a_dxdt * abs( get_unit_value( t2 ) ) ) ) );

is wrong, or type of m_eps_abs is wrong. In a vector space there must not be operator + between elements of state_type and and coefficients. Moreover the operator / between state_type elements is questionable.

Dominant language
C++
Stars
55
Forks
59
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/odeint

All issues in boostorg/odeint

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.