-
Notifications
You must be signed in to change notification settings - Fork 1
/
libbinmat.h
93 lines (70 loc) · 3.48 KB
/
libbinmat.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
/*
* Copyright (C) 2013 Kevin Pulo <[email protected]>.
*
* This file is part of binmat.
*
* binmat 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 3 of the License, or
* (at your option) any later version.
*
* binmat 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 binmat. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBINMAT_H
#define LIBBINMAT_H
#include <stdio.h>
#if defined(BINMAT_DATA_TYPE)
typedef BINMAT_DATA_TYPE binmat_data_t;
#else
#ifdef HAVE_UNSIGNED_LONG_LONG_INT
typedef unsigned long long binmat_data_t;
#define BINMAT_PRINTF_MODIFIER "ll"
#else
typedef unsigned long binmat_data_t;
#define BINMAT_PRINTF_MODIFIER "l"
#endif
/*typedef unsigned char binmat_data_t;*/
/*typedef unsigned int binmat_data_t;*/
#endif
extern const binmat_data_t one;
extern const binmat_data_t zero;
typedef unsigned int binmat_index_t;
typedef unsigned char binmat_bool_t;
#define binmat_chunkbytes (sizeof(binmat_data_t))
#define binmat_chunkbits (binmat_chunkbytes*8)
#define binmat_numchunks(n) ( ((n)%binmat_chunkbits==0) ? (n)/binmat_chunkbits : (n)/binmat_chunkbits + 1 )
#define binmat_numbytes(n) (binmat_numchunks(n) * binmat_chunkbytes)
#define binmat_numbits(n) (binmat_numchunks(n) * binmat_chunkbits)
#define binmat_numbytes_matrix(n) ((n) * binmat_numbytes(n))
#define binmat_finalchunkbits(n) ( ((n)%binmat_chunkbits==0) ? binmat_chunkbits : (n)%binmat_chunkbits )
#define binmat_finalchunkmask(n) ( ((n)%binmat_chunkbits==0) ? ((binmat_data_t)(zero - 1)) : ((one << binmat_finalchunkbits(n)) - 1) )
#define binmat_binary_bufn_t(x,n) char x[(n) * binmat_chunkbits + 1]
#define binmat_binary_buf_t(x) binmat_binary_bufn_t(x,1)
#if defined(BINMAT_DEBUG)
int binmat_dprintf(const char *format, ...);
#else
#define binmat_dprintf(...)
#endif
binmat_data_t *binmat_alloc(binmat_index_t n);
void binmat_free(binmat_data_t *m);
binmat_bool_t binmat_getbit(const binmat_data_t *m, binmat_index_t n, binmat_index_t row, binmat_index_t col);
void binmat_setbit(binmat_data_t *m, binmat_index_t n, binmat_index_t row, binmat_index_t col, binmat_bool_t value);
char *binmat_format_chunk(binmat_data_t x, char *buf);
void binmat_print_matrix_slow(FILE *f, const binmat_data_t *m, binmat_index_t n);
void binmat_print_matrix_fast(FILE *f, const binmat_data_t *m, binmat_index_t n);
void binmat_print_matrix_hex(FILE *f, const binmat_data_t *m, binmat_index_t n);
void binmat_transpose(binmat_data_t *output, const binmat_data_t *input, binmat_index_t n);
int binmat_are_identical(const binmat_data_t *a, const binmat_data_t *b, binmat_index_t n);
void binmat_copy(binmat_data_t *a, const binmat_data_t *b, binmat_index_t n);
void binmat_multiply_slow(binmat_data_t *output, const binmat_data_t *a, const binmat_data_t *b, binmat_index_t n);
/* b MUST BE PRE-TRANSPOSED */
void binmat_multiply(binmat_data_t *output, const binmat_data_t *a, const binmat_data_t *b, binmat_index_t n);
void binmat_power(binmat_data_t *output, const binmat_data_t *a, const binmat_data_t *trans, binmat_index_t n, unsigned int pow);
void binmat_power_slow(binmat_data_t *output, const binmat_data_t *a, binmat_index_t n, unsigned int pow);
#endif