需要帮助优化.... [英] Need help optimizing....

查看:56
本文介绍了需要帮助优化....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个例程,它计算一个多项式方程,该方程有3个变量

x,y,z为1,2,3,多项式的系数在数组中。

这个例程非常慢,我想优化它。

有什么建议吗?


简单地说pts是
typdef struct

double x;

double y;

double z;

double val;

} vect


xorder,yorder和zorder是

等式的最大多项式指数

喜欢val = fn(x,y,z)。


void EvaluatePoly(Vector< vect>& pts,int xorder,int yorder,int

zorder)

{

for(int pn = 0; pn< pts.length(); ++ pn)

{

int cn = 0;

for(int k = 0; k< = zorder; ++ k)

{

float zexp = pow(pts [pn] .z,k);

for(int j = 0; j< = yorder; ++ j)

{

float zyexp = zexp * pow(pts [pn] .y,j);

for(int i = 0;我< = xorder; ++ i)

{

pts [pn] .val = c [cn ++] * pow(pts [pn] .x,i)* zyexp;

}

}

}

}

}

解决方案

JustSomeGuy写道:

< snip>


为什么你把这个交叉发布到几个小组?大规模的交叉发布是非常糟糕的。我不知道所有团体的主题,但我非常感谢你怀疑你的问题在所有人中都是热门话题。


如果你觉得需要交叉发布到2个或3个小组,请仔细考虑是否非常关注您的消息是否在所有消息中都是热门话题。如果你感觉需要交叉发送到*超过2或3组,不要。


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。

" JustSomeGuy" <无** @ nottelling.com>在消息中写道

news:MBtbb.8974


TM4.4494@pd7tw2no ...

我有一个例程来评估a多项式方程具有3个变量x,y,z,阶数为1,2,3,多项式的系数在一个数组中。这个例程很慢,我想要优化它。有什么建议吗?
[...]




是的。 1)不要交叉发布到9个新闻组。你几乎将会收到一些愤怒的回复,这将无法帮助你解决优化问题(这是一个

元 - 下次有问题的优化提示)。

2)看看Blitz ++和/或GNU Scientific Library。

虽然我不确定是否有一个与你的

问题完全相关,他们可能是。但你的问题不是C ++ -

特定的问题(至少,不是你诬陷它的方式)。

但是,如果你尝试Blitz ++,它可能会成为一个。我的

猜测comp.programming将是

最合适的团体首先尝试。


Dave


I have a routine that evaluates a polynomial equation that have 3 variables
x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array.
This routine is quite slow and I''d like to optimize it.
Any suggestions?

simply put pts is a vector of
typdef struct
double x;
double y;
double z;
double val;
} vect

xorder, yorder and zorder are the maximum polynomial exponents for an
equation
like val = fn(x,y,z).

void EvaluatePoly(Vector<vect> & pts, int xorder, int yorder, int
zorder)
{
for (int pn=0; pn < pts.length(); ++pn)
{
int cn=0;
for (int k=0; k <= zorder; ++k)
{
float zexp = pow(pts[pn].z, k);
for (int j=0; j <= yorder; ++j)
{
float zyexp = zexp * pow(pts[pn].y, j);
for (int i=0; i <= xorder; ++i)
{
pts[pn].val = c[cn++] * pow(pts[pn].x, i) * zyexp;
}
}
}
}
}

解决方案

JustSomeGuy wrote:
<snip>

Why did you cross-post this to several groups? Massive cross-posting is
very bad. I don''t know the topics of all the groups, but I very much
doubt your question is topical in all of them.

If you feel the need to cross post to 2 or 3 groups, stop and think very
carefully about whether your message is topical in all of them. If you
feel the need to cross post to *more* than 2 or 3 groups, don''t.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


"JustSomeGuy" <no**@nottelling.com> wrote in message
news:MBtbb.8974


TM4.4494@pd7tw2no...

I have a routine that evaluates a polynomial equation that
have 3 variables x,y,z of orders 1,2,3 the coefficients of the
polynomial are in an array. This routine is quite slow and I''d
like to optimize it. Any suggestions?
[...]



Yes. 1) Don''t cross-post to 9 newsgroups. You will almost
certainly receive a number of angry responses, which will
not help you solve your optimization problem (this is a
meta-optimization tip for the next time you have a question).
2) Take a look at Blitz++ and/or the GNU Scientific Library.
While I am not sure either one is totally relevant to your
problem, they might be. But your question is not a C++-
specific question (at least, not the way you framed it).
However, if you try Blitz++, it might become one. My
guess is that comp.programming would have been the
most appropriate group to try first.

Dave


这篇关于需要帮助优化....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆