42
42
T BM_ALIGN16 value[ROWS][COLS] BM_ALIGN16ATTR;
51
/// Row characteristics for transposed matrix
56
bm::set_representation best_rep;
44
59
static unsigned rows() { return ROWS; }
45
60
static unsigned cols() { return COLS; }
47
62
const T* row(unsigned row_idx) const { return value[row_idx]; }
63
T* row(unsigned row_idx) { return value[row_idx]; }
413
422
unsigned char pc = ibpc_uncompr;
414
423
unsigned row_bitcount = distance[i][i];
425
const unsigned total_possible_max = sizeof(T)*8*BPS;
416
426
switch (row_bitcount)
419
429
pc_vector[i] = ibpc_all_zero;
421
case sizeof(T)*8*BPS:
431
case total_possible_max:
422
432
pc_vector[i] = ibpc_all_one;
436
// Dense-populated set, leave it as is
437
if (row_bitcount > total_possible_max/2)
439
pc_vector[i] = ibpc_uncompr;
426
443
// scan for the closest neighbor
428
445
unsigned rmin = ~0;
547
\brief Transposed Matrix reduction based on transformation pc vector
549
template<class TMatrix>
550
void tmatrix_reduce(TMatrix& tmatrix,
551
const unsigned char* pc_vector,
552
const unsigned effective_cols)
554
BM_ASSERT(pc_vector);
556
typedef typename TMatrix::value_type value_type;
558
const unsigned char* pc_vector_end = pc_vector + tmatrix.rows();
560
unsigned cols = effective_cols ? effective_cols : tmatrix.cols();
564
unsigned ibpc = *pc_vector & 7;
567
case bm::ibpc_uncompr:
568
case bm::ibpc_all_zero:
569
case bm::ibpc_all_one:
574
unsigned n_row = *pc_vector >> 3;
575
BM_ASSERT(n_row > row);
577
value_type* r1 = tmatrix.row(row);
578
const value_type* r2 = tmatrix.row(n_row);
579
for (unsigned i = 0; i < cols; ++i)
590
} while (++pc_vector < pc_vector_end);
594
\brief Transposed Matrix restore based on transformation pc vector
596
template<class TMatrix>
597
void tmatrix_restore(TMatrix& tmatrix,
598
const unsigned char* pc_vector,
599
const unsigned effective_cols)
601
BM_ASSERT(pc_vector);
603
typedef typename TMatrix::value_type value_type;
605
unsigned cols = effective_cols ? effective_cols : tmatrix.cols();
606
for (int row = tmatrix.rows()-1; row >= 0; --row)
608
unsigned ibpc = pc_vector[row] & 7;
609
int n_row = pc_vector[row] >> 3;
611
value_type* r1 = tmatrix.row(row);
615
case bm::ibpc_uncompr:
617
case bm::ibpc_all_zero:
618
for (unsigned i = 0; i < cols; ++i)
621
case bm::ibpc_all_one:
622
for (unsigned i = 0; i < cols; ++i)
627
BM_ASSERT(n_row > row);
628
const value_type* r2 = tmatrix.row(n_row);
629
for (unsigned i = 0; i < cols; ++i)
635
BM_ASSERT(n_row > row);
636
const value_type* r2 = tmatrix.row(n_row);
637
for (unsigned i = 0; i < cols; ++i)
531
652
\brief Copy GAP block body to bit block with DGap transformation
674
@brief Compute t-matrix rows statistics used for compression
676
@param tmatrix - transposed matrix
677
@param pc_vector - row content vector
678
@param rstat - output row vector
682
template<class TMatrix>
683
void compute_tmatrix_rstat(const TMatrix& tmatrix,
684
const unsigned char* pc_vector,
685
typename TMatrix::rstat* rstat,
686
unsigned effective_cols)
689
typedef typename TMatrix::value_type value_type;
691
unsigned cols = effective_cols ? effective_cols : tmatrix.cols();
692
//unsigned cols = tmatrix.cols();
693
unsigned rows = tmatrix.rows();
695
for (unsigned i = 0; i < rows; ++i)
697
unsigned ibpc = pc_vector[i] & 7;
700
case bm::ibpc_all_zero:
701
case bm::ibpc_all_one:
703
rstat[i].bit_count = rstat[i].gap_count = 0;
704
rstat[i].best_rep = bm::set_bitset;
706
case bm::ibpc_uncompr:
709
const value_type* r1 = tmatrix.row(i);
710
const value_type* r1_end = r1 + cols;
711
// TODO: find how to deal with the potentially incorrect type-cast
712
bm::bit_count_change32((bm::word_t*)r1, (bm::word_t*)r1_end,
713
&rstat[i].bit_count, &rstat[i].gap_count);
715
const unsigned bitset_size = sizeof(value_type) * cols;
716
const unsigned total_possible_max_bits = sizeof(value_type)*8*cols;
719
bm::best_representation(rstat[i].bit_count,
720
total_possible_max_bits,
553
737
\brief Compute effective right column border of the t-matrix
602
787
void transpose(const GT* BMRESTRICT gap_buf,
603
788
BT* BMRESTRICT tmp_block)
605
const unsigned plain_count = sizeof(GT)*8;
606
const unsigned block_size = BLOCK_SIZE * sizeof(unsigned);
607
const unsigned plain_size = block_size / (sizeof(GT) * plain_count);
608
790
const unsigned arr_size = BLOCK_SIZE * sizeof(unsigned) / sizeof(GT);
610
BM_ASSERT(sizeof(tmatrix_.value) == plain_size * plain_count * sizeof(GT));
792
BM_ASSERT(sizeof(tmatrix_.value) == tmatrix_type::n_columns *
793
tmatrix_type::n_rows * sizeof(GT));
612
795
// load all GAP as D-GAP(but not head word) into aligned bit-block
613
796
gap_2_bitblock(gap_buf, tmp_block, BLOCK_SIZE);
616
vect_bit_transpose<GT, plain_count, plain_size>
799
vect_bit_transpose<GT, tmatrix_type::n_rows, tmatrix_type::n_columns>
617
800
((GT*)tmp_block, arr_size, tmatrix_.value);
619
802
// calculate number of non-zero columns
620
eff_cols_ = find_effective_columns(tmatrix_);
803
eff_cols_ = find_effective_columns(tmatrix_);
806
void compute_distance_matrix()
808
tmatrix_distance<typename tmatrix_type::value_type,
809
tmatrix_type::n_rows, tmatrix_type::n_columns>
810
(tmatrix_.value, distance_);
812
// make compression descriptor vector and statistics vector
813
bit_iblock_make_pcv<unsigned char,
814
tmatrix_type::n_rows, tmatrix_type::n_columns>
815
(distance_, pc_vector_);
817
bit_iblock_pcv_stat(pc_vector_,
818
pc_vector_ + tmatrix_type::n_rows,
824
tmatrix_reduce(tmatrix_, pc_vector_, eff_cols_);
825
compute_tmatrix_rstat(tmatrix_, pc_vector_, rstat_vector_, eff_cols_);
830
tmatrix_restore(tmatrix_, pc_vector_, eff_cols_);
624
834
/// Restore GAP block from the transposed matrix
627
837
GT* BMRESTRICT gap_buf,
628
838
BT* BMRESTRICT tmp_block)
630
const unsigned plain_count = sizeof(GT)*8;
631
const unsigned block_size = BLOCK_SIZE * sizeof(unsigned);
632
const unsigned plain_size = block_size / (sizeof(GT) * plain_count);
634
BM_ASSERT(sizeof(tmatrix_.value) == plain_size * plain_count * sizeof(GT));
840
BM_ASSERT(sizeof(tmatrix_.value) == tmatrix_type::n_columns *
841
tmatrix_type::n_rows * sizeof(GT));
636
843
// restore into a temp buffer
637
844
GT* gap_tmp = (GT*)tmp_block;
638
845
//*gap_tmp++ = gap_head;
640
vect_bit_trestore<GT, plain_count, plain_size>(tmatrix_.value, gap_tmp);
847
vect_bit_trestore<GT, tmatrix_type::n_rows, tmatrix_type::n_columns>(tmatrix_.value, gap_tmp);
642
849
// D-Gap to GAP block recalculation
643
850
gap_tmp = (GT*)tmp_block;