diff -r 000000000000 -r 2f259fa3e83a ode/src/matrix.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ode/src/matrix.cpp Tue Feb 02 01:00:49 2010 +0200 @@ -0,0 +1,391 @@ +/************************************************************************* + * * + * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * + * All rights reserved. Email: russ@q12.org Web: www.q12.org * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of EITHER: * + * (1) The GNU Lesser General Public License as published by the Free * + * Software Foundation; either version 2.1 of the License, or (at * + * your option) any later version. The text of the GNU Lesser * + * General Public License is included with this library in the * + * file LICENSE.TXT. * + * (2) The BSD-style license that is included with this library in * + * the file LICENSE-BSD.TXT. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * + * LICENSE.TXT and LICENSE-BSD.TXT for more details. * + * * + *************************************************************************/ + +#include +#include + +// misc defines +//#define ALLOCA dALLOCA16 + + +EXPORT_C void dSetZero (dReal *a, int n) +{ + while (n > 0) { + *(a++) = 0; + n--; + } +} + + +EXPORT_C void dSetValue (dReal *a, int n, dReal value) +{ + while (n > 0) { + *(a++) = value; + n--; + } +} + + +EXPORT_C void dMultiply0 (dReal *A, const dReal *B, const dReal *C, int p, int q, int r) +{ + int i,j,k,qskip,rskip,rpad; + qskip = dPAD(q); + rskip = dPAD(r); + rpad = rskip - r; + dReal sum; + const dReal *b,*c,*bb; + bb = B; + for (i=p; i; i--) { + for (j=0 ; j= 0; i--) { + sum = 0; + for (k=i+1; k < n; k++) sum += dMUL(L[k*nskip+i],b[k]); + b[i] = dDIV((y[i]-sum),L[i*nskip+i]); + } + free(y); +} + + +EXPORT_C int dInvertPDMatrix (const dReal *A, dReal *Ainv, int n) +{ + int i,j,nskip; + dReal *L,*x; + nskip = dPAD (n); + L = (dReal*) malloc (nskip*n*sizeof(dReal)); + if (L == NULL) { + return 0; + } + memcpy (L,A,nskip*n*sizeof(dReal)); + x = (dReal*) malloc (n*sizeof(dReal)); + if (x == NULL) { + free(L); + return 0; + } + if (dFactorCholesky (L,n)==0) { + free(L); + free(x); + return 0; + } + dSetZero (Ainv,n*nskip); // make sure all padding elements set to 0 + for (i=0; i=0; i--) { + sum = 0; + for (j=i+1; j j) ? _GETA(i,j) : _GETA(j,i)) + + +EXPORT_C void dLDLTRemove (dReal **A, const int *p, dReal *L, dReal *d, + int /*n1*/, int n2, int r, int nskip) +{ + int i; + + + if (r==n2-1) { + return; // deleting last row/col is easy + } + else if (r==0) { + dReal *a = (dReal*) malloc (n2 * sizeof(dReal)); + if (a == NULL) { + return; + } + for (i=0; i= n-1) return; + if (r > 0) { + for (i=0; i