Category : C Source Code
Archive   : CEPHES22.ZIP
Filename : BLAS.C

 
Output of file : BLAS.C contained in archive : CEPHES22.ZIP
/* Assorted matrix functions.
*/


/* Multiply r (rows) by c (columns) matrix A on the left
* by column vector V of dimension c on the right
* to produce a (column) vector Y output of dimension r.
*/
mvmpy( r, c, A, V, Y )
int r, c;
double *A, *V, *Y;
{
register double s;
double *pA, *pV, *pY;
int i, j;

pA = A;
pY = Y;
for( i=0; i {
pV = V;
s = 0.0;
for( j=0; j {
s += *pA++ * *pV++;
}
*pY++ = s;
}
}


/* Multiply an r (rows) by c (columns) matrix A on the left
* by a c (rows) by r (columns) matrix B on the right
* to produce an r by r matrix Y.
*/
mmmpy( r, c, A, B, Y )
int r, c;
double *A, *B, *Y;
{
register double s;
double *pA, *pB, *pY, *pt;
int i, j, k;

pY = Y;
pB = B;
for( i=0; i {
pA = A;
for( j=0; j {
pt = pB;
s = 0.0;
for( k=0; k {
s += *pA++ * *pt;
pt += r; /* increment to next row underneath */
}
*pY++ = s;
}
pB += 1;
}
}


/* Transpose the n by n square matrix A and put the result in T.
* T may occupy the same storage as A.
*/
mtransp( n, A, T )
int n;
double *A, *T;
{
int i, j, np1;
double *pAc, *pAr, *pTc, *pTr, *pA0, *pT0;
double x, y;

np1 = n+1;
pA0 = A;
pT0 = T;
for( i=0; i {
pAc = pA0; /* next diagonal element of input */
pAr = pAc + n; /* next row down underneath the diagonal element */
pTc = pT0; /* next diagonal element of the output */
pTr = pTc + n; /* next row underneath */
*pTc++ = *pAc++; /* copy the diagonal element */
for( j=i+1; j {
x = *pAr;
*pTr = *pAc++;
*pTc++ = x;
pAr += n;
pTr += n;
}
pA0 += np1; /* &A[n*i+i] for next i */
pT0 += np1; /* &T[n*i+i] for next i */
}
*pT0 = *pA0; /* copy the diagonal element */
}


/* Return maximum off-diagonal element of n by n square matrix A
*/
double maxoffd( n, A )
int n;
double *A;
{
double e, x;
int i, j, nm1;
double *pA;

nm1 = n-1;
e = 0.0;
pA = A;
for( i=0; i {
++pA; /* skip over the diagonal element */
for( j=0; j {
x = *pA++;
if( x < 0 )
x = -x;
if( x > e )
e = x;
}
}
return( e );
}




/* Unpack symmetric matrix T stored in lower triangular form
* into a symmetric n by n square matrix S.
*/
tritosquare( n, T, S )
int n;
double T[], S[];
{
double *pT;
int i, j, ni, nj;

/* offset to (i,j) element is (j*j+j)/2 + i */
pT = T;
ni = 0;
for( i=0; i {
nj = 0;
for( j=0; j {
S[ni+j] = *pT;
S[nj+i] = *pT++;
nj += n;
}
S[ni+i] = *pT++;
ni += n;
}
}


  3 Responses to “Category : C Source Code
Archive   : CEPHES22.ZIP
Filename : BLAS.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/