File: test_transpose.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 (116 lines) | stat: -rw-r--r-- 2,833 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * test_transpose.c
 *
 * Application to test functionality of mzd_transpose.
 *
 * Copyright (C) 2011  Carlo Wood  <carlo@alinoe.com>
 * RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
 * Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <m4ri/m4ri.h>

int test_size[18] = {
  1, 3, 4, 7, 8, 11, 16, 17, 32, 40, 64, 80, 128, 160, 192, 240, 256, 512
};

int test_transpose(int i)
{
  int failure = 0;
  rci_t m = test_size[i];
  printf("transpose m: %4d, n: ", m);
  for (int j = 0; j < 18 && !failure; ++j) {
    rci_t n = test_size[j];
    printf("%d", n);
    if (j != 17)
      printf(",");
    int size = m * n;
    int loop_size = MAX(64 * 64 / size, 2);
    for (int i = 0; i < loop_size && !failure; ++i)
    {
      mzd_t* A = mzd_init(m, n);
      mzd_t* B = mzd_init(m, n);
      mzd_randomize(A);
      mzd_randomize(B);
      mzd_t* C = mzd_add(NULL, A, B);
      mzd_t* AT = mzd_init(n, m);
      mzd_randomize(AT);
      mzd_transpose(AT, A);
      mzd_t* BT = mzd_transpose(NULL, B);
      mzd_t* CT = mzd_add(NULL, AT, BT);
      mzd_t* CTT = mzd_transpose(NULL, CT);
      if (!mzd_equal(C, CTT))
	++failure;
      mzd_free(A);
      mzd_free(B);
      mzd_free(C);
      mzd_free(AT);
      mzd_free(BT);
      mzd_free(CT);
      mzd_free(CTT);
    }
  }
  printf("  ");
  if (failure) {
    printf("FAILED\n");
  }
  else
    printf("passed\n");
  return failure;
}

int main()
{
  int status = 0;

  int m=3;
  int n=64;

  mzd_t* A = mzd_init(m, n);
  mzd_t* B = mzd_init(m, n);
  mzd_randomize(A);
  mzd_randomize(B);
  mzd_t* C = mzd_add(NULL, A, B);
  mzd_t* AT = mzd_init(n, m);
  mzd_randomize(AT);
  mzd_transpose(AT, A);
  mzd_t* BT = mzd_transpose(NULL, B);
  mzd_t* CT = mzd_add(NULL, AT, BT);
  mzd_t* CTT = mzd_transpose(NULL, CT);
  if (!mzd_equal(C, CTT))
    ++status;
  mzd_free(A);
  mzd_free(B);
  mzd_free(C);
  mzd_free(AT);
  mzd_free(BT);
  mzd_free(CT);
  mzd_free(CTT);


  /* for (int i = 0; i < 18; ++i) { */
  /*     status += test_transpose(i); */
  /* } */

  if (!status) {
    printf("All tests passed.\n");
  } else {
    printf("TEST FAILED!\n");
    return 1;
  }

  return 0;
}