| 353 | |
| 354 | |
| 355 | def test_fuse_reductions_single_input(): |
| 356 | def f(*args): |
| 357 | return args |
| 358 | |
| 359 | d = {"a": 1, "b1": (f, "a"), "b2": (f, "a", "a"), "c": (f, "b1", "b2")} |
| 360 | assert fuse(d, ave_width=1.9, rename_keys=False) == with_deps(d) |
| 361 | assert fuse(d, ave_width=1.9, rename_keys=True) == with_deps(d) |
| 362 | assert fuse(d, ave_width=2, rename_keys=False) == with_deps( |
| 363 | {"a": 1, "c": (f, (f, "a"), (f, "a", "a"))} |
| 364 | ) |
| 365 | assert fuse(d, ave_width=2, rename_keys=True) == with_deps( |
| 366 | {"a": 1, "b1-b2-c": (f, (f, "a"), (f, "a", "a")), "c": "b1-b2-c"} |
| 367 | ) |
| 368 | |
| 369 | d = { |
| 370 | "a": 1, |
| 371 | "b1": (f, "a"), |
| 372 | "b2": (f, "a", "a"), |
| 373 | "b3": (f, "a", "a", "a"), |
| 374 | "c": (f, "b1", "b2", "b3"), |
| 375 | } |
| 376 | assert fuse(d, ave_width=2.9, rename_keys=False) == with_deps(d) |
| 377 | assert fuse(d, ave_width=2.9, rename_keys=True) == with_deps(d) |
| 378 | assert fuse(d, ave_width=3, rename_keys=False) == with_deps( |
| 379 | {"a": 1, "c": (f, (f, "a"), (f, "a", "a"), (f, "a", "a", "a"))} |
| 380 | ) |
| 381 | assert fuse(d, ave_width=3, rename_keys=True) == with_deps( |
| 382 | { |
| 383 | "a": 1, |
| 384 | "b1-b2-b3-c": (f, (f, "a"), (f, "a", "a"), (f, "a", "a", "a")), |
| 385 | "c": "b1-b2-b3-c", |
| 386 | } |
| 387 | ) |
| 388 | |
| 389 | d = {"a": 1, "b1": (f, "a"), "b2": (f, "a"), "c": (f, "a", "b1", "b2")} |
| 390 | assert fuse(d, ave_width=1.9, rename_keys=False) == with_deps(d) |
| 391 | assert fuse(d, ave_width=1.9, rename_keys=True) == with_deps(d) |
| 392 | assert fuse(d, ave_width=2, rename_keys=False) == with_deps( |
| 393 | {"a": 1, "c": (f, "a", (f, "a"), (f, "a"))} |
| 394 | ) |
| 395 | assert fuse(d, ave_width=2, rename_keys=True) == with_deps( |
| 396 | {"a": 1, "b1-b2-c": (f, "a", (f, "a"), (f, "a")), "c": "b1-b2-c"} |
| 397 | ) |
| 398 | |
| 399 | d = { |
| 400 | "a": 1, |
| 401 | "b1": (f, "a"), |
| 402 | "b2": (f, "a"), |
| 403 | "c": (f, "b1", "b2"), |
| 404 | "d1": (f, "c"), |
| 405 | "d2": (f, "c"), |
| 406 | "e": (f, "d1", "d2"), |
| 407 | } |
| 408 | assert fuse(d, ave_width=1.9, rename_keys=False) == with_deps(d) |
| 409 | assert fuse(d, ave_width=1.9, rename_keys=True) == with_deps(d) |
| 410 | assert fuse(d, ave_width=2, rename_keys=False) == with_deps( |
| 411 | {"a": 1, "c": (f, (f, "a"), (f, "a")), "e": (f, (f, "c"), (f, "c"))} |
| 412 | ) |