-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpz_mat.h
144 lines (106 loc) · 3.88 KB
/
mpz_mat.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===============================================================================*/
/******************************************************************************
mpz_mat.h: Matrices over Z, implemented as an array of mpz_t's
Not intended to be efficient
Copyright (C) 2009, Andy Novocin
Copyright (C) 2008, William Hart
******************************************************************************/
#ifndef MPZ_MAT_H
#define MPZ_MAT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
#include "memory-manager.h"
typedef struct
{
mpz_t* entries;
unsigned long r;
unsigned long c;
} mpz_mat_struct;
// mpz_poly_t allows reference-like semantics for mpz_poly_struct:
typedef mpz_mat_struct mpz_mat_t[1];
// ------------------------------------------------------
// Initialisation and memory management
void mpz_mat_init(mpz_mat_t mat, ulong r, ulong c);
void mpz_mat_clear(mpz_mat_t mat);
// ------------------------------------------------------
// Comparison
static inline
int mpz_mat_equal(mpz_mat_t mat1, mpz_mat_t mat2)
{
long i;
for (i = 0; i < mat1->r*mat1->c; i++)
if (mpz_cmp(mat1->entries[i], mat2->entries[i])) return 0;
return 1;
}
// ------------------------------------------------------
// Addition and subtraction
void mpz_mat_add(mpz_mat_t res, mpz_mat_t mat1, mpz_mat_t mat2);
void mpz_mat_sub(mpz_mat_t res, mpz_mat_t mat1, mpz_mat_t mat2);
// ------------------------------------------------------
// Multiplication
void mpz_mat_mul_classical(mpz_mat_t res, mpz_mat_t mat1, mpz_mat_t mat2);
// ------------------------------------------------------
// I/O
/**
\fn int mpz_mat_from_string(mpz_mat_t mat, const char *s)
\brief Read an mpz_mat_t from a string at s
*/
int mpz_mat_from_string(mpz_mat_t mat, const char *s);
/**
\fn char* mpz_mat_to_string(mpz_mat_t mat)
\brief Read a string from an mpz_mat_t
*/
char* mpz_mat_to_string(mpz_mat_t mat);
/**
\fn int mpz_mat_from_string_pretty(mpz_mat_t mat, char *s)
\brief Read an mpz_mat_t from a pretty string at s. A pretty string
starts with [[
*/
int mpz_mat_from_string_pretty(mpz_mat_t mat, char *s);
/**
\fn char* mpz_mat_to_string_pretty(mpz_mat_t mat)
\brief Read a pretty string from an mpz_mat_t
*/
char* mpz_mat_to_string_pretty(mpz_mat_t mat);
/**
\fn void mpz_mat_fprint(mpz_mat_t mat, FILE* f)
\brief Print an mpz_mat_t to a file stream
*/
void mpz_mat_fprint(mpz_mat_t mat, FILE* f);
/**
\fn void mpz_mat_fprint_pretty(mpz_mat_t mat, FILE* f)
\brief Print a pretty format mpz_mat_t to a file stream
*/
void mpz_mat_fprint_pretty(mpz_mat_t mat, FILE* f);
/**
\fn int mpz_mat_fread(mpz_mat_t mat, FILE* f)
\brief Read an mpz_mat_t from a file stream
*/
int mpz_mat_fread(mpz_mat_t mat, FILE* f);
/**
\fn int mpz_mat_fread_pretty(mpz_mat_t mat, FILE* f)
\brief Read a an mpz_mat_t from a file stream with pretty formatting
*/
int mpz_mat_fread_pretty(mpz_mat_t mat, FILE* f);
// *************** end of file
#ifdef __cplusplus
}
#endif
#endif