By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,902 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,902 IT Pros & Developers. It's quick & easy.

candidate operator for convolution?

P: n/a
I want to define a convolution operator for two Array objects.
Unfortunately, * operator has been used for Array class. +,-,/ are not
good candidates for convolution. Is there any other alternatives for
convolution?

Thanks,
Peng

Nov 11 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Pe*******@gmail.com wrote:
I want to define a convolution operator for two Array objects.
Unfortunately, * operator has been used for Array class. +,-,/ are not
good candidates for convolution. Is there any other alternatives for
convolution?


I would use function calls:

template < typename ComplexIterA,
typename ComplexIterB,
typename ComplexIterC >
void convolve_cyclic ( ComplexIterA const & from1,
size_type const & length,
ComplexIterB const & from2,
ComplexIterC const & where );
template < typename ComplexIterA,
typename ComplexIterB,
typename ComplexIterC >
void convolve_cyclic ( ComplexIterA const & from1,
ComplexIterA const & to1,
ComplexIterB const & from2,
ComplexIterC const & where );
There is no really convincing operator in C++ that will unambiguously denote
convolution. Thus, a function call is more explicit and therefore might
make code more easy to maintain.

Best regards

Kai-Uwe Bux

Nov 11 '05 #2

P: n/a
Pe*******@gmail.com wrote:
I want to define a convolution operator for two Array objects.
Unfortunately, * operator has been used for Array class. +,-,/ are not
good candidates for convolution. Is there any other alternatives for
convolution?

Thanks,
Peng


I'm sure there are a lot of good reasons not to do this but if you insist...

You could define Array::operator*() to return a proxy object ArrayProxy
that acts as a handle to the Array and then define
Array::operator*(const ArrayProxy&) to perform the convolution between
*this and the Array inside the proxy handle.

This lets you write, for example, array1**array2 and use the somewhat
conventional ** syntax for convolution.

But personally, aside from being mildly amusing, I don't think it's
worth the trouble and I would opt for a named function instead.

Mark
Nov 11 '05 #3

P: n/a
Mark P wrote:
Pe*******@gmail.com wrote:
I want to define a convolution operator for two Array objects.
Unfortunately, * operator has been used for Array class. +,-,/ are not
good candidates for convolution. Is there any other alternatives for
convolution?

Thanks,
Peng


I'm sure there are a lot of good reasons not to do this but if you
insist...

You could define Array::operator*() to return a proxy object ArrayProxy
that acts as a handle to the Array and then define
Array::operator*(const ArrayProxy&) to perform the convolution between
*this and the Array inside the proxy handle.

This lets you write, for example, array1**array2 and use the somewhat
conventional ** syntax for convolution.

But personally, aside from being mildly amusing, I don't think it's
worth the trouble and I would opt for a named function instead.

Mark


Just for fun, here's a little sample of this idea: (I've used ** for
exponentiation rather than convolution, but the idea is the same)

#include <iostream>
#include <cmath>
using namespace std;

struct A;

struct AProxy
{
AProxy (const A& theA) : theA(theA) {}
const A& theA;
};

struct A
{
A(double value) : value(value) {}
AProxy operator*() {return AProxy(*this);}
double operator*(const AProxy& ap) {return pow(value, ap.theA.value);}
double value;
};

int main()
{
A a1(3.7);
A a2(4.13);
cout << a1**a2 << endl;
}
Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.