zoukankan      html  css  js  c++  java
  • [Eigen] Issues when using Eigen

    1. Efficient Expression

    Refer to this post http://eigen.tuxfamily.org/dox/TopicWritingEfficientProductExpression.html, for dense matrix calculation.

    But what about sparse matrix product??

    What does Eigen do when:

    - [Enhancement, unsolved] Sparse matrix product –> Sparse m? dense matrix and vector? Does it make itself dense first?

    Is this expression fast when using SpMat? When a_, y_, lambda_*_,  is a (dense) vector, penalty_ a scalar?

    a_ = - penalty_ * (A_.transpose() * y_)
        + A_.transpose() * lambda_y_
        + Q_.transpose() * lambda_stf_;

    or this one better following the post above?

    a_ = - penalty_ * (A_.transpose() * y_);
    a_.noalias() += A_.transpose() * lambda_y_;
    a_.noalias() += Q_.transpose() * lambda_stf_;

    - [Enhancement, unsolved] Will it be faster to use sparse vector when do multiplication with sparse matrix, instead of dense one?

    - [Bugs, unsolved] When I ran the following I got bugs:

    VX dual_res_v         = -lambda_stf_.transpose() * (Q_ - Q_new);
    dual_res_v.noalias() += - penalty_ * (y_ - y_prev).transpose() * A_;
    dual_res_v.noalias() += - (lambda_y_ - lambda_y_prev).transpose() * A_;
    dual_res_v.noalias() += penalty_ * x_.transpose() * (Q_ - Q_new).transpose() * Q_;

    Where VX is dense vector in Eigen, and lambda_*_, y_* and x_* are dense vector, Q_ and A_ are sparse matrix.

    The index is compatible. The following lines work fine in my code:

    VX dual_res_v = -lambda_stf_.transpose() * (Q_ - Q_new)
        - penalty_ * (y_ - y_prev).transpose() * A_
        - (lambda_y_ - lambda_y_prev).transpose() * A_
        + penalty_ * x_.transpose() * (Q_ - Q_new).transpose() * Q_;

    But I don’t know what’s wrong with the new one.

  • 相关阅读:
    BZOJ1233 干草堆
    POJ1321棋盘问题【搜索】
    1008
    10.2训练赛
    2014 ACM/ICPC Asia Regional Shanghai Online【未完成】
    hdu5045||2014 ACM/ICPC Asia Regional Shanghai Online【数位dp】
    0926
    poj1007【求逆序数】
    hlg1287数字去重和排序II【hash】
    hlgChocolate Auction【并查集】
  • 原文地址:https://www.cnblogs.com/duckie/p/5772415.html
Copyright © 2011-2022 走看看