Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563580 views
1
#include "typedef.h"
2
#include "matrix.h"
3
/**************************************************************************\
4
@---------------------------------------------------------------------------
5
@---------------------------------------------------------------------------
6
@ FILE: real_mat.c
7
@---------------------------------------------------------------------------
8
@---------------------------------------------------------------------------
9
@
10
\**************************************************************************/
11
12
/*{{{}}}*/
13
/*{{{ real_mat*/
14
/*
15
@-------------------------------------------------------------------------
16
@ void real_mat( mat, rows, cols);
17
@ matrix_TYP *mat;
18
@ int rows, cols;
19
@
20
| Erzeugt aus mat eine Matrix mit rows Zeilen und cols Spalten.
21
| Dabei wird die Matrix passend vergroessert und verkleinert
22
| und mit Nullen aufgefuellt.
23
@ Generates form mat a matrix with 'rows' rows and 'cols' columns
24
@ Therefore the matrix is shrinked or enlarged and filled up with zeros.
25
@
26
@-------------------------------------------------------------------------
27
*/
28
void real_mat(mat, rows, cols)
29
matrix_TYP *mat;
30
int rows, cols;
31
{
32
int i,j;
33
int **Z, **N;
34
35
Z = mat->array.SZ;
36
N = mat->array.N;
37
38
if (rows < mat->rows) {
39
if( Z ) {
40
for (i = rows; i < mat->rows; i++) {
41
free( Z[i] );
42
}
43
Z = (int **)realloc((int *)Z,rows * sizeof(int *));
44
}
45
46
if( N ) {
47
for (i = rows; i < mat->rows; i++) {
48
free( N[i] );
49
}
50
N = (int **)realloc((int *)N,rows * sizeof(int *));
51
}
52
} else if( rows > mat->rows ) {
53
if ( !quick_null_mat( mat ) ) {
54
mat->flags.Scalar = FALSE;
55
}
56
if( Z ) {
57
Z = (int **)realloc((int *)Z,rows * sizeof(int *));
58
for (i = mat->rows; i < rows; i++) {
59
Z[i]= (int *)calloc(cols , sizeof(int ));
60
}
61
}
62
if( N ) {
63
N = (int **)realloc((int *)N,rows * sizeof(int *));
64
for (i = mat->rows; i < rows; i++) {
65
N[i]= (int *)calloc(cols , sizeof(int ));
66
}
67
}
68
69
}
70
if (mat->cols > cols ) {
71
if( Z ) {
72
for (i = 0; i < rows;i++) {
73
Z[i] = (int *)realloc((int *)Z[i], cols*sizeof(int));
74
}
75
}
76
} else if(mat->cols < cols) {
77
if( !quick_null_mat( mat ) ) {
78
mat->flags.Scalar = FALSE;
79
}
80
if( Z ) {
81
for (i = 0; i < rows;i++) {
82
Z[i] = (int *)realloc((int *)Z[i], cols*sizeof(int));
83
for (j = mat->cols; j < cols; j++) {
84
Z[i][j] = 0;
85
}
86
}
87
}
88
if( N ) {
89
for (i = 0; i < mat->rows;i++) {
90
N[i] = (int *)realloc((int *)N[i], cols*sizeof(int));
91
for (j = mat->cols; j < cols; j++) {
92
N[i][j] = 1;
93
}
94
}
95
}
96
}
97
mat->rows = rows;
98
mat->cols = cols;
99
mat->flags.Symmetric = mat->flags.Symmetric && (rows == cols);
100
mat->flags.Diagonal = mat->flags.Diagonal && (rows == cols);
101
mat->flags.Scalar = mat->flags.Scalar && (rows == cols);
102
mat->array.SZ = Z;
103
mat->array.N = N;
104
}
105
106
/*}}} */
107
108
109
110