forked from flame/blis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
02level1m_diag.c
246 lines (178 loc) · 7.71 KB
/
02level1m_diag.c
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas at Austin
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of The University of Texas nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "blis.h"
int main( int argc, char** argv )
{
double* a;
double* b;
double* c;
double* d;
double* e;
double* h;
dim_t m, n;
inc_t rs, cs;
// Initialize some basic constants.
double zero = 0.0;
double minus_one = -1.0;
//
// This file demonstrates level-1m operations on structured matrices.
//
//
// Example 1: Initialize the upper triangle of a matrix to random values.
//
printf( "\n#\n# -- Example 1 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
a = malloc( m * n * sizeof( double ) );
// Set the upper triangle to random values.
bli_drandm( 0, BLIS_UPPER, m, n, a, rs, cs );
bli_dprintm( "a: randomize upper part (lower part may contain garbage)",
m, n, a, rs, cs, "%4.1f", "" );
//
// Example 2: Initialize the upper triangle of a matrix to random values
// but also explicitly set the strictly lower triangle to zero.
//
printf( "\n#\n# -- Example 2 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
b = malloc( m * n * sizeof( double ) );
// Set the upper triangle to random values.
bli_drandm( 0, BLIS_UPPER, m, n, b, rs, cs );
// Set the strictly lower triangle of 'b' to zero (by setting the lower
// triangle of 'bl' to zero).
bli_dsetm( BLIS_NO_CONJUGATE, -1, BLIS_NONUNIT_DIAG, BLIS_LOWER,
m, n, &zero, b, rs, cs );
bli_dprintm( "b: randomize upper part; set strictly lower part to 0.0)",
m, n, b, rs, cs, "%4.1f", "" );
// You may not see the effect of setting the strictly lower part to zero,
// since those values may already be zero (instead of random junk). So
// let's set it to something you'll notice, like -1.0.
bli_dsetm( BLIS_NO_CONJUGATE, -1, BLIS_NONUNIT_DIAG, BLIS_LOWER,
m, n, &minus_one, b, rs, cs );
bli_dprintm( "b: randomize upper part; set strictly lower part to -1.0)",
m, n, b, rs, cs, "%4.1f", "" );
//
// Example 3: Copy the lower triangle of an existing matrix to a newly
// created (but otherwise uninitialized) matrix.
//
printf( "\n#\n# -- Example 3 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
c = malloc( m * n * sizeof( double ) );
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_LOWER, BLIS_NO_TRANSPOSE,
m, n, b, rs, cs, c, rs, cs );
bli_dprintm( "c: copy lower part of b (upper part may contain garbage)",
m, n, c, rs, cs, "%4.1f", "" );
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_LOWER, BLIS_NO_TRANSPOSE,
m, n, b, rs, cs, a, rs, cs );
bli_dprintm( "a: copy lower triangle of b to upper triangular a",
m, n, a, rs, cs, "%4.1f", "" );
//
// Example 4: Copy the lower triangle of an existing object into the
// upper triangle of an existing object.
//
printf( "\n#\n# -- Example 4 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
d = malloc( m * n * sizeof( double ) );
// Let's start by setting entire destination matrix to zero.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &zero, d, rs, cs );
bli_dprintm( "d: initial value (all zeros)",
m, n, d, rs, cs, "%4.1f", "" );
// Let's change a few values of b manually so we can later see the full
// effect of the transposition.
bli_dsetijm( 2.0, 0.0, 2, 0, b, rs, cs );
bli_dsetijm( 3.0, 0.0, 3, 0, b, rs, cs );
bli_dsetijm( 4.0, 0.0, 4, 0, b, rs, cs );
bli_dsetijm( 3.1, 0.0, 2, 1, b, rs, cs );
bli_dsetijm( 3.2, 0.0, 3, 2, b, rs, cs );
bli_dprintm( "b:",
m, n, b, rs, cs, "%4.1f", "" );
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_LOWER, BLIS_TRANSPOSE,
m, n, b, rs, cs, d, rs, cs );
bli_dprintm( "d: transpose of lower triangle of b copied to d",
m, n, d, rs, cs, "%4.1f", "" );
//
// Example 5: Create a rectangular matrix (m > n) with a lower trapezoid
// containing random values, then set the strictly upper
// triangle to zeros.
//
printf( "\n#\n# -- Example 5 --\n#\n\n" );
// Create a matrix to work with.
m = 6; n = 4; rs = 1; cs = m;
e = malloc( m * n * sizeof( double ) );
// Initialize the entire matrix to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &minus_one, e, rs, cs );
bli_dprintm( "e: initial value (all -1.0)",
m, n, e, rs, cs, "%4.1f", "" );
// Randomize the lower trapezoid.
bli_drandm( 0, BLIS_LOWER, m, n, e, rs, cs );
bli_dprintm( "e: after lower trapezoid randomized",
m, n, e, rs, cs, "%4.1f", "" );
// Set the upper triangle to zero.
bli_dsetm( BLIS_NO_CONJUGATE, 1, BLIS_NONUNIT_DIAG, BLIS_UPPER,
m, n, &zero, e, rs, cs );
bli_dprintm( "e: after upper triangle set to zero",
m, n, e, rs, cs, "%4.1f", "" );
//
// Example 6: Create an upper Hessenberg matrix of random values and then
// set the "unstored" values to zero.
//
printf( "\n#\n# -- Example 6 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
h = malloc( m * n * sizeof( double ) );
// Initialize the entire matrix to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &minus_one, h, rs, cs );
bli_dprintm( "h: initial value (all -1.0)",
m, n, h, rs, cs, "%4.1f", "" );
// Randomize the elements on and above the first subdiagonal.
bli_drandm( -1, BLIS_UPPER, m, n, h, rs, cs );
bli_dprintm( "h: after randomizing above first subdiagonal",
m, n, h, rs, cs, "%4.1f", "" );
// Set the region strictly below the first subdiagonal (on or below
// the second subdiagonal) to zero.
bli_dsetm( BLIS_NO_CONJUGATE, -2, BLIS_NONUNIT_DIAG, BLIS_LOWER,
m, n, &zero, h, rs, cs );
bli_dprintm( "h: after setting elements below first subdiagonal to zero",
m, n, h, rs, cs, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( c );
free( d );
free( e );
free( h );
return 0;
}
// -----------------------------------------------------------------------------