由买买提看人间百态

topics

全部话题 - 话题: valarray
(共0页)
h****e
发帖数: 2125
1
来自主题: Programming版 - template metaprogramming 的问题
大家都知道STL里面有个valarray,definition是
template
class valarray
{
...
}
有人说有个更efficient的definition就是
template
class valarray
{
static const unsigned int count = N;
...
}
说因为array size在compile time就知道了,所以可以使用例如
valarray a = { 1, 2, 3 };
我比较confused的是,如果程序中都是valarry这类的东东,是比
valarray a(3);要efficient。但是code如果都是象
void func(const unsigned int size)
{
valarray a;
...
}
这样的,有何efficiency可言呢?这只是一个小例子来反映我
对template metaprogramming的很
y**b
发帖数: 10166
2
来自主题: Programming版 - C++能不能加入一些Matlab的能力呢?
今天把一个三维CFD超声速模拟的Matlab code转成C++代码同其他模拟进行耦合,
发现C++在处理多维数组方面实在是繁琐,比如处理一个动态五维数组,光分配
就得这么搞:
std::valarray< std::valarray< std::valarray AL> > > > > arrayRoeFlux;
arrayRoeFlux.resize(nx);
for (std::size_t i = 0; i < arrayRoeFlux.size(); ++i) {
arrayRoeFlux[i].resize(ny);
for (std::size_t j = 0; j < arrayRoeFlux[i].size(); ++j) {
arrayRoeFlux[i][j].resize(nz);
for (std::size_t k = 0; k < arrayRoeFlux[i][j].size(); ++k) {
... 阅读全帖
p*u
发帖数: 2454
3
来自主题: Programming版 - template metaprogramming 的问题

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~he said he's got a different
implementation of valarray, which is
template class valarray.
Why doesn't std::valarray allow size parameter?
h**o
发帖数: 347
4
来自主题: Programming版 - 请问一个关于 cost of pointer的问题
想自已写一个 matrix class并用 valarray作成员变量存储数据
现在的问题是用指向valarray的指针好还是valarray直接作变量好
CS的同学给我建议说如果要频繁寻址,用指针的话开销会比较大
请问是这样吗?
我的另一个concern是直接作变量,放在stack 上面,是不是有大小上的限制?
那在设计 member variable的时候用指针又有什么好处?
新手问题啊,多谢指教
h****e
发帖数: 2125
5
来自主题: Programming版 - template metaprogramming 的问题
不好意思我的语法错了,但是我的问题是,如果array size能够
在compile time就知道,那么我们完全可以用
static std::valarray a(3) = {1, 2, 3};
为什么说valarray a = {1, 2, 3}更efficient呢??
k**f
发帖数: 372
6
来自主题: Programming版 - 请问一个关于 cost of pointer的问题
Although it is an implementation detail, the fact that size of a valarray
can be determined at runtime indicates that the underlying memory of
valarray is very likely to be allocated on heap, not on stack. So the size
of a valarry variable may not be directly related to the size of the data
inside it. So I'd say use the valarry directly. You may try to initiate a
very big valarry to see if there's any stack overflow issue. At least some
compiler will complain when it happens.
Good luck.
s****a
发帖数: 238
7
来自主题: Physics版 - 一个C++问题求助
我想算一个大的矩阵,先作一些处理,然后FFT再 处理一下,然后IFFT.
如果处理的话用valarray很方便,但fftw库只支持complex*的类型,所以要么
必须在数组和valarray之间来回转换,要么只用数组,所有的操作全部用for loop,没
有任何的优化。请问有什么比较好的解决方法?
t****t
发帖数: 6806
8
来自主题: Programming版 - template metaprogramming 的问题
first thing you need to know:
(non-type, non-template> template parameter must be either (integral)
constant, or some object with external linkage. In other words, it must be
either constant value, or has constant address, at least (string literals
are exception, they are not allowed). So it is not possible to have a
template with auto variable as parameter.
second, std::valarray does not allow size parameter.
b***y
发帖数: 2799
9
☆─────────────────────────────────────☆
yjhsjtu (xx) 于 (Wed Sep 21 10:34:36 2005) 提到:
C++ STL provides 1D dynamic array like valarray or vector. However, they can
not be applied to multidimensional arrays directly.
Anybody know whether there is a library for multidimensional array in c++(such
as that provided by MATLAB)?
Thanks!
☆─────────────────────────────────────☆
DongCunrui (LIG) 于 (Wed Sep 21 17:51:45 2005) 提到:

such
Cann't you use vector of vectors?
以下是附件内容:
t****t
发帖数: 6806
10
来自主题: Programming版 - 容器里边放指针怎么办?
首先容器里不能放auto_ptr. 一定会出问题. STL container对元素的要求是
assignable. 基于这个理由, auto_ptr和valarray都不能作为STL container的元素
其次就是ownership要注意了. 一般指针没有ownership的说法, 但你自己心里要有数,
ownership是不是这个container. 如果是, 那么在erase, pop, pop_back, dtor等地方
要记得delete. 如果不是, 那就所有的地方都没有delete.
放shared_ptr就没有问题了. shared_ptr是assignable的, 所以不用你自己管.
c**********e
发帖数: 2007
11
来自主题: Programming版 - C++ Q11: iterator
Which one of the following standard containers does NOT invalidate iterators
when elements are inserted within the existing sequence?
a) queue
b) deque
c) list
d) stack
e) valarray
s****a
发帖数: 238
12
来自主题: Programming版 - 重新编一遍 c++0x
貌似valarray变成array了,吸收了点blitz++的东西但功能还不完整
g****c
发帖数: 20
13
来自主题: Computation版 - c++为什么比c慢?
I put my c++ code below. The aim is to solve one dimensional multi-variable
PDE. I use a higher-order-time method.
I first defined a class containing three variables, then overloaded all
algorithmic operators to it and also the vector of it. You may skip some
part of the code. The essential part is the evolve function to make the
vector of my class step forward in time.
Thanks in advance for any advice.
#include
#include
#include
#include
#include
(共0页)