473,221 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

expression template and FFT

Hi,

Expression template can be used for the implementation of simple
operators without using temporaries (e.g. the ones in the book C++
Template).

I'm wondering whether expression template is useful for the
convolution operation.

For example, I have two arrays a1 and a2. To compute the convolution
between them I need to compute the FFT of both of them, which shall be
stored in two temporary arrays. These arrays then shall be multiplied
and FFT back, which also need a temporary arrays. There are totally
three temporary arrays.

It seems that expression template would not reduce the number of
temporary arrays. Are there any better way to reduce the temporaries?

Thanks,
Peng
Oct 20 '08 #1
12 2477
On Oct 19, 7:49*pm, Peng Yu <PengYu...@gmail.comwrote:
Hi,

Expression template can be used for the implementation of simple
operators without using temporaries (e.g. the ones in the book C++
Template).

I'm wondering whether expression template is useful for the
convolution operation.

For example, I have two arrays a1 and a2. To compute the convolution
between them I need to compute the FFT of both of them, which shall be
stored in two temporary arrays. These arrays then shall be multiplied
and FFT back, which also need a temporary arrays. There are totally
three temporary arrays.

It seems that expression template would not reduce the number of
temporary arrays. Are there any better way to reduce the temporaries?

Thanks,
Peng
If you want to reduce temporaries, try to read Alexandrescu's mojo
code. Expression templates are too advanced for what you need to do,
so it may not pay the time in coding it. Hope it helps,

aa
Oct 20 '08 #2
On 20 Okt., 05:53, aaragon <alejandro.ara...@gmail.comwrote:
>
If you want to reduce temporaries, try to read Alexandrescu's mojo
code. Expression templates are too advanced for what you need to do,
so it may not pay the time in coding it. Hope it helps,

aa
Hm, I didn't know the term "mojo". Just search-machined for it and
found:
- http://www.ddj.com/database/184403855
I'll have a look into this. Thanks for hint.

-- Maik
Oct 20 '08 #3
On Oct 20, 5:01*am, Maik <Beckmann.M...@googlemail.comwrote:
On 20 Okt., 05:53, aaragon <alejandro.ara...@gmail.comwrote:
If you want to reduce temporaries, try to read Alexandrescu's mojo
code. Expression templates are too advanced for what you need to do,
so it may not pay the time in coding it. Hope it helps,
aa

Hm, I didn't know the term "mojo". *Just search-machined for it and
found:
*-http://www.ddj.com/database/184403855
I'll have a look into this. Thanks for hint.

-- Maik
That is very easy to implement after you understand how it works. Good
luck,

aa
Oct 20 '08 #4
SG
On 20 Okt., 02:49, Peng Yu <PengYu...@gmail.comwrote:
I'm wondering whether expression template is useful for the
convolution operation.
Calculating the FFT and inverse FFT can be done in-place. No
temporaries needed. If you want to keep the original signals 'a1' and
'a2' you can do it with TWO temporaries:

<pseudo code>
t1 = a1; fft(t1); // copy 'a1' to 't1' and do an FFT on it
t2 = a2; fft(t2); // copy 'a2' to 't2' and do an FFT on it
t1 *= t2; // element-wise complex product
ifft(t1); // t1 will contains the (circular-)convolution result
</pseudo code>

I don't think that expression templates can help here.

Cheers,
SG
Oct 20 '08 #5
On Oct 20, 2:11 pm, aaragon <alejandro.ara...@gmail.comwrote:
On Oct 20, 5:01 am, Maik <Beckmann.M...@googlemail.comwrote:
On 20 Okt., 05:53, aaragon <alejandro.ara...@gmail.comwrote:
If you want to reduce temporaries, try to read Alexandrescu's mojo
code. Expression templates are too advanced for what you need to do,
so it may not pay the time in coding it. Hope it helps,
aa
Hm, I didn't know the term "mojo". Just search-machined for it and
found:
-http://www.ddj.com/database/184403855
I'll have a look into this. Thanks for hint.
-- Maik

That is very easy to implement after you understand how it works. Good
luck,
Hi,

It is too long to read the webpage. Can somebody explain in a brief
way what the main point is and what the major steps to use mojo?

Thanks,
Peng
Oct 21 '08 #6
Peng Yu wrote:
On Oct 20, 2:11 pm, aaragon <alejandro.ara...@gmail.comwrote:
>On Oct 20, 5:01 am, Maik <Beckmann.M...@googlemail.comwrote:
[...]
>> -http://www.ddj.com/database/184403855
I'll have a look into this. Thanks for hint.
-- Maik
That is very easy to implement after you understand how it works. Good
luck,

Hi,

It is too long to read the webpage. Can somebody explain in a brief
way what the main point is and what the major steps to use mojo?
It's main point is to avoid unnecessary copying. It does so by
"stealing" the data from temporary objects instead. This is what
rvalue references will be in C++0x.
If you want to use it to write fast code, you won't get around
reading and understanding it.
Thanks,
Peng
Schobi
Oct 21 '08 #7
On Oct 21, 3:33 am, Hendrik Schober <spamt...@gmx.dewrote:
Peng Yu wrote:
On Oct 20, 2:11 pm, aaragon <alejandro.ara...@gmail.comwrote:
On Oct 20, 5:01 am, Maik <Beckmann.M...@googlemail.comwrote:
[...]
> -http://www.ddj.com/database/184403855
I'll have a look into this. Thanks for hint.
-- Maik
That is very easy to implement after you understand how it works. Good
luck,
Hi,
It is too long to read the webpage. Can somebody explain in a brief
way what the main point is and what the major steps to usemojo?

It's main point is to avoid unnecessary copying. It does so by
"stealing" the data from temporary objects instead. This is what
rvalue references will be in C++0x.
If you want to use it to write fast code, you won't get around
reading and understanding it.
So it is still quite useful even after 5 years since it was written,
and no other technique beats it right now? Is it a widely used and
necessary technique today?

Thanks,
Peng
Oct 21 '08 #8
Peng Yu wrote:
On Oct 21, 3:33 am, Hendrik Schober <spamt...@gmx.dewrote:
>Peng Yu wrote:
>>On Oct 20, 2:11 pm, aaragon <alejandro.ara...@gmail.comwrote:
On Oct 20, 5:01 am, Maik <Beckmann.M...@googlemail.comwrote:
[...]
-http://www.ddj.com/database/184403855
I'll have a look into this. Thanks for hint.
-- Maik
That is very easy to implement after you understand how it works. Good
luck,
Hi,
It is too long to read the webpage. Can somebody explain in a brief
way what the main point is and what the major steps to usemojo?
It's main point is to avoid unnecessary copying. It does so by
"stealing" the data from temporary objects instead. This is what
rvalue references will be in C++0x.
If you want to use it to write fast code, you won't get around
reading and understanding it.

So it is still quite useful even after 5 years since it was written,
and no other technique beats it right now? Is it a widely used and
necessary technique today?
From what I read, rvalue references seem to be better, but
until you get your hands on a compiler that has them, Andrei's
code and ideas are most likely the best you can get.
Peng
Schobi
Oct 21 '08 #9
On Oct 21, 11:28 am, Hendrik Schober <spamt...@gmx.dewrote:
Peng Yu wrote:
On Oct 21, 3:33 am, Hendrik Schober <spamt...@gmx.dewrote:
Peng Yu wrote:
On Oct 20, 2:11 pm, aaragon <alejandro.ara...@gmail.comwrote:
On Oct 20, 5:01 am, Maik <Beckmann.M...@googlemail.comwrote:
[...]
-http://www.ddj.com/database/184403855
I'll have a look into this. Thanks for hint.
-- Maik
That is very easy to implement after you understand how it works. Good
luck,
Hi,
It is too long to read the webpage. Can somebody explain in a brief
way what the main point is and what the major steps to usemojo?
It's main point is to avoid unnecessary copying. It does so by
"stealing" the data from temporary objects instead. This is what
rvalue references will be in C++0x.
If you want to use it to write fast code, you won't get around
reading and understanding it.
So it is still quite useful even after 5 years since it was written,
and no other technique beats it right now? Is it a widely used and
necessary technique today?

From what I read, rvalue references seem to be better, but
until you get your hands on a compiler that has them, Andrei's
code and ideas are most likely the best you can get.
I see a proposal to add rvalue reference in the standard. Is it in the
standard now? Is there any compiler that supports it?

Thanks,
Peng
Oct 21 '08 #10
Peng Yu wrote:
>
I see a proposal to add rvalue reference in the standard. Is it in the
standard now? Is there any compiler that supports it?
Well you just said it's a proposal, didn't you? The new standard has
yet to be published.

Have a look at gcc 4.3.

--
Ian Collins
Oct 21 '08 #11
On Oct 21, 3:27*pm, Ian Collins <ian-n...@hotmail.comwrote:
Peng Yu wrote:
I see a proposal to add rvalue reference in the standard. Is it in the
standard now? Is there any compiler that supports it?

Well you just said it's a proposal, didn't you? *The new standard has
yet to be published.

Have a look at gcc 4.3.

--
Ian Collins
You should try to use Andrei's code. It's only a header file and the
implementation is really a piece of cake. I think it's gonna take a
while until compilers support this idea of rvalue references. The idea
behind the mojo code is that if you use objects that allocate memory
dynamically, you can avoid the creation of temporaries (for example
when you return an object from a function) by stealing the pointer to
the memory allocated. This is what move constructors do. This can also
be done by the RVO (Return Value Optimization), but this is up to the
compiler because it depends on how messy the function is. The mojo
code works regardless, but it won't be useful unless you allocate a
lot of memory on the heap. I used it because I coded myself Matrix and
Vector classes to do numerical computations and all elements in these
objects were allocated through an array in the heap.

I hope it helps.

aa
Oct 30 '08 #12
Peng Yu wrote:
[...]
I see a proposal to add rvalue reference in the standard. Is it in the
standard now? Is there any compiler that supports it?
I just came across this:
http://gcc.gnu.org/projects/cxx0x.html

HTH!
Peng
Schobi
Oct 30 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rex_chaos | last post by:
Hi all, As some book tells, I try the following example of expression template. template < typename LeftOpd, typename Op, typename RightOpd > struct LOP { LeftOpd lod; RightOpd rod;
3
by: Peter Rohleder | last post by:
Hi, I'm using a style-sheet where I make use of the XPATH-"following-sibling"-expression. The part which makes problems looks similar to the following code: --------------------------- ...
8
by: bartek | last post by:
Hello, I've been toying around with expression templates recently while writing a simple static lexical analyser, hence I have some questions which keep bothering me... The expression objects...
1
by: PengYu.UT | last post by:
Hi, I read Klaus Kreft & Angelika Langer's C++ Expression Templates: An Introduction to the Principles of Expression Templates at...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
6
by: Lawrence Spector | last post by:
I ran into a problem using g++. Visual Studio 2005 never complained about this, but with g++ I ran into this error. I can't figure out if I've done something wrong or if this is a compiler bug. ...
3
by: Dan Smithers | last post by:
What constitutes a constant-expression? I know that it is something that can be determined at compile time. I am trying to use template code and keep getting compiler errors "error: cannot...
2
by: madhu.srikkanth | last post by:
Hi, I came across a paper by Angelika Langer in C++ Users Journal on Expression Templates. In the article she had mentioned that the code snippet below used to calculate a dot product is an...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.