@@ -58,6 +58,7 @@ TEST_FUNCTION_START(gr_mat_scalar, state)
58
58
d = gr_heap_init (ctx );
59
59
c_other = gr_heap_init (ctx_other );
60
60
61
+ GR_MUST_SUCCEED (gr_mat_randtest (A , state , ctx ));
61
62
GR_MUST_SUCCEED (gr_randtest (c , state , ctx ));
62
63
63
64
have_other = (gr_set_other (c_other , c , ctx , ctx_other ) == GR_SUCCESS );
@@ -70,62 +71,78 @@ TEST_FUNCTION_START(gr_mat_scalar, state)
70
71
{
71
72
status = GR_SUCCESS ;
72
73
74
+ gr_mat_struct * A_or_B2_alias ;
75
+ gr_mat_struct * A_or_B3_alias ;
76
+
77
+ if (n_randint (state , 2 ))
78
+ {
79
+ A_or_B2_alias = A ;
80
+ A_or_B3_alias = A ;
81
+ }
82
+ else
83
+ {
84
+ status |= gr_mat_set (B2 , A , ctx );
85
+ status |= gr_mat_set (B3 , A , ctx );
86
+ A_or_B2_alias = B2 ;
87
+ A_or_B3_alias = B3 ;
88
+ }
89
+
73
90
if (testcase == 0 )
74
91
{
75
92
/* A + c == A + C */
76
93
status |= gr_mat_add (B1 , A , Cmn , ctx );
77
- status |= gr_mat_add_scalar (B2 , A , c , ctx );
94
+ status |= gr_mat_add_scalar (B2 , A_or_B2_alias , c , ctx );
78
95
if (have_other )
79
- status |= gr_mat_add_scalar_other (B3 , A , c_other , ctx_other , ctx );
96
+ status |= gr_mat_add_scalar_other (B3 , A_or_B3_alias , c_other , ctx_other , ctx );
80
97
}
81
98
else if (testcase == 1 )
82
99
{
83
100
/* c + A == C + A */
84
101
status |= gr_mat_add (B1 , Cmn , A , ctx );
85
- status |= gr_mat_scalar_add (B2 , c , A , ctx );
102
+ status |= gr_mat_scalar_add (B2 , c , A_or_B2_alias , ctx );
86
103
if (have_other )
87
- status |= gr_mat_scalar_other_add (B3 , c_other , ctx_other , A , ctx );
104
+ status |= gr_mat_scalar_other_add (B3 , c_other , ctx_other , A_or_B3_alias , ctx );
88
105
}
89
106
else if (testcase == 2 )
90
107
{
91
108
/* A - c == A - C */
92
109
status |= gr_mat_sub (B1 , A , Cmn , ctx );
93
- status |= gr_mat_sub_scalar (B2 , A , c , ctx );
110
+ status |= gr_mat_sub_scalar (B2 , A_or_B2_alias , c , ctx );
94
111
if (have_other )
95
- status |= gr_mat_sub_scalar_other (B3 , A , c_other , ctx_other , ctx );
112
+ status |= gr_mat_sub_scalar_other (B3 , A_or_B3_alias , c_other , ctx_other , ctx );
96
113
}
97
114
else if (testcase == 3 )
98
115
{
99
116
/* c - A == C - A */
100
117
status |= gr_mat_sub (B1 , Cmn , A , ctx );
101
- status |= gr_mat_scalar_sub (B2 , c , A , ctx );
118
+ status |= gr_mat_scalar_sub (B2 , c , A_or_B2_alias , ctx );
102
119
if (have_other )
103
- status |= gr_mat_scalar_other_sub (B3 , c_other , ctx_other , A , ctx );
120
+ status |= gr_mat_scalar_other_sub (B3 , c_other , ctx_other , A_or_B3_alias , ctx );
104
121
}
105
122
else if (testcase == 4 )
106
123
{
107
124
/* A * c == A * C */
108
125
status |= gr_mat_mul (B1 , A , Cnn , ctx );
109
- status |= gr_mat_mul_scalar (B2 , A , c , ctx );
126
+ status |= gr_mat_mul_scalar (B2 , A_or_B2_alias , c , ctx );
110
127
if (have_other )
111
- status |= gr_mat_mul_scalar_other (B3 , A , c_other , ctx_other , ctx );
128
+ status |= gr_mat_mul_scalar_other (B3 , A_or_B3_alias , c_other , ctx_other , ctx );
112
129
}
113
130
else if (testcase == 5 )
114
131
{
115
132
/* A * c == A * C */
116
133
status |= gr_mat_mul (B1 , Cmm , A , ctx );
117
- status |= gr_mat_scalar_mul (B2 , c , A , ctx );
134
+ status |= gr_mat_scalar_mul (B2 , c , A_or_B2_alias , ctx );
118
135
if (have_other )
119
- status |= gr_mat_scalar_other_mul (B3 , c_other , ctx_other , A , ctx );
136
+ status |= gr_mat_scalar_other_mul (B3 , c_other , ctx_other , A_or_B3_alias , ctx );
120
137
}
121
138
else if (testcase == 6 )
122
139
{
123
140
/* A / c == A * c^(-1) */
124
141
status |= gr_inv (d , c , ctx );
125
142
status |= gr_mat_mul_scalar (B1 , A , d , ctx );
126
- status |= gr_mat_div_scalar (B2 , A , c , ctx );
143
+ status |= gr_mat_div_scalar (B2 , A_or_B2_alias , c , ctx );
127
144
if (have_other )
128
- status |= gr_mat_div_scalar_other (B3 , A , c_other , ctx_other , ctx );
145
+ status |= gr_mat_div_scalar_other (B3 , A_or_B3_alias , c_other , ctx_other , ctx );
129
146
}
130
147
131
148
if (status == GR_SUCCESS && gr_mat_equal (B1 , B2 , ctx ) == T_FALSE )
0 commit comments