gonum.org/v1/gonum@v0.14.0/internal/asm/f64/stubs_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 package f64_test 6 7 import ( 8 "testing" 9 10 "gonum.org/v1/gonum/floats/scalar" 11 . "gonum.org/v1/gonum/internal/asm/f64" 12 ) 13 14 func TestL1Norm(t *testing.T) { 15 var src_gd float64 = 1 16 for j, v := range []struct { 17 want float64 18 x []float64 19 }{ 20 {want: 0, x: []float64{}}, 21 {want: 2, x: []float64{2}}, 22 {want: 6, x: []float64{1, 2, 3}}, 23 {want: 6, x: []float64{-1, -2, -3}}, 24 {want: nan, x: []float64{nan}}, 25 {want: 40, x: []float64{8, -8, 8, -8, 8}}, 26 {want: 5, x: []float64{0, 1, 0, -1, 0, 1, 0, -1, 0, 1}}, 27 } { 28 g_ln := 4 + j%2 29 v.x = guardVector(v.x, src_gd, g_ln) 30 src := v.x[g_ln : len(v.x)-g_ln] 31 ret := L1Norm(src) 32 if !scalar.Same(ret, v.want) { 33 t.Errorf("Test %d L1Norm error Got: %f Expected: %f", j, ret, v.want) 34 } 35 if !isValidGuard(v.x, src_gd, g_ln) { 36 t.Errorf("Test %d Guard violated in src vector %v %v", j, v.x[:g_ln], v.x[len(v.x)-g_ln:]) 37 } 38 } 39 } 40 41 func TestL1NormInc(t *testing.T) { 42 var src_gd float64 = 1 43 for j, v := range []struct { 44 inc int 45 want float64 46 x []float64 47 }{ 48 {inc: 2, want: 0, x: []float64{}}, 49 {inc: 3, want: 2, x: []float64{2}}, 50 {inc: 10, want: 6, x: []float64{1, 2, 3}}, 51 {inc: 5, want: 6, x: []float64{-1, -2, -3}}, 52 {inc: 3, want: nan, x: []float64{nan}}, 53 {inc: 15, want: 40, x: []float64{8, -8, 8, -8, 8}}, 54 {inc: 1, want: 5, x: []float64{0, 1, 0, -1, 0, 1, 0, -1, 0, 1}}, 55 } { 56 g_ln, ln := 4+j%2, len(v.x) 57 v.x = guardIncVector(v.x, src_gd, v.inc, g_ln) 58 src := v.x[g_ln : len(v.x)-g_ln] 59 ret := L1NormInc(src, ln, v.inc) 60 if !scalar.Same(ret, v.want) { 61 t.Errorf("Test %d L1NormInc error Got: %f Expected: %f", j, ret, v.want) 62 } 63 checkValidIncGuard(t, v.x, src_gd, v.inc, g_ln) 64 } 65 } 66 67 func TestAdd(t *testing.T) { 68 var src_gd, dst_gd float64 = 1, 0 69 for j, v := range []struct { 70 dst, src, expect []float64 71 }{ 72 { 73 dst: []float64{1}, 74 src: []float64{0}, 75 expect: []float64{1}, 76 }, 77 { 78 dst: []float64{1, 2, 3}, 79 src: []float64{1}, 80 expect: []float64{2, 2, 3}, 81 }, 82 { 83 dst: []float64{}, 84 src: []float64{}, 85 expect: []float64{}, 86 }, 87 { 88 dst: []float64{1}, 89 src: []float64{nan}, 90 expect: []float64{nan}, 91 }, 92 { 93 dst: []float64{8, 8, 8, 8, 8}, 94 src: []float64{2, 4, nan, 8, 9}, 95 expect: []float64{10, 12, nan, 16, 17}, 96 }, 97 { 98 dst: []float64{0, 1, 2, 3, 4}, 99 src: []float64{-inf, 4, nan, 8, 9}, 100 expect: []float64{-inf, 5, nan, 11, 13}, 101 }, 102 { 103 dst: make([]float64, 50)[1:49], 104 src: make([]float64, 50)[1:49], 105 expect: make([]float64, 50)[1:49], 106 }, 107 } { 108 sg_ln, dg_ln := 4+j%2, 4+j%3 109 v.src, v.dst = guardVector(v.src, src_gd, sg_ln), guardVector(v.dst, dst_gd, dg_ln) 110 src, dst := v.src[sg_ln:len(v.src)-sg_ln], v.dst[dg_ln:len(v.dst)-dg_ln] 111 Add(dst, src) 112 for i := range v.expect { 113 if !scalar.Same(dst[i], v.expect[i]) { 114 t.Errorf("Test %d Add error at %d Got: %v Expected: %v", j, i, dst[i], v.expect[i]) 115 } 116 } 117 if !isValidGuard(v.src, src_gd, sg_ln) { 118 t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:sg_ln], v.src[len(v.src)-sg_ln:]) 119 } 120 if !isValidGuard(v.dst, dst_gd, dg_ln) { 121 t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:dg_ln], v.dst[len(v.dst)-dg_ln:]) 122 } 123 } 124 } 125 126 func TestAddConst(t *testing.T) { 127 var src_gd float64 = 0 128 for j, v := range []struct { 129 alpha float64 130 src, expect []float64 131 }{ 132 { 133 alpha: 1, 134 src: []float64{0}, 135 expect: []float64{1}, 136 }, 137 { 138 alpha: 5, 139 src: []float64{}, 140 expect: []float64{}, 141 }, 142 { 143 alpha: 1, 144 src: []float64{nan}, 145 expect: []float64{nan}, 146 }, 147 { 148 alpha: 8, 149 src: []float64{2, 4, nan, 8, 9}, 150 expect: []float64{10, 12, nan, 16, 17}, 151 }, 152 { 153 alpha: inf, 154 src: []float64{-inf, 4, nan, 8, 9}, 155 expect: []float64{nan, inf, nan, inf, inf}, 156 }, 157 } { 158 g_ln := 4 + j%2 159 v.src = guardVector(v.src, src_gd, g_ln) 160 src := v.src[g_ln : len(v.src)-g_ln] 161 AddConst(v.alpha, src) 162 for i := range v.expect { 163 if !scalar.Same(src[i], v.expect[i]) { 164 t.Errorf("Test %d AddConst error at %d Got: %v Expected: %v", j, i, src[i], v.expect[i]) 165 } 166 } 167 if !isValidGuard(v.src, src_gd, g_ln) { 168 t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) 169 } 170 } 171 } 172 173 func TestCumSum(t *testing.T) { 174 var src_gd, dst_gd float64 = -1, 0 175 for j, v := range []struct { 176 dst, src, expect []float64 177 }{ 178 { 179 dst: []float64{}, 180 src: []float64{}, 181 expect: []float64{}, 182 }, 183 { 184 dst: []float64{0}, 185 src: []float64{1}, 186 expect: []float64{1}, 187 }, 188 { 189 dst: []float64{nan}, 190 src: []float64{nan}, 191 expect: []float64{nan}, 192 }, 193 { 194 dst: []float64{0, 0, 0}, 195 src: []float64{1, 2, 3}, 196 expect: []float64{1, 3, 6}, 197 }, 198 { 199 dst: []float64{0, 0, 0, 0}, 200 src: []float64{1, 2, 3}, 201 expect: []float64{1, 3, 6}, 202 }, 203 { 204 dst: []float64{0, 0, 0, 0}, 205 src: []float64{1, 2, 3, 4}, 206 expect: []float64{1, 3, 6, 10}, 207 }, 208 { 209 dst: []float64{1, nan, nan, 1, 1}, 210 src: []float64{1, 1, nan, 1, 1}, 211 expect: []float64{1, 2, nan, nan, nan}, 212 }, 213 { 214 dst: []float64{nan, 4, inf, -inf, 9}, 215 src: []float64{inf, 4, nan, -inf, 9}, 216 expect: []float64{inf, inf, nan, nan, nan}, 217 }, 218 { 219 dst: make([]float64, 16), 220 src: []float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 221 expect: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, 222 }, 223 } { 224 g_ln := 4 + j%2 225 v.src, v.dst = guardVector(v.src, src_gd, g_ln), guardVector(v.dst, dst_gd, g_ln) 226 src, dst := v.src[g_ln:len(v.src)-g_ln], v.dst[g_ln:len(v.dst)-g_ln] 227 ret := CumSum(dst, src) 228 for i := range v.expect { 229 if !scalar.Same(ret[i], v.expect[i]) { 230 t.Errorf("Test %d CumSum error at %d Got: %v Expected: %v", j, i, ret[i], v.expect[i]) 231 } 232 if !scalar.Same(ret[i], dst[i]) { 233 t.Errorf("Test %d CumSum ret/dst mismatch %d Ret: %v Dst: %v", j, i, ret[i], dst[i]) 234 } 235 } 236 if !isValidGuard(v.src, src_gd, g_ln) { 237 t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) 238 } 239 if !isValidGuard(v.dst, dst_gd, g_ln) { 240 t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) 241 } 242 } 243 } 244 245 func TestCumProd(t *testing.T) { 246 var src_gd, dst_gd float64 = -1, 1 247 for j, v := range []struct { 248 dst, src, expect []float64 249 }{ 250 { 251 dst: []float64{}, 252 src: []float64{}, 253 expect: []float64{}, 254 }, 255 { 256 dst: []float64{1}, 257 src: []float64{1}, 258 expect: []float64{1}, 259 }, 260 { 261 dst: []float64{nan}, 262 src: []float64{nan}, 263 expect: []float64{nan}, 264 }, 265 { 266 dst: []float64{0, 0, 0, 0}, 267 src: []float64{1, 2, 3, 4}, 268 expect: []float64{1, 2, 6, 24}, 269 }, 270 { 271 dst: []float64{0, 0, 0}, 272 src: []float64{1, 2, 3}, 273 expect: []float64{1, 2, 6}, 274 }, 275 { 276 dst: []float64{0, 0, 0, 0}, 277 src: []float64{1, 2, 3}, 278 expect: []float64{1, 2, 6}, 279 }, 280 { 281 dst: []float64{nan, 1, nan, 1, 0}, 282 src: []float64{1, 1, nan, 1, 1}, 283 expect: []float64{1, 1, nan, nan, nan}, 284 }, 285 { 286 dst: []float64{nan, 4, nan, -inf, 9}, 287 src: []float64{inf, 4, nan, -inf, 9}, 288 expect: []float64{inf, inf, nan, nan, nan}, 289 }, 290 { 291 dst: make([]float64, 18), 292 src: []float64{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, 293 expect: []float64{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536}, 294 }, 295 } { 296 sg_ln, dg_ln := 4+j%2, 4+j%3 297 v.src, v.dst = guardVector(v.src, src_gd, sg_ln), guardVector(v.dst, dst_gd, dg_ln) 298 src, dst := v.src[sg_ln:len(v.src)-sg_ln], v.dst[dg_ln:len(v.dst)-dg_ln] 299 ret := CumProd(dst, src) 300 for i := range v.expect { 301 if !scalar.Same(ret[i], v.expect[i]) { 302 t.Errorf("Test %d CumProd error at %d Got: %v Expected: %v", j, i, ret[i], v.expect[i]) 303 } 304 if !scalar.Same(ret[i], dst[i]) { 305 t.Errorf("Test %d CumProd ret/dst mismatch %d Ret: %v Dst: %v", j, i, ret[i], dst[i]) 306 } 307 } 308 if !isValidGuard(v.src, src_gd, sg_ln) { 309 t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:sg_ln], v.src[len(v.src)-sg_ln:]) 310 } 311 if !isValidGuard(v.dst, dst_gd, dg_ln) { 312 t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:dg_ln], v.dst[len(v.dst)-dg_ln:]) 313 } 314 } 315 } 316 317 func TestDiv(t *testing.T) { 318 var src_gd, dst_gd float64 = -1, 0.5 319 for j, v := range []struct { 320 dst, src, expect []float64 321 }{ 322 { 323 dst: []float64{1}, 324 src: []float64{1}, 325 expect: []float64{1}, 326 }, 327 { 328 dst: []float64{nan}, 329 src: []float64{nan}, 330 expect: []float64{nan}, 331 }, 332 { 333 dst: []float64{1, 2, 3, 4}, 334 src: []float64{1, 2, 3, 4}, 335 expect: []float64{1, 1, 1, 1}, 336 }, 337 { 338 dst: []float64{1, 2, 3, 4, 2, 4, 6, 8}, 339 src: []float64{1, 2, 3, 4, 1, 2, 3, 4}, 340 expect: []float64{1, 1, 1, 1, 2, 2, 2, 2}, 341 }, 342 { 343 dst: []float64{2, 4, 6}, 344 src: []float64{1, 2, 3}, 345 expect: []float64{2, 2, 2}, 346 }, 347 { 348 dst: []float64{0, 0, 0, 0}, 349 src: []float64{1, 2, 3}, 350 expect: []float64{0, 0, 0}, 351 }, 352 { 353 dst: []float64{nan, 1, nan, 1, 0, nan, 1, nan, 1, 0}, 354 src: []float64{1, 1, nan, 1, 1, 1, 1, nan, 1, 1}, 355 expect: []float64{nan, 1, nan, 1, 0, nan, 1, nan, 1, 0}, 356 }, 357 { 358 dst: []float64{inf, 4, nan, -inf, 9, inf, 4, nan, -inf, 9}, 359 src: []float64{inf, 4, nan, -inf, 3, inf, 4, nan, -inf, 3}, 360 expect: []float64{nan, 1, nan, nan, 3, nan, 1, nan, nan, 3}, 361 }, 362 } { 363 sg_ln, dg_ln := 4+j%2, 4+j%3 364 v.src, v.dst = guardVector(v.src, src_gd, sg_ln), guardVector(v.dst, dst_gd, dg_ln) 365 src, dst := v.src[sg_ln:len(v.src)-sg_ln], v.dst[dg_ln:len(v.dst)-dg_ln] 366 Div(dst, src) 367 for i := range v.expect { 368 if !scalar.Same(dst[i], v.expect[i]) { 369 t.Errorf("Test %d Div error at %d Got: %v Expected: %v", j, i, dst[i], v.expect[i]) 370 } 371 } 372 if !isValidGuard(v.src, src_gd, sg_ln) { 373 t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:sg_ln], v.src[len(v.src)-sg_ln:]) 374 } 375 if !isValidGuard(v.dst, dst_gd, dg_ln) { 376 t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:dg_ln], v.dst[len(v.dst)-dg_ln:]) 377 } 378 } 379 } 380 381 func TestDivTo(t *testing.T) { 382 var dst_gd, x_gd, y_gd float64 = -1, 0.5, 0.25 383 for j, v := range []struct { 384 dst, x, y, expect []float64 385 }{ 386 { 387 dst: []float64{1}, 388 x: []float64{1}, 389 y: []float64{1}, 390 expect: []float64{1}, 391 }, 392 { 393 dst: []float64{1}, 394 x: []float64{nan}, 395 y: []float64{nan}, 396 expect: []float64{nan}, 397 }, 398 { 399 dst: []float64{-2, -2, -2}, 400 x: []float64{1, 2, 3}, 401 y: []float64{1, 2, 3}, 402 expect: []float64{1, 1, 1}, 403 }, 404 { 405 dst: []float64{0, 0, 0}, 406 x: []float64{2, 4, 6}, 407 y: []float64{1, 2, 3, 4}, 408 expect: []float64{2, 2, 2}, 409 }, 410 { 411 dst: []float64{-1, -1, -1}, 412 x: []float64{0, 0, 0}, 413 y: []float64{1, 2, 3}, 414 expect: []float64{0, 0, 0}, 415 }, 416 { 417 dst: []float64{inf, inf, inf, inf, inf, inf, inf, inf, inf, inf}, 418 x: []float64{nan, 1, nan, 1, 0, nan, 1, nan, 1, 0}, 419 y: []float64{1, 1, nan, 1, 1, 1, 1, nan, 1, 1}, 420 expect: []float64{nan, 1, nan, 1, 0, nan, 1, nan, 1, 0}, 421 }, 422 { 423 dst: []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 424 x: []float64{inf, 4, nan, -inf, 9, inf, 4, nan, -inf, 9}, 425 y: []float64{inf, 4, nan, -inf, 3, inf, 4, nan, -inf, 3}, 426 expect: []float64{nan, 1, nan, nan, 3, nan, 1, nan, nan, 3}, 427 }, 428 } { 429 xg_ln, yg_ln := 4+j%2, 4+j%3 430 v.y, v.x = guardVector(v.y, y_gd, yg_ln), guardVector(v.x, x_gd, xg_ln) 431 y, x := v.y[yg_ln:len(v.y)-yg_ln], v.x[xg_ln:len(v.x)-xg_ln] 432 v.dst = guardVector(v.dst, dst_gd, xg_ln) 433 dst := v.dst[xg_ln : len(v.dst)-xg_ln] 434 ret := DivTo(dst, x, y) 435 for i := range v.expect { 436 if !scalar.Same(ret[i], v.expect[i]) { 437 t.Errorf("Test %d DivTo error at %d Got: %v Expected: %v", j, i, ret[i], v.expect[i]) 438 } 439 if !scalar.Same(ret[i], dst[i]) { 440 t.Errorf("Test %d DivTo ret/dst mismatch %d Ret: %v Dst: %v", j, i, ret[i], dst[i]) 441 } 442 } 443 if !isValidGuard(v.y, y_gd, yg_ln) { 444 t.Errorf("Test %d Guard violated in y vector %v %v", j, v.y[:yg_ln], v.y[len(v.y)-yg_ln:]) 445 } 446 if !isValidGuard(v.x, x_gd, xg_ln) { 447 t.Errorf("Test %d Guard violated in x vector %v %v", j, v.x[:xg_ln], v.x[len(v.x)-xg_ln:]) 448 } 449 if !isValidGuard(v.dst, dst_gd, xg_ln) { 450 t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:xg_ln], v.dst[len(v.dst)-xg_ln:]) 451 } 452 } 453 } 454 455 func TestL1Dist(t *testing.T) { 456 t_gd, s_gd := -inf, inf 457 for j, v := range []struct { 458 s, t []float64 459 expect float64 460 }{ 461 { 462 s: []float64{1}, 463 t: []float64{1}, 464 expect: 0, 465 }, 466 { 467 s: []float64{nan}, 468 t: []float64{nan}, 469 expect: nan, 470 }, 471 { 472 s: []float64{1, 2, 3, 4}, 473 t: []float64{1, 2, 3, 4}, 474 expect: 0, 475 }, 476 { 477 s: []float64{2, 4, 6}, 478 t: []float64{1, 2, 3, 4}, 479 expect: 6, 480 }, 481 { 482 s: []float64{0, 0, 0}, 483 t: []float64{1, 2, 3}, 484 expect: 6, 485 }, 486 { 487 s: []float64{0, -4, -10}, 488 t: []float64{1, 2, 3}, 489 expect: 20, 490 }, 491 { 492 s: []float64{0, 1, 0, 1, 0}, 493 t: []float64{1, 1, inf, 1, 1}, 494 expect: inf, 495 }, 496 { 497 s: []float64{inf, 4, nan, -inf, 9}, 498 t: []float64{inf, 4, nan, -inf, 3}, 499 expect: nan, 500 }, 501 } { 502 sg_ln, tg_ln := 4+j%2, 4+j%3 503 v.s, v.t = guardVector(v.s, s_gd, sg_ln), guardVector(v.t, t_gd, tg_ln) 504 s_lc, t_lc := v.s[sg_ln:len(v.s)-sg_ln], v.t[tg_ln:len(v.t)-tg_ln] 505 ret := L1Dist(s_lc, t_lc) 506 if !scalar.Same(ret, v.expect) { 507 t.Errorf("Test %d L1Dist error Got: %f Expected: %f", j, ret, v.expect) 508 } 509 if !isValidGuard(v.s, s_gd, sg_ln) { 510 t.Errorf("Test %d Guard violated in s vector %v %v", j, v.s[:sg_ln], v.s[len(v.s)-sg_ln:]) 511 } 512 if !isValidGuard(v.t, t_gd, tg_ln) { 513 t.Errorf("Test %d Guard violated in t vector %v %v", j, v.t[:tg_ln], v.t[len(v.t)-tg_ln:]) 514 } 515 } 516 } 517 518 func TestLinfDist(t *testing.T) { 519 var t_gd, s_gd float64 = 0, inf 520 for j, v := range []struct { 521 s, t []float64 522 expect float64 523 }{ 524 { 525 s: []float64{}, 526 t: []float64{}, 527 expect: 0, 528 }, 529 { 530 s: []float64{1}, 531 t: []float64{1}, 532 expect: 0, 533 }, 534 { 535 s: []float64{nan}, 536 t: []float64{nan}, 537 expect: nan, 538 }, 539 { 540 s: []float64{1, 2, 3, 4}, 541 t: []float64{1, 2, 3, 4}, 542 expect: 0, 543 }, 544 { 545 s: []float64{2, 4, 6}, 546 t: []float64{1, 2, 3, 4}, 547 expect: 3, 548 }, 549 { 550 s: []float64{0, 0, 0}, 551 t: []float64{1, 2, 3}, 552 expect: 3, 553 }, 554 { 555 s: []float64{0, 1, 0, 1, 0}, 556 t: []float64{1, 1, inf, 1, 1}, 557 expect: inf, 558 }, 559 { 560 s: []float64{inf, 4, nan, -inf, 9}, 561 t: []float64{inf, 4, nan, -inf, 3}, 562 expect: 6, 563 }, 564 } { 565 sg_ln, tg_ln := 4+j%2, 4+j%3 566 v.s, v.t = guardVector(v.s, s_gd, sg_ln), guardVector(v.t, t_gd, tg_ln) 567 s_lc, t_lc := v.s[sg_ln:len(v.s)-sg_ln], v.t[tg_ln:len(v.t)-tg_ln] 568 ret := LinfDist(s_lc, t_lc) 569 if !scalar.Same(ret, v.expect) { 570 t.Errorf("Test %d LinfDist error Got: %f Expected: %f", j, ret, v.expect) 571 } 572 if !isValidGuard(v.s, s_gd, sg_ln) { 573 t.Errorf("Test %d Guard violated in s vector %v %v", j, v.s[:sg_ln], v.s[len(v.s)-sg_ln:]) 574 } 575 if !isValidGuard(v.t, t_gd, tg_ln) { 576 t.Errorf("Test %d Guard violated in t vector %v %v", j, v.t[:tg_ln], v.t[len(v.t)-tg_ln:]) 577 } 578 } 579 } 580 581 func TestSum(t *testing.T) { 582 var srcGd float64 = -1 583 for j, v := range []struct { 584 src []float64 585 expect float64 586 }{ 587 { 588 src: []float64{}, 589 expect: 0, 590 }, 591 { 592 src: []float64{1}, 593 expect: 1, 594 }, 595 { 596 src: []float64{nan}, 597 expect: nan, 598 }, 599 { 600 src: []float64{1, 2, 3}, 601 expect: 6, 602 }, 603 { 604 src: []float64{1, -4, 3}, 605 expect: 0, 606 }, 607 { 608 src: []float64{1, 2, 3, 4}, 609 expect: 10, 610 }, 611 { 612 src: []float64{1, 1, nan, 1, 1}, 613 expect: nan, 614 }, 615 { 616 src: []float64{inf, 4, nan, -inf, 9}, 617 expect: nan, 618 }, 619 { 620 src: []float64{1, 1, 1, 1, 9, 1, 1, 1, 2, 1, 1, 1, 1, 1, 5, 1}, 621 expect: 29, 622 }, 623 { 624 src: []float64{1, 1, 1, 1, 9, 1, 1, 1, 2, 1, 1, 1, 1, 1, 5, 11, 1, 1, 1, 9, 1, 1, 1, 2, 1, 1, 1, 1, 1, 5, 1}, 625 expect: 67, 626 }, 627 } { 628 gdLn := 4 + j%2 629 gsrc := guardVector(v.src, srcGd, gdLn) 630 src := gsrc[gdLn : len(gsrc)-gdLn] 631 ret := Sum(src) 632 if !scalar.Same(ret, v.expect) { 633 t.Errorf("Test %d Sum error Got: %v Expected: %v", j, ret, v.expect) 634 } 635 if !isValidGuard(gsrc, srcGd, gdLn) { 636 t.Errorf("Test %d Guard violated in src vector %v %v", j, gsrc[:gdLn], gsrc[len(gsrc)-gdLn:]) 637 } 638 639 gdLn++ 640 gsrc = guardVector(v.src, srcGd, gdLn) 641 src = gsrc[gdLn : len(gsrc)-gdLn] 642 ret = Sum(src) 643 if !scalar.Same(ret, v.expect) { 644 t.Errorf("Test %d Sum error Got: %v Expected: %v", j, ret, v.expect) 645 } 646 if !isValidGuard(gsrc, srcGd, gdLn) { 647 t.Errorf("Test %d Guard violated in src vector %v %v", j, gsrc[:gdLn], gsrc[len(gsrc)-gdLn:]) 648 } 649 } 650 }