hi,
I have a piece of code implementing the FFT algorithm in c++ and i
have to convert it into java. i am getting stuck trying to understand
these pointers. Anyone who has experience in java and C++, could you
please explain the code below , esp the lines a1+=nFFT2( i know it
increments the a1 variable/pointer by nFFT2 but how does this give the
methos FBFilter new elements of each array). Anyone who could
translate this to java would be a star!!!
Cormac.
nFrames = 249;
nFFT2 = 128;
nChn =25;
float* s=new float[nFrames*nFFT2]; // FFT
float* u=new float[nFrames*nChn]; // FB
// s and u have operations done on them here
a1=s;
float* a2=u;
for(int i=0;i<nFrames;i++) {
FBFilter(a1,a2);
a1+=nFFT2;
a2+=nChn;
} 12 1332
Cormac O'Donnell wrote: hi,
I have a piece of code implementing the FFT algorithm in c++ and i have to convert it into java. i am getting stuck trying to understand these pointers. Anyone who has experience in java and C++, could you please explain the code below ,
I don't know Java, but C++, so maybe I can still help.
esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer by nFFT2 but how does this give the methos FBFilter new elements of each array).
a1 starts with pointing to the first element of an array of
nFrames*nFFT2 elements. Incrementing a pointer means letting it point
to the next element, adding e.g. 10 to it means letting it point 10
elements further. So in the first iteration, the function gets a
pointer to the first element, in the second one, a pointer to the 128th
element, then to the 256th and so on. I guess that FBFilter will always
take a block of 128 elements.
Anyone who could translate this to java would be a star!!!
Cormac.
nFrames = 249; nFFT2 = 128; nChn =25;
float* s=new float[nFrames*nFFT2]; // FFT float* u=new float[nFrames*nChn]; // FB
// s and u have operations done on them here
a1=s; float* a2=u; for(int i=0;i<nFrames;i++) { FBFilter(a1,a2); a1+=nFFT2; a2+=nChn; }
--
Size (bytes): 141,067
(Download page of Microsoft DirectX 8 SDK.)
"Cormac O'Donnell" <co************@hotmail.com> wrote in message
news:26*************************@posting.google.co m... hi,
I have a piece of code implementing the FFT algorithm in c++ and i have to convert it into java. i am getting stuck trying to understand these pointers. Anyone who has experience in java and C++, could you please explain the code below , esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer by nFFT2 but how does this give the methos FBFilter new elements of each array). Anyone who could translate this to java would be a star!!!
Cormac.
nFrames = 249; nFFT2 = 128; nChn =25;
float* s=new float[nFrames*nFFT2]; // FFT float* u=new float[nFrames*nChn]; // FB
// s and u have operations done on them here
a1=s; float* a2=u; for(int i=0;i<nFrames;i++) { FBFilter(a1,a2); a1+=nFFT2; a2+=nChn; }
The way pointers are being used here is pretty pointless (pardon the pun).
Perhaps you'll find this equivalent code easier to understand.
nFrames = 249;
nFFT2 = 128;
nChn =25;
float* s=new float[nFrames*nFFT2]; // FFT
float* u=new float[nFrames*nChn]; // FB
// s and u have operations done on them here
int i1=0;
int i2=0;
for(int i=0;i<nFrames;i++) {
FBFilter(&s[i1],&u[i2]);
i1+=nFFT2;
i2+=nChn;
}
It's really that simple.
john
"Cormac O'Donnell" <co************@hotmail.com> wrote hi,
I have a piece of code implementing the FFT algorithm in c++ and i have to convert it into java. i am getting stuck trying to understand these pointers. Anyone who has experience in java and C++, could you please explain the code below , esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer by nFFT2 but how does this give the methos FBFilter new elements of each array). Anyone who could translate this to java would be a star!!!
From a practical point of view, why don't you just wrap the C++ code with a JNI
interface? That way, you don't need to put effort into translating it AND your
FFT doesn't suddenly become a S L O W Fourier Transform.
Claudio Puviani
* "Claudio Puviani" <pu*****@hotmail.com> schriebt: "Cormac O'Donnell" <co************@hotmail.com> wrote hi,
I have a piece of code implementing the FFT algorithm in c++ and i have to convert it into java. i am getting stuck trying to understand these pointers. Anyone who has experience in java and C++, could you please explain the code below , esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer by nFFT2 but how does this give the methos FBFilter new elements of each array). Anyone who could translate this to java would be a star!!!
From a practical point of view, why don't you just wrap the C++ code with a JNI interface? That way, you don't need to put effort into translating it AND your FFT doesn't suddenly become a S L O W Fourier Transform.
Your suggestion may (or may not, but probably may) have the opposite effect
of what you think.
Wrt. computational tasks Java implementations have many times outperformed
C++ implementations; whatever the causes might be it's a fact.
Otoh. JNI is well-known as introducing extreme overhead, as well as complexity,
so the end result of going that way might be something slow and incorrect...
"Cormac O'Donnell" <co************@hotmail.com> wrote in message
news:26*************************@posting.google.co m... hi,
I have a piece of code implementing the FFT algorithm in c++ and i have to convert it into java. i am getting stuck trying to understand these pointers. Anyone who has experience in java and C++, could you please explain the code below , esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer by nFFT2 but how does this give the methos FBFilter new elements of each array). Anyone who could translate this to java would be a star!!!
Cormac.
nFrames = 249; nFFT2 = 128; nChn =25;
float* s=new float[nFrames*nFFT2]; // FFT float* u=new float[nFrames*nChn]; // FB
// s and u have operations done on them here
a1=s; float* a2=u; for(int i=0;i<nFrames;i++) { FBFilter(a1,a2); a1+=nFFT2; a2+=nChn; }
Perhaps you should consider FFTW. I have never used it in Java, but I have
had very good luck with it in C++. They claim to have a Java wrapper here: http://www.fftw.org/download.html
--
Cy http://home.rochester.rr.com/cyhome/
Alf P. Steinbach wrote: * "Claudio Puviani" <pu*****@hotmail.com> schriebt:
"Cormac O'Donnell" <co************@hotmail.com> wrote
.... From a practical point of view, why don't you just wrap the C++ code with a JNI interface? That way, you don't need to put effort into translating it AND your FFT doesn't suddenly become a S L O W Fourier Transform.
Your suggestion may (or may not, but probably may) have the opposite effect of what you think.
Wrt. computational tasks Java implementations have many times outperformed C++ implementations; whatever the causes might be it's a fact.
Can you show a computational application where this is the case ? (i.e.
Java implementation has outperformed a C++ implementation ?)
BTW - I have heard that comment made many times, and I could probably
thing of a case where it may be true, but I have yet to see any evidence
where Java is faster than C++.
* Gianni Mariani <gi*******@mariani.ws> schriebt: Alf P. Steinbach wrote: * "Claudio Puviani" <pu*****@hotmail.com> schriebt:
"Cormac O'Donnell" <co************@hotmail.com> wrote ... From a practical point of view, why don't you just wrap the C++ code with a JNI interface? That way, you don't need to put effort into translating it AND your FFT doesn't suddenly become a S L O W Fourier Transform.
Your suggestion may (or may not, but probably may) have the opposite effect of what you think.
Wrt. computational tasks Java implementations have many times outperformed C++ implementations; whatever the causes might be it's a fact.
Can you show a computational application where this is the case ? (i.e. Java implementation has outperformed a C++ implementation ?)
Google is your friend. This is several years old news. Just to check it out I
did an initial Googling, just entering "Java outperforms C++ computation", and near
the top of the list came <url: http://www.javagrande.org/leapforward/cacm-ron.pdf>;
I'm sure you'll be able to find more recent results. Also check with Sun. Of
course you'll find evidence also for Java implementations being slow... ;-)
BTW - I have heard that comment made many times, and I could probably thing of a case where it may be true, but I have yet to see any evidence where Java is faster than C++.
What has language speed, a non-existent concept, to do with anything?
"Alf P. Steinbach" <al***@start.no> wrote Can you show a computational application where this is the case ? (i.e. Java implementation has outperformed a C++ implementation ?) Google is your friend. This is several years old news. Just to check it out
I did an initial Googling, just entering "Java outperforms C++ computation", and
near the top of the list came <url:
http://www.javagrande.org/leapforward/cacm-ron.pdf>; I'm sure you'll be able to find more recent results. Also check with Sun. Of course you'll find evidence also for Java implementations being slow... ;-)
Unfortunately, that article is vague to the point of being useless. It's easy
to demonstrate that a programmer who is fluent in Java but not in C++ can write
Java code that's faster than his (bad) C++ code. The only thing comparisons like
that demonstrate is the need for people to program in the language they're
familiar with.
I'll second Gianni and say that since the inception of Java, I've yet to see a
credible comparison shows a well-written Java (non-trivial) numerics program
reaching the speed of a well-written C++ (non-trivial) numerics program. I've
seen plenty of toy examples showing that a couple of nested loops performing a
banal computation can be comparable with the two languages, but anyone who
extrapolates that to real-world calculations (which I'm not insinuating that you
do) never so much as sneezed in the general direction of a numerical
application.
As to the overhead of JNI, it's rendered irrelevant if the goal is to call a
function that takes non-negligible time to execute. You wouldn't wrap the sin()
function in a JNI call, but with things like time series analysis, minimax
problems, and so on, the fraction of the time spent in the JNI overhead would be
ridiculously small. In fact, in practice, you often see these types of
calculations offloaded to a remote server because even the network chatter is
trivialized by the size of the problem.
Claudio Puviani
> I have a piece of code implementing the FFT algorithm in c++ and i have to convert it into java. i am getting stuck trying to understand these pointers. Anyone who has experience in java and C++, could you please explain the code below , esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer by nFFT2 but how does this give the methos FBFilter new elements of each array). Anyone who could translate this to java would be a star!!!
I think a Java translation is pretty straight-forward....
int nFrames = 249;
int nFFT2 = 128;
int nChn =25;
float[] s=new float[nFrames*nFFT2]; // FFT
float[] u=new float[nFrames*nChn]; // FB
// s and u have operations done on them here
int index1 = 0;
int index2 = 0;
for(int i=0;i<nFrames;i++) {
// In Java, FBFilter would take a float instead
// of a float*
FBFilter(s[index1],u[index2]);
index1 += nFFT2;
index2 += nChn;
// If the previous lines don't compile, try
// index1 = index1 + nFFT2;
// index2 = index2 + nChn;
}
Alf P. Steinbach wrote: * Gianni Mariani <gi*******@mariani.ws> schriebt:
Alf P. Steinbach wrote:
* "Claudio Puviani" <pu*****@hotmail.com> schriebt:
"Cormac O'Donnell" <co************@hotmail.com> wrote ...
From a practical point of view, why don't you just wrap the C++ code with a JNI
interface? That way, you don't need to put effort into translating it AND your FFT doesn't suddenly become a S L O W Fourier Transform.
Your suggestion may (or may not, but probably may) have the opposite effect of what you think.
Wrt. computational tasks Java implementations have many times outperformed C++ implementations; whatever the causes might be it's a fact.
Can you show a computational application where this is the case ? (i.e. Java implementation has outperformed a C++ implementation ?)
Google is your friend. This is several years old news. Just to check it out I did an initial Googling, just entering "Java outperforms C++ computation", and near the top of the list came <url: http://www.javagrande.org/leapforward/cacm-ron.pdf>; I'm sure you'll be able to find more recent results. Also check with Sun. Of course you'll find evidence also for Java implementations being slow... ;-)
Believe me, I have done that many times and I have yet to find *ANY*
ACTUAL examples of code that runs slower with a compiled language.
The article you cite is yet another example of vapour ware.
Again, I'll say that there *could* be an example, I've heard of so much
research in this are but I have yet to see an example *in-the-wild* so
to speak.
After so many years of vapourware claims, and yet not being able to see
any real advances in this area, my sceptiscism meter has pegged.
It's interesting also that the example describes working on complex
numbers. Complex numbers are supported as part of the C++ standard now
and it is significantly easier to work with compared to Java. BTW - I have heard that comment made many times, and I could probably thing of a case where it may be true, but I have yet to see any evidence where Java is faster than C++.
What has language speed, a non-existent concept, to do with anything?
I think you'll need to read everything again in the context of
"computational tasks".
"Alf P. Steinbach" <al***@start.no> wrote in message : * Gianni Mariani <gi*******@mariani.ws> schriebt:
Google is your friend. This is several years old news. Just to
check it out I did an initial Googling, just entering "Java outperforms C++
computation", and near the top of the list came <url:
http://www.javagrande.org/leapforward/cacm-ron.pdf>; I'm sure you'll be able to find more recent results. Also check
with Sun. Of course you'll find evidence also for Java implementations being
slow... ;-)
BTW - I have heard that comment made many times, and I could
probably thing of a case where it may be true, but I have yet to see any
evidence where Java is faster than C++. What has language speed, a non-existent concept, to do with
anything?
Language speed a non-existent concept? The authors of the article you
cite don't think so:
"For example, a similar comparison on a Sun UltraSPARC, shows that
Java is only 60% the speed of compiled C."
Jonathan
There will be a problem with the line FBFilter(s[index1],u[index2]);
In the C++ code you pass pointers to two locations in the respective arrays
to the function FBFilter. It seems to me that this function will do some
calculation using all 128 (=nFFT2) resp. 25 (=nChn) Values starting at the
passed location.
So the function would have to be adapted in order to take references to the
arrays as well as the current indices. The call could then look like:
FBFilter(s,index1,u,index2);
greetings
Martin
"Jorge Rivera" <jo*****@rochester.rr.com> schrieb im Newsbeitrag
news:%l*******************@twister.nyroc.rr.com... I have a piece of code implementing the FFT algorithm in c++ and i have to convert it into java. i am getting stuck trying to understand these pointers. Anyone who has experience in java and C++, could you please explain the code below , esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer by nFFT2 but how does this give the methos FBFilter new elements of each array). Anyone who could translate this to java would be a star!!!
I think a Java translation is pretty straight-forward....
int nFrames = 249; int nFFT2 = 128; int nChn =25;
float[] s=new float[nFrames*nFFT2]; // FFT float[] u=new float[nFrames*nChn]; // FB
// s and u have operations done on them here
int index1 = 0; int index2 = 0;
for(int i=0;i<nFrames;i++) { // In Java, FBFilter would take a float instead // of a float* FBFilter(s[index1],u[index2]);
index1 += nFFT2; index2 += nChn;
// If the previous lines don't compile, try // index1 = index1 + nFFT2; // index2 = index2 + nChn; } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Susan Baker |
last post by:
Hi,
I'm just reading about smart pointers..
I have some existing C code that I would like to provide wrapper classes
for. Specifically, I would like to provide wrappers for two stucts
defined...
|
by: ozbear |
last post by:
This is probably an obvious question.
I know that pointer comparisons are only defined if the two pointers
point somewhere "into" the storage allocated to the same object, or if
they are NULL,...
|
by: Mikhail Teterin |
last post by:
Hello!
I'd like to have a variable of a pointer-to-function type. The two possible
values are of type (*)(FILE *) and (*)(void *). For example:
getter = straight ? fgetc : gzgetc;
nextchar...
|
by: Lance |
last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
|
by: Alf P. Steinbach |
last post by:
Not yet perfect, but:
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip
To access the table of...
|
by: Jim Langston |
last post by:
Someone made the statement in a newsgroup that most C++ programmers use
smart pointers. His actual phrase was "most of us" but I really don't think
that most C++ programmers use smart pointers,...
|
by: Josefo |
last post by:
Hello, is someone so kind to tell me why I am getting the following
errors ?
vector_static_function.c:20: error: expected constructor, destructor,
or type conversion before '.' token...
|
by: J Caesar |
last post by:
In C you can compare two pointers, p<q, as long as they come from the
same array or the same malloc()ated block. Otherwise you can't.
What I'd like to do is write a function
int comparable(void...
|
by: Boris |
last post by:
I had a 3 hours meeting today with some fellow programmers that are partly
not convinced about using smart pointers in C++. Their main concern is a
possible performance impact. I've been explaining...
|
by: StevenChiasson |
last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller.
This is more or less, your...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |