CLA3P v0.3.1
Compact Linear Algebra Parallel Portable Package
Loading...
Searching...
No Matches
ex03d_permutation_matrix_create_random.cpp
#include <iostream>
#include <cla3p/perms.hpp>
/*-----------------------------------------------------*/
cla3p::int_t* permToDense(const cla3p::prm::PiMatrix& P)
{
cla3p::int_t n = P.size();
cla3p::int_t *ret = cla3p::i_calloc_t<cla3p::int_t>(n * n);
for(cla3p::int_t i = 0; i < n; i++)
ret[i * n + P(i)] = 1;
return ret;
}
/*-----------------------------------------------------*/
int main()
{
/*
* (4x4) permutation matrix
* with randomly generated unique values
*/
std::cout << P.info("P") << P;
cla3p::int_t *P4x4 = permToDense(P);
std::cout << "As a dense matrix:\n";
cla3p::blk::dns::print_to_stream(std::cout, cla3p::uplo_t::Full, 4, 4, P4x4, 4);
return 0;
}
T_Int size() const
Vector size.
Definition meta1d.hpp:50
std::string info(const std::string &header="") const
Get information about the vector.
static PxMatrix< int_t > random(int_t n)
void i_free(void *ptr)
Default deallocator for cla3p allocations.
T_Elem * i_calloc_t(std::size_t nmemb)
Type-safe allocator for zero-initialized storage.
Definition imalloc.hpp:80
@ Full
Definition enums.hpp:55
PxMatrix< int_t > PiMatrix
Integer Permutation Matrix.
Definition perms.hpp:29