| 1 |
// Code generated by genlib2. DO NOT EDIT. |
| 2 |
|
| 3 |
package tensor |
| 4 |
|
| 5 |
import ( |
| 6 |
"testing" |
| 7 |
"testing/quick" |
| 8 |
) |
| 9 |
|
| 10 |
func TestNeg(t *testing.T) { |
| 11 |
invFn := func(q *Dense) bool { |
| 12 |
a := q.Clone().(*Dense) |
| 13 |
correct := a.Clone().(*Dense) |
| 14 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 15 |
_, ok := q.Engine().(Neger) |
| 16 |
we = we || !ok |
| 17 |
|
| 18 |
ret, err := Neg(a) |
| 19 |
if err, retEarly := qcErrCheck(t, "Neg", a, nil, we, err); retEarly { |
| 20 |
if err != nil { |
| 21 |
return false |
| 22 |
} |
| 23 |
return true |
| 24 |
} |
| 25 |
Neg(ret, UseUnsafe()) |
| 26 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 27 |
return false |
| 28 |
} |
| 29 |
return true |
| 30 |
} |
| 31 |
|
| 32 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 33 |
t.Errorf("Inv tests for Neg failed: %v", err) |
| 34 |
} |
| 35 |
} |
| 36 |
func TestSquare(t *testing.T) { |
| 37 |
invFn := func(q *Dense) bool { |
| 38 |
a := q.Clone().(*Dense) |
| 39 |
correct := a.Clone().(*Dense) |
| 40 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 41 |
_, ok := q.Engine().(Squarer) |
| 42 |
we = we || !ok |
| 43 |
|
| 44 |
ret, err := Square(a) |
| 45 |
if err, retEarly := qcErrCheck(t, "Square", a, nil, we, err); retEarly { |
| 46 |
if err != nil { |
| 47 |
return false |
| 48 |
} |
| 49 |
return true |
| 50 |
} |
| 51 |
if err := typeclassCheck(a.Dtype(), floatcmplxTypes); err != nil { |
| 52 |
return true // uninvertible due to type class implementation issues |
| 53 |
} |
| 54 |
Sqrt(ret, UseUnsafe()) |
| 55 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 56 |
return false |
| 57 |
} |
| 58 |
return true |
| 59 |
} |
| 60 |
|
| 61 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 62 |
t.Errorf("Inv tests for Square failed: %v", err) |
| 63 |
} |
| 64 |
} |
| 65 |
func TestCube(t *testing.T) { |
| 66 |
invFn := func(q *Dense) bool { |
| 67 |
a := q.Clone().(*Dense) |
| 68 |
correct := a.Clone().(*Dense) |
| 69 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 70 |
_, ok := q.Engine().(Cuber) |
| 71 |
we = we || !ok |
| 72 |
|
| 73 |
ret, err := Cube(a) |
| 74 |
if err, retEarly := qcErrCheck(t, "Cube", a, nil, we, err); retEarly { |
| 75 |
if err != nil { |
| 76 |
return false |
| 77 |
} |
| 78 |
return true |
| 79 |
} |
| 80 |
if err := typeclassCheck(a.Dtype(), floatTypes); err != nil { |
| 81 |
return true // uninvertible due to type class implementation issues |
| 82 |
} |
| 83 |
Cbrt(ret, UseUnsafe()) |
| 84 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 85 |
return false |
| 86 |
} |
| 87 |
return true |
| 88 |
} |
| 89 |
|
| 90 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 91 |
t.Errorf("Inv tests for Cube failed: %v", err) |
| 92 |
} |
| 93 |
} |
| 94 |
func TestExp(t *testing.T) { |
| 95 |
invFn := func(q *Dense) bool { |
| 96 |
a := q.Clone().(*Dense) |
| 97 |
correct := a.Clone().(*Dense) |
| 98 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 99 |
_, ok := q.Engine().(Exper) |
| 100 |
we = we || !ok |
| 101 |
|
| 102 |
ret, err := Exp(a) |
| 103 |
if err, retEarly := qcErrCheck(t, "Exp", a, nil, we, err); retEarly { |
| 104 |
if err != nil { |
| 105 |
return false |
| 106 |
} |
| 107 |
return true |
| 108 |
} |
| 109 |
Log(ret, UseUnsafe()) |
| 110 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 111 |
return false |
| 112 |
} |
| 113 |
return true |
| 114 |
} |
| 115 |
|
| 116 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 117 |
t.Errorf("Inv tests for Exp failed: %v", err) |
| 118 |
} |
| 119 |
} |
| 120 |
func TestLog(t *testing.T) { |
| 121 |
invFn := func(q *Dense) bool { |
| 122 |
a := q.Clone().(*Dense) |
| 123 |
correct := a.Clone().(*Dense) |
| 124 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 125 |
_, ok := q.Engine().(Loger) |
| 126 |
we = we || !ok |
| 127 |
|
| 128 |
ret, err := Log(a) |
| 129 |
if err, retEarly := qcErrCheck(t, "Log", a, nil, we, err); retEarly { |
| 130 |
if err != nil { |
| 131 |
return false |
| 132 |
} |
| 133 |
return true |
| 134 |
} |
| 135 |
Exp(ret, UseUnsafe()) |
| 136 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 137 |
return false |
| 138 |
} |
| 139 |
return true |
| 140 |
} |
| 141 |
|
| 142 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 143 |
t.Errorf("Inv tests for Log failed: %v", err) |
| 144 |
} |
| 145 |
} |
| 146 |
func TestSqrt(t *testing.T) { |
| 147 |
invFn := func(q *Dense) bool { |
| 148 |
a := q.Clone().(*Dense) |
| 149 |
correct := a.Clone().(*Dense) |
| 150 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 151 |
_, ok := q.Engine().(Sqrter) |
| 152 |
we = we || !ok |
| 153 |
|
| 154 |
ret, err := Sqrt(a) |
| 155 |
if err, retEarly := qcErrCheck(t, "Sqrt", a, nil, we, err); retEarly { |
| 156 |
if err != nil { |
| 157 |
return false |
| 158 |
} |
| 159 |
return true |
| 160 |
} |
| 161 |
Square(ret, UseUnsafe()) |
| 162 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 163 |
return false |
| 164 |
} |
| 165 |
return true |
| 166 |
} |
| 167 |
|
| 168 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 169 |
t.Errorf("Inv tests for Sqrt failed: %v", err) |
| 170 |
} |
| 171 |
} |
| 172 |
func TestCbrt(t *testing.T) { |
| 173 |
invFn := func(q *Dense) bool { |
| 174 |
a := q.Clone().(*Dense) |
| 175 |
correct := a.Clone().(*Dense) |
| 176 |
we, willFailEq := willerr(a, floatTypes, nil) |
| 177 |
_, ok := q.Engine().(Cbrter) |
| 178 |
we = we || !ok |
| 179 |
|
| 180 |
ret, err := Cbrt(a) |
| 181 |
if err, retEarly := qcErrCheck(t, "Cbrt", a, nil, we, err); retEarly { |
| 182 |
if err != nil { |
| 183 |
return false |
| 184 |
} |
| 185 |
return true |
| 186 |
} |
| 187 |
Cube(ret, UseUnsafe()) |
| 188 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 189 |
return false |
| 190 |
} |
| 191 |
return true |
| 192 |
} |
| 193 |
|
| 194 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 195 |
t.Errorf("Inv tests for Cbrt failed: %v", err) |
| 196 |
} |
| 197 |
} |
| 198 |
func TestNeg_unsafe(t *testing.T) { |
| 199 |
invFn := func(q *Dense) bool { |
| 200 |
a := q.Clone().(*Dense) |
| 201 |
correct := a.Clone().(*Dense) |
| 202 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 203 |
_, ok := q.Engine().(Neger) |
| 204 |
we = we || !ok |
| 205 |
|
| 206 |
ret, err := Neg(a, UseUnsafe()) |
| 207 |
if err, retEarly := qcErrCheck(t, "Neg", a, nil, we, err); retEarly { |
| 208 |
if err != nil { |
| 209 |
return false |
| 210 |
} |
| 211 |
return true |
| 212 |
} |
| 213 |
Neg(ret, UseUnsafe()) |
| 214 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 215 |
return false |
| 216 |
} |
| 217 |
if ret != a { |
| 218 |
t.Errorf("Expected ret to be the same as a") |
| 219 |
return false |
| 220 |
} |
| 221 |
|
| 222 |
return true |
| 223 |
} |
| 224 |
|
| 225 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 226 |
t.Errorf("Inv tests for Neg failed: %v", err) |
| 227 |
} |
| 228 |
} |
| 229 |
func TestSquare_unsafe(t *testing.T) { |
| 230 |
invFn := func(q *Dense) bool { |
| 231 |
a := q.Clone().(*Dense) |
| 232 |
correct := a.Clone().(*Dense) |
| 233 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 234 |
_, ok := q.Engine().(Squarer) |
| 235 |
we = we || !ok |
| 236 |
|
| 237 |
ret, err := Square(a, UseUnsafe()) |
| 238 |
if err, retEarly := qcErrCheck(t, "Square", a, nil, we, err); retEarly { |
| 239 |
if err != nil { |
| 240 |
return false |
| 241 |
} |
| 242 |
return true |
| 243 |
} |
| 244 |
if err := typeclassCheck(a.Dtype(), floatcmplxTypes); err != nil { |
| 245 |
return true // uninvertible due to type class implementation issues |
| 246 |
} |
| 247 |
Sqrt(ret, UseUnsafe()) |
| 248 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 249 |
return false |
| 250 |
} |
| 251 |
if ret != a { |
| 252 |
t.Errorf("Expected ret to be the same as a") |
| 253 |
return false |
| 254 |
} |
| 255 |
|
| 256 |
return true |
| 257 |
} |
| 258 |
|
| 259 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 260 |
t.Errorf("Inv tests for Square failed: %v", err) |
| 261 |
} |
| 262 |
} |
| 263 |
func TestCube_unsafe(t *testing.T) { |
| 264 |
invFn := func(q *Dense) bool { |
| 265 |
a := q.Clone().(*Dense) |
| 266 |
correct := a.Clone().(*Dense) |
| 267 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 268 |
_, ok := q.Engine().(Cuber) |
| 269 |
we = we || !ok |
| 270 |
|
| 271 |
ret, err := Cube(a, UseUnsafe()) |
| 272 |
if err, retEarly := qcErrCheck(t, "Cube", a, nil, we, err); retEarly { |
| 273 |
if err != nil { |
| 274 |
return false |
| 275 |
} |
| 276 |
return true |
| 277 |
} |
| 278 |
if err := typeclassCheck(a.Dtype(), floatTypes); err != nil { |
| 279 |
return true // uninvertible due to type class implementation issues |
| 280 |
} |
| 281 |
Cbrt(ret, UseUnsafe()) |
| 282 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 283 |
return false |
| 284 |
} |
| 285 |
if ret != a { |
| 286 |
t.Errorf("Expected ret to be the same as a") |
| 287 |
return false |
| 288 |
} |
| 289 |
|
| 290 |
return true |
| 291 |
} |
| 292 |
|
| 293 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 294 |
t.Errorf("Inv tests for Cube failed: %v", err) |
| 295 |
} |
| 296 |
} |
| 297 |
func TestExp_unsafe(t *testing.T) { |
| 298 |
invFn := func(q *Dense) bool { |
| 299 |
a := q.Clone().(*Dense) |
| 300 |
correct := a.Clone().(*Dense) |
| 301 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 302 |
_, ok := q.Engine().(Exper) |
| 303 |
we = we || !ok |
| 304 |
|
| 305 |
ret, err := Exp(a, UseUnsafe()) |
| 306 |
if err, retEarly := qcErrCheck(t, "Exp", a, nil, we, err); retEarly { |
| 307 |
if err != nil { |
| 308 |
return false |
| 309 |
} |
| 310 |
return true |
| 311 |
} |
| 312 |
Log(ret, UseUnsafe()) |
| 313 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 314 |
return false |
| 315 |
} |
| 316 |
if ret != a { |
| 317 |
t.Errorf("Expected ret to be the same as a") |
| 318 |
return false |
| 319 |
} |
| 320 |
|
| 321 |
return true |
| 322 |
} |
| 323 |
|
| 324 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 325 |
t.Errorf("Inv tests for Exp failed: %v", err) |
| 326 |
} |
| 327 |
} |
| 328 |
func TestLog_unsafe(t *testing.T) { |
| 329 |
invFn := func(q *Dense) bool { |
| 330 |
a := q.Clone().(*Dense) |
| 331 |
correct := a.Clone().(*Dense) |
| 332 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 333 |
_, ok := q.Engine().(Loger) |
| 334 |
we = we || !ok |
| 335 |
|
| 336 |
ret, err := Log(a, UseUnsafe()) |
| 337 |
if err, retEarly := qcErrCheck(t, "Log", a, nil, we, err); retEarly { |
| 338 |
if err != nil { |
| 339 |
return false |
| 340 |
} |
| 341 |
return true |
| 342 |
} |
| 343 |
Exp(ret, UseUnsafe()) |
| 344 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 345 |
return false |
| 346 |
} |
| 347 |
if ret != a { |
| 348 |
t.Errorf("Expected ret to be the same as a") |
| 349 |
return false |
| 350 |
} |
| 351 |
|
| 352 |
return true |
| 353 |
} |
| 354 |
|
| 355 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 356 |
t.Errorf("Inv tests for Log failed: %v", err) |
| 357 |
} |
| 358 |
} |
| 359 |
func TestSqrt_unsafe(t *testing.T) { |
| 360 |
invFn := func(q *Dense) bool { |
| 361 |
a := q.Clone().(*Dense) |
| 362 |
correct := a.Clone().(*Dense) |
| 363 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 364 |
_, ok := q.Engine().(Sqrter) |
| 365 |
we = we || !ok |
| 366 |
|
| 367 |
ret, err := Sqrt(a, UseUnsafe()) |
| 368 |
if err, retEarly := qcErrCheck(t, "Sqrt", a, nil, we, err); retEarly { |
| 369 |
if err != nil { |
| 370 |
return false |
| 371 |
} |
| 372 |
return true |
| 373 |
} |
| 374 |
Square(ret, UseUnsafe()) |
| 375 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 376 |
return false |
| 377 |
} |
| 378 |
if ret != a { |
| 379 |
t.Errorf("Expected ret to be the same as a") |
| 380 |
return false |
| 381 |
} |
| 382 |
|
| 383 |
return true |
| 384 |
} |
| 385 |
|
| 386 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 387 |
t.Errorf("Inv tests for Sqrt failed: %v", err) |
| 388 |
} |
| 389 |
} |
| 390 |
func TestCbrt_unsafe(t *testing.T) { |
| 391 |
invFn := func(q *Dense) bool { |
| 392 |
a := q.Clone().(*Dense) |
| 393 |
correct := a.Clone().(*Dense) |
| 394 |
we, willFailEq := willerr(a, floatTypes, nil) |
| 395 |
_, ok := q.Engine().(Cbrter) |
| 396 |
we = we || !ok |
| 397 |
|
| 398 |
ret, err := Cbrt(a, UseUnsafe()) |
| 399 |
if err, retEarly := qcErrCheck(t, "Cbrt", a, nil, we, err); retEarly { |
| 400 |
if err != nil { |
| 401 |
return false |
| 402 |
} |
| 403 |
return true |
| 404 |
} |
| 405 |
Cube(ret, UseUnsafe()) |
| 406 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 407 |
return false |
| 408 |
} |
| 409 |
if ret != a { |
| 410 |
t.Errorf("Expected ret to be the same as a") |
| 411 |
return false |
| 412 |
} |
| 413 |
|
| 414 |
return true |
| 415 |
} |
| 416 |
|
| 417 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 418 |
t.Errorf("Inv tests for Cbrt failed: %v", err) |
| 419 |
} |
| 420 |
} |
| 421 |
func TestNeg_reuse(t *testing.T) { |
| 422 |
invFn := func(q *Dense) bool { |
| 423 |
a := q.Clone().(*Dense) |
| 424 |
reuse := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 425 |
correct := a.Clone().(*Dense) |
| 426 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 427 |
_, ok := q.Engine().(Neger) |
| 428 |
we = we || !ok |
| 429 |
|
| 430 |
ret, err := Neg(a, WithReuse(reuse)) |
| 431 |
if err, retEarly := qcErrCheck(t, "Neg", a, nil, we, err); retEarly { |
| 432 |
if err != nil { |
| 433 |
return false |
| 434 |
} |
| 435 |
return true |
| 436 |
} |
| 437 |
Neg(ret, UseUnsafe()) |
| 438 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 439 |
return false |
| 440 |
} |
| 441 |
if reuse != ret { |
| 442 |
t.Errorf("Expected reuse to be the same as retVal") |
| 443 |
return false |
| 444 |
} |
| 445 |
|
| 446 |
return true |
| 447 |
} |
| 448 |
|
| 449 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 450 |
t.Errorf("Inv tests for Neg failed: %v", err) |
| 451 |
} |
| 452 |
} |
| 453 |
func TestSquare_reuse(t *testing.T) { |
| 454 |
invFn := func(q *Dense) bool { |
| 455 |
a := q.Clone().(*Dense) |
| 456 |
reuse := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 457 |
correct := a.Clone().(*Dense) |
| 458 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 459 |
_, ok := q.Engine().(Squarer) |
| 460 |
we = we || !ok |
| 461 |
|
| 462 |
ret, err := Square(a, WithReuse(reuse)) |
| 463 |
if err, retEarly := qcErrCheck(t, "Square", a, nil, we, err); retEarly { |
| 464 |
if err != nil { |
| 465 |
return false |
| 466 |
} |
| 467 |
return true |
| 468 |
} |
| 469 |
if err := typeclassCheck(a.Dtype(), floatcmplxTypes); err != nil { |
| 470 |
return true // uninvertible due to type class implementation issues |
| 471 |
} |
| 472 |
Sqrt(ret, UseUnsafe()) |
| 473 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 474 |
return false |
| 475 |
} |
| 476 |
if reuse != ret { |
| 477 |
t.Errorf("Expected reuse to be the same as retVal") |
| 478 |
return false |
| 479 |
} |
| 480 |
|
| 481 |
return true |
| 482 |
} |
| 483 |
|
| 484 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 485 |
t.Errorf("Inv tests for Square failed: %v", err) |
| 486 |
} |
| 487 |
} |
| 488 |
func TestCube_reuse(t *testing.T) { |
| 489 |
invFn := func(q *Dense) bool { |
| 490 |
a := q.Clone().(*Dense) |
| 491 |
reuse := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 492 |
correct := a.Clone().(*Dense) |
| 493 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 494 |
_, ok := q.Engine().(Cuber) |
| 495 |
we = we || !ok |
| 496 |
|
| 497 |
ret, err := Cube(a, WithReuse(reuse)) |
| 498 |
if err, retEarly := qcErrCheck(t, "Cube", a, nil, we, err); retEarly { |
| 499 |
if err != nil { |
| 500 |
return false |
| 501 |
} |
| 502 |
return true |
| 503 |
} |
| 504 |
if err := typeclassCheck(a.Dtype(), floatTypes); err != nil { |
| 505 |
return true // uninvertible due to type class implementation issues |
| 506 |
} |
| 507 |
Cbrt(ret, UseUnsafe()) |
| 508 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 509 |
return false |
| 510 |
} |
| 511 |
if reuse != ret { |
| 512 |
t.Errorf("Expected reuse to be the same as retVal") |
| 513 |
return false |
| 514 |
} |
| 515 |
|
| 516 |
return true |
| 517 |
} |
| 518 |
|
| 519 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 520 |
t.Errorf("Inv tests for Cube failed: %v", err) |
| 521 |
} |
| 522 |
} |
| 523 |
func TestExp_reuse(t *testing.T) { |
| 524 |
invFn := func(q *Dense) bool { |
| 525 |
a := q.Clone().(*Dense) |
| 526 |
reuse := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 527 |
correct := a.Clone().(*Dense) |
| 528 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 529 |
_, ok := q.Engine().(Exper) |
| 530 |
we = we || !ok |
| 531 |
|
| 532 |
ret, err := Exp(a, WithReuse(reuse)) |
| 533 |
if err, retEarly := qcErrCheck(t, "Exp", a, nil, we, err); retEarly { |
| 534 |
if err != nil { |
| 535 |
return false |
| 536 |
} |
| 537 |
return true |
| 538 |
} |
| 539 |
Log(ret, UseUnsafe()) |
| 540 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 541 |
return false |
| 542 |
} |
| 543 |
if reuse != ret { |
| 544 |
t.Errorf("Expected reuse to be the same as retVal") |
| 545 |
return false |
| 546 |
} |
| 547 |
|
| 548 |
return true |
| 549 |
} |
| 550 |
|
| 551 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 552 |
t.Errorf("Inv tests for Exp failed: %v", err) |
| 553 |
} |
| 554 |
} |
| 555 |
func TestLog_reuse(t *testing.T) { |
| 556 |
invFn := func(q *Dense) bool { |
| 557 |
a := q.Clone().(*Dense) |
| 558 |
reuse := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 559 |
correct := a.Clone().(*Dense) |
| 560 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 561 |
_, ok := q.Engine().(Loger) |
| 562 |
we = we || !ok |
| 563 |
|
| 564 |
ret, err := Log(a, WithReuse(reuse)) |
| 565 |
if err, retEarly := qcErrCheck(t, "Log", a, nil, we, err); retEarly { |
| 566 |
if err != nil { |
| 567 |
return false |
| 568 |
} |
| 569 |
return true |
| 570 |
} |
| 571 |
Exp(ret, UseUnsafe()) |
| 572 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 573 |
return false |
| 574 |
} |
| 575 |
if reuse != ret { |
| 576 |
t.Errorf("Expected reuse to be the same as retVal") |
| 577 |
return false |
| 578 |
} |
| 579 |
|
| 580 |
return true |
| 581 |
} |
| 582 |
|
| 583 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 584 |
t.Errorf("Inv tests for Log failed: %v", err) |
| 585 |
} |
| 586 |
} |
| 587 |
func TestSqrt_reuse(t *testing.T) { |
| 588 |
invFn := func(q *Dense) bool { |
| 589 |
a := q.Clone().(*Dense) |
| 590 |
reuse := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 591 |
correct := a.Clone().(*Dense) |
| 592 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 593 |
_, ok := q.Engine().(Sqrter) |
| 594 |
we = we || !ok |
| 595 |
|
| 596 |
ret, err := Sqrt(a, WithReuse(reuse)) |
| 597 |
if err, retEarly := qcErrCheck(t, "Sqrt", a, nil, we, err); retEarly { |
| 598 |
if err != nil { |
| 599 |
return false |
| 600 |
} |
| 601 |
return true |
| 602 |
} |
| 603 |
Square(ret, UseUnsafe()) |
| 604 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 605 |
return false |
| 606 |
} |
| 607 |
if reuse != ret { |
| 608 |
t.Errorf("Expected reuse to be the same as retVal") |
| 609 |
return false |
| 610 |
} |
| 611 |
|
| 612 |
return true |
| 613 |
} |
| 614 |
|
| 615 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 616 |
t.Errorf("Inv tests for Sqrt failed: %v", err) |
| 617 |
} |
| 618 |
} |
| 619 |
func TestCbrt_reuse(t *testing.T) { |
| 620 |
invFn := func(q *Dense) bool { |
| 621 |
a := q.Clone().(*Dense) |
| 622 |
reuse := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 623 |
correct := a.Clone().(*Dense) |
| 624 |
we, willFailEq := willerr(a, floatTypes, nil) |
| 625 |
_, ok := q.Engine().(Cbrter) |
| 626 |
we = we || !ok |
| 627 |
|
| 628 |
ret, err := Cbrt(a, WithReuse(reuse)) |
| 629 |
if err, retEarly := qcErrCheck(t, "Cbrt", a, nil, we, err); retEarly { |
| 630 |
if err != nil { |
| 631 |
return false |
| 632 |
} |
| 633 |
return true |
| 634 |
} |
| 635 |
Cube(ret, UseUnsafe()) |
| 636 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 637 |
return false |
| 638 |
} |
| 639 |
if reuse != ret { |
| 640 |
t.Errorf("Expected reuse to be the same as retVal") |
| 641 |
return false |
| 642 |
} |
| 643 |
|
| 644 |
return true |
| 645 |
} |
| 646 |
|
| 647 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 648 |
t.Errorf("Inv tests for Cbrt failed: %v", err) |
| 649 |
} |
| 650 |
} |
| 651 |
func TestNeg_incr(t *testing.T) { |
| 652 |
invFn := func(q *Dense) bool { |
| 653 |
a := q.Clone().(*Dense) |
| 654 |
incr := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 655 |
correct := a.Clone().(*Dense) |
| 656 |
incr.Memset(identityVal(100, a.t)) |
| 657 |
correct.Add(incr, UseUnsafe()) |
| 658 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 659 |
_, ok := q.Engine().(Neger) |
| 660 |
we = we || !ok |
| 661 |
|
| 662 |
ret, err := Neg(a, WithIncr(incr)) |
| 663 |
if err, retEarly := qcErrCheck(t, "Neg", a, nil, we, err); retEarly { |
| 664 |
if err != nil { |
| 665 |
return false |
| 666 |
} |
| 667 |
return true |
| 668 |
} |
| 669 |
if ret, err = Sub(ret, identityVal(100, a.Dtype()), UseUnsafe()); err != nil { |
| 670 |
t.Errorf("err while subtracting incr: %v", err) |
| 671 |
return false |
| 672 |
} |
| 673 |
Neg(ret, UseUnsafe()) |
| 674 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 675 |
return false |
| 676 |
} |
| 677 |
return true |
| 678 |
} |
| 679 |
|
| 680 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 681 |
t.Errorf("Inv tests for Neg failed: %v", err) |
| 682 |
} |
| 683 |
} |
| 684 |
func TestSquare_incr(t *testing.T) { |
| 685 |
invFn := func(q *Dense) bool { |
| 686 |
a := q.Clone().(*Dense) |
| 687 |
incr := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 688 |
correct := a.Clone().(*Dense) |
| 689 |
incr.Memset(identityVal(100, a.t)) |
| 690 |
correct.Add(incr, UseUnsafe()) |
| 691 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 692 |
_, ok := q.Engine().(Squarer) |
| 693 |
we = we || !ok |
| 694 |
|
| 695 |
ret, err := Square(a, WithIncr(incr)) |
| 696 |
if err, retEarly := qcErrCheck(t, "Square", a, nil, we, err); retEarly { |
| 697 |
if err != nil { |
| 698 |
return false |
| 699 |
} |
| 700 |
return true |
| 701 |
} |
| 702 |
if err := typeclassCheck(a.Dtype(), floatcmplxTypes); err != nil { |
| 703 |
return true // uninvertible due to type class implementation issues |
| 704 |
} |
| 705 |
if ret, err = Sub(ret, identityVal(100, a.Dtype()), UseUnsafe()); err != nil { |
| 706 |
t.Errorf("err while subtracting incr: %v", err) |
| 707 |
return false |
| 708 |
} |
| 709 |
Sqrt(ret, UseUnsafe()) |
| 710 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 711 |
return false |
| 712 |
} |
| 713 |
return true |
| 714 |
} |
| 715 |
|
| 716 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 717 |
t.Errorf("Inv tests for Square failed: %v", err) |
| 718 |
} |
| 719 |
} |
| 720 |
func TestCube_incr(t *testing.T) { |
| 721 |
invFn := func(q *Dense) bool { |
| 722 |
a := q.Clone().(*Dense) |
| 723 |
incr := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 724 |
correct := a.Clone().(*Dense) |
| 725 |
incr.Memset(identityVal(100, a.t)) |
| 726 |
correct.Add(incr, UseUnsafe()) |
| 727 |
we, willFailEq := willerr(a, numberTypes, nil) |
| 728 |
_, ok := q.Engine().(Cuber) |
| 729 |
we = we || !ok |
| 730 |
|
| 731 |
ret, err := Cube(a, WithIncr(incr)) |
| 732 |
if err, retEarly := qcErrCheck(t, "Cube", a, nil, we, err); retEarly { |
| 733 |
if err != nil { |
| 734 |
return false |
| 735 |
} |
| 736 |
return true |
| 737 |
} |
| 738 |
if err := typeclassCheck(a.Dtype(), floatTypes); err != nil { |
| 739 |
return true // uninvertible due to type class implementation issues |
| 740 |
} |
| 741 |
if ret, err = Sub(ret, identityVal(100, a.Dtype()), UseUnsafe()); err != nil { |
| 742 |
t.Errorf("err while subtracting incr: %v", err) |
| 743 |
return false |
| 744 |
} |
| 745 |
Cbrt(ret, UseUnsafe()) |
| 746 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 747 |
return false |
| 748 |
} |
| 749 |
return true |
| 750 |
} |
| 751 |
|
| 752 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 753 |
t.Errorf("Inv tests for Cube failed: %v", err) |
| 754 |
} |
| 755 |
} |
| 756 |
func TestExp_incr(t *testing.T) { |
| 757 |
invFn := func(q *Dense) bool { |
| 758 |
a := q.Clone().(*Dense) |
| 759 |
incr := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 760 |
correct := a.Clone().(*Dense) |
| 761 |
incr.Memset(identityVal(100, a.t)) |
| 762 |
correct.Add(incr, UseUnsafe()) |
| 763 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 764 |
_, ok := q.Engine().(Exper) |
| 765 |
we = we || !ok |
| 766 |
|
| 767 |
ret, err := Exp(a, WithIncr(incr)) |
| 768 |
if err, retEarly := qcErrCheck(t, "Exp", a, nil, we, err); retEarly { |
| 769 |
if err != nil { |
| 770 |
return false |
| 771 |
} |
| 772 |
return true |
| 773 |
} |
| 774 |
if ret, err = Sub(ret, identityVal(100, a.Dtype()), UseUnsafe()); err != nil { |
| 775 |
t.Errorf("err while subtracting incr: %v", err) |
| 776 |
return false |
| 777 |
} |
| 778 |
Log(ret, UseUnsafe()) |
| 779 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 780 |
return false |
| 781 |
} |
| 782 |
return true |
| 783 |
} |
| 784 |
|
| 785 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 786 |
t.Errorf("Inv tests for Exp failed: %v", err) |
| 787 |
} |
| 788 |
} |
| 789 |
func TestLog_incr(t *testing.T) { |
| 790 |
invFn := func(q *Dense) bool { |
| 791 |
a := q.Clone().(*Dense) |
| 792 |
incr := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 793 |
correct := a.Clone().(*Dense) |
| 794 |
incr.Memset(identityVal(100, a.t)) |
| 795 |
correct.Add(incr, UseUnsafe()) |
| 796 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 797 |
_, ok := q.Engine().(Loger) |
| 798 |
we = we || !ok |
| 799 |
|
| 800 |
ret, err := Log(a, WithIncr(incr)) |
| 801 |
if err, retEarly := qcErrCheck(t, "Log", a, nil, we, err); retEarly { |
| 802 |
if err != nil { |
| 803 |
return false |
| 804 |
} |
| 805 |
return true |
| 806 |
} |
| 807 |
if ret, err = Sub(ret, identityVal(100, a.Dtype()), UseUnsafe()); err != nil { |
| 808 |
t.Errorf("err while subtracting incr: %v", err) |
| 809 |
return false |
| 810 |
} |
| 811 |
Exp(ret, UseUnsafe()) |
| 812 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 813 |
return false |
| 814 |
} |
| 815 |
return true |
| 816 |
} |
| 817 |
|
| 818 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 819 |
t.Errorf("Inv tests for Log failed: %v", err) |
| 820 |
} |
| 821 |
} |
| 822 |
func TestSqrt_incr(t *testing.T) { |
| 823 |
invFn := func(q *Dense) bool { |
| 824 |
a := q.Clone().(*Dense) |
| 825 |
incr := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 826 |
correct := a.Clone().(*Dense) |
| 827 |
incr.Memset(identityVal(100, a.t)) |
| 828 |
correct.Add(incr, UseUnsafe()) |
| 829 |
we, willFailEq := willerr(a, floatcmplxTypes, nil) |
| 830 |
_, ok := q.Engine().(Sqrter) |
| 831 |
we = we || !ok |
| 832 |
|
| 833 |
ret, err := Sqrt(a, WithIncr(incr)) |
| 834 |
if err, retEarly := qcErrCheck(t, "Sqrt", a, nil, we, err); retEarly { |
| 835 |
if err != nil { |
| 836 |
return false |
| 837 |
} |
| 838 |
return true |
| 839 |
} |
| 840 |
if ret, err = Sub(ret, identityVal(100, a.Dtype()), UseUnsafe()); err != nil { |
| 841 |
t.Errorf("err while subtracting incr: %v", err) |
| 842 |
return false |
| 843 |
} |
| 844 |
Square(ret, UseUnsafe()) |
| 845 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 846 |
return false |
| 847 |
} |
| 848 |
return true |
| 849 |
} |
| 850 |
|
| 851 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 852 |
t.Errorf("Inv tests for Sqrt failed: %v", err) |
| 853 |
} |
| 854 |
} |
| 855 |
func TestCbrt_incr(t *testing.T) { |
| 856 |
invFn := func(q *Dense) bool { |
| 857 |
a := q.Clone().(*Dense) |
| 858 |
incr := New(Of(a.t), WithShape(a.Shape().Clone()...)) |
| 859 |
correct := a.Clone().(*Dense) |
| 860 |
incr.Memset(identityVal(100, a.t)) |
| 861 |
correct.Add(incr, UseUnsafe()) |
| 862 |
we, willFailEq := willerr(a, floatTypes, nil) |
| 863 |
_, ok := q.Engine().(Cbrter) |
| 864 |
we = we || !ok |
| 865 |
|
| 866 |
ret, err := Cbrt(a, WithIncr(incr)) |
| 867 |
if err, retEarly := qcErrCheck(t, "Cbrt", a, nil, we, err); retEarly { |
| 868 |
if err != nil { |
| 869 |
return false |
| 870 |
} |
| 871 |
return true |
| 872 |
} |
| 873 |
if ret, err = Sub(ret, identityVal(100, a.Dtype()), UseUnsafe()); err != nil { |
| 874 |
t.Errorf("err while subtracting incr: %v", err) |
| 875 |
return false |
| 876 |
} |
| 877 |
Cube(ret, UseUnsafe()) |
| 878 |
if !qcEqCheck(t, a.Dtype(), willFailEq, correct.Data(), ret.Data()) { |
| 879 |
return false |
| 880 |
} |
| 881 |
return true |
| 882 |
} |
| 883 |
|
| 884 |
if err := quick.Check(invFn, &quick.Config{Rand: newRand(), MaxCount: quickchecks}); err != nil { |
| 885 |
t.Errorf("Inv tests for Cbrt failed: %v", err) |
| 886 |
} |
| 887 |
} |