HPCombi
High Performance Combinatorics in C++ using vector instructions v1.0.3
Loading...
Searching...
No Matches
bmat16.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/libsemigroups/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
22// This file contains a declaration of fast boolean matrices up to dimension 16.
23
24#ifndef HPCOMBI_BMAT16_HPP_
25#define HPCOMBI_BMAT16_HPP_
26
27#include <array> // for array
28#include <cstddef> // for size_t
29#include <cstdint> // for uint64_t, uint8_t
30#include <iostream> // for ostream
31#include <utility> // for pair, swap
32#include <vector> // for vector
33
34#include "bmat8.hpp" // for BMat8
35#include "debug.hpp" // for HPCOMBI_ASSERT
36
37#include "simde/x86/avx2.h"
38
39namespace HPCombi {
40using xpu16 = uint16_t __attribute__((vector_size(32)));
41using xpu64 = uint64_t __attribute__((vector_size(32)));
42
47xpu64 to_line(xpu64 vect);
48
54xpu64 to_block(xpu64 vect);
55
65class BMat16 {
66 public:
70 BMat16() noexcept = default;
71
77 explicit BMat16(xpu64 mat) noexcept : _data{mat} {}
78
83 explicit BMat16(uint64_t n0, uint64_t n1, uint64_t n2,
84 uint64_t n3) noexcept;
85
90 explicit BMat16(std::vector<std::vector<bool>> const &mat) noexcept;
91
95 BMat16(BMat16 const &) noexcept = default;
96
100 BMat16(BMat16 &&) noexcept = default;
101
105 BMat16 &operator=(BMat16 const &) noexcept = default;
106
110 BMat16 &operator=(BMat16 &&) noexcept = default;
111
113 ~BMat16() = default;
114
118 bool operator==(BMat16 const &that) const noexcept;
119
123 bool operator!=(BMat16 const &that) const noexcept {
124 return !(*this == that);
125 }
126
130 bool operator<(BMat16 const &that) const noexcept;
131
135 bool operator>(BMat16 const &that) const noexcept;
136
142 bool operator()(size_t i, size_t j) const noexcept;
143
149 void set(size_t i, size_t j, bool val) noexcept;
150
154 std::array<std::array<bool, 16>, 16> to_array() const noexcept;
155
160 BMat16 operator|(BMat16 const &that) const noexcept {
161 return BMat16(_data | that._data);
162 }
163
168 BMat16 transpose_naive() const noexcept;
169
174 BMat16 transpose() const noexcept;
175
182 BMat16 mult_transpose(BMat16 const &that) const noexcept;
183
190 BMat16 mult_4bmat8(BMat16 const &that) const noexcept;
191
197 BMat16 operator*(BMat16 const &that) const noexcept {
198 return mult_transpose(that.transpose());
199 }
200
207 BMat16 mult_naive(BMat16 const &that) const noexcept;
208
214 BMat16 mult_naive_array(BMat16 const &that) const noexcept;
215
217 size_t nr_rows() const noexcept;
218
220 // Not noexcept because it constructs a vector
221 std::vector<uint16_t> rows() const;
222
226 static BMat16 one(size_t dim = 16) noexcept {
227 HPCOMBI_ASSERT(dim <= 16);
228 static std::array<uint64_t, 9> const ones = {0,
229 1,
230 0x201,
231 0x40201,
232 0x8040201,
233 0x1008040201,
234 0x201008040201,
235 0x40201008040201,
236 0x8040201008040201};
237 return BMat16(ones[dim >= 8 ? 8 : dim], 0, 0,
238 ones[dim >= 8 ? dim - 8 : 0]);
239 }
240
244 // Not noexcept because random things aren't
245 static BMat16 random();
246
251 // Not noexcept because BMat16::random above is not
252 static BMat16 random(size_t dim);
253
254 void swap(BMat16 &that) noexcept { std::swap(this->_data, that._data); }
255
257 // Not noexcept
258 std::ostream &write(std::ostream &os) const;
259
260 private:
261 xpu64 _data;
262};
263
264} // namespace HPCombi
265
266#include "bmat16_impl.hpp"
267
268#endif // HPCOMBI_BMAT16_HPP_
declaration of HPCombi::BMat8
Class for fast boolean matrices of dimension up to 16 x 16.
Definition bmat16.hpp:65
std::ostream & write(std::ostream &os) const
Write this on os.
Definition bmat16_impl.hpp:350
size_t nr_rows() const noexcept
Returns the number of non-zero rows of this.
Definition bmat16_impl.hpp:228
void swap(BMat16 &that) noexcept
Definition bmat16.hpp:254
bool operator>(BMat16 const &that) const noexcept
Returns true if this is greater than that.
Definition bmat16_impl.hpp:93
BMat16 mult_transpose(BMat16 const &that) const noexcept
Returns the matrix product of this and the transpose of that.
Definition bmat16_impl.hpp:151
std::vector< uint16_t > rows() const
Returns a std::vector for rows of this.
Definition bmat16_impl.hpp:242
BMat16 mult_4bmat8(BMat16 const &that) const noexcept
Returns the matrix product of this and that.
Definition bmat16_impl.hpp:173
BMat16(BMat16 &&) noexcept=default
A constructor.
static BMat16 one(size_t dim=16) noexcept
Returns the identity BMat16.
Definition bmat16.hpp:226
BMat16 mult_naive(BMat16 const &that) const noexcept
Returns the matrix product of this and that.
Definition bmat16_impl.hpp:184
BMat16(BMat16 const &) noexcept=default
A constructor.
BMat16 mult_naive_array(BMat16 const &that) const noexcept
Returns the matrix product of this and that.
Definition bmat16_impl.hpp:207
BMat16 transpose() const noexcept
Returns the transpose of this.
Definition bmat16_impl.hpp:132
void set(size_t i, size_t j, bool val) noexcept
Sets the (i, j)th position to val.
Definition bmat16_impl.hpp:69
std::array< std::array< bool, 16 >, 16 > to_array() const noexcept
Returns the array representation of this.
Definition bmat16_impl.hpp:102
BMat16 transpose_naive() const noexcept
Returns the transpose of this.
Definition bmat16_impl.hpp:119
bool operator<(BMat16 const &that) const noexcept
Returns true if this is less than that.
Definition bmat16_impl.hpp:84
static BMat16 random()
Returns a random BMat16.
Definition bmat16_impl.hpp:258
BMat16() noexcept=default
A default constructor.
bool operator()(size_t i, size_t j) const noexcept
Returns the entry in the (i, j)th position.
Definition bmat16_impl.hpp:65
defines the macro HPCOMBI_ASSERT
#define HPCOMBI_ASSERT(x)
Definition debug.hpp:31
Definition bmat16.hpp:39
xpu64 to_block(xpu64 vect)
Converting storage type from rows to blocks of a xpu64 representing a 16x16 matrix (used in BMat16).
Definition bmat16_impl.hpp:41
uint64_t __attribute__((vector_size(32))) xpu64
Definition bmat16.hpp:41
uint16_t __attribute__((vector_size(32))) xpu16
Definition bmat16.hpp:40
xpu64 to_line(xpu64 vect)
Converting storage type from blocks to rows of a xpu64 representing a 16x16 matrix (used in BMat16).
Definition bmat16_impl.hpp:37
Definition bmat16_impl.hpp:362