| 1 |
# Start of scalar.py. |
| 2 |
|
| 3 |
import numpy as np |
| 4 |
import math |
| 5 |
import struct |
| 6 |
|
| 7 |
pi16 = np.float16(np.pi) |
| 8 |
pi32 = np.float32(np.pi) |
| 9 |
pi64 = np.float64(np.pi) |
| 10 |
|
| 11 |
|
| 12 |
def intlit(t, x): |
| 13 |
if t == np.int8: |
| 14 |
return np.int8(x) |
| 15 |
elif t == np.int16: |
| 16 |
return np.int16(x) |
| 17 |
elif t == np.int32: |
| 18 |
return np.int32(x) |
| 19 |
else: |
| 20 |
return np.int64(x) |
| 21 |
|
| 22 |
|
| 23 |
def signed(x): |
| 24 |
if type(x) == np.uint8: |
| 25 |
return np.int8(x) |
| 26 |
elif type(x) == np.uint16: |
| 27 |
return np.int16(x) |
| 28 |
elif type(x) == np.uint32: |
| 29 |
return np.int32(x) |
| 30 |
else: |
| 31 |
return np.int64(x) |
| 32 |
|
| 33 |
|
| 34 |
def unsigned(x): |
| 35 |
if type(x) == np.int8: |
| 36 |
return np.uint8(x) |
| 37 |
elif type(x) == np.int16: |
| 38 |
return np.uint16(x) |
| 39 |
elif type(x) == np.int32: |
| 40 |
return np.uint32(x) |
| 41 |
else: |
| 42 |
return np.uint64(x) |
| 43 |
|
| 44 |
|
| 45 |
def shlN(x, y): |
| 46 |
return x << y |
| 47 |
|
| 48 |
|
| 49 |
def ashrN(x, y): |
| 50 |
return x >> y |
| 51 |
|
| 52 |
|
| 53 |
# Python is so slow that we just make all the unsafe operations safe, |
| 54 |
# always. |
| 55 |
|
| 56 |
|
| 57 |
def sdivN(x, y): |
| 58 |
if y == 0: |
| 59 |
return intlit(type(x), 0) |
| 60 |
else: |
| 61 |
return x // y |
| 62 |
|
| 63 |
|
| 64 |
def sdiv_upN(x, y): |
| 65 |
if y == 0: |
| 66 |
return intlit(type(x), 0) |
| 67 |
else: |
| 68 |
return (x + y - intlit(type(x), 1)) // y |
| 69 |
|
| 70 |
|
| 71 |
def smodN(x, y): |
| 72 |
if y == 0: |
| 73 |
return intlit(type(x), 0) |
| 74 |
else: |
| 75 |
return x % y |
| 76 |
|
| 77 |
|
| 78 |
def udivN(x, y): |
| 79 |
if y == 0: |
| 80 |
return intlit(type(x), 0) |
| 81 |
else: |
| 82 |
return signed(unsigned(x) // unsigned(y)) |
| 83 |
|
| 84 |
|
| 85 |
def udiv_upN(x, y): |
| 86 |
if y == 0: |
| 87 |
return intlit(type(x), 0) |
| 88 |
else: |
| 89 |
return signed( |
| 90 |
(unsigned(x) + unsigned(y) - unsigned(intlit(type(x), 1))) |
| 91 |
// unsigned(y) |
| 92 |
) |
| 93 |
|
| 94 |
|
| 95 |
def umodN(x, y): |
| 96 |
if y == 0: |
| 97 |
return intlit(type(x), 0) |
| 98 |
else: |
| 99 |
return signed(unsigned(x) % unsigned(y)) |
| 100 |
|
| 101 |
|
| 102 |
def squotN(x, y): |
| 103 |
if y == 0: |
| 104 |
return intlit(type(x), 0) |
| 105 |
else: |
| 106 |
return np.floor_divide(np.abs(x), np.abs(y)) * np.sign(x) * np.sign(y) |
| 107 |
|
| 108 |
|
| 109 |
def sremN(x, y): |
| 110 |
if y == 0: |
| 111 |
return intlit(type(x), 0) |
| 112 |
else: |
| 113 |
return np.remainder(np.abs(x), np.abs(y)) * np.sign(x) |
| 114 |
|
| 115 |
|
| 116 |
def sminN(x, y): |
| 117 |
return min(x, y) |
| 118 |
|
| 119 |
|
| 120 |
def smaxN(x, y): |
| 121 |
return max(x, y) |
| 122 |
|
| 123 |
|
| 124 |
def uminN(x, y): |
| 125 |
return signed(min(unsigned(x), unsigned(y))) |
| 126 |
|
| 127 |
|
| 128 |
def umaxN(x, y): |
| 129 |
return signed(max(unsigned(x), unsigned(y))) |
| 130 |
|
| 131 |
|
| 132 |
def fminN(x, y): |
| 133 |
return np.fmin(x, y) |
| 134 |
|
| 135 |
|
| 136 |
def fmaxN(x, y): |
| 137 |
return np.fmax(x, y) |
| 138 |
|
| 139 |
|
| 140 |
def powN(x, y): |
| 141 |
return x**y |
| 142 |
|
| 143 |
|
| 144 |
def fpowN(x, y): |
| 145 |
return x**y |
| 146 |
|
| 147 |
|
| 148 |
def sleN(x, y): |
| 149 |
return x <= y |
| 150 |
|
| 151 |
|
| 152 |
def sltN(x, y): |
| 153 |
return x < y |
| 154 |
|
| 155 |
|
| 156 |
def uleN(x, y): |
| 157 |
return unsigned(x) <= unsigned(y) |
| 158 |
|
| 159 |
|
| 160 |
def ultN(x, y): |
| 161 |
return unsigned(x) < unsigned(y) |
| 162 |
|
| 163 |
|
| 164 |
def lshr8(x, y): |
| 165 |
return np.int8(np.uint8(x) >> np.uint8(y)) |
| 166 |
|
| 167 |
|
| 168 |
def lshr16(x, y): |
| 169 |
return np.int16(np.uint16(x) >> np.uint16(y)) |
| 170 |
|
| 171 |
|
| 172 |
def lshr32(x, y): |
| 173 |
return np.int32(np.uint32(x) >> np.uint32(y)) |
| 174 |
|
| 175 |
|
| 176 |
def lshr64(x, y): |
| 177 |
return np.int64(np.uint64(x) >> np.uint64(y)) |
| 178 |
|
| 179 |
|
| 180 |
def sext_T_i8(x): |
| 181 |
return np.int8(x) |
| 182 |
|
| 183 |
|
| 184 |
def sext_T_i16(x): |
| 185 |
return np.int16(x) |
| 186 |
|
| 187 |
|
| 188 |
def sext_T_i32(x): |
| 189 |
return np.int32(x) |
| 190 |
|
| 191 |
|
| 192 |
def sext_T_i64(x): |
| 193 |
return np.int64(x) |
| 194 |
|
| 195 |
|
| 196 |
def itob_T_bool(x): |
| 197 |
return bool(x) |
| 198 |
|
| 199 |
|
| 200 |
def btoi_bool_i8(x): |
| 201 |
return np.int8(x) |
| 202 |
|
| 203 |
|
| 204 |
def btoi_bool_i16(x): |
| 205 |
return np.int16(x) |
| 206 |
|
| 207 |
|
| 208 |
def btoi_bool_i32(x): |
| 209 |
return np.int32(x) |
| 210 |
|
| 211 |
|
| 212 |
def btoi_bool_i64(x): |
| 213 |
return np.int64(x) |
| 214 |
|
| 215 |
|
| 216 |
def ftob_T_bool(x): |
| 217 |
return bool(x) |
| 218 |
|
| 219 |
|
| 220 |
def btof_bool_f16(x): |
| 221 |
return np.float16(x) |
| 222 |
|
| 223 |
|
| 224 |
def btof_bool_f32(x): |
| 225 |
return np.float32(x) |
| 226 |
|
| 227 |
|
| 228 |
def btof_bool_f64(x): |
| 229 |
return np.float64(x) |
| 230 |
|
| 231 |
|
| 232 |
def zext_i8_i8(x): |
| 233 |
return np.int8(np.uint8(x)) |
| 234 |
|
| 235 |
|
| 236 |
def zext_i8_i16(x): |
| 237 |
return np.int16(np.uint8(x)) |
| 238 |
|
| 239 |
|
| 240 |
def zext_i8_i32(x): |
| 241 |
return np.int32(np.uint8(x)) |
| 242 |
|
| 243 |
|
| 244 |
def zext_i8_i64(x): |
| 245 |
return np.int64(np.uint8(x)) |
| 246 |
|
| 247 |
|
| 248 |
def zext_i16_i8(x): |
| 249 |
return np.int8(np.uint16(x)) |
| 250 |
|
| 251 |
|
| 252 |
def zext_i16_i16(x): |
| 253 |
return np.int16(np.uint16(x)) |
| 254 |
|
| 255 |
|
| 256 |
def zext_i16_i32(x): |
| 257 |
return np.int32(np.uint16(x)) |
| 258 |
|
| 259 |
|
| 260 |
def zext_i16_i64(x): |
| 261 |
return np.int64(np.uint16(x)) |
| 262 |
|
| 263 |
|
| 264 |
def zext_i32_i8(x): |
| 265 |
return np.int8(np.uint32(x)) |
| 266 |
|
| 267 |
|
| 268 |
def zext_i32_i16(x): |
| 269 |
return np.int16(np.uint32(x)) |
| 270 |
|
| 271 |
|
| 272 |
def zext_i32_i32(x): |
| 273 |
return np.int32(np.uint32(x)) |
| 274 |
|
| 275 |
|
| 276 |
def zext_i32_i64(x): |
| 277 |
return np.int64(np.uint32(x)) |
| 278 |
|
| 279 |
|
| 280 |
def zext_i64_i8(x): |
| 281 |
return np.int8(np.uint64(x)) |
| 282 |
|
| 283 |
|
| 284 |
def zext_i64_i16(x): |
| 285 |
return np.int16(np.uint64(x)) |
| 286 |
|
| 287 |
|
| 288 |
def zext_i64_i32(x): |
| 289 |
return np.int32(np.uint64(x)) |
| 290 |
|
| 291 |
|
| 292 |
def zext_i64_i64(x): |
| 293 |
return np.int64(np.uint64(x)) |
| 294 |
|
| 295 |
|
| 296 |
sdiv8 = sdiv16 = sdiv32 = sdiv64 = sdivN |
| 297 |
sdiv_up8 = sdiv1_up6 = sdiv_up32 = sdiv_up64 = sdiv_upN |
| 298 |
sdiv_safe8 = sdiv1_safe6 = sdiv_safe32 = sdiv_safe64 = sdivN |
| 299 |
sdiv_up_safe8 = sdiv_up1_safe6 = sdiv_up_safe32 = sdiv_up_safe64 = sdiv_upN |
| 300 |
smod8 = smod16 = smod32 = smod64 = smodN |
| 301 |
smod_safe8 = smod_safe16 = smod_safe32 = smod_safe64 = smodN |
| 302 |
udiv8 = udiv16 = udiv32 = udiv64 = udivN |
| 303 |
udiv_up8 = udiv_up16 = udiv_up32 = udiv_up64 = udivN |
| 304 |
udiv_safe8 = udiv_safe16 = udiv_safe32 = udiv_safe64 = udiv_upN |
| 305 |
udiv_up_safe8 = udiv_up_safe16 = udiv_up_safe32 = udiv_up_safe64 = udiv_upN |
| 306 |
umod8 = umod16 = umod32 = umod64 = umodN |
| 307 |
umod_safe8 = umod_safe16 = umod_safe32 = umod_safe64 = umodN |
| 308 |
squot8 = squot16 = squot32 = squot64 = squotN |
| 309 |
squot_safe8 = squot_safe16 = squot_safe32 = squot_safe64 = squotN |
| 310 |
srem8 = srem16 = srem32 = srem64 = sremN |
| 311 |
srem_safe8 = srem_safe16 = srem_safe32 = srem_safe64 = sremN |
| 312 |
|
| 313 |
shl8 = shl16 = shl32 = shl64 = shlN |
| 314 |
ashr8 = ashr16 = ashr32 = ashr64 = ashrN |
| 315 |
smax8 = smax16 = smax32 = smax64 = smaxN |
| 316 |
smin8 = smin16 = smin32 = smin64 = sminN |
| 317 |
umax8 = umax16 = umax32 = umax64 = umaxN |
| 318 |
umin8 = umin16 = umin32 = umin64 = uminN |
| 319 |
pow8 = pow16 = pow32 = pow64 = powN |
| 320 |
fpow16 = fpow32 = fpow64 = fpowN |
| 321 |
fmax16 = fmax32 = fmax64 = fmaxN |
| 322 |
fmin16 = fmin32 = fmin64 = fminN |
| 323 |
sle8 = sle16 = sle32 = sle64 = sleN |
| 324 |
slt8 = slt16 = slt32 = slt64 = sltN |
| 325 |
ule8 = ule16 = ule32 = ule64 = uleN |
| 326 |
ult8 = ult16 = ult32 = ult64 = ultN |
| 327 |
sext_i8_i8 = sext_i16_i8 = sext_i32_i8 = sext_i64_i8 = sext_T_i8 |
| 328 |
sext_i8_i16 = sext_i16_i16 = sext_i32_i16 = sext_i64_i16 = sext_T_i16 |
| 329 |
sext_i8_i32 = sext_i16_i32 = sext_i32_i32 = sext_i64_i32 = sext_T_i32 |
| 330 |
sext_i8_i64 = sext_i16_i64 = sext_i32_i64 = sext_i64_i64 = sext_T_i64 |
| 331 |
itob_i8_bool = itob_i16_bool = itob_i32_bool = itob_i64_bool = itob_T_bool |
| 332 |
ftob_f16_bool = ftob_f32_bool = ftob_f64_bool = ftob_T_bool |
| 333 |
|
| 334 |
|
| 335 |
def clz_T(x): |
| 336 |
n = np.int32(0) |
| 337 |
bits = x.itemsize * 8 |
| 338 |
for i in range(bits): |
| 339 |
if x < 0: |
| 340 |
break |
| 341 |
n += np.int32(1) |
| 342 |
x <<= np.int8(1) |
| 343 |
return n |
| 344 |
|
| 345 |
|
| 346 |
def ctz_T(x): |
| 347 |
n = np.int32(0) |
| 348 |
bits = x.itemsize * 8 |
| 349 |
for i in range(bits): |
| 350 |
if (x & 1) == 1: |
| 351 |
break |
| 352 |
n += np.int32(1) |
| 353 |
x >>= np.int8(1) |
| 354 |
return n |
| 355 |
|
| 356 |
|
| 357 |
def popc_T(x): |
| 358 |
c = np.int32(0) |
| 359 |
while x != 0: |
| 360 |
x &= x - np.int8(1) |
| 361 |
c += np.int32(1) |
| 362 |
return c |
| 363 |
|
| 364 |
|
| 365 |
futhark_popc8 = futhark_popc16 = futhark_popc32 = futhark_popc64 = popc_T |
| 366 |
futhark_clzz8 = futhark_clzz16 = futhark_clzz32 = futhark_clzz64 = clz_T |
| 367 |
futhark_ctzz8 = futhark_ctzz16 = futhark_ctzz32 = futhark_ctzz64 = ctz_T |
| 368 |
|
| 369 |
|
| 370 |
def ssignum(x): |
| 371 |
return np.sign(x) |
| 372 |
|
| 373 |
|
| 374 |
def usignum(x): |
| 375 |
if x < 0: |
| 376 |
return ssignum(-x) |
| 377 |
else: |
| 378 |
return ssignum(x) |
| 379 |
|
| 380 |
|
| 381 |
def sitofp_T_f32(x): |
| 382 |
return np.float32(x) |
| 383 |
|
| 384 |
|
| 385 |
sitofp_i8_f32 = sitofp_i16_f32 = sitofp_i32_f32 = sitofp_i64_f32 = sitofp_T_f32 |
| 386 |
|
| 387 |
|
| 388 |
def sitofp_T_f64(x): |
| 389 |
return np.float64(x) |
| 390 |
|
| 391 |
|
| 392 |
sitofp_i8_f64 = sitofp_i16_f64 = sitofp_i32_f64 = sitofp_i64_f64 = sitofp_T_f64 |
| 393 |
|
| 394 |
|
| 395 |
def uitofp_T_f32(x): |
| 396 |
return np.float32(unsigned(x)) |
| 397 |
|
| 398 |
|
| 399 |
uitofp_i8_f32 = uitofp_i16_f32 = uitofp_i32_f32 = uitofp_i64_f32 = uitofp_T_f32 |
| 400 |
|
| 401 |
|
| 402 |
def uitofp_T_f64(x): |
| 403 |
return np.float64(unsigned(x)) |
| 404 |
|
| 405 |
|
| 406 |
uitofp_i8_f64 = uitofp_i16_f64 = uitofp_i32_f64 = uitofp_i64_f64 = uitofp_T_f64 |
| 407 |
|
| 408 |
|
| 409 |
def fptosi_T_i8(x): |
| 410 |
if np.isnan(x) or np.isinf(x): |
| 411 |
return np.int8(0) |
| 412 |
else: |
| 413 |
return np.int8(np.trunc(x)) |
| 414 |
|
| 415 |
|
| 416 |
fptosi_f16_i8 = fptosi_f32_i8 = fptosi_f64_i8 = fptosi_T_i8 |
| 417 |
|
| 418 |
|
| 419 |
def fptosi_T_i16(x): |
| 420 |
if np.isnan(x) or np.isinf(x): |
| 421 |
return np.int16(0) |
| 422 |
else: |
| 423 |
return np.int16(np.trunc(x)) |
| 424 |
|
| 425 |
|
| 426 |
fptosi_f16_i16 = fptosi_f32_i16 = fptosi_f64_i16 = fptosi_T_i16 |
| 427 |
|
| 428 |
|
| 429 |
def fptosi_T_i32(x): |
| 430 |
if np.isnan(x) or np.isinf(x): |
| 431 |
return np.int32(0) |
| 432 |
else: |
| 433 |
return np.int32(np.trunc(x)) |
| 434 |
|
| 435 |
|
| 436 |
fptosi_f16_i32 = fptosi_f32_i32 = fptosi_f64_i32 = fptosi_T_i32 |
| 437 |
|
| 438 |
|
| 439 |
def fptosi_T_i64(x): |
| 440 |
if np.isnan(x) or np.isinf(x): |
| 441 |
return np.int64(0) |
| 442 |
else: |
| 443 |
return np.int64(np.trunc(x)) |
| 444 |
|
| 445 |
|
| 446 |
fptosi_f16_i64 = fptosi_f32_i64 = fptosi_f64_i64 = fptosi_T_i64 |
| 447 |
|
| 448 |
|
| 449 |
def fptoui_T_i8(x): |
| 450 |
if np.isnan(x) or np.isinf(x): |
| 451 |
return np.int8(0) |
| 452 |
else: |
| 453 |
return np.int8(np.trunc(x)) |
| 454 |
|
| 455 |
|
| 456 |
fptoui_f16_i8 = fptoui_f32_i8 = fptoui_f64_i8 = fptoui_T_i8 |
| 457 |
|
| 458 |
|
| 459 |
def fptoui_T_i16(x): |
| 460 |
if np.isnan(x) or np.isinf(x): |
| 461 |
return np.int16(0) |
| 462 |
else: |
| 463 |
return np.int16(np.trunc(x)) |
| 464 |
|
| 465 |
|
| 466 |
fptoui_f16_i16 = fptoui_f32_i16 = fptoui_f64_i16 = fptoui_T_i16 |
| 467 |
|
| 468 |
|
| 469 |
def fptoui_T_i32(x): |
| 470 |
if np.isnan(x) or np.isinf(x): |
| 471 |
return np.int32(0) |
| 472 |
else: |
| 473 |
return np.int32(np.trunc(x)) |
| 474 |
|
| 475 |
|
| 476 |
fptoui_f16_i32 = fptoui_f32_i32 = fptoui_f64_i32 = fptoui_T_i32 |
| 477 |
|
| 478 |
|
| 479 |
def fptoui_T_i64(x): |
| 480 |
if np.isnan(x) or np.isinf(x): |
| 481 |
return np.int64(0) |
| 482 |
else: |
| 483 |
return np.int64(np.trunc(x)) |
| 484 |
|
| 485 |
|
| 486 |
fptoui_f16_i64 = fptoui_f32_i64 = fptoui_f64_i64 = fptoui_T_i64 |
| 487 |
|
| 488 |
|
| 489 |
def fpconv_f16_f32(x): |
| 490 |
return np.float32(x) |
| 491 |
|
| 492 |
|
| 493 |
def fpconv_f16_f64(x): |
| 494 |
return np.float64(x) |
| 495 |
|
| 496 |
|
| 497 |
def fpconv_f32_f16(x): |
| 498 |
return np.float16(x) |
| 499 |
|
| 500 |
|
| 501 |
def fpconv_f32_f64(x): |
| 502 |
return np.float64(x) |
| 503 |
|
| 504 |
|
| 505 |
def fpconv_f64_f16(x): |
| 506 |
return np.float16(x) |
| 507 |
|
| 508 |
|
| 509 |
def fpconv_f64_f32(x): |
| 510 |
return np.float32(x) |
| 511 |
|
| 512 |
|
| 513 |
def futhark_umul_hi8(a, b): |
| 514 |
return np.int8( |
| 515 |
(np.uint64(np.uint8(a)) * np.uint64(np.uint8(b))) >> np.uint64(8) |
| 516 |
) |
| 517 |
|
| 518 |
|
| 519 |
def futhark_umul_hi16(a, b): |
| 520 |
return np.int16( |
| 521 |
(np.uint64(np.uint16(a)) * np.uint64(np.uint16(b))) >> np.uint64(16) |
| 522 |
) |
| 523 |
|
| 524 |
|
| 525 |
def futhark_umul_hi32(a, b): |
| 526 |
return np.int32( |
| 527 |
(np.uint64(np.uint32(a)) * np.uint64(np.uint32(b))) >> np.uint64(32) |
| 528 |
) |
| 529 |
|
| 530 |
|
| 531 |
def futhark_umul_hi64(a, b): |
| 532 |
return np.int64(np.uint64(int(np.uint64(a)) * int(np.uint64(b)) >> 64)) |
| 533 |
|
| 534 |
|
| 535 |
def futhark_smul_hi8(a, b): |
| 536 |
return np.int8((np.int64(a) * np.int64(b)) >> np.int64(8)) |
| 537 |
|
| 538 |
|
| 539 |
def futhark_smul_hi16(a, b): |
| 540 |
return np.int16((np.int64(a) * np.int64(b)) >> np.int64(16)) |
| 541 |
|
| 542 |
|
| 543 |
def futhark_smul_hi32(a, b): |
| 544 |
return np.int32((np.int64(a) * np.int64(b)) >> np.int64(32)) |
| 545 |
|
| 546 |
|
| 547 |
def futhark_smul_hi64(a, b): |
| 548 |
return np.int64(int(a) * int(b) >> 64) |
| 549 |
|
| 550 |
|
| 551 |
def futhark_umad_hi8(a, b, c): |
| 552 |
return futhark_umul_hi8(a, b) + c |
| 553 |
|
| 554 |
|
| 555 |
def futhark_umad_hi16(a, b, c): |
| 556 |
return futhark_umul_hi16(a, b) + c |
| 557 |
|
| 558 |
|
| 559 |
def futhark_umad_hi32(a, b, c): |
| 560 |
return futhark_umul_hi32(a, b) + c |
| 561 |
|
| 562 |
|
| 563 |
def futhark_umad_hi64(a, b, c): |
| 564 |
return futhark_umul_hi64(a, b) + c |
| 565 |
|
| 566 |
|
| 567 |
def futhark_smad_hi8(a, b, c): |
| 568 |
return futhark_smul_hi8(a, b) + c |
| 569 |
|
| 570 |
|
| 571 |
def futhark_smad_hi16(a, b, c): |
| 572 |
return futhark_smul_hi16(a, b) + c |
| 573 |
|
| 574 |
|
| 575 |
def futhark_smad_hi32(a, b, c): |
| 576 |
return futhark_smul_hi32(a, b) + c |
| 577 |
|
| 578 |
|
| 579 |
def futhark_smad_hi64(a, b, c): |
| 580 |
return futhark_smul_hi64(a, b) + c |
| 581 |
|
| 582 |
|
| 583 |
def futhark_log64(x): |
| 584 |
return np.float64(np.log(x)) |
| 585 |
|
| 586 |
|
| 587 |
def futhark_log2_64(x): |
| 588 |
return np.float64(np.log2(x)) |
| 589 |
|
| 590 |
|
| 591 |
def futhark_log10_64(x): |
| 592 |
return np.float64(np.log10(x)) |
| 593 |
|
| 594 |
|
| 595 |
def futhark_log1p_64(x): |
| 596 |
return np.float64(np.log1p(x)) |
| 597 |
|
| 598 |
|
| 599 |
def futhark_sqrt64(x): |
| 600 |
return np.sqrt(x) |
| 601 |
|
| 602 |
|
| 603 |
def futhark_rsqrt64(x): |
| 604 |
return 1 / np.sqrt(x) |
| 605 |
|
| 606 |
|
| 607 |
def futhark_cbrt64(x): |
| 608 |
return np.cbrt(x) |
| 609 |
|
| 610 |
|
| 611 |
def futhark_exp64(x): |
| 612 |
return np.exp(x) |
| 613 |
|
| 614 |
|
| 615 |
def futhark_cos64(x): |
| 616 |
return np.cos(x) |
| 617 |
|
| 618 |
|
| 619 |
def futhark_cospi64(x): |
| 620 |
return np.cos(pi64 * x) |
| 621 |
|
| 622 |
|
| 623 |
def futhark_sin64(x): |
| 624 |
return np.sin(x) |
| 625 |
|
| 626 |
|
| 627 |
def futhark_sinpi64(x): |
| 628 |
return np.sin(pi64 * x) |
| 629 |
|
| 630 |
|
| 631 |
def futhark_tan64(x): |
| 632 |
return np.tan(x) |
| 633 |
|
| 634 |
|
| 635 |
def futhark_tanpi64(x): |
| 636 |
return np.tan(pi64 * x) |
| 637 |
|
| 638 |
|
| 639 |
def futhark_acos64(x): |
| 640 |
return np.arccos(x) |
| 641 |
|
| 642 |
|
| 643 |
def futhark_acospi64(x): |
| 644 |
return np.arccos(x) / pi64 |
| 645 |
|
| 646 |
|
| 647 |
def futhark_asin64(x): |
| 648 |
return np.arcsin(x) |
| 649 |
|
| 650 |
|
| 651 |
def futhark_asinpi64(x): |
| 652 |
return np.arcsin(x) / pi64 |
| 653 |
|
| 654 |
|
| 655 |
def futhark_atan64(x): |
| 656 |
return np.arctan(x) |
| 657 |
|
| 658 |
|
| 659 |
def futhark_atanpi64(x): |
| 660 |
return np.arctan(x) / pi64 |
| 661 |
|
| 662 |
|
| 663 |
def futhark_cosh64(x): |
| 664 |
return np.cosh(x) |
| 665 |
|
| 666 |
|
| 667 |
def futhark_sinh64(x): |
| 668 |
return np.sinh(x) |
| 669 |
|
| 670 |
|
| 671 |
def futhark_tanh64(x): |
| 672 |
return np.tanh(x) |
| 673 |
|
| 674 |
|
| 675 |
def futhark_acosh64(x): |
| 676 |
return np.arccosh(x) |
| 677 |
|
| 678 |
|
| 679 |
def futhark_asinh64(x): |
| 680 |
return np.arcsinh(x) |
| 681 |
|
| 682 |
|
| 683 |
def futhark_atanh64(x): |
| 684 |
return np.arctanh(x) |
| 685 |
|
| 686 |
|
| 687 |
def futhark_atan2_64(x, y): |
| 688 |
return np.arctan2(x, y) |
| 689 |
|
| 690 |
|
| 691 |
def futhark_atan2pi_64(x, y): |
| 692 |
return np.arctan2(x, y) / pi64 |
| 693 |
|
| 694 |
|
| 695 |
def futhark_hypot64(x, y): |
| 696 |
return np.hypot(x, y) |
| 697 |
|
| 698 |
|
| 699 |
def futhark_gamma64(x): |
| 700 |
return np.float64(math.gamma(x)) |
| 701 |
|
| 702 |
|
| 703 |
def futhark_lgamma64(x): |
| 704 |
return np.float64(math.lgamma(x)) |
| 705 |
|
| 706 |
|
| 707 |
def futhark_erf64(x): |
| 708 |
return np.float64(math.erf(x)) |
| 709 |
|
| 710 |
|
| 711 |
def futhark_erfc64(x): |
| 712 |
return np.float64(math.erfc(x)) |
| 713 |
|
| 714 |
|
| 715 |
def futhark_round64(x): |
| 716 |
return np.round(x) |
| 717 |
|
| 718 |
|
| 719 |
def futhark_ceil64(x): |
| 720 |
return np.ceil(x) |
| 721 |
|
| 722 |
|
| 723 |
def futhark_floor64(x): |
| 724 |
return np.floor(x) |
| 725 |
|
| 726 |
|
| 727 |
def futhark_nextafter64(x, y): |
| 728 |
return np.nextafter(x, y) |
| 729 |
|
| 730 |
|
| 731 |
def futhark_isnan64(x): |
| 732 |
return np.isnan(x) |
| 733 |
|
| 734 |
|
| 735 |
def futhark_isinf64(x): |
| 736 |
return np.isinf(x) |
| 737 |
|
| 738 |
|
| 739 |
def fptobits_f64_i64(x): |
| 740 |
return x.view(np.int64) |
| 741 |
|
| 742 |
|
| 743 |
def bitstofp_i64_f64(x): |
| 744 |
return x.view(np.float64) |
| 745 |
|
| 746 |
|
| 747 |
def futhark_log32(x): |
| 748 |
return np.float32(np.log(x)) |
| 749 |
|
| 750 |
|
| 751 |
def futhark_log2_32(x): |
| 752 |
return np.float32(np.log2(x)) |
| 753 |
|
| 754 |
|
| 755 |
def futhark_log10_32(x): |
| 756 |
return np.float32(np.log10(x)) |
| 757 |
|
| 758 |
|
| 759 |
def futhark_log1p_32(x): |
| 760 |
return np.float32(np.log1p(x)) |
| 761 |
|
| 762 |
|
| 763 |
def futhark_sqrt32(x): |
| 764 |
return np.float32(np.sqrt(x)) |
| 765 |
|
| 766 |
|
| 767 |
def futhark_rsqrt32(x): |
| 768 |
return np.float32(1 / np.sqrt(x)) |
| 769 |
|
| 770 |
|
| 771 |
def futhark_cbrt32(x): |
| 772 |
return np.float32(np.cbrt(x)) |
| 773 |
|
| 774 |
|
| 775 |
def futhark_exp32(x): |
| 776 |
return np.exp(x) |
| 777 |
|
| 778 |
|
| 779 |
def futhark_cos32(x): |
| 780 |
return np.cos(x) |
| 781 |
|
| 782 |
|
| 783 |
def futhark_cospi32(x): |
| 784 |
return np.cos(pi32 * x) |
| 785 |
|
| 786 |
|
| 787 |
def futhark_sin32(x): |
| 788 |
return np.sin(x) |
| 789 |
|
| 790 |
|
| 791 |
def futhark_sinpi32(x): |
| 792 |
return np.sin(pi32 * x) |
| 793 |
|
| 794 |
|
| 795 |
def futhark_tan32(x): |
| 796 |
return np.tan(x) |
| 797 |
|
| 798 |
|
| 799 |
def futhark_tanpi32(x): |
| 800 |
return np.tan(pi32 * x) |
| 801 |
|
| 802 |
|
| 803 |
def futhark_acos32(x): |
| 804 |
return np.arccos(x) |
| 805 |
|
| 806 |
|
| 807 |
def futhark_acospi32(x): |
| 808 |
return np.arccos(x) / pi32 |
| 809 |
|
| 810 |
|
| 811 |
def futhark_asin32(x): |
| 812 |
return np.arcsin(x) |
| 813 |
|
| 814 |
|
| 815 |
def futhark_asinpi32(x): |
| 816 |
return np.arcsin(x) / pi32 |
| 817 |
|
| 818 |
|
| 819 |
def futhark_atan32(x): |
| 820 |
return np.arctan(x) |
| 821 |
|
| 822 |
|
| 823 |
def futhark_atanpi32(x): |
| 824 |
return np.arctan(x) / pi32 |
| 825 |
|
| 826 |
|
| 827 |
def futhark_cosh32(x): |
| 828 |
return np.cosh(x) |
| 829 |
|
| 830 |
|
| 831 |
def futhark_sinh32(x): |
| 832 |
return np.sinh(x) |
| 833 |
|
| 834 |
|
| 835 |
def futhark_tanh32(x): |
| 836 |
return np.tanh(x) |
| 837 |
|
| 838 |
|
| 839 |
def futhark_acosh32(x): |
| 840 |
return np.arccosh(x) |
| 841 |
|
| 842 |
|
| 843 |
def futhark_asinh32(x): |
| 844 |
return np.arcsinh(x) |
| 845 |
|
| 846 |
|
| 847 |
def futhark_atanh32(x): |
| 848 |
return np.arctanh(x) |
| 849 |
|
| 850 |
|
| 851 |
def futhark_atan2_32(x, y): |
| 852 |
return np.arctan2(x, y) |
| 853 |
|
| 854 |
|
| 855 |
def futhark_atan2pi_32(x, y): |
| 856 |
return np.arctan2(x, y) / pi32 |
| 857 |
|
| 858 |
|
| 859 |
def futhark_hypot32(x, y): |
| 860 |
return np.hypot(x, y) |
| 861 |
|
| 862 |
|
| 863 |
def futhark_gamma32(x): |
| 864 |
return np.float32(math.gamma(x)) |
| 865 |
|
| 866 |
|
| 867 |
def futhark_lgamma32(x): |
| 868 |
return np.float32(math.lgamma(x)) |
| 869 |
|
| 870 |
|
| 871 |
def futhark_erf32(x): |
| 872 |
return np.float32(math.erf(x)) |
| 873 |
|
| 874 |
|
| 875 |
def futhark_erfc32(x): |
| 876 |
return np.float32(math.erfc(x)) |
| 877 |
|
| 878 |
|
| 879 |
def futhark_round32(x): |
| 880 |
return np.round(x) |
| 881 |
|
| 882 |
|
| 883 |
def futhark_ceil32(x): |
| 884 |
return np.ceil(x) |
| 885 |
|
| 886 |
|
| 887 |
def futhark_floor32(x): |
| 888 |
return np.floor(x) |
| 889 |
|
| 890 |
|
| 891 |
def futhark_nextafter32(x, y): |
| 892 |
return np.nextafter(x, y) |
| 893 |
|
| 894 |
|
| 895 |
def futhark_isnan32(x): |
| 896 |
return np.isnan(x) |
| 897 |
|
| 898 |
|
| 899 |
def futhark_isinf32(x): |
| 900 |
return np.isinf(x) |
| 901 |
|
| 902 |
|
| 903 |
def fptobits_f32_i32(x): |
| 904 |
return x.view(np.int32) |
| 905 |
|
| 906 |
|
| 907 |
def bitstofp_i32_f32(x): |
| 908 |
return x.view(np.float32) |
| 909 |
|
| 910 |
|
| 911 |
def futhark_log16(x): |
| 912 |
return np.float16(np.log(x)) |
| 913 |
|
| 914 |
|
| 915 |
def futhark_log2_16(x): |
| 916 |
return np.float16(np.log2(x)) |
| 917 |
|
| 918 |
|
| 919 |
def futhark_log10_16(x): |
| 920 |
return np.float16(np.log10(x)) |
| 921 |
|
| 922 |
|
| 923 |
def futhark_log1p_16(x): |
| 924 |
return np.float16(np.log1p(x)) |
| 925 |
|
| 926 |
|
| 927 |
def futhark_sqrt16(x): |
| 928 |
return np.float16(np.sqrt(x)) |
| 929 |
|
| 930 |
|
| 931 |
def futhark_rsqrt16(x): |
| 932 |
return np.float16(1 / np.sqrt(x)) |
| 933 |
|
| 934 |
|
| 935 |
def futhark_cbrt16(x): |
| 936 |
return np.float16(np.cbrt(x)) |
| 937 |
|
| 938 |
|
| 939 |
def futhark_exp16(x): |
| 940 |
return np.exp(x) |
| 941 |
|
| 942 |
|
| 943 |
def futhark_cos16(x): |
| 944 |
return np.cos(x) |
| 945 |
|
| 946 |
|
| 947 |
def futhark_cospi16(x): |
| 948 |
return np.cos(pi16 * x) |
| 949 |
|
| 950 |
|
| 951 |
def futhark_sin16(x): |
| 952 |
return np.sin(x) |
| 953 |
|
| 954 |
|
| 955 |
def futhark_sinpi16(x): |
| 956 |
return np.sin(pi16 * x) |
| 957 |
|
| 958 |
|
| 959 |
def futhark_tan16(x): |
| 960 |
return np.tan(x) |
| 961 |
|
| 962 |
|
| 963 |
def futhark_tanpi16(x): |
| 964 |
return np.tan(pi16 * x) |
| 965 |
|
| 966 |
|
| 967 |
def futhark_acos16(x): |
| 968 |
return np.arccos(x) |
| 969 |
|
| 970 |
|
| 971 |
def futhark_acospi16(x): |
| 972 |
return np.arccos(x) / pi16 |
| 973 |
|
| 974 |
|
| 975 |
def futhark_asin16(x): |
| 976 |
return np.arcsin(x) |
| 977 |
|
| 978 |
|
| 979 |
def futhark_asinpi16(x): |
| 980 |
return np.arcsin(x) / pi16 |
| 981 |
|
| 982 |
|
| 983 |
def futhark_atan16(x): |
| 984 |
return np.arctan(x) |
| 985 |
|
| 986 |
|
| 987 |
def futhark_atanpi16(x): |
| 988 |
return np.arctan(x) / pi16 |
| 989 |
|
| 990 |
|
| 991 |
def futhark_cosh16(x): |
| 992 |
return np.cosh(x) |
| 993 |
|
| 994 |
|
| 995 |
def futhark_sinh16(x): |
| 996 |
return np.sinh(x) |
| 997 |
|
| 998 |
|
| 999 |
def futhark_tanh16(x): |
| 1000 |
return np.tanh(x) |
| 1001 |
|
| 1002 |
|
| 1003 |
def futhark_acosh16(x): |
| 1004 |
return np.arccosh(x) |
| 1005 |
|
| 1006 |
|
| 1007 |
def futhark_asinh16(x): |
| 1008 |
return np.arcsinh(x) |
| 1009 |
|
| 1010 |
|
| 1011 |
def futhark_atanh16(x): |
| 1012 |
return np.arctanh(x) |
| 1013 |
|
| 1014 |
|
| 1015 |
def futhark_atan2_16(x, y): |
| 1016 |
return np.arctan2(x, y) |
| 1017 |
|
| 1018 |
|
| 1019 |
def futhark_atan2pi_16(x, y): |
| 1020 |
return np.arctan2(x, y) / pi16 |
| 1021 |
|
| 1022 |
|
| 1023 |
def futhark_hypot16(x, y): |
| 1024 |
return np.hypot(x, y) |
| 1025 |
|
| 1026 |
|
| 1027 |
def futhark_gamma16(x): |
| 1028 |
return np.float16(math.gamma(x)) |
| 1029 |
|
| 1030 |
|
| 1031 |
def futhark_lgamma16(x): |
| 1032 |
return np.float16(math.lgamma(x)) |
| 1033 |
|
| 1034 |
|
| 1035 |
def futhark_erf16(x): |
| 1036 |
return np.float16(math.erf(x)) |
| 1037 |
|
| 1038 |
|
| 1039 |
def futhark_erfc16(x): |
| 1040 |
return np.float16(math.erfc(x)) |
| 1041 |
|
| 1042 |
|
| 1043 |
def futhark_round16(x): |
| 1044 |
return np.round(x) |
| 1045 |
|
| 1046 |
|
| 1047 |
def futhark_ceil16(x): |
| 1048 |
return np.ceil(x) |
| 1049 |
|
| 1050 |
|
| 1051 |
def futhark_floor16(x): |
| 1052 |
return np.floor(x) |
| 1053 |
|
| 1054 |
|
| 1055 |
def futhark_nextafter16(x, y): |
| 1056 |
return np.nextafter(x, y) |
| 1057 |
|
| 1058 |
|
| 1059 |
def futhark_isnan16(x): |
| 1060 |
return np.isnan(x) |
| 1061 |
|
| 1062 |
|
| 1063 |
def futhark_isinf16(x): |
| 1064 |
return np.isinf(x) |
| 1065 |
|
| 1066 |
|
| 1067 |
def fptobits_f16_i16(x): |
| 1068 |
return x.view(np.int16) |
| 1069 |
|
| 1070 |
|
| 1071 |
def bitstofp_i16_f16(x): |
| 1072 |
return x.view(np.float16) |
| 1073 |
|
| 1074 |
|
| 1075 |
def futhark_lerp16(v0, v1, t): |
| 1076 |
return v0 + (v1 - v0) * t |
| 1077 |
|
| 1078 |
|
| 1079 |
def futhark_lerp32(v0, v1, t): |
| 1080 |
return v0 + (v1 - v0) * t |
| 1081 |
|
| 1082 |
|
| 1083 |
def futhark_lerp64(v0, v1, t): |
| 1084 |
return v0 + (v1 - v0) * t |
| 1085 |
|
| 1086 |
|
| 1087 |
def futhark_ldexp16(x, y): |
| 1088 |
return np.ldexp(x, y) |
| 1089 |
|
| 1090 |
|
| 1091 |
def futhark_ldexp32(x, y): |
| 1092 |
return np.ldexp(x, y) |
| 1093 |
|
| 1094 |
|
| 1095 |
def futhark_ldexp64(x, y): |
| 1096 |
return np.ldexp(x, y) |
| 1097 |
|
| 1098 |
|
| 1099 |
def futhark_mad16(a, b, c): |
| 1100 |
return a * b + c |
| 1101 |
|
| 1102 |
|
| 1103 |
def futhark_mad32(a, b, c): |
| 1104 |
return a * b + c |
| 1105 |
|
| 1106 |
|
| 1107 |
def futhark_mad64(a, b, c): |
| 1108 |
return a * b + c |
| 1109 |
|
| 1110 |
|
| 1111 |
def futhark_fma16(a, b, c): |
| 1112 |
return a * b + c |
| 1113 |
|
| 1114 |
|
| 1115 |
def futhark_fma32(a, b, c): |
| 1116 |
return a * b + c |
| 1117 |
|
| 1118 |
|
| 1119 |
def futhark_fma64(a, b, c): |
| 1120 |
return a * b + c |
| 1121 |
|
| 1122 |
|
| 1123 |
futhark_copysign16 = futhark_copysign32 = futhark_copysign64 = np.copysign |
| 1124 |
|
| 1125 |
|
| 1126 |
def futhark_cond(x, y, z): |
| 1127 |
return y if x else z |
| 1128 |
|
| 1129 |
|
| 1130 |
futhark_cond_f16 = futhark_cond_f32 = futhark_cond_f64 = futhark_cond |
| 1131 |
futhark_cond_i18 = futhark_cond_i16 = futhark_cond_i32 = futhark_cond_i64 = ( |
| 1132 |
futhark_cond |
| 1133 |
) |
| 1134 |
futhark_cond_bool = futhark_cond_unit = futhark_cond |
| 1135 |
|
| 1136 |
|
| 1137 |
# End of scalar.py. |