Modify

Ticket #8292 (closed Bugs: fixed)

Opened 4 years ago

Last modified 4 years ago

[multiprecision] et_on with uBLAS become bad result

Reported by: Akira Takahashi <faithandbrave@…> Owned by: johnmaddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

cpp_dec_float with et_on with uBLAS become bad result.

following example is basic vector processing with et_on:

#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

namespace mp = boost::multiprecision;
namespace ublas = boost::numeric::ublas;

using float_type = mp::number<mp::cpp_dec_float<50>>;
using vec = ublas::vector<float_type>;

vec make_vector3(float_type x, float_type y, float_type z)
{
    vec v(3);
    v[0] = x;
    v[1] = y;
    v[2] = z;
    return v;
}

vec normalize(vec v)
{
    return v / ublas::norm_2(v);
}

int main()
{
    vec p = make_vector3(0.0f, 0.0f, 0.0f); // now position
    vec q = make_vector3(3.0f, 0.0f, 6.0f); // target position

    vec v = normalize(q - p);
    std::cout << "vector : " << v << std::endl;

    float_type speed = 0.1f;
    float_type accel = 0.1f;
    for (int i = 0; i < 20; ++i) {
        p += v * speed;
        speed += accel;
    }

    std::cout << "result pos : " << p << std::endl;
}

result:

vector : [3](1,0,1)
result pos : [3](1,0,1)

this result is bad. should be:

vector : [3](0.447214,0,0.894427)
result pos : [3](9.39149,0,18.783)

following code is using et_off:

#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

namespace mp = boost::multiprecision;
namespace ublas = boost::numeric::ublas;

using float_type = mp::number<mp::cpp_dec_float<50>, mp::et_off>;
using vec = ublas::vector<float_type>;

vec make_vector3(float_type x, float_type y, float_type z)
{
    vec v(3);
    v[0] = x;
    v[1] = y;
    v[2] = z;
    return v;
}

vec normalize(vec v)
{
    return v / ublas::norm_2(v);
}

int main()
{
    vec p = make_vector3(0.0f, 0.0f, 0.0f); // now position
    vec q = make_vector3(3.0f, 0.0f, 6.0f); // target position

    vec v = normalize(q - p);
    std::cout << "vector : " << v << std::endl;

    float_type speed = 0.1f;
    float_type accel = 0.1f;
    for (int i = 0; i < 20; ++i) {
        p += v * speed;
        speed += accel;
    }

    std::cout << "result pos : " << p << std::endl;
}

result:

vector : [3](0.447214,0,0.894427)
result pos : [3](9.39149,0,18.783)

this result is correct.

And, associated issue is here: http://stackoverflow.com/questions/14948102/boost-matrix-product-for-multiprecision-numbers this is et_on's issue too.

Attachments

Change History

comment:1 Changed 4 years ago by Akira Takahashi <faithandbrave@…>

  • Owner set to johnmaddock
  • Component changed from None to multiprecision

comment:2 Changed 4 years ago by anonymous

The compiler errors you reported on stack overflow are to be expected - uBlas knows nothing about expression template number types internally and can't currently be used with them.

I'll investigate the runtime issues shortly.

comment:3 Changed 4 years ago by johnmaddock

  • Status changed from new to closed
  • Resolution set to fixed

(In [83439]) Improve uBas integration to allow use of expression templates inside uBas templates. Fixes #8292.

comment:4 Changed 4 years ago by johnmaddock

(In [83448]) Add missing file, refs #8292

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.