Just wondering if something like this would be faster....
warning it may be a bad idea. it may not run faster.Code:... for(i=0;j=0;i<M||j<n;i++;j++){ coeffs[i][j] = xpwr * ypwr; ypwr *= y; sol += C[i][j] * coeffs[i][j]; } return sol;
Just wondering if something like this would be faster....
warning it may be a bad idea. it may not run faster.Code:... for(i=0;j=0;i<M||j<n;i++;j++){ coeffs[i][j] = xpwr * ypwr; ypwr *= y; sol += C[i][j] * coeffs[i][j]; } return sol;
Please explain that for loop to me.Originally Posted by kryptkat
Quzah.
Hope is the first step on the road to disappointment.
sure. i was asking if taking the four for() loops in the previous example and combining them in to two loops using one for() statement would be any faster. it was just an example to get the point across.... the example will not work as is the actual modifications to get it to work you or the op would have to do for themself. for(var1loop1;var2loop2;compairstatment or statements;loopinc;loopinc){statements};
i know i messed up the forstatement logic but it was just an example and would not work as is. did it quik with out thinking.
also is there a proper name for the double loop for() ? messed up look to it but it is more compact.
Last edited by kryptkat; 10-22-2006 at 05:54 AM.
@Lina
It would be really useful if you could provide a main() which sets up some data, calls that function and prints the expected results.
And it would be useful to know how you calculate ACPE for a given function.
It's a lot easier to see whether an optimisation works if we have a working frame of reference to compare against.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Yes, that was definitely apparent.Originally Posted by kryptkat
Quzah.
Hope is the first step on the road to disappointment.
queston still stands .... would it be faster to use one for() with multi var?
Quote:
Originally Posted by kryptkat
did it quik with out thinking.
Yes, that was definitely apparent.
Hi,
whenever i type
i get an error tha says=Code:static val_t coeffs[M][N] = {0};
missing braces around initializer
(near initialization for `coffs[0]')
why is that?
For just the reason it says. It is saying that it would prefer full braces, but I chose not to. It does what I expect, and the warning is telling me something I am aware of, but choose to ignore.Originally Posted by Lina
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
can you show how you would do it coz i tried to do it and i didn't work
Is it an error or is it a warning? I get the warning, understand it, ignore it; the code builds, I run it.
To do the full bracing, you need to do this
for whatever dimensions M and N are. Or do the same for any M and N using {0}.Code:static val_t coeffs[M][N] = {{0,0,0},{0,0,0},{0,0,0}};
[edit]Attached my test code.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
when i tested the following, it gave me wrong results.
Code:val_t poly2d_dave(val_t C[M][N]) { static val_t coeffs[M][N] = {0}; static int init = 0; int i, j; val_t sol = 0.0; if ( init == 0 ) { val_t xpwr = 1.0; val_t ypwr = 1.0; val_t x = *x_p; val_t y = *y_p; for ( i = 0; i < M; i++ ) { ypwr = 1.0; for ( j = 0; j < N; j++ ) { coeffs[i][j] = xpwr * ypwr; ypwr *= y; } xpwr *= x; } init = 1; } for ( i = 0; i < M; i++ ) { for ( j = 0; j < N; j++ ) { sol += C[i][j] * coeffs[i][j]; } } return sol; }
> when i tested the following, it gave me wrong results.
Which is why YOU need to post a complete compilable program which we can just load and run without having to do any guessing as to what input data to pass, or what output to expect.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
If you really want help, let us all play on the same field. Show your actual code, please.
Originally Posted by SalemOriginally Posted by Dave_SinkulaOriginally Posted by Dave_Sinkula
Last edited by Dave_Sinkula; 10-22-2006 at 12:18 PM. Reason: D'oh! Pokey again. :(
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
M=83, N=97, system clock rate=3190 MHz
Error in poly2d_dave
x=1.062500 y=-0.937500 Output = 3538.000000 but should be 44581.437500
Now if only I had C, i might have a prayer at reproducing this.
Code:val_t C[M][N] = {{1.2,3.4,5.6},{7.8,9.0,-2.3},{-4.5,-6.7,-8.9}}; val_t X = 1.062500, *x_p = &X; val_t Y = -0.937500, *y_p = &Y; int main(void) { long count = 10000; test(count, BIND(poly2d_base), C); test(count, BIND(poly2d_precomp), C); test(count, BIND(poly2d_dave), C); test(count, BIND(poly2d_horner), C); return 0; } /* my output poly2d_base = -6.71054, 10000 iterations : 2.493 poly2d_precomp = -6.71054, 10000 iterations : 2.294 poly2d_dave = -6.71054, 10000 iterations : 2.042 poly2d_horner = -6.71054, 10000 iterations : 2.114 */
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*