campreilly / UnderSeaModelingLibrary

The Under Sea Modeling Library (USML) is a collection of C++ software development modules for sonar modeling and simulation.
Other
45 stars 22 forks source link

Sequences can't be used as uBLAS vectors in some operations #66

Closed campreilly closed 9 years ago

campreilly commented 9 years ago

Because usml::types::seq_vector is missing some functionality, sequences can't be used as uBLAS vectors in some operations. Example from usml::ocean::reflect_loss_rough::reflect_loss()

We'd like to write:

    noalias(*amplitude) = exp( ( -TWO_PI / _sound_speed
            * _wave_height * abs(sin(angle)) )
            * frequencies ) ;

But this generates errors in the form

/usr/local/include/boost/numeric/ublas/vector_expression.hpp: In instantiation of ‘boost::numeric::ublas::vector_reference<const usml::types::seq_vector>’:
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:1222:   instantiated from ‘boost::numeric::ublas::vector_binary_scalar1<const double, usml::types::seq_vector, boost::numeric::ublas::scalar_multiplies<double, double> >’
/home/sreilly/Projects/usml/../usml/ocean/reflect_loss_rough.h:70:   instantiated from here
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:172: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:180: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:204: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:208: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:214: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:234: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’
/usr/local/include/boost/numeric/ublas/vector_expression.hpp:238: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’

So, instead we write:

    noalias(*amplitude) = frequencies ; // copy sequence into vector
    noalias(*amplitude) = exp( ( -TWO_PI / _sound_speed
            * _wave_height * abs(sin(angle)) )
            * (*amplitude) ) ;
Tibonium commented 9 years ago

Should seq_vector be extended to have a non-const iterator calls? Making a seq_vector a true vector class of ublas

On Nov 29, 2014 11:05 AM, Sean Reilly notifications@github.com wrote:

Because usml::types::seq_vector is missing some functionality, sequences can't be used as uBLAS vectors in some operations. Example from usml::ocean::reflect_loss_rough::reflect_loss()

We'd like to write:

noalias(*amplitude) = exp( ( -TWO_PI / _sound_speed
        * _wave_height * abs(sin(angle)) )
        * frequencies ) ;

But this generates errors in the form

/usr/local/include/boost/numeric/ublas/vector_expression.hpp: In instantiation of ‘boost::numeric::ublas::vector_reference’: /usr/local/include/boost/numeric/ublas/vector_expression.hpp:1222: instantiated from ‘boost::numeric::ublas::vector_binary_scalar1<const double, usml::types::seq_vector, boost::numeric::ublas::scalar_multiplies<double, double> >’ /home/sreilly/Projects/usml/../usml/ocean/reflect_loss_rough.h:70: instantiated from here /usr/local/include/boost/numeric/ublas/vector_expression.hpp:172: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’ /usr/local/include/boost/numeric/ublas/vector_expression.hpp:180: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’ /usr/local/include/boost/numeric/ublas/vector_expression.hpp:204: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’ /usr/local/include/boost/numeric/ublas/vector_expression.hpp:208: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’ /usr/local/include/boost/numeric/ublas/vector_expression.hpp:214: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’ /usr/local/include/boost/numeric/ublas/vector_expression.hpp:234: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’ /usr/local/include/boost/numeric/ublas/vector_expression.hpp:238: error: no type named ‘iterator’ in ‘const class usml::types::seq_vector’

So, instead we write:

noalias(*amplitude) = frequencies ; // copy sequence into vector
noalias(*amplitude) = exp( ( -TWO_PI / _sound_speed
        * _wave_height * abs(sin(angle)) )
        * (*amplitude) ) ;

— Reply to this email directly or view it on GitHubhttps://github.com/campreilly/UnderSeaModelingLibrary/issues/66.

The information contained in this message, and any attachments, may contain privileged and/or proprietary information that is intended solely for the person or entity to which it is addressed. Moreover, it may contain export restricted technical data controlled by Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR). Any review, retransmission, dissemination, or re-export to foreign or domestic entities by anyone other than the intended recipient in accordance with EAR and/or ITAR regulations is prohibited.

campreilly commented 9 years ago

No. I'd like to find a way to fix this while maintaining the read-only nature of sequences.

Tibonium commented 9 years ago

I do not believe this is possible to solve with the current implementation of seq_vector, based on

"\brief A zero vector of type \c T and a given \c size A zero vector of type \c T and a given \c size. This is a virtual vector in the sense that no memory is allocated for storing the zero values: it still acts like any other vector. However assigning values to it will not change the zero vector into a normal vector. It must first be assigned to another normal vector by any suitable means. Its memory footprint is constant."

Which is the basis for the seq_vector class, "This design uses zero_vector as a model of how to implement a read-only uBLAS vector." As such all sequences are NOT vector_expression/vectors and therefore do not have the iterator defined. Even after adding a typedef iterator does not produce the expected results. I believe that the inheritance and formulation of sequence classes prevent the boost from treating it as a vector in compound statements.

The only workaround that currently exists outside of first assigning, is to create a temporary vector live such as:

noalias(amplitude) = exp( ( -TWO_PI / _sound_speed * _wave_height * abs(sin(angle)) ) \ vector(frequencies.data()) ) ;

campreilly commented 9 years ago

In this case, we aren't actually trying to assign any values to the frequencies vector. I wonder why is doesn't work. Weird. Does using a zero vector in place of the frequencies vector compile?

Tibonium commented 9 years ago

I have figured out how to do it, however, it does require that the seq_vector class be rewritten. I am trying to find a way to adapt it to be usable in usml with minimal changes, if plausible. My prototype sequence class does follow the protected data design as desired with all seq_vectors.