-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatrix-blocking.h
55 lines (45 loc) · 2.34 KB
/
matrix-blocking.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef _matrix_blocking_h
#define _matrix_blocking_h
#include <stdlib.h>
#include "matrix-storage.h"
/* Describes a square block located somewhere inside a larger square matrix.
* For example, the trivial block has matrix_size = block_size and
* block_row_idx = block_col_idx = 0.
*
* For efficiency reasons, this contains only metadata about the block. The
* data itself are stored elsewhere, and this struct only provides methods to
* calculate indices in the data matrix.
*/
typedef struct square_mat_square_block {
// The edge size of each block.
int block_size;
// The indices of the block. For example, if matrix_size is 10, block_size is 3,
// block_row_idx is 1, and block_col_idx is 2, then the top-left corner of
// this block is element M[3,6] of the original matrix M, and the bottom-left
// corner is element M[5,8].
int block_row_idx, block_col_idx;
square_matrix_storage_format *format;
} square_mat_square_block;
square_mat_square_block* square_mat_square_block_new(int block_size, int block_row_idx, int block_col_idx, square_matrix_storage_format* format);
square_mat_square_block* trivial_block(square_matrix_storage_format* format);
/* Make @next_b into a subblock of @b. It is assumed that we are dividing
* b into subblock_count^2 blocks, and we want subblock (subblock_row_idx, subblock_col_idx)
* in that collection of subblocks.
* @param subblock_count must be a divisor of b->block_size.
*
* Similar to get_subblock, but useful when we care about performance and we
* already have a block object available for mutation.
*/
void set_subblock(square_mat_square_block* next_b, square_mat_square_block* b, int subblock_count, int subblock_row_idx, int subblock_col_idx);
/* Get a subblock of some existing block. It is assumed that we are dividing
* b into subblock_count^2 blocks, and we want subblock (subblock_row_idx, subblock_col_idx)
* in that collection of subblocks.
* @param subblock_count must be a divisor of b->block_size.
*/
square_mat_square_block* get_subblock(square_mat_square_block* b, int subblock_count, int subblock_row_idx, int subblock_col_idx);
int get_top_left_index(square_mat_square_block* b);
/* Get the index in the full matrix of element
* (row_in_block_idx, col_in_block_idx) of block b.
*/
int get_index_in_matrix(square_mat_square_block* b, int row_in_block_idx, int col_in_block_idx);
#endif