File: mtransp.c

package info (click to toggle)
python-scipy 0.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 52,228 kB
  • ctags: 63,719
  • sloc: python: 112,726; fortran: 88,685; cpp: 86,979; ansic: 85,860; makefile: 530; sh: 236
file content (60 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*                                                     mtransp.c
 *
 *     Matrix transpose
 *
 *
 *
 * SYNOPSIS:
 *
 * int n;
 * double A[n*n], T[n*n];
 *
 * mtransp( n, A, T );
 *
 *
 *
 * DESCRIPTION:
 *
 *
 * T[r][c] = A[c][r]
 *
 *
 * Transposes the n by n square matrix A and puts the result in T.
 * The output, T, may occupy the same storage as A.
 *
 *
 *
 */


void mtransp(int, double *, double *);

void mtransp(n, A, T)
int n;
double *A, *T;
{
    int i, j, np1;
    double *pAc, *pAr, *pTc, *pTr, *pA0, *pT0;
    double x;

    np1 = n + 1;
    pA0 = A;
    pT0 = T;
    for (i = 0; i < n - 1; i++) {	/* row index */
	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 < n; j++) {	/* column index */
	    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 */
}