i agree this is mysterious. the "size" message is a mistake just in the fprintf line, so it can be ignored. we're looking at the rest of the problem... dt On Aug 22, 2007, at 1:24 PM, eduard wrote:
The following patch shows either a misbehaviour or a misuse of CurveTable, dunno. Two different functions (rand_coefs1 and rand_coefs2) are used to assign coefficients to CurveTable.coefs(). While the first seems to do the job alright, the latter doesn't and throws the following error message: [chuck](via CurveTable): usage: size, time1, value1, curvature1, [ timeN-1, valueN-1, curvatureN-1, ] timeN, valueN)
Maybe I'm doing something wrong that | don't see, but can't understand why this happens. Could anyone explain? Also, don't understand why the error message tells me the size needs to be supplied. The examples say that coefs are arrays of the type [time1, value1, curvature1, ..., timeN-1, valueN-1, curvatureN-1, timeN, valueN] and Gen's size, if I'm not mistaken, is hard coded as 4096.
Thanks in advance,
eduard
The patch:
fun void rand_coefs1( CurveTable table ) { [-1, 0, 1 ] @=> int curvature[]; [0., 0., curvature[ Std.rand2(0, 2)], 1, Std.rand2f(.5,1.), curvature[ Std.rand2(0, 2)], 2, Std.rand2f(.5,1.), curvature[ Std.rand2(0, 2)], 3, Std.rand2f(0.,1.), curvature[ Std.rand2(0, 2)], 4, Std.rand2f(0.,1.), curvature[ Std.rand2(0, 2)], 5, Std.rand2f(0.,1.), curvature[ Std.rand2(0, 2)], 6, Std.rand2f(0.,1.), curvature[ Std.rand2(0, 2)], 7, Std.rand2f(0.,1.), curvature[ Std.rand2(0, 2)], 8, Std.rand2f(0.,1.), curvature[ Std.rand2(0, 2)], 9, 0] @=> float coefs[]; coefs => table.coefs;
<<<"\n", "CURVE 1:\n" >>>; <<<"\t index", " value", " curvature">>>; <<<"\t----------------------------------","\t">>>; for( 0 => int i; i < 8; i++ ) <<<"\t",coefs[i++], coefs[i++], coefs[i]>>>; <<<"\t", coefs[8], coefs[9] >>>; <<<"\t----------------------------------","\t">>>; }
fun void rand_coefs2( CurveTable table, int n_breakpoints ) { // this function does not assign values stored in coefs correctly to // CurveTable.coefs(). Why? It also throws an error message.
[-1, 0, 1 ] @=> int curvature[]; n_breakpoints*3 - 1 => n_breakpoints; float coefs[ n_breakpoints]; 0. => coefs[0]; 0. => coefs[1]; for( 2 => int i; i < n_breakpoints; i++ ) { curvature[ Std.rand2(0, 2)] => coefs[i++]; i/3 => coefs[i++]; Std.rand2f(0.,1.) => coefs[i]; } 0 => coefs[n_breakpoints-1]; coefs => table.coefs;
<<<"\n", "CURVE 2:\n" >>>; <<<"\t index", " value", " curvature">>>; <<<"\t----------------------------------","\t">>>; for( 0 => int i; i < n_breakpoints-2; i++ ) <<<"\t", coefs[i++], coefs[i++], coefs[i]>>>; <<< "\t", coefs[n_breakpoints-2], coefs[n_breakpoints-1] >>>; <<<"\t----------------------------------","\t">>>; }
CurveTable curve1; CurveTable curve2; 1024 => int size;
<<< "\n*Assigning coefs via rand_coefs1()","\t">>>; rand_coefs1( curve1 ); 0 => float sum; for( 0 => int i; i < size; i++ ) { curve1.lookup(i) +=> sum; } if( sum > 0 ) <<<"Ok", "sum[i=0,N=1023] =", sum>>>; else <<< "Error:", "sum[i=0,N=1023] =", sum, ". Coefs were not assigned. All values are 0." >>>;
<<< "\n*Assigning coefs via rand_coefs2()","\t">>>; rand_coefs2( curve2, 10 ); 0 => sum; for( 0 => int i; i < size; i++ ) { curve2.lookup(i) +=> sum; } if( sum > 0 ) <<<"Ok", "sum[i=0,N=1023] =", sum>>>; else <<< "Error:", "sum[i=0,N=1023] =", sum, ". Coefs were not assigned. All values are 0.\n">>>; _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users