candidate operator for convolution?

P

PengYu.UT

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
 
K

Kai-Uwe Bux

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
 
M

Mark P

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::eek:perator*() to return a proxy object ArrayProxy
that acts as a handle to the Array and then define
Array::eek:perator*(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
 
M

Mark P

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

You could define Array::eek:perator*() to return a proxy object ArrayProxy
that acts as a handle to the Array and then define
Array::eek:perator*(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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top