How to integrate a library that uses expression templates?

后端 未结 4 1276
轻奢々
轻奢々 2021-01-01 17:44

I would like to use the Eigen matrix library as the linear algebra engine in my program. Eigen uses expression templates to implement lazy evaluation and to simplify loops a

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 18:22

    I don't understand all your question I will try to answer you most of them. In this sentence:

     UsingEigen operator + (const UsingEigen& adee)const
        {
            return UsingEigen(data_ + adee.data_);
        }
    

    You have an overload operator ( sorry I don't know if this is the correct way to write in English), for this reason you can write:

    a = b + c + d;
    

    instead of:

    a.data_ = b.data_ + c.data_ + d.data_;
    

    You won't have any problem, cost of your program will be the same. In addition you will have encapsulation and efficiency.

    On the other way if you want define your own operator you can do it like the template do it. You can find information on the web searching "overload operator" but is similar to this:

    UsingEigen operator + (const UsingEigen& adee)const
        {
            return UsingEigen(data_ + adee.data_);
        }
    

    Instead of "+" you can put the operator and do the operations you need.

    If you want to create a matrix it is simple. You only need to create a array of array or vector of vector.

    I think is something like this:

    std::vector>
    

    I am not sure but it is easy, on the other hand you can use a simple matrix on this way:

    float YourMatrix [size][size];

    I hope it could help you. I don't understand all your question if you need something more add me on google+ and I will try to help you.

    Sorry for my English, I hope you can understand all and it helps you.

提交回复
热议问题