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
     56
     57
     58
     59
     60
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>

// function initGeMatrix
/*
   Your Code here.
*/

// function printGeMatrix
/*
   Your Code here.
*/

#ifndef COLMAJOR
#define COLMAJOR 1
#endif

int
main()
{
    printf("COLMAJOR = %d\n", COLMAJOR);

    size_t m = 5, n = 10;

    ptrdiff_t incRowA = COLMAJOR ? 0 : 0;       // <- FIXME
    ptrdiff_t incColA = COLMAJOR ? 0 : 0;       // <- FIXME

    // allocate memory for A
    double *A = malloc(m*n*sizeof(double));
    if (!A) {
        abort();
    }

    // initialize matrix A
    initGeMatrix(m, n, A, incRowA, incColA);

    // print matrix A
    printf("A =\n");
    printGeMatrix(m, n, A, incRowA, incColA);

    // print how elements are stored in memory
    printf("memory layout of A:\n");
    // use printGeMatrix!                       // <- Your code here

    // print a matrix view of A
    printf("A(0:2, 0:3) =\n");
    printGeMatrix(0, 0, A, incRowA, incColA);   // <- FIXME

    // print a matrix view of A
    printf("A(2:4, 3:8) =\n");
    printGeMatrix(0, 0, A, incRowA, incColA);   // <- FIXME

    // print a matrix view of A
    printf("A(2:4, 3:8)^T =\n");
    printGeMatrix(0, 0, A, incRowA, incColA);   // <- FIXME

    // release memory
    free(A);
}