-
Notifications
You must be signed in to change notification settings - Fork 139
/
bool_mat.h
176 lines (118 loc) · 3.67 KB
/
bool_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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
Copyright (C) 2016 Arb authors
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#ifndef BOOL_MAT_H
#define BOOL_MAT_H
#ifdef BOOL_MAT_INLINES_C
#define BOOL_MAT_INLINE
#else
#define BOOL_MAT_INLINE static __inline__
#endif
#include <stdio.h>
#include "flint/flint.h"
#include "flint/fmpz_mat.h"
#ifndef flint_abort
#if __FLINT_RELEASE <= 20502
#define flint_abort abort
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* currently defined in the arb module, but global to the library */
double arb_test_multiplier(void);
typedef struct
{
int *entries;
slong r;
slong c;
int **rows;
}
bool_mat_struct;
typedef bool_mat_struct bool_mat_t[1];
#define bool_mat_nrows(mat) ((mat)->r)
#define bool_mat_ncols(mat) ((mat)->c)
BOOL_MAT_INLINE int
bool_mat_get_entry(const bool_mat_t mat, slong i, slong j)
{
return mat->rows[i][j];
}
BOOL_MAT_INLINE void
bool_mat_set_entry(bool_mat_t mat, slong i, slong j, int value)
{
mat->rows[i][j] = value;
}
/* Memory management */
void bool_mat_init(bool_mat_t mat, slong r, slong c);
void bool_mat_clear(bool_mat_t mat);
BOOL_MAT_INLINE void
bool_mat_swap(bool_mat_t mat1, bool_mat_t mat2)
{
bool_mat_struct t = *mat1;
*mat1 = *mat2;
*mat2 = t;
}
/* Conversions */
void bool_mat_set(bool_mat_t dest, const bool_mat_t src);
/* Random generation */
void bool_mat_randtest(bool_mat_t mat, flint_rand_t state);
void bool_mat_randtest_diagonal(bool_mat_t mat, flint_rand_t state);
void bool_mat_randtest_nilpotent(bool_mat_t mat, flint_rand_t state);
/* I/O */
void bool_mat_fprint(FILE * file, const bool_mat_t mat);
BOOL_MAT_INLINE void
bool_mat_print(const bool_mat_t mat)
{
bool_mat_fprint(stdout, mat);
}
/* Comparisons */
int bool_mat_equal(const bool_mat_t mat1, const bool_mat_t mat2);
int bool_mat_any(const bool_mat_t mat);
int bool_mat_all(const bool_mat_t mat);
int bool_mat_is_diagonal(const bool_mat_t mat);
int bool_mat_is_lower_triangular(const bool_mat_t mat);
int bool_mat_is_transitive(const bool_mat_t mat);
int bool_mat_is_nilpotent(const bool_mat_t mat);
BOOL_MAT_INLINE int
bool_mat_is_empty(const bool_mat_t mat)
{
return (mat->r == 0) || (mat->c == 0);
}
BOOL_MAT_INLINE int
bool_mat_is_square(const bool_mat_t mat)
{
return (mat->r == mat->c);
}
/* Special matrices */
void bool_mat_zero(bool_mat_t mat);
void bool_mat_one(bool_mat_t mat);
void bool_mat_directed_path(bool_mat_t mat);
void bool_mat_directed_cycle(bool_mat_t mat);
/* Transpose */
void bool_mat_transpose(bool_mat_t mat1, const bool_mat_t mat2);
/* Arithmetic */
void bool_mat_complement(bool_mat_t mat1, const bool_mat_t mat2);
void bool_mat_add(bool_mat_t res, const bool_mat_t mat1, const bool_mat_t mat2);
void bool_mat_mul(bool_mat_t res, const bool_mat_t mat1, const bool_mat_t mat2);
void bool_mat_mul_entrywise(bool_mat_t res, const bool_mat_t mat1, const bool_mat_t mat2);
void bool_mat_pow_ui(bool_mat_t B, const bool_mat_t A, ulong exp);
BOOL_MAT_INLINE void
bool_mat_sqr(bool_mat_t B, const bool_mat_t A)
{
bool_mat_mul(B, A, A);
}
/* Special functions */
int bool_mat_trace(const bool_mat_t mat);
slong bool_mat_nilpotency_degree(const bool_mat_t mat);
void bool_mat_transitive_closure(bool_mat_t dest, const bool_mat_t src);
slong bool_mat_get_strongly_connected_components(slong *partition, const bool_mat_t A);
slong bool_mat_all_pairs_longest_walk(fmpz_mat_t B, const bool_mat_t A);
#ifdef __cplusplus
}
#endif
#endif