checkpoint commit

This commit is contained in:
Miguel M 2023-05-01 14:38:56 +01:00
parent bba8aa9e17
commit 4b1db5cec0
4 changed files with 32 additions and 29 deletions

View File

@ -33,24 +33,26 @@
#include <stddef.h>
#include "../includes/data.h"
#include "../includes/permutation.h"
// Convert from CG representation to P representation.
//
// `p` isn't required to be initialized, as this function will overwrite every
// entry (provided that `p` is of the expected size).row
// `p` isn't required to be initialized, only allocated.
void FromCgToP(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* restrict cg, data_t* restrict p);
// Convert from P representation to CG representation.
//
// `cg` isn't required to be initialized, only allocated.
void FromPToCg(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
data_t* restrict cg, const data_t* restrict p);
// Debug print a CG row.
void PrintCg(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* cg);
const data_t* cg);
// Debug print a P row.
void PrintP(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* p);
const data_t* p);
#endif

View File

@ -2,17 +2,17 @@
#define ACED_INCLUDES_MATRIX_H_
#include <stddef.h>
#include "../includes/data.h"
// Struct representing the input matrix.
typedef struct
{
// Number of elements in one row.
size_t row_len;
// Pointer to the buffer containing the matrix's entries.
data_t *head;
// Number of entries in the matrix.
size_t len;
typedef struct {
// Number of elements in one row.
size_t row_len;
// Pointer to the buffer containing the matrix's entries.
data_t *head;
// Number of entries in the matrix.
size_t len;
} matrix_t;
// Prints a debug view of a `matrix_t` to standard output.
@ -22,7 +22,7 @@ void DebugPrintMatrix(matrix_t *matrix);
void PrintMatrixRow(matrix_t *matrix, size_t row);
// Parse a matrix from the standard input.
//
//
// 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.
@ -31,4 +31,4 @@ void PrintMatrixRow(matrix_t *matrix, size_t row);
// row_len The number of entries in one row.
matrix_t ParseMatrix(size_t row_len);
#endif // ACED_INCLUDES_MATRIX_H_
#endif // ACED_INCLUDES_MATRIX_H_

View File

@ -9,23 +9,22 @@
// References:
// [1]: https://en.m.wikipedia.org/wiki/Heap%27s_algorithm
#include <stddef.h>
#include <stdbool.h>
#include <stddef.h>
typedef struct
{
size_t len; // The number of elements being permuted.
size_t *permutation; // Current permutation, as indices.
_Bool exhausted; // Whether there are any permutations left to generate.
size_t *stack;
size_t pointer;
typedef struct {
size_t len; // The number of elements being permuted.
size_t *restrict permutation; // Current permutation, as indices.
_Bool exhausted; // Whether there are any permutations left to generate.
size_t *restrict stack;
size_t pointer;
} permutation_generator_t;
// Create a `permutation_generator_t`.
// This needs to be done only once. Afterwards, use only `PermutationReset`.
// After getting a new generator, you still need to call `PermutationReset`, or
// behaviour is undefined.
//
//
// Arguments:
// len Number of elements to permute (from `0` to `len-1`).
permutation_generator_t PermutationNewGenerator(size_t len);
@ -35,7 +34,7 @@ permutation_generator_t PermutationNewGenerator(size_t len);
void PermutationReset(permutation_generator_t *permutation_generator);
// Generate the next permutation.
//
//
// Calling this after `permutation_generator->exhausted` is true results in
// undefined behaviour.
void PermutationNext(permutation_generator_t *permutation_generator);
@ -45,4 +44,4 @@ void PermutationNext(permutation_generator_t *permutation_generator);
// This will invalidate the generator.
void PermutationFree(permutation_generator_t *permutation_generator);
#endif //ACED_INCLUDES_PERMUTATION_H_
#endif // ACED_INCLUDES_PERMUTATION_H_

View File

@ -2,7 +2,8 @@
#include <stdio.h>
static inline size_t CgJointIndex(size_t a_out, size_t b_out, size_t a_in __attribute__((unused)),
static inline size_t CgJointIndex(size_t a_out, size_t b_out,
size_t a_in __attribute__((unused)),
size_t b_in, size_t a_out_i, size_t b_out_i,
size_t a_in_i, size_t b_in_i) {
return b_out_i +
@ -23,9 +24,10 @@ static inline size_t CgBMarginalIndex(size_t a_out, size_t b_out, size_t a_in,
b_out_i + (b_out - 1) * b_in_i;
}
static inline size_t PIndex(size_t a_out, size_t b_out, size_t a_in __attribute__((unused)),
size_t b_in, size_t a_out_i, size_t b_out_i,
size_t a_in_i, size_t b_in_i) {
static inline size_t PIndex(size_t a_out, size_t b_out,
size_t a_in __attribute__((unused)), size_t b_in,
size_t a_out_i, size_t b_out_i, size_t a_in_i,
size_t b_in_i) {
return b_out_i + b_out * (b_in_i + b_in * (a_out_i + a_out * a_in_i));
}