github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/mathext/internal/amos/amos_fortran_test.go (about) 1 // Copyright ©2016 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 // +build fortran 6 7 package amos 8 9 import ( 10 "flag" 11 "runtime" 12 "testing" 13 14 "golang.org/x/exp/rand" 15 16 "github.com/jingcheng-WU/gonum/mathext/internal/amos/amoslib" 17 ) 18 19 // BUG(kortschak): Some tests here comparing the direct Go translation 20 // of the Fortran code fail. Do not delete these tests or this file until 21 // https://github.com/gonum/gonum/issues/1322 has been satisfactorily 22 // resolved. 23 var runFailing = flag.Bool("failing", false, "run known failing cases") 24 25 func TestAiryFortran(t *testing.T) { 26 rnd := rand.New(rand.NewSource(1)) 27 for i := 0; i < nInputs; i++ { 28 in := randInput(rnd) 29 zairytestFort(t, in.x, in.kode, in.id) 30 } 31 } 32 33 func TestZacaiFortran(t *testing.T) { 34 if !*runFailing { 35 t.Skip("fails") 36 } 37 38 switch runtime.GOARCH { 39 case "arm64": 40 t.Skipf("skipping on GOARCH=%s", runtime.GOARCH) 41 } 42 rnd := rand.New(rand.NewSource(1)) 43 for i := 0; i < nInputs; i++ { 44 in := randInput(rnd) 45 zacaitestFort(t, in.x, in.is, in.tol, in.n, in.yr, in.yi, in.kode) 46 } 47 } 48 49 func TestZbknuFortran(t *testing.T) { 50 if !*runFailing { 51 t.Skip("fails") 52 } 53 54 rnd := rand.New(rand.NewSource(1)) 55 for i := 0; i < nInputs; i++ { 56 in := randInput(rnd) 57 zbknutestFort(t, in.x, in.is, in.tol, in.n, in.yr, in.yi, in.kode) 58 } 59 } 60 61 func TestZasyiFortran(t *testing.T) { 62 if !*runFailing { 63 t.Skip("fails") 64 } 65 66 rnd := rand.New(rand.NewSource(1)) 67 for i := 0; i < nInputs; i++ { 68 in := randInput(rnd) 69 zasyitestFort(t, in.x, in.is, in.tol, in.n, in.yr, in.yi, in.kode) 70 } 71 } 72 73 func TestZseriFortran(t *testing.T) { 74 switch runtime.GOARCH { 75 case "arm64": 76 t.Skipf("skipping on GOARCH=%s", runtime.GOARCH) 77 } 78 rnd := rand.New(rand.NewSource(1)) 79 for i := 0; i < nInputs; i++ { 80 in := randInput(rnd) 81 zseritestFort(t, in.x, in.is, in.tol, in.n, in.yr, in.yi, in.kode) 82 } 83 } 84 85 func TestZmlriFortran(t *testing.T) { 86 if !*runFailing { 87 t.Skip("fails") 88 } 89 90 rnd := rand.New(rand.NewSource(1)) 91 for i := 0; i < nInputs; i++ { 92 in := randInput(rnd) 93 zmlritestFort(t, in.x, in.is, in.tol, in.n, in.yr, in.yi, in.kode) 94 } 95 } 96 97 func TestZksclFortran(t *testing.T) { 98 if !*runFailing { 99 t.Skip("fails") 100 } 101 102 rnd := rand.New(rand.NewSource(1)) 103 for i := 0; i < nInputs; i++ { 104 in := randInput(rnd) 105 zkscltestFort(t, in.x, in.is, in.tol, in.n, in.yr, in.yi) 106 } 107 } 108 109 func TestZuchkFortran(t *testing.T) { 110 rnd := rand.New(rand.NewSource(1)) 111 for i := 0; i < nInputs; i++ { 112 in := randInput(rnd) 113 zuchktestFort(t, in.x, in.is, in.tol) 114 } 115 } 116 117 func TestZs1s2Fortran(t *testing.T) { 118 rnd := rand.New(rand.NewSource(1)) 119 for i := 0; i < nInputs; i++ { 120 in := randInput(rnd) 121 zs1s2testFort(t, in.x, in.is) 122 } 123 } 124 125 func zs1s2testFort(t *testing.T, x []float64, is []int) { 126 const tol = 1e-11 127 128 type data struct { 129 ZRR, ZRI, S1R, S1I, S2R, S2I float64 130 NZ int 131 ASCLE, ALIM float64 132 IUF int 133 } 134 135 input := data{ 136 x[0], x[1], x[2], x[3], x[4], x[5], 137 is[0], 138 x[6], x[7], 139 is[1], 140 } 141 142 impl := func(input data) data { 143 zrr, zri, s1r, s1i, s2r, s2i, nz, ascle, alim, iuf := 144 amoslib.Zs1s2Fort(input.ZRR, input.ZRI, input.S1R, input.S1I, input.S2R, input.S2I, input.NZ, input.ASCLE, input.ALIM, input.IUF) 145 return data{zrr, zri, s1r, s1i, s2r, s2i, nz, ascle, alim, iuf} 146 } 147 148 comp := func(input data) data { 149 zrr, zri, s1r, s1i, s2r, s2i, nz, ascle, alim, iuf := 150 zs1s2Orig(input.ZRR, input.ZRI, input.S1R, input.S1I, input.S2R, input.S2I, input.NZ, input.ASCLE, input.ALIM, input.IUF) 151 return data{zrr, zri, s1r, s1i, s2r, s2i, nz, ascle, alim, iuf} 152 } 153 154 oi := impl(input) 155 oc := comp(input) 156 157 sameF64Approx(t, "zs1s2 zrr", oc.ZRR, oi.ZRR, tol) 158 sameF64Approx(t, "zs1s2 zri", oc.ZRI, oi.ZRI, tol) 159 sameF64Approx(t, "zs1s2 s1r", oc.S1R, oi.S1R, tol) 160 sameF64Approx(t, "zs1s2 s1i", oc.S1I, oi.S1I, tol) 161 sameF64Approx(t, "zs1s2 s2r", oc.S2R, oi.S2R, tol) 162 sameF64Approx(t, "zs1s2 s2i", oc.S2I, oi.S2I, tol) 163 sameF64Approx(t, "zs1s2 ascle", oc.ASCLE, oi.ASCLE, tol) 164 sameF64Approx(t, "zs1s2 alim", oc.ALIM, oi.ALIM, tol) 165 sameInt(t, "iuf", oc.IUF, oi.IUF) 166 sameInt(t, "nz", oc.NZ, oi.NZ) 167 } 168 169 func zuchktestFort(t *testing.T, x []float64, is []int, tol float64) { 170 t.Helper() 171 172 YR := x[0] 173 YI := x[1] 174 NZ := is[0] 175 ASCLE := x[2] 176 TOL := tol 177 178 YRfort, YIfort, NZfort, ASCLEfort, TOLfort := zuchkOrig(YR, YI, NZ, ASCLE, TOL) 179 YRamoslib, YIamoslib, NZamoslib, ASCLEamoslib, TOLamoslib := amoslib.ZuchkFort(YR, YI, NZ, ASCLE, TOL) 180 181 sameF64(t, "zuchk yr", YRfort, YRamoslib) 182 sameF64(t, "zuchk yi", YIfort, YIamoslib) 183 sameInt(t, "zuchk nz", NZfort, NZamoslib) 184 sameF64(t, "zuchk ascle", ASCLEfort, ASCLEamoslib) 185 sameF64(t, "zuchk tol", TOLfort, TOLamoslib) 186 } 187 188 func zkscltestFort(t *testing.T, x []float64, is []int, tol float64, n int, yr, yi []float64) { 189 t.Helper() 190 191 ZRR := x[0] 192 ZRI := x[1] 193 FNU := x[2] 194 NZ := is[1] 195 ELIM := x[3] 196 ASCLE := x[4] 197 RZR := x[6] 198 RZI := x[7] 199 200 yrfort := make([]float64, len(yr)) 201 copy(yrfort, yr) 202 yifort := make([]float64, len(yi)) 203 copy(yifort, yi) 204 ZRRfort, ZRIfort, FNUfort, Nfort, YRfort, YIfort, NZfort, RZRfort, RZIfort, ASCLEfort, TOLfort, ELIMfort := 205 zksclOrig(ZRR, ZRI, FNU, n, yrfort, yifort, NZ, RZR, RZI, ASCLE, tol, ELIM) 206 207 yramos := make([]float64, len(yr)) 208 copy(yramos, yr) 209 yiamos := make([]float64, len(yi)) 210 copy(yiamos, yi) 211 ZRRamoslib, ZRIamoslib, FNUamoslib, Namoslib, YRamoslib, YIamoslib, NZamoslib, RZRamoslib, RZIamoslib, ASCLEamoslib, TOLamoslib, ELIMamoslib := 212 amoslib.ZksclFort(ZRR, ZRI, FNU, n, yramos, yiamos, NZ, RZR, RZI, ASCLE, tol, ELIM) 213 214 sameF64(t, "zkscl zrr", ZRRfort, ZRRamoslib) 215 sameF64(t, "zkscl zri", ZRIfort, ZRIamoslib) 216 sameF64(t, "zkscl fnu", FNUfort, FNUamoslib) 217 sameInt(t, "zkscl n", Nfort, Namoslib) 218 sameInt(t, "zkscl nz", NZfort, NZamoslib) 219 sameF64(t, "zkscl rzr", RZRfort, RZRamoslib) 220 sameF64(t, "zkscl rzi", RZIfort, RZIamoslib) 221 sameF64(t, "zkscl ascle", ASCLEfort, ASCLEamoslib) 222 sameF64(t, "zkscl tol", TOLfort, TOLamoslib) 223 sameF64(t, "zkscl elim", ELIMfort, ELIMamoslib) 224 225 sameF64SApprox(t, "zkscl yr", YRfort, YRamoslib, 1e-14) 226 sameF64SApprox(t, "zkscl yi", YIfort, YIamoslib, 1e-14) 227 } 228 229 func zmlritestFort(t *testing.T, x []float64, is []int, tol float64, n int, yr, yi []float64, kode int) { 230 t.Helper() 231 232 ZR := x[0] 233 ZI := x[1] 234 FNU := x[2] 235 KODE := kode 236 NZ := is[1] 237 238 yrfort := make([]float64, len(yr)) 239 copy(yrfort, yr) 240 yifort := make([]float64, len(yi)) 241 copy(yifort, yi) 242 ZRfort, ZIfort, FNUfort, KODEfort, Nfort, YRfort, YIfort, NZfort, TOLfort := 243 zmlriOrig(ZR, ZI, FNU, KODE, n, yrfort, yifort, NZ, tol) 244 245 yramos := make([]float64, len(yr)) 246 copy(yramos, yr) 247 yiamos := make([]float64, len(yi)) 248 copy(yiamos, yi) 249 ZRamoslib, ZIamoslib, FNUamoslib, KODEamoslib, Namoslib, YRamoslib, YIamoslib, NZamoslib, TOLamoslib := 250 amoslib.ZmlriFort(ZR, ZI, FNU, KODE, n, yramos, yiamos, NZ, tol) 251 252 sameF64(t, "zmlri zr", ZRfort, ZRamoslib) 253 sameF64(t, "zmlri zi", ZIfort, ZIamoslib) 254 sameF64(t, "zmlri fnu", FNUfort, FNUamoslib) 255 sameInt(t, "zmlri kode", KODEfort, KODEamoslib) 256 sameInt(t, "zmlri n", Nfort, Namoslib) 257 sameInt(t, "zmlri nz", NZfort, NZamoslib) 258 sameF64(t, "zmlri tol", TOLfort, TOLamoslib) 259 260 sameF64S(t, "zmlri yr", YRfort, YRamoslib) 261 sameF64S(t, "zmlri yi", YIfort, YIamoslib) 262 } 263 264 func zseritestFort(t *testing.T, x []float64, is []int, tol float64, n int, yr, yi []float64, kode int) { 265 t.Helper() 266 267 ZR := x[0] 268 ZI := x[1] 269 FNU := x[2] 270 KODE := kode 271 NZ := is[1] 272 ELIM := x[3] 273 ALIM := x[4] 274 275 yrfort := make([]float64, len(yr)) 276 copy(yrfort, yr) 277 yifort := make([]float64, len(yi)) 278 copy(yifort, yi) 279 ZRfort, ZIfort, FNUfort, KODEfort, Nfort, YRfort, YIfort, NZfort, TOLfort, ELIMfort, ALIMfort := 280 zseriOrig(ZR, ZI, FNU, KODE, n, yrfort, yifort, NZ, tol, ELIM, ALIM) 281 282 yramos := make([]float64, len(yr)) 283 copy(yramos, yr) 284 yiamos := make([]float64, len(yi)) 285 copy(yiamos, yi) 286 y := make([]complex128, len(yramos)) 287 for i, v := range yramos { 288 y[i] = complex(v, yiamos[i]) 289 } 290 291 ZRamoslib, ZIamoslib, FNUamoslib, KODEamoslib, Namoslib, YRamoslib, YIamoslib, NZamoslib, TOLamoslib, ELIMamoslib, ALIMamoslib := 292 amoslib.ZseriFort(ZR, ZI, FNU, KODE, n, yrfort, yifort, NZ, tol, ELIM, ALIM) 293 294 sameF64(t, "zseri zr", ZRfort, ZRamoslib) 295 sameF64(t, "zseri zi", ZIfort, ZIamoslib) 296 sameF64(t, "zseri fnu", FNUfort, FNUamoslib) 297 sameInt(t, "zseri kode", KODEfort, KODEamoslib) 298 sameInt(t, "zseri n", Nfort, Namoslib) 299 if *runFailing { 300 sameInt(t, "zseri nz", NZfort, NZamoslib) 301 } 302 sameF64(t, "zseri tol", TOLfort, TOLamoslib) 303 sameF64(t, "zseri elim", ELIMfort, ELIMamoslib) 304 sameF64(t, "zseri elim", ALIMfort, ALIMamoslib) 305 306 sameF64SApprox(t, "zseri yr", YRfort, YRamoslib, 1e-9) 307 sameF64SApprox(t, "zseri yi", YIfort, YIamoslib, 1e-10) 308 } 309 310 func zasyitestFort(t *testing.T, x []float64, is []int, tol float64, n int, yr, yi []float64, kode int) { 311 t.Helper() 312 313 ZR := x[0] 314 ZI := x[1] 315 FNU := x[2] 316 KODE := kode 317 NZ := is[1] 318 ELIM := x[3] 319 ALIM := x[4] 320 RL := x[5] 321 322 yrfort := make([]float64, len(yr)) 323 copy(yrfort, yr) 324 yifort := make([]float64, len(yi)) 325 copy(yifort, yi) 326 ZRfort, ZIfort, FNUfort, KODEfort, Nfort, YRfort, YIfort, NZfort, RLfort, TOLfort, ELIMfort, ALIMfort := 327 zasyiOrig(ZR, ZI, FNU, KODE, n, yrfort, yifort, NZ, RL, tol, ELIM, ALIM) 328 329 yramos := make([]float64, len(yr)) 330 copy(yramos, yr) 331 yiamos := make([]float64, len(yi)) 332 copy(yiamos, yi) 333 ZRamoslib, ZIamoslib, FNUamoslib, KODEamoslib, Namoslib, YRamoslib, YIamoslib, NZamoslib, RLamoslib, TOLamoslib, ELIMamoslib, ALIMamoslib := 334 amoslib.ZasyiFort(ZR, ZI, FNU, KODE, n, yramos, yiamos, NZ, RL, tol, ELIM, ALIM) 335 336 sameF64(t, "zasyi zr", ZRfort, ZRamoslib) 337 sameF64(t, "zasyi zr", ZIfort, ZIamoslib) 338 sameF64(t, "zasyi fnu", FNUfort, FNUamoslib) 339 sameInt(t, "zasyi kode", KODEfort, KODEamoslib) 340 sameInt(t, "zasyi n", Nfort, Namoslib) 341 sameInt(t, "zasyi nz", NZfort, NZamoslib) 342 sameF64(t, "zasyi rl", RLfort, RLamoslib) 343 sameF64(t, "zasyi tol", TOLfort, TOLamoslib) 344 sameF64(t, "zasyi elim", ELIMfort, ELIMamoslib) 345 sameF64(t, "zasyi alim", ALIMfort, ALIMamoslib) 346 347 sameF64SApprox(t, "zasyi yr", YRfort, YRamoslib, 1e-12) 348 sameF64SApprox(t, "zasyi yi", YIfort, YIamoslib, 1e-12) 349 } 350 351 func zbknutestFort(t *testing.T, x []float64, is []int, tol float64, n int, yr, yi []float64, kode int) { 352 t.Helper() 353 354 ZR := x[0] 355 ZI := x[1] 356 FNU := x[2] 357 KODE := kode 358 NZ := is[1] 359 ELIM := x[3] 360 ALIM := x[4] 361 362 yrfort := make([]float64, len(yr)) 363 copy(yrfort, yr) 364 yifort := make([]float64, len(yi)) 365 copy(yifort, yi) 366 ZRfort, ZIfort, FNUfort, KODEfort, Nfort, YRfort, YIfort, NZfort, TOLfort, ELIMfort, ALIMfort := 367 zbknuOrig(ZR, ZI, FNU, KODE, n, yrfort, yifort, NZ, tol, ELIM, ALIM) 368 369 yramos := make([]float64, len(yr)) 370 copy(yramos, yr) 371 yiamos := make([]float64, len(yi)) 372 copy(yiamos, yi) 373 ZRamoslib, ZIamoslib, FNUamoslib, KODEamoslib, Namoslib, YRamoslib, YIamoslib, NZamoslib, TOLamoslib, ELIMamoslib, ALIMamoslib := 374 amoslib.ZbknuFort(ZR, ZI, FNU, KODE, n, yramos, yiamos, NZ, tol, ELIM, ALIM) 375 376 sameF64(t, "zbknu zr", ZRfort, ZRamoslib) 377 sameF64(t, "zbknu zr", ZIfort, ZIamoslib) 378 sameF64(t, "zbknu fnu", FNUfort, FNUamoslib) 379 sameInt(t, "zbknu kode", KODEfort, KODEamoslib) 380 sameInt(t, "zbknu n", Nfort, Namoslib) 381 sameInt(t, "zbknu nz", NZfort, NZamoslib) 382 sameF64(t, "zbknu tol", TOLfort, TOLamoslib) 383 sameF64(t, "zbknu elim", ELIMfort, ELIMamoslib) 384 sameF64(t, "zbknu alim", ALIMfort, ALIMamoslib) 385 386 sameF64SApprox(t, "zbknu yr", YRfort, YRamoslib, 1e-12) 387 sameF64SApprox(t, "zbknu yi", YIfort, YIamoslib, 1e-12) 388 } 389 390 func zairytestFort(t *testing.T, x []float64, kode, id int) { 391 const tol = 1e-8 392 t.Helper() 393 394 ZR := x[0] 395 ZI := x[1] 396 KODE := kode 397 ID := id 398 399 AIRfort, AIIfort, NZfort, IERRfort := zairyOrig(ZR, ZI, ID, KODE) 400 AIRamos, AIIamos, NZamos, IERRamos := amoslib.ZairyFort(ZR, ZI, ID, KODE) 401 402 sameF64Approx(t, "zairy air", AIRfort, AIRamos, tol) 403 sameF64Approx(t, "zairy aii", AIIfort, AIIamos, tol) 404 sameInt(t, "zairy nz", NZfort, NZamos) 405 sameInt(t, "zairy ierr", IERRfort, IERRamos) 406 } 407 408 func zacaitestFort(t *testing.T, x []float64, is []int, tol float64, n int, yr, yi []float64, kode int) { 409 t.Helper() 410 411 ZR := x[0] 412 ZI := x[1] 413 FNU := x[2] 414 KODE := kode 415 NZ := is[1] 416 MR := is[2] 417 ELIM := x[3] 418 ALIM := x[4] 419 RL := x[5] 420 421 yrfort := make([]float64, len(yr)) 422 copy(yrfort, yr) 423 yifort := make([]float64, len(yi)) 424 copy(yifort, yi) 425 ZRfort, ZIfort, FNUfort, KODEfort, MRfort, Nfort, YRfort, YIfort, NZfort, RLfort, TOLfort, ELIMfort, ALIMfort := 426 zacaiOrig(ZR, ZI, FNU, KODE, MR, n, yrfort, yifort, NZ, RL, tol, ELIM, ALIM) 427 428 yramos := make([]float64, len(yr)) 429 copy(yramos, yr) 430 yiamos := make([]float64, len(yi)) 431 copy(yiamos, yi) 432 ZRamoslib, ZIamoslib, FNUamoslib, KODEamoslib, MRamoslib, Namoslib, YRamoslib, YIamoslib, NZamoslib, RLamoslib, TOLamoslib, ELIMamoslib, ALIMamoslib := 433 amoslib.ZacaiFort(ZR, ZI, FNU, KODE, MR, n, yramos, yiamos, NZ, RL, tol, ELIM, ALIM) 434 435 sameF64(t, "zacai zr", ZRfort, ZRamoslib) 436 sameF64(t, "zacai zi", ZIfort, ZIamoslib) 437 sameF64(t, "zacai fnu", FNUfort, FNUamoslib) 438 sameInt(t, "zacai kode", KODEfort, KODEamoslib) 439 sameInt(t, "zacai mr", MRfort, MRamoslib) 440 sameInt(t, "zacai n", Nfort, Namoslib) 441 sameInt(t, "zacai nz", NZfort, NZamoslib) 442 sameF64(t, "zacai rl", RLfort, RLamoslib) 443 sameF64(t, "zacai tol", TOLfort, TOLamoslib) 444 sameF64(t, "zacai elim", ELIMfort, ELIMamoslib) 445 sameF64(t, "zacai elim", ALIMfort, ALIMamoslib) 446 447 sameF64SApprox(t, "zacai yr", YRfort, YRamoslib, 1e-12) 448 sameF64SApprox(t, "zacai yi", YIfort, YIamoslib, 1e-12) 449 }