github.com/wzzhu/tensor@v0.9.24/test_test.go (about) 1 // Code generated by genlib2. DO NOT EDIT. 2 3 package tensor 4 5 import ( 6 "fmt" 7 "math" 8 "math/cmplx" 9 "unsafe" 10 11 "github.com/chewxy/math32" 12 ) 13 14 func anyToFloat64s(x interface{}) (retVal []float64) { 15 switch xt := x.(type) { 16 case []int: 17 retVal = make([]float64, len(xt)) 18 for i, v := range xt { 19 retVal[i] = float64(v) 20 } 21 return 22 case []int8: 23 retVal = make([]float64, len(xt)) 24 for i, v := range xt { 25 retVal[i] = float64(v) 26 } 27 return 28 case []int16: 29 retVal = make([]float64, len(xt)) 30 for i, v := range xt { 31 retVal[i] = float64(v) 32 } 33 return 34 case []int32: 35 retVal = make([]float64, len(xt)) 36 for i, v := range xt { 37 retVal[i] = float64(v) 38 } 39 return 40 case []int64: 41 retVal = make([]float64, len(xt)) 42 for i, v := range xt { 43 retVal[i] = float64(v) 44 } 45 return 46 case []uint: 47 retVal = make([]float64, len(xt)) 48 for i, v := range xt { 49 retVal[i] = float64(v) 50 } 51 return 52 case []uint8: 53 retVal = make([]float64, len(xt)) 54 for i, v := range xt { 55 retVal[i] = float64(v) 56 } 57 return 58 case []uint16: 59 retVal = make([]float64, len(xt)) 60 for i, v := range xt { 61 retVal[i] = float64(v) 62 } 63 return 64 case []uint32: 65 retVal = make([]float64, len(xt)) 66 for i, v := range xt { 67 retVal[i] = float64(v) 68 } 69 return 70 case []uint64: 71 retVal = make([]float64, len(xt)) 72 for i, v := range xt { 73 retVal[i] = float64(v) 74 } 75 return 76 case []float32: 77 retVal = make([]float64, len(xt)) 78 for i, v := range xt { 79 switch { 80 case math32.IsNaN(v): 81 retVal[i] = math.NaN() 82 case math32.IsInf(v, 1): 83 retVal[i] = math.Inf(1) 84 case math32.IsInf(v, -1): 85 retVal[i] = math.Inf(-1) 86 default: 87 retVal[i] = float64(v) 88 } 89 } 90 return 91 case []float64: 92 return xt 93 case []complex64: 94 retVal = make([]float64, len(xt)) 95 for i, v := range xt { 96 switch { 97 case cmplx.IsNaN(complex128(v)): 98 retVal[i] = math.NaN() 99 case cmplx.IsInf(complex128(v)): 100 retVal[i] = math.Inf(1) 101 default: 102 retVal[i] = float64(real(v)) 103 } 104 } 105 return 106 case []complex128: 107 retVal = make([]float64, len(xt)) 108 for i, v := range xt { 109 switch { 110 case cmplx.IsNaN(v): 111 retVal[i] = math.NaN() 112 case cmplx.IsInf(v): 113 retVal[i] = math.Inf(1) 114 default: 115 retVal[i] = real(v) 116 } 117 } 118 return 119 } 120 panic("Unreachable") 121 } 122 123 func identityVal(x int, dt Dtype) interface{} { 124 switch dt { 125 case Int: 126 return int(x) 127 case Int8: 128 return int8(x) 129 case Int16: 130 return int16(x) 131 case Int32: 132 return int32(x) 133 case Int64: 134 return int64(x) 135 case Uint: 136 return uint(x) 137 case Uint8: 138 return uint8(x) 139 case Uint16: 140 return uint16(x) 141 case Uint32: 142 return uint32(x) 143 case Uint64: 144 return uint64(x) 145 case Float32: 146 return float32(x) 147 case Float64: 148 return float64(x) 149 case Complex64: 150 var c complex64 151 if x == 0 { 152 return c 153 } 154 c = 1 155 return c 156 case Complex128: 157 var c complex128 158 if x == 0 { 159 return c 160 } 161 c = 1 162 return c 163 case Bool: 164 if x == 0 { 165 return false 166 } 167 return true 168 case String: 169 if x == 0 { 170 return "" 171 } 172 return fmt.Sprintf("%v", x) 173 default: 174 return x 175 } 176 } 177 func threewayEq(a, b, c interface{}) bool { 178 switch at := a.(type) { 179 case []int: 180 bt := b.([]int) 181 ct := c.([]int) 182 183 for i, va := range at { 184 if va == 1 && bt[i] == 1 { 185 if ct[i] != 1 { 186 return false 187 } 188 } 189 } 190 return true 191 case []int8: 192 bt := b.([]int8) 193 ct := c.([]int8) 194 195 for i, va := range at { 196 if va == 1 && bt[i] == 1 { 197 if ct[i] != 1 { 198 return false 199 } 200 } 201 } 202 return true 203 case []int16: 204 bt := b.([]int16) 205 ct := c.([]int16) 206 207 for i, va := range at { 208 if va == 1 && bt[i] == 1 { 209 if ct[i] != 1 { 210 return false 211 } 212 } 213 } 214 return true 215 case []int32: 216 bt := b.([]int32) 217 ct := c.([]int32) 218 219 for i, va := range at { 220 if va == 1 && bt[i] == 1 { 221 if ct[i] != 1 { 222 return false 223 } 224 } 225 } 226 return true 227 case []int64: 228 bt := b.([]int64) 229 ct := c.([]int64) 230 231 for i, va := range at { 232 if va == 1 && bt[i] == 1 { 233 if ct[i] != 1 { 234 return false 235 } 236 } 237 } 238 return true 239 case []uint: 240 bt := b.([]uint) 241 ct := c.([]uint) 242 243 for i, va := range at { 244 if va == 1 && bt[i] == 1 { 245 if ct[i] != 1 { 246 return false 247 } 248 } 249 } 250 return true 251 case []uint8: 252 bt := b.([]uint8) 253 ct := c.([]uint8) 254 255 for i, va := range at { 256 if va == 1 && bt[i] == 1 { 257 if ct[i] != 1 { 258 return false 259 } 260 } 261 } 262 return true 263 case []uint16: 264 bt := b.([]uint16) 265 ct := c.([]uint16) 266 267 for i, va := range at { 268 if va == 1 && bt[i] == 1 { 269 if ct[i] != 1 { 270 return false 271 } 272 } 273 } 274 return true 275 case []uint32: 276 bt := b.([]uint32) 277 ct := c.([]uint32) 278 279 for i, va := range at { 280 if va == 1 && bt[i] == 1 { 281 if ct[i] != 1 { 282 return false 283 } 284 } 285 } 286 return true 287 case []uint64: 288 bt := b.([]uint64) 289 ct := c.([]uint64) 290 291 for i, va := range at { 292 if va == 1 && bt[i] == 1 { 293 if ct[i] != 1 { 294 return false 295 } 296 } 297 } 298 return true 299 case []float32: 300 bt := b.([]float32) 301 ct := c.([]float32) 302 303 for i, va := range at { 304 if va == 1 && bt[i] == 1 { 305 if ct[i] != 1 { 306 return false 307 } 308 } 309 } 310 return true 311 case []float64: 312 bt := b.([]float64) 313 ct := c.([]float64) 314 315 for i, va := range at { 316 if va == 1 && bt[i] == 1 { 317 if ct[i] != 1 { 318 return false 319 } 320 } 321 } 322 return true 323 case []complex64: 324 bt := b.([]complex64) 325 ct := c.([]complex64) 326 327 for i, va := range at { 328 if va == 1 && bt[i] == 1 { 329 if ct[i] != 1 { 330 return false 331 } 332 } 333 } 334 return true 335 case []complex128: 336 bt := b.([]complex128) 337 ct := c.([]complex128) 338 339 for i, va := range at { 340 if va == 1 && bt[i] == 1 { 341 if ct[i] != 1 { 342 return false 343 } 344 } 345 } 346 return true 347 case int: 348 bt := b.(int) 349 ct := c.(int) 350 if (at == 1 && bt == 1) && ct != 1 { 351 return false 352 } 353 return true 354 case int8: 355 bt := b.(int8) 356 ct := c.(int8) 357 if (at == 1 && bt == 1) && ct != 1 { 358 return false 359 } 360 return true 361 case int16: 362 bt := b.(int16) 363 ct := c.(int16) 364 if (at == 1 && bt == 1) && ct != 1 { 365 return false 366 } 367 return true 368 case int32: 369 bt := b.(int32) 370 ct := c.(int32) 371 if (at == 1 && bt == 1) && ct != 1 { 372 return false 373 } 374 return true 375 case int64: 376 bt := b.(int64) 377 ct := c.(int64) 378 if (at == 1 && bt == 1) && ct != 1 { 379 return false 380 } 381 return true 382 case uint: 383 bt := b.(uint) 384 ct := c.(uint) 385 if (at == 1 && bt == 1) && ct != 1 { 386 return false 387 } 388 return true 389 case uint8: 390 bt := b.(uint8) 391 ct := c.(uint8) 392 if (at == 1 && bt == 1) && ct != 1 { 393 return false 394 } 395 return true 396 case uint16: 397 bt := b.(uint16) 398 ct := c.(uint16) 399 if (at == 1 && bt == 1) && ct != 1 { 400 return false 401 } 402 return true 403 case uint32: 404 bt := b.(uint32) 405 ct := c.(uint32) 406 if (at == 1 && bt == 1) && ct != 1 { 407 return false 408 } 409 return true 410 case uint64: 411 bt := b.(uint64) 412 ct := c.(uint64) 413 if (at == 1 && bt == 1) && ct != 1 { 414 return false 415 } 416 return true 417 case float32: 418 bt := b.(float32) 419 ct := c.(float32) 420 if (at == 1 && bt == 1) && ct != 1 { 421 return false 422 } 423 return true 424 case float64: 425 bt := b.(float64) 426 ct := c.(float64) 427 if (at == 1 && bt == 1) && ct != 1 { 428 return false 429 } 430 return true 431 case complex64: 432 bt := b.(complex64) 433 ct := c.(complex64) 434 if (at == 1 && bt == 1) && ct != 1 { 435 return false 436 } 437 return true 438 case complex128: 439 bt := b.(complex128) 440 ct := c.(complex128) 441 if (at == 1 && bt == 1) && ct != 1 { 442 return false 443 } 444 return true 445 } 446 447 return false 448 } 449 450 func identityB(a bool) bool { return a } 451 func identityI(a int) int { return a } 452 func identityI8(a int8) int8 { return a } 453 func identityI16(a int16) int16 { return a } 454 func identityI32(a int32) int32 { return a } 455 func identityI64(a int64) int64 { return a } 456 func identityU(a uint) uint { return a } 457 func identityU8(a uint8) uint8 { return a } 458 func identityU16(a uint16) uint16 { return a } 459 func identityU32(a uint32) uint32 { return a } 460 func identityU64(a uint64) uint64 { return a } 461 func identityUintptr(a uintptr) uintptr { return a } 462 func identityF32(a float32) float32 { return a } 463 func identityF64(a float64) float64 { return a } 464 func identityC64(a complex64) complex64 { return a } 465 func identityC128(a complex128) complex128 { return a } 466 func identityStr(a string) string { return a } 467 func identityUnsafePointer(a unsafe.Pointer) unsafe.Pointer { return a } 468 func mutateB(a bool) bool { return true } 469 func mutateI(a int) int { return 1 } 470 func mutateI8(a int8) int8 { return 1 } 471 func mutateI16(a int16) int16 { return 1 } 472 func mutateI32(a int32) int32 { return 1 } 473 func mutateI64(a int64) int64 { return 1 } 474 func mutateU(a uint) uint { return 1 } 475 func mutateU8(a uint8) uint8 { return 1 } 476 func mutateU16(a uint16) uint16 { return 1 } 477 func mutateU32(a uint32) uint32 { return 1 } 478 func mutateU64(a uint64) uint64 { return 1 } 479 func mutateUintptr(a uintptr) uintptr { return 0xdeadbeef } 480 func mutateF32(a float32) float32 { return 1 } 481 func mutateF64(a float64) float64 { return 1 } 482 func mutateC64(a complex64) complex64 { return 1 } 483 func mutateC128(a complex128) complex128 { return 1 } 484 func mutateStr(a string) string { return "Hello World" } 485 func mutateUnsafePointer(a unsafe.Pointer) unsafe.Pointer { return unsafe.Pointer(uintptr(0xdeadbeef)) }