HPCombi
High Performance Combinatorics in C++ using vector instructions v1.0.3
Loading...
Searching...
No Matches
HPCombi::BMat16 Class Reference

Class for fast boolean matrices of dimension up to 16 x 16. More...

#include <bmat16.hpp>

Public Member Functions

 BMat16 () noexcept=default
 A default constructor.
 
 BMat16 (xpu64 mat) noexcept
 A constructor.
 
 BMat16 (uint64_t n0, uint64_t n1, uint64_t n2, uint64_t n3) noexcept
 A constructor.
 
 BMat16 (std::vector< std::vector< bool > > const &mat) noexcept
 A constructor.
 
 BMat16 (BMat16 const &) noexcept=default
 A constructor.
 
 BMat16 (BMat16 &&) noexcept=default
 A constructor.
 
BMat16operator= (BMat16 const &) noexcept=default
 A constructor.
 
BMat16operator= (BMat16 &&) noexcept=default
 A constructor.
 
 ~BMat16 ()=default
 A default destructor.
 
bool operator== (BMat16 const &that) const noexcept
 Returns true if this equals that.
 
bool operator!= (BMat16 const &that) const noexcept
 Returns true if this does not equal that.
 
bool operator< (BMat16 const &that) const noexcept
 Returns true if this is less than that.
 
bool operator> (BMat16 const &that) const noexcept
 Returns true if this is greater than that.
 
bool operator() (size_t i, size_t j) const noexcept
 Returns the entry in the (i, j)th position.
 
void set (size_t i, size_t j, bool val) noexcept
 Sets the (i, j)th position to val.
 
std::array< std::array< bool, 16 >, 16 > to_array () const noexcept
 Returns the array representation of this.
 
BMat16 operator| (BMat16 const &that) const noexcept
 Returns the bitwise or between this and that.
 
BMat16 transpose_naive () const noexcept
 Returns the transpose of this.
 
BMat16 transpose () const noexcept
 Returns the transpose of this.
 
BMat16 mult_transpose (BMat16 const &that) const noexcept
 Returns the matrix product of this and the transpose of that.
 
BMat16 mult_4bmat8 (BMat16 const &that) const noexcept
 Returns the matrix product of this and that.
 
BMat16 operator* (BMat16 const &that) const noexcept
 Returns the matrix product of this and that.
 
BMat16 mult_naive (BMat16 const &that) const noexcept
 Returns the matrix product of this and that.
 
BMat16 mult_naive_array (BMat16 const &that) const noexcept
 Returns the matrix product of this and that.
 
size_t nr_rows () const noexcept
 Returns the number of non-zero rows of this.
 
std::vector< uint16_t > rows () const
 Returns a std::vector for rows of this.
 
void swap (BMat16 &that) noexcept
 
std::ostream & write (std::ostream &os) const
 Write this on os.
 

Static Public Member Functions

static BMat16 one (size_t dim=16) noexcept
 Returns the identity BMat16.
 
static BMat16 random ()
 Returns a random BMat16.
 
static BMat16 random (size_t dim)
 Returns a random square BMat16 up to dimension dim.
 

Detailed Description

Class for fast boolean matrices of dimension up to 16 x 16.

The methods for these small matrices over the boolean semiring are more optimised than the generic methods for boolean matrices. Note that all BMat16 are represented internally as an 16 x 16 matrix; any entries not defined by the user are taken to be 0. This does not affect the results of any calculations.

BMat16 is a trivial class.

Constructor & Destructor Documentation

◆ BMat16() [1/6]

HPCombi::BMat16::BMat16 ( )
defaultnoexcept

A default constructor.

This constructor gives no guarantees on what the matrix will contain.

◆ BMat16() [2/6]

HPCombi::BMat16::BMat16 ( xpu64 mat)
inlineexplicitnoexcept

A constructor.

This constructor initializes a matrix with a 256-bit register The rows are equal to the 16 chunks, of 16 bits each, of the binary representation of the matrix.

◆ BMat16() [3/6]

HPCombi::BMat16::BMat16 ( uint64_t n0,
uint64_t n1,
uint64_t n2,
uint64_t n3 )
inlineexplicitnoexcept

A constructor.

This constructor initializes a matrix with 4 64 bits unsigned int Each uint represents one of the four quarter (8x8 matrix).

◆ BMat16() [4/6]

HPCombi::BMat16::BMat16 ( std::vector< std::vector< bool > > const & mat)
inlineexplicitnoexcept

A constructor.

This constructor initializes a matrix where the rows of the matrix are the vectors in mat.

◆ BMat16() [5/6]

HPCombi::BMat16::BMat16 ( BMat16 const & )
defaultnoexcept

A constructor.

This is the copy constructor.

◆ BMat16() [6/6]

HPCombi::BMat16::BMat16 ( BMat16 && )
defaultnoexcept

A constructor.

This is the move constructor.

◆ ~BMat16()

HPCombi::BMat16::~BMat16 ( )
default

A default destructor.

Member Function Documentation

◆ mult_4bmat8()

BMat16 HPCombi::BMat16::mult_4bmat8 ( BMat16 const & that) const
inlinenoexcept

Returns the matrix product of this and that.

This method returns the standard matrix product (over the boolean semiring) of two BMat16 objects. It comes down to 8 products of 8x8 matrices, which make up a 16x16 when we cut it into 4.

◆ mult_naive()

BMat16 HPCombi::BMat16::mult_naive ( BMat16 const & that) const
inlinenoexcept

Returns the matrix product of this and that.

This method returns the standard matrix product (over the boolean semiring) of two BMat16 objects. It performs the most naive approach by simply iterating through all entries using the access operator of BMat16

◆ mult_naive_array()

BMat16 HPCombi::BMat16::mult_naive_array ( BMat16 const & that) const
inlinenoexcept

Returns the matrix product of this and that.

This method returns the standard matrix product (over the boolean semiring) of two BMat16 objects. It performs the most naive approach by simply iterating through all entries using array conversion.

◆ mult_transpose()

BMat16 HPCombi::BMat16::mult_transpose ( BMat16 const & that) const
inlinenoexcept

Returns the matrix product of this and the transpose of that.

This method returns the standard matrix product (over the boolean semiring) of two BMat16 objects. This is faster than transposing that and calling the product of this with it. Implementation uses vector instructions.

◆ nr_rows()

size_t HPCombi::BMat16::nr_rows ( ) const
inlinenoexcept

Returns the number of non-zero rows of this.

Vectorized version which doesn't work due to the absence of popcnt in simde

◆ one()

static BMat16 HPCombi::BMat16::one ( size_t dim = 16)
inlinestaticnoexcept

Returns the identity BMat16.

This method returns the 16 x 16 BMat16 with 1s on the main diagonal.

◆ operator!=()

bool HPCombi::BMat16::operator!= ( BMat16 const & that) const
inlinenoexcept

Returns true if this does not equal that.

This method checks the mathematical inequality of two BMat16 objects.

◆ operator()()

bool HPCombi::BMat16::operator() ( size_t i,
size_t j ) const
inlinenoexcept

Returns the entry in the (i, j)th position.

This method returns the entry in the (i, j)th position. Note that since all matrices are internally represented as 16 x 16, it is possible to access entries that you might not believe exist.

◆ operator*()

BMat16 HPCombi::BMat16::operator* ( BMat16 const & that) const
inlinenoexcept

Returns the matrix product of this and that.

This method returns the standard matrix product (over the boolean semiring) of two BMat16 objects. This is a fast implementation using transposition and vector instructions.

◆ operator<()

bool HPCombi::BMat16::operator< ( BMat16 const & that) const
inlinenoexcept

Returns true if this is less than that.

This method checks whether a BMat16 objects is less than another.

◆ operator=() [1/2]

BMat16 & HPCombi::BMat16::operator= ( BMat16 && )
defaultnoexcept

A constructor.

This is the move assignment constructor.

◆ operator=() [2/2]

BMat16 & HPCombi::BMat16::operator= ( BMat16 const & )
defaultnoexcept

A constructor.

This is the copy assignment constructor.

◆ operator==()

bool HPCombi::BMat16::operator== ( BMat16 const & that) const
inlinenoexcept

Returns true if this equals that.

This method checks the mathematical equality of two BMat16 objects.

◆ operator>()

bool HPCombi::BMat16::operator> ( BMat16 const & that) const
inlinenoexcept

Returns true if this is greater than that.

This method checks whether a BMat16 objects is greater than another.

◆ operator|()

BMat16 HPCombi::BMat16::operator| ( BMat16 const & that) const
inlinenoexcept

Returns the bitwise or between this and that.

This method perform the bitwise operator on the matrices and returns the result as a BMat16.

◆ random() [1/2]

BMat16 HPCombi::BMat16::random ( )
inlinestatic

Returns a random BMat16.

This method returns a BMat16 chosen at random.

◆ random() [2/2]

BMat16 HPCombi::BMat16::random ( size_t dim)
inlinestatic

Returns a random square BMat16 up to dimension dim.

This method returns a BMat16 chosen at random, where only the top-left dim x dim entries may be non-zero.

◆ rows()

std::vector< uint16_t > HPCombi::BMat16::rows ( ) const
inline

Returns a std::vector for rows of this.

◆ set()

void HPCombi::BMat16::set ( size_t i,
size_t j,
bool val )
inlinenoexcept

Sets the (i, j)th position to val.

This method sets the (i, j)th entry of this to val. Uses the bit twiddle for setting bits found here.

◆ swap()

void HPCombi::BMat16::swap ( BMat16 & that)
inlinenoexcept

◆ to_array()

std::array< std::array< bool, 16 >, 16 > HPCombi::BMat16::to_array ( ) const
inlinenoexcept

Returns the array representation of this.

Returns a two dimensional 16 x 16 array representing the matrix.

◆ transpose()

BMat16 HPCombi::BMat16::transpose ( ) const
inlinenoexcept

Returns the transpose of this.

Returns the standard matrix transpose of a BMat16. Uses the technique found in Knuth AoCP Vol. 4 Fasc. 1a, p. 15.

◆ transpose_naive()

BMat16 HPCombi::BMat16::transpose_naive ( ) const
inlinenoexcept

Returns the transpose of this.

Returns the standard matrix transpose of a BMat16. Uses a naive technique, by simply iterating through all entries.

◆ write()

std::ostream & HPCombi::BMat16::write ( std::ostream & os) const
inline

Write this on os.


The documentation for this class was generated from the following files: