Changeset 10605
- Timestamp:
- Dec 9, 2006, 6:13:25 PM (20 years ago)
- Location:
- trunk/psLib
- Files:
-
- 3 edited
-
src/math/psPolynomial.c (modified) (2 diffs)
-
src/math/psPolynomialUtils.c (modified) (2 diffs)
-
test/math/tap_psPolynomialUtils_Derivatives.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psPolynomial.c
r10598 r10605 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.15 3$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-12- 09 14:19:56$9 * @version $Revision: 1.154 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-12-10 04:13:25 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 690 690 { 691 691 if (out == NULL) { 692 psPolynomial2DAlloc (poly->type, poly->nX, poly->nY);692 out = psPolynomial2DAlloc (poly->type, poly->nX, poly->nY); 693 693 } else { 694 694 psPolynomial2DRecycle (out, poly->type, poly->nX, poly->nY); -
trunk/psLib/src/math/psPolynomialUtils.c
r10598 r10605 180 180 psPolynomial2D *psPolynomial2D_dX (psPolynomial2D *out, psPolynomial2D *poly) 181 181 { 182 psPolynomial2D *dest = NULL; 182 183 int nXout = poly->nX - 1; 183 184 int nYout = poly->nY; 184 185 186 if (poly->nX == 0) 187 return NULL; 188 189 bool inPlace = false; 190 185 191 if (out == NULL) { 186 out = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout); 187 } else { 188 psPolynomial2DRecycle (out, poly->type, nXout, nYout); 192 dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout); 193 out = dest; 194 } else { 195 if (out == poly) { 196 inPlace = true; 197 dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout); 198 } else { 199 dest = out; 200 psPolynomial2DRecycle (dest, poly->type, nXout, nYout); 201 } 189 202 } 190 203 191 204 for (int i = 0; i < nXout + 1; i++) { 192 205 for (int j = 0; j < nYout + 1; j++) { 193 out->mask[i][j] = poly->mask[i+1][j]; 194 out->coeff[i][j] = poly->coeff[i+1][j] * (i+1); 195 } 206 dest->mask[i][j] = poly->mask[i+1][j]; 207 dest->coeff[i][j] = poly->coeff[i+1][j] * (i+1); 208 } 209 } 210 211 if (inPlace) { 212 psFree (poly); 213 out = dest; 196 214 } 197 215 return out; … … 200 218 psPolynomial2D *psPolynomial2D_dY (psPolynomial2D *out, psPolynomial2D *poly) 201 219 { 202 203 int nXout = poly->nX - 1; 204 int nYout = poly->nY; 220 psPolynomial2D *dest = NULL; 221 int nXout = poly->nX; 222 int nYout = poly->nY - 1; 223 224 if (poly->nY == 0) 225 return NULL; 226 227 bool inPlace = false; 205 228 206 229 if (out == NULL) { 207 out = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout); 208 } else { 209 psPolynomial2DRecycle (out, poly->type, nXout, nYout); 230 dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout); 231 out = dest; 232 } else { 233 if (out == poly) { 234 inPlace = true; 235 dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout); 236 } else { 237 dest = out; 238 psPolynomial2DRecycle (dest, poly->type, nXout, nYout); 239 } 210 240 } 211 241 212 242 for (int i = 0; i < nXout + 1; i++) { 213 243 for (int j = 0; j < nYout + 1; j++) { 214 out->mask[i][j] = poly->mask[i][j+1]; 215 out->coeff[i][j] = poly->coeff[i][j+1] * (j+1); 216 } 244 dest->mask[i][j] = poly->mask[i][j+1]; 245 dest->coeff[i][j] = poly->coeff[i][j+1] * (j+1); 246 } 247 } 248 249 if (inPlace) { 250 psFree (poly); 251 out = dest; 217 252 } 218 253 return out; -
trunk/psLib/test/math/tap_psPolynomialUtils_Derivatives.c
r10597 r10605 8 8 int main (void) 9 9 { 10 plan_tests( 48);10 plan_tests(72); 11 11 12 12 diag("psPolynomial2D Derivative tests"); … … 109 109 } 110 110 111 // test psPolynomial2D_dX (inPlace: supplied output == supplied input) 112 { 113 psMemId id = psMemGetId(); 114 115 diag ("test psPolynomial2D_dX (supplied output)"); 116 117 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); 118 ok(poly != NULL, "psPolynomial2D successfully allocated"); 119 skip_start(poly == NULL, 5, "Skipping tests because psPolynomial2DAlloc() failed"); 120 121 // build sample polynomial (upper-left elements only) 122 // z = 5 + 2x + 3y - 3x^2 + 4xy - 2y^2 123 // dz/dx = 2 - 6x + 4y 124 poly->coeff[0][0] = 5.0; 125 poly->coeff[1][0] = 2.0; 126 poly->coeff[0][1] = 3.0; 127 poly->coeff[2][0] = -3.0; 128 poly->coeff[1][1] = 4.0; 129 poly->coeff[0][2] = -2.0; 130 131 // mask remaining elements 132 poly->mask[2][1] = 1; 133 poly->mask[1][2] = 1; 134 poly->mask[2][2] = 1; 135 136 poly = psPolynomial2D_dX (poly, poly); 137 138 ok(poly->nX == 1, "new x order is %d", poly->nX); 139 ok(poly->nY == 2, "new y order is %d", poly->nY); 140 141 ok_float(poly->coeff[0][0], +2.0, "x^0 y^0 coeff is %f", poly->coeff[0][0]); 142 ok_float(poly->coeff[1][0], -6.0, "x^1 y^0 coeff is %f", poly->coeff[1][0]); 143 ok_float(poly->coeff[0][1], +4.0, "x^0 y^1 coeff is %f", poly->coeff[0][1]); 144 145 ok(!poly->mask[0][0], "x^0 y^0 coeff is unmasked"); 146 ok(!poly->mask[1][0], "x^1 y^0 coeff is unmasked"); 147 ok(!poly->mask[0][1], "x^0 y^1 coeff is unmasked"); 148 149 ok(poly->mask[1][1], "x^1 y^1 coeff is masked"); 150 ok(poly->mask[1][2], "x^1 y^2 coeff is masked"); 151 152 psFree (poly); 153 154 skip_end(); 155 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 156 } 157 111 158 // test psPolynomial2D_dY (no supplied output) 112 159 { … … 136 183 psPolynomial2D *dY = psPolynomial2D_dY (NULL, poly); 137 184 138 ok(dY->nX == 1, "new x order is %d", dY->nX);139 ok(dY->nY == 2, "new y order is %d", dY->nY);185 ok(dY->nX == 2, "new x order is %d", dY->nX); 186 ok(dY->nY == 1, "new y order is %d", dY->nY); 140 187 141 188 ok_float(dY->coeff[0][0], +3.0, "x^0 y^0 coeff is %f", dY->coeff[0][0]); … … 185 232 psPolynomial2D_dY (dY, poly); 186 233 187 ok(dY->nX == 1, "new x order is %d", dY->nX);188 ok(dY->nY == 2, "new y order is %d", dY->nY);234 ok(dY->nX == 2, "new x order is %d", dY->nX); 235 ok(dY->nY == 1, "new y order is %d", dY->nY); 189 236 190 237 ok_float(dY->coeff[0][0], +3.0, "x^0 y^0 coeff is %f", dY->coeff[0][0]); … … 206 253 } 207 254 255 // test psPolynomial2D_dY (supplied output) 256 { 257 psMemId id = psMemGetId(); 258 259 diag ("test psPolynomial2D_dY (supplied output)"); 260 261 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); 262 ok(poly != NULL, "psPolynomial2D successfully allocated"); 263 skip_start(poly == NULL, 5, "Skipping tests because psPolynomial2DAlloc() failed"); 264 265 // build sample polynomial (upper-left elements only) 266 // z = 5 + 2x + 3y - 3x^2 + 4xy - 2y^2 267 // dz/dy = 3 + 4x - 4y 268 poly->coeff[0][0] = 5.0; 269 poly->coeff[1][0] = 2.0; 270 poly->coeff[0][1] = 3.0; 271 poly->coeff[2][0] = -3.0; 272 poly->coeff[1][1] = 4.0; 273 poly->coeff[0][2] = -2.0; 274 275 // mask remaining elements 276 poly->mask[2][1] = 1; 277 poly->mask[1][2] = 1; 278 poly->mask[2][2] = 1; 279 280 poly = psPolynomial2D_dY (poly, poly); 281 282 ok(poly->nX == 2, "new x order is %d", poly->nX); 283 ok(poly->nY == 1, "new y order is %d", poly->nY); 284 285 ok_float(poly->coeff[0][0], +3.0, "x^0 y^0 coeff is %f", poly->coeff[0][0]); 286 ok_float(poly->coeff[1][0], +4.0, "x^1 y^0 coeff is %f", poly->coeff[1][0]); 287 ok_float(poly->coeff[0][1], -4.0, "x^0 y^1 coeff is %f", poly->coeff[0][1]); 288 289 ok(!poly->mask[0][0], "x^0 y^0 coeff is unmasked"); 290 ok(!poly->mask[1][0], "x^1 y^0 coeff is unmasked"); 291 ok(!poly->mask[0][1], "x^0 y^1 coeff is unmasked"); 292 293 ok(poly->mask[1][1], "x^1 y^1 coeff is masked"); 294 ok(poly->mask[1][2], "x^1 y^2 coeff is masked"); 295 296 psFree (poly); 297 298 skip_end(); 299 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 300 } 301 208 302 return exit_status(); 209 303 }
Note:
See TracChangeset
for help on using the changeset viewer.
