HPCombi
High Performance Combinatorics in C++ using vector instructions v1.0.3
Loading...
Searching...
No Matches
bmat8.hpp
Go to the documentation of this file.
1//****************************************************************************//
2// Copyright (C) 2018-2024 Finn Smith <fls3@st-andrews.ac.uk> //
3// Copyright (C) 2018-2024 James Mitchell <jdm3@st-andrews.ac.uk> //
4// Copyright (C) 2018-2024 Florent Hivert <Florent.Hivert@lisn.fr>, //
5// //
6// This file is part of HP-Combi <https://github.com//HPCombi> //
7// //
8// HP-Combi is free software: you can redistribute it and/or modify it //
9// under the terms of the GNU General Public License as published by the //
10// Free Software Foundation, either version 3 of the License, or //
11// (at your option) any later version. //
12// //
13// HP-Combi is distributed in the hope that it will be useful, but WITHOUT //
14// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //
15// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License //
16// for more details. //
17// //
18// You should have received a copy of the GNU General Public License along //
19// with HP-Combi. If not, see <https://www.gnu.org/licenses/>. //
20//****************************************************************************//
21
24
25#ifndef HPCOMBI_BMAT8_HPP_
26#define HPCOMBI_BMAT8_HPP_
27
28#include <array> // for array
29#include <bitset> // for bitset
30#include <cstddef> // for size_t
31#include <cstdint> // for uint64_t, uint8_t
32#include <functional> // for hash, __scalar_hash
33#include <iostream> // for ostream
34#include <memory> // for hash
35#include <utility> // for pair, swap
36#include <vector> // for vector
37
38#include "debug.hpp" // for HPCOMBI_ASSERT
39#include "epu8.hpp" // for epu8
40#include "perm16.hpp" // for Perm16
41
42namespace HPCombi {
43
55class BMat8 {
56 public:
60 BMat8() noexcept = default;
61
66 explicit BMat8(uint64_t mat) noexcept : _data(mat) {}
67
72 // Not sure if this is noexcept or not
73 explicit BMat8(std::vector<std::vector<bool>> const &mat);
74
78 BMat8(BMat8 const &) noexcept = default;
79
83 BMat8(BMat8 &&) noexcept = default;
84
88 BMat8 &operator=(BMat8 const &) noexcept = default;
89
93 BMat8 &operator=(BMat8 &&) noexcept = default;
94
96 ~BMat8() = default;
97
101 bool operator==(BMat8 const &that) const noexcept {
102 return _data == that._data;
103 }
104
108 bool operator!=(BMat8 const &that) const noexcept {
109 return _data != that._data;
110 }
111
116 bool operator<(BMat8 const &that) const noexcept {
117 return _data < that._data;
118 }
119
124 bool operator>(BMat8 const &that) const noexcept {
125 return _data > that._data;
126 }
127
133 bool operator()(size_t i, size_t j) const noexcept;
134
140 void set(size_t i, size_t j, bool val) noexcept;
141
147 uint64_t to_int() const noexcept { return _data; }
148
152 std::array<std::array<bool, 8>, 8> to_array() const noexcept;
153
158 BMat8 operator|(BMat8 const &that) const noexcept {
159 return BMat8(to_int() | that.to_int());
160 }
161
166 BMat8 transpose_naive() const noexcept;
167
172 BMat8 transpose() const noexcept;
173
178 BMat8 transpose_mask() const noexcept;
179
184 BMat8 transpose_maskd() const noexcept;
185
190 static void transpose2(BMat8 &, BMat8 &) noexcept;
191
198 BMat8 mult_transpose(BMat8 const &that) const noexcept;
199
205 BMat8 operator*(BMat8 const &that) const noexcept {
206 return mult_transpose(that.transpose());
207 }
208
215 BMat8 mult_naive(BMat8 const &that) const noexcept;
216
222 BMat8 mult_naive_array(BMat8 const &that) const noexcept;
223
230 BMat8 row_space_basis() const noexcept;
231
236 BMat8 col_space_basis() const noexcept {
238 }
239
241 size_t nr_rows() const noexcept;
242
244 // Not noexcept because it constructs a vector
245 std::vector<uint8_t> rows() const;
246
250 // Not noexcept because row_space_bitset_ref isn't
251 uint64_t row_space_size_ref() const;
252
256 // Not noexcept because it creates a vector
257 std::bitset<256> row_space_bitset_ref() const;
258
262 void row_space_bitset(epu8 &res1, epu8 &res2) const noexcept;
263
268 uint64_t row_space_size_bitset() const noexcept;
269
275 uint64_t row_space_size_incl() const noexcept;
276
281 uint64_t row_space_size_incl1() const noexcept;
282
286 uint64_t row_space_size() const noexcept { return row_space_size_incl(); }
287
291 bool row_space_included_ref(BMat8 other) const noexcept;
292
296 bool row_space_included_bitset(BMat8 other) const noexcept;
297
302 epu8 row_space_mask(epu8 vects) const noexcept;
303
307 bool row_space_included(BMat8 other) const noexcept;
308
312 // Not noexcept because std::make_pair is not
313 static std::pair<bool, bool> row_space_included2(BMat8 a1, BMat8 b1,
314 BMat8 a2, BMat8 b2);
315
320 BMat8 row_permuted(Perm16 p) const noexcept;
321
326 BMat8 col_permuted(Perm16 p) const noexcept;
327
332 static BMat8 row_permutation_matrix(Perm16 p) noexcept;
333
338 static BMat8 col_permutation_matrix(Perm16 p) noexcept;
339
346
352 // Not noexcept because vectors are allocated
354
358 static BMat8 one(size_t dim = 8) noexcept {
359 HPCOMBI_ASSERT(dim <= 8);
360 static std::array<uint64_t, 9> const ones = {
361 0x0000000000000000, 0x8000000000000000, 0x8040000000000000,
362 0x8040200000000000, 0x8040201000000000, 0x8040201008000000,
363 0x8040201008040000, 0x8040201008040200, 0x8040201008040201};
364 return BMat8(ones[dim]);
365 }
366
370 // Not noexcept because random things aren't
371 static BMat8 random();
372
377 // Not noexcept because BMat8::random above is not
378 static BMat8 random(size_t dim);
379
380 void swap(BMat8 &that) noexcept { std::swap(this->_data, that._data); }
381
383 // Not noexcept
384 std::ostream &write(std::ostream &os) const;
385
386#ifdef HPCOMBI_HAVE_DENSEHASHMAP
387 // FIXME do this another way
388 BMat8 empty_key() const noexcept { return BMat8(0xFF7FBFDFEFF7FBFE); }
389#endif
390
391 private:
392 uint64_t _data;
393
394 epu8 row_space_basis_internal() const noexcept;
395};
396
397} // namespace HPCombi
398
399#include "bmat8_impl.hpp"
400
401namespace std {
402template <> struct hash<HPCombi::BMat8> {
403 inline size_t operator()(HPCombi::BMat8 const &bm) const {
404 return hash<uint64_t>()(bm.to_int());
405 }
406};
407} // namespace std
408#endif // HPCOMBI_BMAT8_HPP_
uint8_t __attribute__((vector_size(16))) epu8
epu8 stands for Extended Packed Unsigned, grouped by 8 bits; this is the low level type chosen by Int...
Definition epu8.hpp:73
Boolean matrices of dimension up to 8×8, stored as a single uint64; isomorph to binary relations with...
Definition bmat8.hpp:55
std::array< std::array< bool, 8 >, 8 > to_array() const noexcept
Returns the array representation of this.
Definition bmat8_impl.hpp:117
uint64_t row_space_size_incl() const noexcept
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:367
BMat8 mult_naive_array(BMat8 const &that) const noexcept
Returns the matrix product of this and that.
Definition bmat8_impl.hpp:261
BMat8 row_space_basis() const noexcept
Returns a canonical basis of the row space of this.
Definition bmat8_impl.hpp:289
BMat8 mult_naive(BMat8 const &that) const noexcept
Returns the matrix product of this and that.
Definition bmat8_impl.hpp:248
static std::pair< bool, bool > row_space_included2(BMat8 a1, BMat8 b1, BMat8 a2, BMat8 b2)
Returns inclusion of row spaces.
Definition bmat8_impl.hpp:412
static void transpose2(BMat8 &, BMat8 &) noexcept
Transpose two matrices at once.
Definition bmat8_impl.hpp:212
uint64_t row_space_size_bitset() const noexcept
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:342
static BMat8 row_permutation_matrix(Perm16 p) noexcept
Returns the matrix associated to the permutation p by rows.
Definition bmat8_impl.hpp:487
BMat8 mult_transpose(BMat8 const &that) const noexcept
Returns the matrix product of this and the transpose of that.
Definition bmat8_impl.hpp:232
BMat8(BMat8 const &) noexcept=default
A constructor.
BMat8 transpose_maskd() const noexcept
Returns the transpose of this.
Definition bmat8_impl.hpp:198
BMat8(BMat8 &&) noexcept=default
A constructor.
bool row_space_included_bitset(BMat8 other) const noexcept
Returns whether the row space of this is included in other's.
Definition bmat8_impl.hpp:383
bool operator>(BMat8 const &that) const noexcept
Returns true if this is greater than that.
Definition bmat8.hpp:124
BMat8 transpose() const noexcept
Returns the transpose of this.
Definition bmat8_impl.hpp:175
static BMat8 col_permutation_matrix(Perm16 p) noexcept
Returns the matrix associated to the permutation p by columns.
Definition bmat8_impl.hpp:491
epu8 row_space_mask(epu8 vects) const noexcept
Returns a mask for which vectors of a 16 rows epu8 are in the row space of this.
Definition bmat8_impl.hpp:402
BMat8 row_permuted(Perm16 p) const noexcept
Returns the matrix whose rows have been permuted according to p.
Definition bmat8_impl.hpp:475
BMat8() noexcept=default
A default constructor.
BMat8 col_space_basis() const noexcept
Returns a canonical basis of the col space of this.
Definition bmat8.hpp:236
bool row_space_included(BMat8 other) const noexcept
Returns whether the row space of this is included in other's.
Definition bmat8_impl.hpp:391
std::ostream & write(std::ostream &os) const
Write this on os.
Definition bmat8_impl.hpp:536
void row_space_bitset(epu8 &res1, epu8 &res2) const noexcept
Returns the the row space of this as 256 bits.
Definition bmat8_impl.hpp:327
Perm16 right_perm_action_on_basis(BMat8) const noexcept
Give the permutation whose right multiplication change *this to other.
Definition bmat8_impl.hpp:526
std::bitset< 256 > row_space_bitset_ref() const
Returns the the row space of this.
Definition bmat8_impl.hpp:426
bool operator!=(BMat8 const &that) const noexcept
Returns true if this does not equal that.
Definition bmat8.hpp:108
BMat8 col_permuted(Perm16 p) const noexcept
Returns the matrix whose columns have been permuted according to p.
Definition bmat8_impl.hpp:483
uint64_t to_int() const noexcept
Returns the integer representation of this.
Definition bmat8.hpp:147
uint64_t row_space_size_ref() const
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:454
BMat8 transpose_naive() const noexcept
Returns the transpose of this.
Definition bmat8_impl.hpp:165
uint64_t row_space_size() const noexcept
Returns the cardinality of the row space of this.
Definition bmat8.hpp:286
BMat8 transpose_mask() const noexcept
Returns the transpose of this.
Definition bmat8_impl.hpp:186
void swap(BMat8 &that) noexcept
Definition bmat8.hpp:380
static BMat8 one(size_t dim=8) noexcept
Returns the identity BMat8.
Definition bmat8.hpp:358
std::vector< uint8_t > rows() const
Returns a std::vector for rows of this.
Definition bmat8_impl.hpp:458
size_t nr_rows() const noexcept
Returns the number of non-zero rows of this.
Definition bmat8_impl.hpp:467
void set(size_t i, size_t j, bool val) noexcept
Sets the (i, j)th position to val.
Definition bmat8_impl.hpp:111
static BMat8 random()
Returns a random BMat8.
Definition bmat8_impl.hpp:145
bool operator()(size_t i, size_t j) const noexcept
Returns the entry in the (i, j)th position.
Definition bmat8_impl.hpp:105
bool operator<(BMat8 const &that) const noexcept
Returns true if this is less than that.
Definition bmat8.hpp:116
uint64_t row_space_size_incl1() const noexcept
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:351
bool row_space_included_ref(BMat8 other) const noexcept
Returns whether the row space of this is included in other's.
Definition bmat8_impl.hpp:448
Perm16 right_perm_action_on_basis_ref(BMat8) const
Give the permutation whose right multiplication change *this to other.
Definition bmat8_impl.hpp:495
defines the macro HPCOMBI_ASSERT
#define HPCOMBI_ASSERT(x)
Definition debug.hpp:31
declaration of HPCombi::epu8.
const Transf16 a1
Definition image.cpp:52
const Transf16 a2
Definition image.cpp:53
Definition bmat16.hpp:39
uint8_t __attribute__((vector_size(16))) epu8
epu8 stands for Extended Packed Unsigned, grouped by 8 bits; this is the low level type chosen by Int...
Definition epu8.hpp:73
Definition bmat16_impl.hpp:362
declaration of PTransf16, Transf16, PPerm16 and Perm16
Permutations of : A permutation is a bijective mapping of a set of n elements onto itself.
Definition perm16.hpp:237
size_t operator()(HPCombi::BMat8 const &bm) const
Definition bmat8.hpp:403