GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "typedef.h"1#include "matrix.h"2/**************************************************************************\3@---------------------------------------------------------------------------4@---------------------------------------------------------------------------5@ FILE: real_mat.c6@---------------------------------------------------------------------------7@---------------------------------------------------------------------------8@9\**************************************************************************/1011/*{{{}}}*/12/*{{{ real_mat*/13/*14@-------------------------------------------------------------------------15@ void real_mat( mat, rows, cols);16@ matrix_TYP *mat;17@ int rows, cols;18@19| Erzeugt aus mat eine Matrix mit rows Zeilen und cols Spalten.20| Dabei wird die Matrix passend vergroessert und verkleinert21| und mit Nullen aufgefuellt.22@ Generates form mat a matrix with 'rows' rows and 'cols' columns23@ Therefore the matrix is shrinked or enlarged and filled up with zeros.24@25@-------------------------------------------------------------------------26*/27void real_mat(mat, rows, cols)28matrix_TYP *mat;29int rows, cols;30{31int i,j;32int **Z, **N;3334Z = mat->array.SZ;35N = mat->array.N;3637if (rows < mat->rows) {38if( Z ) {39for (i = rows; i < mat->rows; i++) {40free( Z[i] );41}42Z = (int **)realloc((int *)Z,rows * sizeof(int *));43}4445if( N ) {46for (i = rows; i < mat->rows; i++) {47free( N[i] );48}49N = (int **)realloc((int *)N,rows * sizeof(int *));50}51} else if( rows > mat->rows ) {52if ( !quick_null_mat( mat ) ) {53mat->flags.Scalar = FALSE;54}55if( Z ) {56Z = (int **)realloc((int *)Z,rows * sizeof(int *));57for (i = mat->rows; i < rows; i++) {58Z[i]= (int *)calloc(cols , sizeof(int ));59}60}61if( N ) {62N = (int **)realloc((int *)N,rows * sizeof(int *));63for (i = mat->rows; i < rows; i++) {64N[i]= (int *)calloc(cols , sizeof(int ));65}66}6768}69if (mat->cols > cols ) {70if( Z ) {71for (i = 0; i < rows;i++) {72Z[i] = (int *)realloc((int *)Z[i], cols*sizeof(int));73}74}75} else if(mat->cols < cols) {76if( !quick_null_mat( mat ) ) {77mat->flags.Scalar = FALSE;78}79if( Z ) {80for (i = 0; i < rows;i++) {81Z[i] = (int *)realloc((int *)Z[i], cols*sizeof(int));82for (j = mat->cols; j < cols; j++) {83Z[i][j] = 0;84}85}86}87if( N ) {88for (i = 0; i < mat->rows;i++) {89N[i] = (int *)realloc((int *)N[i], cols*sizeof(int));90for (j = mat->cols; j < cols; j++) {91N[i][j] = 1;92}93}94}95}96mat->rows = rows;97mat->cols = cols;98mat->flags.Symmetric = mat->flags.Symmetric && (rows == cols);99mat->flags.Diagonal = mat->flags.Diagonal && (rows == cols);100mat->flags.Scalar = mat->flags.Scalar && (rows == cols);101mat->array.SZ = Z;102mat->array.N = N;103}104105/*}}} */106107108109110