github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/dsyr2k.go (about) 1 // Copyright ©2014 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package testblas 6 7 import ( 8 "math" 9 "testing" 10 11 "github.com/jingcheng-WU/gonum/blas" 12 "github.com/jingcheng-WU/gonum/floats" 13 ) 14 15 type Dsyr2ker interface { 16 Dsyr2k(ul blas.Uplo, tA blas.Transpose, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) 17 } 18 19 func Dsyr2kTest(t *testing.T, blasser Dsyr2ker) { 20 for i, test := range []struct { 21 ul blas.Uplo 22 tA blas.Transpose 23 n int 24 k int 25 alpha float64 26 a [][]float64 27 b [][]float64 28 c [][]float64 29 beta float64 30 ans [][]float64 31 }{ 32 { 33 ul: blas.Upper, 34 tA: blas.NoTrans, 35 n: 3, 36 k: 2, 37 alpha: 0, 38 a: [][]float64{ 39 {1, 2}, 40 {3, 4}, 41 {5, 6}, 42 }, 43 b: [][]float64{ 44 {7, 8}, 45 {9, 10}, 46 {11, 12}, 47 }, 48 c: [][]float64{ 49 {1, 2, 3}, 50 {0, 5, 6}, 51 {0, 0, 9}, 52 }, 53 beta: 2, 54 ans: [][]float64{ 55 {2, 4, 6}, 56 {0, 10, 12}, 57 {0, 0, 18}, 58 }, 59 }, 60 { 61 ul: blas.Lower, 62 tA: blas.NoTrans, 63 n: 3, 64 k: 2, 65 alpha: 0, 66 a: [][]float64{ 67 {1, 2}, 68 {3, 4}, 69 {5, 6}, 70 }, 71 b: [][]float64{ 72 {7, 8}, 73 {9, 10}, 74 {11, 12}, 75 }, 76 c: [][]float64{ 77 {1, 0, 0}, 78 {2, 3, 0}, 79 {4, 5, 6}, 80 }, 81 beta: 2, 82 ans: [][]float64{ 83 {2, 0, 0}, 84 {4, 6, 0}, 85 {8, 10, 12}, 86 }, 87 }, 88 { 89 ul: blas.Upper, 90 tA: blas.NoTrans, 91 n: 3, 92 k: 2, 93 alpha: 3, 94 a: [][]float64{ 95 {1, 2}, 96 {3, 4}, 97 {5, 6}, 98 }, 99 b: [][]float64{ 100 {7, 8}, 101 {9, 10}, 102 {11, 12}, 103 }, 104 c: [][]float64{ 105 {1, 2, 3}, 106 {0, 4, 5}, 107 {0, 0, 6}, 108 }, 109 beta: 2, 110 ans: [][]float64{ 111 {140, 250, 360}, 112 {0, 410, 568}, 113 {0, 0, 774}, 114 }, 115 }, 116 { 117 ul: blas.Lower, 118 tA: blas.NoTrans, 119 n: 3, 120 k: 2, 121 alpha: 3, 122 a: [][]float64{ 123 {1, 2}, 124 {3, 4}, 125 {5, 6}, 126 }, 127 b: [][]float64{ 128 {7, 8}, 129 {9, 10}, 130 {11, 12}, 131 }, 132 c: [][]float64{ 133 {1, 0, 0}, 134 {2, 4, 0}, 135 {3, 5, 6}, 136 }, 137 beta: 2, 138 ans: [][]float64{ 139 {140, 0, 0}, 140 {250, 410, 0}, 141 {360, 568, 774}, 142 }, 143 }, 144 { 145 ul: blas.Upper, 146 tA: blas.Trans, 147 n: 3, 148 k: 2, 149 alpha: 3, 150 a: [][]float64{ 151 {1, 3, 5}, 152 {2, 4, 6}, 153 }, 154 b: [][]float64{ 155 {7, 9, 11}, 156 {8, 10, 12}, 157 }, 158 c: [][]float64{ 159 {1, 2, 3}, 160 {0, 4, 5}, 161 {0, 0, 6}, 162 }, 163 beta: 2, 164 ans: [][]float64{ 165 {140, 250, 360}, 166 {0, 410, 568}, 167 {0, 0, 774}, 168 }, 169 }, 170 { 171 ul: blas.Lower, 172 tA: blas.Trans, 173 n: 3, 174 k: 2, 175 alpha: 3, 176 a: [][]float64{ 177 {1, 3, 5}, 178 {2, 4, 6}, 179 }, 180 b: [][]float64{ 181 {7, 9, 11}, 182 {8, 10, 12}, 183 }, 184 c: [][]float64{ 185 {1, 0, 0}, 186 {2, 4, 0}, 187 {3, 5, 6}, 188 }, 189 beta: 2, 190 ans: [][]float64{ 191 {140, 0, 0}, 192 {250, 410, 0}, 193 {360, 568, 774}, 194 }, 195 }, 196 197 { 198 ul: blas.Upper, 199 tA: blas.NoTrans, 200 n: 3, 201 k: 2, 202 alpha: 0, 203 a: [][]float64{ 204 {1, 2}, 205 {3, 4}, 206 {5, 6}, 207 }, 208 b: [][]float64{ 209 {7, 8}, 210 {9, 10}, 211 {11, 12}, 212 }, 213 c: [][]float64{ 214 {math.NaN(), math.NaN(), math.NaN()}, 215 {math.Inf(-1), math.NaN(), math.NaN()}, 216 {math.Inf(-1), math.Inf(-1), math.NaN()}, 217 }, 218 ans: [][]float64{ 219 {0, 0, 0}, 220 {math.Inf(-1), 0, 0}, 221 {math.Inf(-1), math.Inf(-1), 0}, 222 }, 223 }, 224 { 225 ul: blas.Lower, 226 tA: blas.NoTrans, 227 n: 3, 228 k: 2, 229 alpha: 0, 230 a: [][]float64{ 231 {1, 2}, 232 {3, 4}, 233 {5, 6}, 234 }, 235 b: [][]float64{ 236 {7, 8}, 237 {9, 10}, 238 {11, 12}, 239 }, 240 c: [][]float64{ 241 {math.NaN(), math.Inf(-1), math.Inf(-1)}, 242 {math.NaN(), math.NaN(), math.Inf(-1)}, 243 {math.NaN(), math.NaN(), math.NaN()}, 244 }, 245 ans: [][]float64{ 246 {0, math.Inf(-1), math.Inf(-1)}, 247 {0, 0, math.Inf(-1)}, 248 {0, 0, 0}, 249 }, 250 }, 251 { 252 ul: blas.Upper, 253 tA: blas.NoTrans, 254 n: 3, 255 k: 2, 256 alpha: 3, 257 a: [][]float64{ 258 {1, 2}, 259 {3, 4}, 260 {5, 6}, 261 }, 262 b: [][]float64{ 263 {7, 8}, 264 {9, 10}, 265 {11, 12}, 266 }, 267 c: [][]float64{ 268 {math.NaN(), math.NaN(), math.NaN()}, 269 {math.Inf(-1), math.NaN(), math.NaN()}, 270 {math.Inf(-1), math.Inf(-1), math.NaN()}, 271 }, 272 ans: [][]float64{ 273 {138, 246, 354}, 274 {math.Inf(-1), 402, 558}, 275 {math.Inf(-1), math.Inf(-1), 762}, 276 }, 277 }, 278 { 279 ul: blas.Lower, 280 tA: blas.NoTrans, 281 n: 3, 282 k: 2, 283 alpha: 3, 284 a: [][]float64{ 285 {1, 2}, 286 {3, 4}, 287 {5, 6}, 288 }, 289 b: [][]float64{ 290 {7, 8}, 291 {9, 10}, 292 {11, 12}, 293 }, 294 c: [][]float64{ 295 {math.NaN(), math.Inf(-1), math.Inf(-1)}, 296 {math.NaN(), math.NaN(), math.Inf(-1)}, 297 {math.NaN(), math.NaN(), math.NaN()}, 298 }, 299 ans: [][]float64{ 300 {138, math.Inf(-1), math.Inf(-1)}, 301 {246, 402, math.Inf(-1)}, 302 {354, 558, 762}, 303 }, 304 }, 305 { 306 ul: blas.Upper, 307 tA: blas.Trans, 308 n: 3, 309 k: 2, 310 alpha: 3, 311 a: [][]float64{ 312 {1, 3, 5}, 313 {2, 4, 6}, 314 }, 315 b: [][]float64{ 316 {7, 9, 11}, 317 {8, 10, 12}, 318 }, 319 c: [][]float64{ 320 {math.NaN(), math.NaN(), math.NaN()}, 321 {math.Inf(-1), math.NaN(), math.NaN()}, 322 {math.Inf(-1), math.Inf(-1), math.NaN()}, 323 }, 324 ans: [][]float64{ 325 {138, 246, 354}, 326 {math.Inf(-1), 402, 558}, 327 {math.Inf(-1), math.Inf(-1), 762}, 328 }, 329 }, 330 { 331 ul: blas.Lower, 332 tA: blas.Trans, 333 n: 3, 334 k: 2, 335 alpha: 3, 336 a: [][]float64{ 337 {1, 3, 5}, 338 {2, 4, 6}, 339 }, 340 b: [][]float64{ 341 {7, 9, 11}, 342 {8, 10, 12}, 343 }, 344 c: [][]float64{ 345 {math.NaN(), math.Inf(-1), math.Inf(-1)}, 346 {math.NaN(), math.NaN(), math.Inf(-1)}, 347 {math.NaN(), math.NaN(), math.NaN()}, 348 }, 349 ans: [][]float64{ 350 {138, math.Inf(-1), math.Inf(-1)}, 351 {246, 402, math.Inf(-1)}, 352 {354, 558, 762}, 353 }, 354 }, 355 } { 356 aFlat := flatten(test.a) 357 bFlat := flatten(test.b) 358 cFlat := flatten(test.c) 359 ansFlat := flatten(test.ans) 360 blasser.Dsyr2k(test.ul, test.tA, test.n, test.k, test.alpha, aFlat, len(test.a[0]), bFlat, len(test.b[0]), test.beta, cFlat, len(test.c[0])) 361 if !floats.EqualApprox(ansFlat, cFlat, 1e-14) { 362 t.Errorf("Case %v. Want %v, got %v.", i, ansFlat, cFlat) 363 } 364 } 365 }