File: testing.c

package info (click to toggle)
libm4ri 20200125-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,560 kB
  • sloc: ansic: 12,633; sh: 4,304; makefile: 137
file content (42 lines) | stat: -rw-r--r-- 899 bytes parent folder | download | duplicates (2)
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
#include "testing.h"

mzd_t *mzd_init_test_matrix_random(rci_t M, rci_t N, rci_t m, rci_t n, word pattern, mzd_t **A) {
  *A = mzd_init(M, N);

  for(rci_t i=0; i<M; i++) {
    for(rci_t j=0; j<(*A)->width; j++) {
      (*A)->rows[i][j] = pattern;
    }
  }

  mzd_t* a = mzd_init_window(*A, 0, 0, m, n);
  mzd_randomize(a);

  return a;
}

void mzd_free_test_matrix_random(mzd_t *A, mzd_t *a) {
  mzd_free(a);
  mzd_free(A);
}

int mzd_check_pattern(mzd_t *A, rci_t m, rci_t n, word pattern) {

  for(rci_t i=0; i<A->nrows; i++) {
    if (i >= m) {
      for(rci_t j=0; j<A->width; j++)
        if(A->rows[i][j] ^ pattern) {
          return 1;
        }
    } else {
      if ((A->rows[i][n/m4ri_radix] ^ pattern) & ~A->high_bitmask )
        return 1;

      for(rci_t j=n/m4ri_radix+1; j<A->width; j++)
        if(A->rows[i][j] ^ pattern) {
          return 1;
        }
    }
  }
  return 0;
}