@@ -59,19 +59,39 @@ int test_solve_left_random(rci_t mA, rci_t nA, rci_t nB, int consistent) {
59
59
mzd_t * secret = mzd_init (nA , nB );
60
60
mzd_randomize (A );
61
61
mzd_randomize (secret );
62
- mzd_t * B ;
63
- if (consistent ) {
64
- B = mzd_mul (NULL , A , secret , 0 );
62
+ mzd_t * B ;
63
+ if (consistent ) {
64
+ B = mzd_mul (NULL , A , secret , 0 );
65
65
assert (B -> nrows == A -> nrows );
66
66
assert (B -> ncols == nB );
67
67
}
68
68
else {
69
- B = mzd_init (mB , nB );
69
+ B = mzd_init (mA , nB );
70
70
mzd_randomize (B );
71
71
}
72
+ mzd_free (secret );
73
+
72
74
// copy A & B
73
75
mzd_t * Acopy = mzd_copy (NULL , A );
74
76
mzd_t * Bcopy = mzd_copy (NULL , B );
77
+
78
+ // add rows to B, s.t. X fits into B
79
+ if (B -> nrows < mB ) {
80
+ mzd_t * padding = mzd_init (nA - mA , nB );
81
+ if (!consistent )
82
+ mzd_randomize (padding );
83
+ mzd_t * B_padded = mzd_stack (NULL , B , padding );
84
+ mzd_free (B );
85
+ B = B_padded ;
86
+ mzd_free (padding );
87
+
88
+ mzd_t const * Bpad = mzd_init_window_const (B , A -> nrows + 1 , 0 , B -> nrows , B -> ncols );
89
+ mzd_print (Bpad );
90
+ mzd_free_window ((mzd_t * ) Bpad );
91
+ }
92
+ assert (B -> nrows == mB );
93
+ assert (B -> ncols == nB );
94
+
75
95
int consistency = !mzd_solve_left (A , B , 0 , 1 );
76
96
77
97
if (consistent && !consistency ) {
@@ -83,8 +103,8 @@ int test_solve_left_random(rci_t mA, rci_t nA, rci_t nB, int consistent) {
83
103
printf ("skipped (OK, no solution found)\n" );
84
104
return 0 ;
85
105
}
86
- // copy B
87
- mzd_t * X = mzd_submatrix ( NULL , B , 0 , 0 , A -> ncols , B -> ncols );
106
+
107
+ mzd_t const * X = mzd_init_window_const ( B , 0 , 0 , A -> ncols , B -> ncols );
88
108
mzd_t * B1 = mzd_mul (NULL , Acopy , X , 0 );
89
109
mzd_t * Z = mzd_add (NULL , Bcopy , B1 );
90
110
@@ -99,8 +119,8 @@ int test_solve_left_random(rci_t mA, rci_t nA, rci_t nB, int consistent) {
99
119
mzd_free (B1 );
100
120
mzd_free (Z );
101
121
mzd_free (A );
122
+ mzd_free ((mzd_t * ) X );
102
123
mzd_free (B );
103
- mzd_free (X );
104
124
return status ;
105
125
}
106
126
@@ -114,12 +134,14 @@ int main() {
114
134
status += test_solve_left_random (1100 , 1100 , 1000 , 1 );
115
135
status += test_solve_left_random (1000 , 1000 , 1100 , 1 );
116
136
status += test_solve_left_random (1100 , 1000 , 1100 , 1 );
137
+ status += test_solve_left_random (1000 , 1100 , 1000 , 1 );
117
138
118
139
status += test_solve_left_random (1100 , 1000 , 1000 , 0 );
119
140
status += test_solve_left_random (1000 , 1000 , 1000 , 0 );
120
141
status += test_solve_left_random (1100 , 1100 , 1000 , 0 );
121
142
status += test_solve_left_random (1000 , 1000 , 1100 , 0 );
122
143
status += test_solve_left_random (1100 , 1000 , 1100 , 0 );
144
+ status += test_solve_left_random (1000 , 1100 , 1000 , 0 );
123
145
124
146
125
147
for (size_t i = 0 ; i < 100 ; i ++ ) {
0 commit comments