NRVec中的向量乘法 [英] Vector multiplication in NRVec

查看:148
本文介绍了NRVec中的向量乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我尝试做的是以一种

的方式将一个操作符*实现到NRVec中,我可以执行一个操作喜欢数字*矢量而不是

矢量*数字很容易。有任何想法吗?非常感谢,


Holger

Hi everybody,

what I try to do is to implement an operator* into NRVec in such a
way, that I can perform an operation like number*vector rather than
vector*number which is easy. Any ideas? Thanks a lot,

Holger

推荐答案

2007-10-25 11: 08,Holgerson写道:
On 2007-10-25 11:08, Holgerson wrote:

大家好,


我尝试做的是在NRVec中实现一个运算符*这样一种方式,我可以执行像数字*向量而不是

向量*数字这样的操作,这很容易。有任何想法吗?非常感谢,
Hi everybody,

what I try to do is to implement an operator* into NRVec in such a
way, that I can perform an operation like number*vector rather than
vector*number which is easy. Any ideas? Thanks a lot,



我不知道NRVec是什么,但我猜它来自于数字

C ++中的食谱。首先我想问一下你可以做的操作是否是
做的操作是数字向量*数字,还是向量* =数字,后者更有效

更有效,因为它没有需要创建一个新的向量。


如果确实有一个向量*数字运算符,那么应该是微不足道的

添加一个数字*向量运算符,它会看起来像这样:


NRVec算子*(双n,const NRVec& v)

{

return v * n ;

}


因为它不知道NRVec的具体细节以及它是哪个运营商

提供的这是我能做的最好的提供。快速阅读操作员 -

重载应该可以为您提供所需的所有信息

你自己。


-

Erik Wikstr ?? m

I do not know what NRVec is but I guess that it comes from Numerical
Recipes in C++. First I would like to ask whether the operation you can
do is number vector * number, or vector *= number, the latter being much
more effective since it does not need to create a new vector.

If there really is a vector * number operator it should be trivial to
add a number * vector operator, it would look something like this:

NRVec operator*(double n, const NRVec& v)
{
return v * n;
}

Since it do not know the specifics of NRVec and which operators it
provides this is the best I can offer. A quick read-up on operator-
overloading should give you all information you need to know to do it
yourself.

--
Erik Wikstr??m


10月25日下午12:13,Erik Wikstr?m< Erik-wikst。 .. @ telia.comwrote:
On Oct 25, 12:13 pm, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

2007-10-25 11:08,Holgerson写道:
On 2007-10-25 11:08, Holgerson wrote:

大家好,
Hi everybody,


我尝试做的是以一种

的方式将操作符*实现到NRVec中,我可以执行像数字*向量而不是

向量*数字这样的操作,这很容易。有任何想法吗?非常感谢,
what I try to do is to implement an operator* into NRVec in such a
way, that I can perform an operation like number*vector rather than
vector*number which is easy. Any ideas? Thanks a lot,



我不知道NRVec是什么,但我猜它来自于数字

C ++中的食谱。首先我想问一下你可以做的操作是否是
做的操作是数字向量*数字,还是向量* =数字,后者更有效

更有效,因为它没有需要创建一个新的向量。


如果确实有一个向量*数字运算符,那么应该是微不足道的

添加一个数字*向量运算符,它会看起来像这样:


NRVec算子*(双n,const NRVec& v)

{

return v * n ;


}


因为它不知道NRVec的具体情况以及它是哪个运营商

提供的这是我能提供的最好的。快速阅读操作员 -

重载应该可以为您提供所需的所有信息

你自己。


-

Erik Wikstr?m


I do not know what NRVec is but I guess that it comes from Numerical
Recipes in C++. First I would like to ask whether the operation you can
do is number vector * number, or vector *= number, the latter being much
more effective since it does not need to create a new vector.

If there really is a vector * number operator it should be trivial to
add a number * vector operator, it would look something like this:

NRVec operator*(double n, const NRVec& v)
{
return v * n;

}

Since it do not know the specifics of NRVec and which operators it
provides this is the best I can offer. A quick read-up on operator-
overloading should give you all information you need to know to do it
yourself.

--
Erik Wikstr?m



亲爱的Erik,


感谢您的帮助而你是对的,NRVec来自

数字食谱。事实证明,您的解决方案有两个参数

,operator *不允许这样做。事实上,我确实实现了一个执行vector * number的

运算符。这很好用:


声明:


NRVec算子*(const T& rhs);


和原型:


模板< class T>

NRVec< TNRVec< T :: operator *(const T& rhs)

{

NRVec< Tresult(nn);

for(int i = 0; i< nn; i ++)

{

结果[i] = v [i] * rhs;

}

返回结果;

}


然而,看起来我不够聪明,无法弄清楚

" number * vector"事情。有任何想法吗?再次感谢,


Holger

Dear Erik,

thanks for your help and you are right, "NRVec" comes from the
Numerical Recipes. It turns out that your solution has two arguments
which is not allowed for "operator*". I did in fact implemenet an
operator that performs "vector*number" and this works fine:

declaration:

NRVec operator*(const T &rhs);

and prototype:

template <class T>
NRVec<TNRVec<T:: operator*(const T &rhs)
{
NRVec<Tresult(nn);
for(int i=0;i<nn;i++)
{
result[i]=v[i]*rhs;
}
return result;
}

However it looks that I''m not smart enough to figure out the
"number*vector" thing. Any ideas? Thanks again,

Holger


Holgerson写道:
Holgerson wrote:

10月25日下午12:13,Erik Wikstr?m< Erik-wikst ... @ telia.comwrote:
On Oct 25, 12:13 pm, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

> 2007年-10-25 11:08,Holgerson写道:
>On 2007-10-25 11:08, Holgerson wrote:

大家好,
Hi everybody,


我尝试做的是以一种

的方式将一个操作符*实现到NRVec中,我可以执行像number * vector这样的操作而不是

vector * number简单。有任何想法吗?非常感谢,
what I try to do is to implement an operator* into NRVec in such a
way, that I can perform an operation like number*vector rather than
vector*number which is easy. Any ideas? Thanks a lot,


我不知道NRVec是什么,但我想它来自于C ++中的数字配方。首先,我想问一下,你可以做的操作是数字向量*数字,还是向量* =数字,后者更有效,因为它不需要创建一个新的向量。 br />
如果真的有一个向量*数字运算符,那么添加一个数字*向量运算符应该是微不足道的,它看起来像这样:

NRVec运算符* (双n,const NRVec& v)
{
返回v * n;

}

因为它不知道NRVec的具体情况和哪个运营商提供这是我能提供的最好的。快速阅读操作员 -
重载应该为您提供了自己需要知道的所有信息。

-
Erik Wikstr?m


I do not know what NRVec is but I guess that it comes from Numerical
Recipes in C++. First I would like to ask whether the operation you can
do is number vector * number, or vector *= number, the latter being much
more effective since it does not need to create a new vector.

If there really is a vector * number operator it should be trivial to
add a number * vector operator, it would look something like this:

NRVec operator*(double n, const NRVec& v)
{
return v * n;

}

Since it do not know the specifics of NRVec and which operators it
provides this is the best I can offer. A quick read-up on operator-
overloading should give you all information you need to know to do it
yourself.

--
Erik Wikstr?m



亲爱的Erik,


感谢你的帮助,你是对的,NRVec来自

数字食谱。事实证明,您的解决方案有两个参数

,operator *不允许这样做。


Dear Erik,

thanks for your help and you are right, "NRVec" comes from the
Numerical Recipes. It turns out that your solution has two arguments
which is not allowed for "operator*".



这是不正确的。 operator *可以是一个独立的功能(可能是一个朋友)。在那种形式中,它需要两个参数。

That is incorrect. operator* can be a free standing function (possibly a
friend). In that form, it takes two arguments.


我实际上实现了一个执行vector *的

运算符数"这很好用:


声明:


NRVec算子*(const T& rhs);


和原型:


模板< class T>

NRVec< TNRVec< T :: operator *(const T& rhs)

{

NRVec< Tresult(nn);

for(int i = 0; i< nn; i ++)

{

结果[i] = v [i] * rhs;

}

返回结果;

}


然而,看起来我不够聪明,无法弄清楚

" number * vector"事情。有任何想法吗?
I did in fact implemenet an
operator that performs "vector*number" and this works fine:

declaration:

NRVec operator*(const T &rhs);

and prototype:

template <class T>
NRVec<TNRVec<T:: operator*(const T &rhs)
{
NRVec<Tresult(nn);
for(int i=0;i<nn;i++)
{
result[i]=v[i]*rhs;
}
return result;
}

However it looks that I''m not smart enough to figure out the
"number*vector" thing. Any ideas?



使用一个独立运算符*,第一个参数是双参数和第二个参数

vector。


最好


Kai-Uwe Bux

Use a freestanding operator* with first argument double and second argument
vector.

Best

Kai-Uwe Bux


这篇关于NRVec中的向量乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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