uBLAS——Boost 线性代数基础程序库 (三)

uBLAS——Boost 线性代数基础程序库
uBLAS——Boost 线性代数基础程序库 (二)

namespace ublas = boost::numeric::ublas;

row() vs matrix_row<> ,column() vs matrix_column<>

  • (0)功能

    • row(A, m)、column(A, n) 用于索引矩阵的某一行,某一列
    • matrix_row<>、matrix_column<> 根据矩阵的某一行,某一列创建行向量、列向量
  • (1)头文件

    
    #include <boost\numeric\ublas\matrix_proxy.hpp>
    
  • (2)意义和用法

    • (1)row()、column()是函数,接受矩阵,一个行索引/列索引;
    • (2)matrix_row<>,matrix_column<>,是模板类,用于列定义
    • (3)不需要给 row()、column() 指定参数类型,因为函数具有自动类型推导的功能;
  • (3)row()、column() 的实现用到了 matrix_row<>、matrix_column<>

    matrix_column<M> column (M &data, typename M::size_type j) {
        return matrix_column<M> (data, j);
    }

因为函数的自动类型推导,为了避免类型不匹配,推荐使用 row()、column。

矩阵乘法与矩阵向量乘法

使用同一个全局函数:ublas::axpy_prod(),其所在的头文件为

#include <boost\numeric\ublas\operation.hpp>
  • (1)矩阵向量乘法、

    • v=Ax (默认或 init=true)
    • v+=Ax (init=false)
      BOOST_UBLAS_INLINE V& axpy_prod (const matrix_expression< E1 > & A,
              const vector_expression< E2 > & x,
              V & v,
              bool init = true
          )   
  • (2)向量矩阵乘法

    • v=ATx (默认或init=true)
    • v+=ATx (init=false)
      BOOST_UBLAS_INLINE V& axpy_prod( const vector_expression< E1 > &    e1,
              const matrix_expression< E2 > &     e2,
              V &     v,
              bool    init = true
          );      
  • (3)矩阵矩阵乘法

    • M=AX (默认或init=true)
    • M+=AX (init=false)
      BOOST_UBLAS_INLINE M& axpy_prod (const matrix_expression< E1 > &  e1,
              const matrix_expression< E2 > &     e2,
              M &     m,
              bool    init = true
          )   

将 init = true 或者取默认值,其实是执行 M.clear();

References

[1] Special Products

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五道口纳什

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值