Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#8292 closed Bugs (fixed)

[multiprecision] et_on with uBLAS become bad result

Reported by: Akira Takahashi <faithandbrave@…> Owned by: John Maddock
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.

Change History (4)

comment:1 by Akira Takahashi <faithandbrave@…>, 10 years ago

Component: Nonemultiprecision
Owner: set to John Maddock

comment:2 by anonymous, 10 years ago

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 by John Maddock, 10 years ago

Resolution: fixed
Status: newclosed

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

comment:4 by John Maddock, 10 years ago

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

Note: See TracTickets for help on using tickets.