23 if (istensor(p1
) && p1
->u
.tensor
->ndim
== 2 && p1
->u
.tensor
->dim
[0] == p1
->u
.tensor
->dim
[1])
26 stop("adj: square matrix expected");
28 n
= p1
->u
.tensor
->dim
[0];
30 p2
= alloc_tensor(n
* n
);
32 p2
->u
.tensor
->ndim
= 2;
33 p2
->u
.tensor
->dim
[0] = n
;
34 p2
->u
.tensor
->dim
[1] = n
;
36 for (i
= 0; i
< n
; i
++)
37 for (j
= 0; j
< n
; j
++) {
38 cofactor(p1
, n
, i
, j
);
39 p2
->u
.tensor
->elem
[n
* j
+ i
] = pop(); /* transpose */