|||
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/storage.hpp>
namespace ublas = boost::numeric::ublas;
void show_array(const ublas::unbounded_array<double>& a)
{
for(size_t i=0; i<a.size(); ++i)
std::cout << a[i] << ' ';
std::cout << '
';
}
int main()
{
ublas::compressed_matrix<double> m (10, 10, 3 * 10);
m(0, 5) = 1; // underlying array is {1, 0, 0, 0, ...}
show_array(m.value_data());
m(0, 6) = 2; // underlying array is {1, 2, 0, 0, ...}
show_array(m.value_data());
m(0, 4) = 3; // underlying array is {3, 1, 2, 0, ...}
show_array(m.value_data());
m(0, 4) = 7; // underlying array is {7, 1, 2, 0, ...}
show_array(m.value_data());
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2,sizeof 是编绎期运行的操作算子:int main () {
{
compressed_matrix<double,row_major> m (4, 4, 2*2);
cout << sizeof(m) << "
"; // prints 56
cout << m << std::endl;
}
{
matrix<double> m (4, 4);
cout << sizeof(m) << "
"; // prints 20
cout << m << std::endl;
}
return 0;
}
sizeof() is a compile time operator that only looks at
the direct size of the object and not any allocations that the object
might make at runtime. For example:3,使用标准的STL transform 算法:class SizeTest
{
public:
char* m_pData;
SizeTest()
{
m_pData = new char[1000];
}
};
int main (void)
{
SizeTest Test;
cout << sizeof(Test) << "
"; //Probably prints 4 depending on your system
return 0;
}using namespace boost::numeric::ublas;
// Create a 30 element vector of doubles
vector<double> vec(30);
// Assign 8.0 to each element.
std::fill(vec.begin(), vec.end(), 8.0);
// Perform the "Gamma" function on each element and assign the result back
// to the original element in the vector.
std::transform(vec.begin(), vec.end(), vec.begin(), boost::math::tgamma);
4, 提供了boost和lapack等数值代数软件的接口(Dowload):
下载后最新的tar.gz文件,解压到一个位置,解压后的文件里面有两个文件夹:
boost/: 头文件,把其中 numeric/bindings 文件夹 拷贝到/usr/include/boost/numeric/
(boost的通常安装目录)下, 就可以使用了
libs/: 一些测试的例子
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-7-10 15:26
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社