Changeset 20729
- Timestamp:
- 06/14/16 08:53:20 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/shared/Matrix/MatrixUtils.cpp
r20728 r20729 22 22 23 23 int idima,idimb,idimc,idimd; 24 IssmDouble dtemp_static[600]; 24 IssmDouble dtemp_static[600]; 25 IssmDouble* dtemp_dynamic = NULL; 26 IssmDouble* dtemp = NULL; 25 27 _assert_(a && b && c && d); 26 28 … … 51 53 if (ncolc != idimc) _error_("Matrix B and C inner vectors not equal size."); 52 54 idimd=nrowc; 55 } 56 57 /*Depending on the size of incoming matrices, we might need to use a dynamic allocation*/ 58 if(idima*idimc>600){ 59 IssmDouble *dtemp_dynamic=xNew<IssmDouble>(idima*idimc); 60 dtemp = dtemp_dynamic; 61 } 62 else{ 63 dtemp = &dtemp_static[0]; 53 64 } 54 65 … … 61 72 /* multiply (a*b)*c+d */ 62 73 if (idima*idimc*(idimb+idimd) <= idimb*idimd*(idima+idimc)) { 63 if(idima*idimc>600) { 64 /*Use dynamic allocation instead of dtemp_static*/ 65 IssmDouble *dtemp; 66 dtemp=xNew<IssmDouble>(idima*idimc); 67 68 MatrixMultiply(a,nrowa,ncola,itrna,b,nrowb,ncolb,itrnb,dtemp,0); 69 MatrixMultiply(dtemp,idima,idimc,0,c,nrowc,ncolc,itrnc,d,iaddd); 70 xDelete<IssmDouble>(dtemp); 71 return 1; 72 } 73 MatrixMultiply(a,nrowa,ncola,itrna,b,nrowb,ncolb,itrnb,&dtemp_static[0],0); 74 MatrixMultiply(&dtemp_static[0],idima,idimc,0,c,nrowc,ncolc,itrnc,d,iaddd); 74 MatrixMultiply(a,nrowa,ncola,itrna,b,nrowb,ncolb,itrnb,dtemp,0); 75 MatrixMultiply(dtemp,idima,idimc,0,c,nrowc,ncolc,itrnc,d,iaddd); 75 76 } 76 77 77 78 /* multiply a*(b*c)+d */ 78 79 else{ 79 if(idimb*idimd>600) { 80 /*Use dynamic allocation instead of dtemp_static*/ 81 IssmDouble *dtemp; 82 dtemp=xNew<IssmDouble>(idimb*idimd); 83 84 MatrixMultiply(b,nrowb,ncolb,itrnb,c,nrowc,ncolc,itrnc,dtemp,0); 85 MatrixMultiply(a,nrowa,ncola,itrna,dtemp,idimb,idimd,0,d,iaddd); 86 xDelete<IssmDouble>(dtemp); 87 return 1; 88 } 89 MatrixMultiply(b,nrowb,ncolb,itrnb,c,nrowc,ncolc,itrnc,&dtemp_static[0],0); 90 MatrixMultiply(a,nrowa,ncola,itrna,&dtemp_static[0],idimb,idimd,0,d,iaddd); 91 } 92 80 MatrixMultiply(b,nrowb,ncolb,itrnb,c,nrowc,ncolc,itrnc,dtemp,0); 81 MatrixMultiply(a,nrowa,ncola,itrna,dtemp,idimb,idimd,0,d,iaddd); 82 } 83 84 /*Cleanup and return*/ 85 xDelete<IssmDouble>(dtemp); 93 86 return 1; 94 87 }/*}}}*/ … … 337 330 338 331 /*Intermediaries*/ 339 IssmDouble det; 340 IssmDouble det_reciprocal; 332 IssmDouble det,det_reciprocal; 341 333 342 334 /*Compute determinant*/ … … 345 337 346 338 /*Multiplication is faster than divsion, so we multiply by the reciprocal*/ 347 det_reciprocal = 1 /det;339 det_reciprocal = 1./det; 348 340 349 341 /*Compute invert*/ … … 458 450 459 451 /*Intermediaries*/ 460 IssmDouble det; 461 IssmDouble det_reciprocal; 452 IssmDouble det,det_reciprocal; 462 453 463 454 /*Compute determinant*/ … … 466 457 467 458 /*Multiplication is faster than divsion, so we multiply by the reciprocal*/ 468 det_reciprocal = 1 /det;459 det_reciprocal = 1./det; 469 460 470 461 /*Compute invert*/ … … 563 554 564 555 /*Intermediaries*/ 565 IssmDouble det; 566 IssmDouble det_reciprocal; 556 IssmDouble det,det_reciprocal; 567 557 568 558 /*Compute determinant*/ 569 559 Matrix4x4Determinant(&det,A); 570 //if(fabs(det) < DBL_EPSILON) _error_("Determinant smaller than machine epsilon");560 if(fabs(det) < DBL_EPSILON) _error_("Determinant smaller than machine epsilon"); 571 561 572 562 /*Multiplication is faster than division, so we multiply by the reciprocal*/ 573 det_reciprocal = 1 /det;563 det_reciprocal = 1./det; 574 564 575 565 /*Compute adjoint matrix*/
Note:
See TracChangeset
for help on using the changeset viewer.