由买买提看人间百态

topics

全部话题 - 话题: ndim
(共0页)
x*********w
发帖数: 533
1
来自主题: JobHunting版 - 求rotate image的对折算法

const int N = 5;
void Rotate(int A[N][N])
{
int nStart = 0;
int nDim = N;
while (nDim > 1)
{
for (int i = 0; i < nDim-1; i++)
{
swap(A[nStart][nStart+i], A[nStart+i][nStart+nDim-1]);
swap(A[nStart][nStart+i], A[nStart+nDim-1][nStart+nDim-1-i]);
swap(A[nStart][nStart+i], A[nStart+nDim-1-i][nStart]);
}
nStart++;
nDim -= 2;
}
}
是这个旋转算法吗
l*******d
发帖数: 101
2
来自主题: Programming版 - complexity of a recursive
网上下的一段程序。需要分析复杂度。中间的循环完全把我绕糊涂了。该怎样想呢?
谢谢回帖!
void repmat(char *dest, const char *src, int ndim, int *destdimsize,
int *dimsize, const int *dims, int *rep)
{
int d = ndim-1;
int i, chunk;
/* copy the first repetition into dest */
if(d == 0) {
chunk = dimsize[0];
memcpy(dest,src,chunk);
}
else {
/* recursively repeat each slice of src */
for(i=0;i repmat(dest + i*destdimsize[d-1], src + i*dimsize[d-1],
ndim-1, destdimsize, dimsize,
y****n
发帖数: 15
3
下面这段程序使用openmp执行一个类似图像线性插值的算法。
输入为Z(图像),X(坐标),Y(坐标),输出为F(图像)
为了避免同时写入数组F的某个元素,使用了#pragma omp atomic
我遇到的问题是,当把线程数设为1和2时,运行程序会得到不同的结果。实在想不出问
题出在什么地方。肯请大牛们帮忙看一看。
#pragma omp parallel for
for (int n = 0; n < MN; n++)
{
double y = Y[n];
double x = X[n];
int fx = (int)floor(x);
int fy = (int)floor(y);

if (fx<1 || x>nw || fy<1 || y>nh) // image index is [1...nw]
{
for (int i = 0; i < ndim; i++)
{
#pragma omp atomic
F[n+i*MN] += Z... 阅读全帖
a********r
发帖数: 92
4
来自主题: Computation版 - numeric recipe code amotry(), bug or not
in function amotry() for downhill simplex minimization,
why fac2=fac2=fac1-fac; instead of fac2=-fac;
then this may not be a reflection or extrapolation, because
ytry[j] = center * (1-fac) + p[ihi][j]*face - (1-fac)/ndim * p[ihi][j]
the first two terms is the extrapolation, what's the point for the 3rd term?
It will be incorrect in some case, reflection will not be reflection anymore.
float amotry(float **p, float y[], float psum[], int ndim,
float (*funk)(float []), int ihi, float fac)
Extrapo
s*****c
发帖数: 753
5
来自主题: Programming版 - C++ OO approach to use multi-dim array for HPC
Why not put ndim in template also?
template class array;
Too many constructor. Either use stl:vector for dimlen, or the constructor
parameter is size_t *. Same can be done for ele. You could use a stl:vector, or an array (correct size is ensured by your main program). You could also define another template class called pixel, or point, or vector:
template class pixel
{
T data[N]
...
...
}
y**b
发帖数: 10166
6
来自主题: 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) {
... 阅读全帖
g***s
发帖数: 3811
7
来自主题: Computation版 - C 语言问题
Numerical recipes in C [electronic resource] : the art of scientific computing
/ William H. Press ... [et al.].中的一个函数一开始有这样一个宏:
#define GET_PSUM \
for (j=1;j<=ndim;j++) {\
for (sum=0.0,i=1;i<=mpts;i++) sum+=p[i][j];\
psum[j]=sum;}
我的问题是这里的三个反斜杠,"\",是什么意思?
是不是那本书作者在排版的时候想说,要把这四行写在同一行中? 要是这样的话,我在edit
的界面中一行写不下怎么办?
初级问题,见笑了
L*******g
发帖数: 913
8
来自主题: Computation版 - 求助:downhill simplex minimization
我在用numerical recipe的simplex方法找最小值,程序片段如下:
int ntmp;
float p[3][2], y[3];
float getfunc(float x[])
{...}
void amoeba(float **p, float y[], int ndim, float ftol,
float (*funk)(float []), int *nfunk);
p[0][0]=p[0][1]=0.5;
p[1][0]=p[0][0]-0.2;
p[1][1]=p[0][1]-0.2;
p[2][0]=p[0][0]+0.2;
p[2][1]=p[0][1]-0.2;
amoeba(p, y, 2, 1.0e-5, getfunc, &ntmp);
现在问题是amoeba子程序里不能读入p的初值。是不是p的类型有问题?多谢指教!
(共0页)