Quantcast

Problem creating mapping from string to vector_expression

Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem creating mapping from string to vector_expression

Boost - uBLAS mailing list
Hi,
 
I have been trying to create a mapping from string to ublas::vector_expression.

template <class T>
boost::unordered_map<std::string, vector_expression <T> > c;

vector<int> v (10);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
c <int>["first"] = v;


I have been getting this error : 
error: no match for ‘operator=’ (operand types are ‘boost::unordered::unordered_map<std::__cxx11::basic_string<char>, boost::numeric::ublas::vector_expression<int>, boost::hash<std::__cxx11::basic_string<char> >, std::equal_to<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const std::__cxx11::basic_string<char>, boost::numeric::ublas::vector_expression<int> > > >::mapped_type {aka boost::numeric::ublas::vector_expression<int>}’ and ‘boost::numeric::ublas::vector<int>’)
   columns <int>["first"] = v;

Please help.

_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem creating mapping from string to vector_expression

Boost - uBLAS mailing list

It would be kind of convolved to try to cast an ublas vector to a vector expression. Will the following achieve what you want?


#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <unordered_map>
#include <string>
#include <iostream>


int main()
{
    std::unordered_map<std::string, boost::numeric::ublas::vector<int> > c;

    boost::numeric::ublas::vector<int> v (10);
    for (unsigned i = 0; i < v.size (); ++ i)
        v (i) = i;
   
    c["first"] = v;

    std::cout << c["first"] << std::endl;
    return 0;
}



On 03/30/2017 09:30 AM, SHIVAM MITTAL via ublas wrote:
vector<int> v (10);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;

_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem creating mapping from string to vector_expression

Boost - uBLAS mailing list
I want the mapping to be vector_expressions only.  Using vector_expression and not a real vector, means we can algorithmically build a data.frame from the results of other computations.

On Thu, Mar 30, 2017 at 7:31 PM, Nasos Iliopoulos via ublas <[hidden email]> wrote:

It would be kind of convolved to try to cast an ublas vector to a vector expression. Will the following achieve what you want?


#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <unordered_map>
#include <string>
#include <iostream>


int main()
{
    std::unordered_map<std::string, boost::numeric::ublas::vector<int> > c;

    boost::numeric::ublas::vector<int> v (10);
    for (unsigned i = 0; i < v.size (); ++ i)
        v (i) = i;
   
    c["first"] = v;

    std::cout << c["first"] << std::endl;
    return 0;
}



On 03/30/2017 09:30 AM, SHIVAM MITTAL via ublas wrote:
vector<int> v (10);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;

_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]


_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem creating mapping from string to vector_expression

Boost - uBLAS mailing list

I don't think what you are trying to achieve is possible. The reason is that when you try to instantiate anything of the form:

unordered_map<std::string, vector_expression <T> >

it will turn to be a  type like:

unordered_map<std::string, vector_expression < vector<container<vector<int>>> >


So "c" will only be able to deal with vector<int>.

To achieve what you want you probably need to use a variant type in your unordered_map (like std::any), or fiddle with unsafe type casts.


-Nasos


On 03/30/2017 10:21 AM, SHIVAM MITTAL via ublas wrote:
I want the mapping to be vector_expressions only.  Using vector_expression and not a real vector, means we can algorithmically build a data.frame from the results of other computations.

On Thu, Mar 30, 2017 at 7:31 PM, Nasos Iliopoulos via ublas <[hidden email]> wrote:

It would be kind of convolved to try to cast an ublas vector to a vector expression. Will the following achieve what you want?


#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <unordered_map>
#include <string>
#include <iostream>


int main()
{
    std::unordered_map<std::string, boost::numeric::ublas::vector<int> > c;

    boost::numeric::ublas::vector<int> v (10);
    for (unsigned i = 0; i < v.size (); ++ i)
        v (i) = i;
   
    c["first"] = v;

    std::cout << c["first"] << std::endl;
    return 0;
}



On 03/30/2017 09:30 AM, SHIVAM MITTAL via ublas wrote:
vector<int> v (10);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;

_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]



_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]

_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem creating mapping from string to vector_expression

Boost - uBLAS mailing list
On 2017-03-30 16:43, Nasos Iliopoulos via ublas wrote:

> I don't think what you are trying to achieve is possible. The reason
> is that when you try to instantiate anything of the form:
>
> unordered_map<std::string, vector_expression <T> >
>
> it will turn to be a  type like:
>
> unordered_map<std::string, vector_expression <
> vector<container<vector<int>>> >
>
> So "c" will only be able to deal with vector<int>.
Note that this will still fail to work even for vector<int> in the
example as the vector_expression base class itself does not represent
the vector.

Best,
Oswin
_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]
Loading...