为什么我可以初始化一个普通的Boost矩阵像一个标量矩阵

Why can I initialize a regular Boost matrix like a scalar matrix?

本文关键字:一个 我可以 标量 初始化 为什么 Boost      更新时间:2023-10-16

为什么会这样?它不在文档中的任何地方…

#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main()
{
boost::numeric::ublas::matrix<double> twoByTwoMat(2,2,-2);
std::cout << "This is the matrix: " << twoByTwoMat << std::endl;
return 0;
}
输出:

This is the matrix: [2,2]((-2,-2),(-2,-2))

<boost/numeric/ublas/matrix.hpp>头文件中定义。

matrix (size_type size1, size_type size2, const value_type &init):
        matrix_container<self_type> (),
        size1_ (size1), size2_ (size2), data_ (layout_type::storage_size (size1, size2), init) {
    }
相关文章: