Matrix parsing based on compile-time information
This commit is contained in:
parent
0b79ca9ac3
commit
b3de17e14d
|
@ -39,8 +39,10 @@ void DebugPrintGrid(matrix_t *grid);
|
|||
//
|
||||
// This function parses an extended matrix (C|l), where C is an n×m matrix, and
|
||||
// l is an m-sized column vector. This input is given in standard input as
|
||||
// whitespace separated entries.
|
||||
//
|
||||
// <row length> <whitespace separated entries>
|
||||
matrix_t ParseMatrix(void);
|
||||
// Arguments:
|
||||
// row_len The number of entries in one row.
|
||||
matrix_t ParseMatrix(size_t row_len);
|
||||
|
||||
#endif // ACED__MATRIX_H_
|
16
src/main.c
16
src/main.c
|
@ -4,9 +4,21 @@
|
|||
// #define STBDS_NO_SHORT_NAMES
|
||||
// #include "../contrib/stb/stb_ds.h"
|
||||
|
||||
// Temporarily defined here.
|
||||
// Later, should be defined upon compilation, with -D flag (for gcc).
|
||||
#define A_OUTPUTS 3
|
||||
#define B_OUTPUTS 3
|
||||
#define A_INPUTS 3
|
||||
#define B_INPUTS 3
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
matrix_t grid = ParseMatrix();
|
||||
DebugPrintGrid(&grid);
|
||||
size_t a_out = A_OUTPUTS;
|
||||
size_t b_out = B_OUTPUTS;
|
||||
size_t a_in = A_INPUTS;
|
||||
size_t b_in = B_INPUTS;
|
||||
size_t row_len = ((a_out-1)*(b_out-1)*a_in*b_in + (a_out-1)*a_in +
|
||||
(b_out-1)*b_in);
|
||||
matrix_t matrix = ParseMatrix(row_len);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -104,11 +104,8 @@ matrix_bufs_t compact_buffers(matrix_t *matrix) {
|
|||
// what we have is contiguous blocks of strings, structured as
|
||||
//
|
||||
// <string length> <characters...>
|
||||
matrix_t ParseMatrix(void)
|
||||
matrix_t ParseMatrix(size_t row_len)
|
||||
{
|
||||
size_t row_len;
|
||||
scanf("%zu", &row_len);
|
||||
|
||||
size_t data_cap = 32; // Initial value is arbitrary.
|
||||
size_t data_len = 0; // Number of characters written so far.
|
||||
size_t entries_len = 0; // Number of strings written so far.
|
||||
|
|
Loading…
Reference in New Issue