lazy
EffectBlob
The EffectBlob class represents a collection of prior queries in a lazy
evaluation context, which can be extracted into a linear trace of
LogicStatements (in the order they were issued). Note that the global
effect_stamp counter is required to maintain the relative ordering of
effect blobs in the face of in-place mutations to tensors. Each effect blob
contains a logic statement and references to other effect blobs. The
datastructure is designed to be immutable, mergeable in O(1) time, and
support linear time extraction. To achieve linear time, we use a hash table
to avoid re-extracting already seen blobs.
Source code in src/finch/interface/lazy.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
LazyTensor
Bases: OverrideTensor
Source code in src/finch/interface/lazy.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
element_type
property
Data type of the tensor elements.
fill_value
property
Default value to fill the tensor.
shape
property
Returns the shape of the LazyTensor as a tuple. The shape is determined by the data and is a static property.
shape_type
property
Shape type of the tensor.
__bool__()
Converts the LazyTensor to a bool. This is a no-op for LazyTensors, as they are symbolic representations.
Source code in src/finch/interface/lazy.py
356 357 358 359 360 361 362 363 | |
__complex__()
Converts the LazyTensor to a complex number. This is a no-op for LazyTensors, as they are symbolic representations.
Source code in src/finch/interface/lazy.py
329 330 331 332 333 334 335 336 | |
__float__()
Converts the LazyTensor to a float. This is a no-op for LazyTensors, as they are symbolic representations.
Source code in src/finch/interface/lazy.py
338 339 340 341 342 343 344 345 | |
__int__()
Converts the LazyTensor to an int. This is a no-op for LazyTensors, as they are symbolic representations.
Source code in src/finch/interface/lazy.py
347 348 349 350 351 352 353 354 | |
LazyTensorFType
Bases: TensorFType
Source code in src/finch/interface/lazy.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
__call__(val)
Convert a tensor to this tensor type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
Any
|
A tensor to convert to this tensor type. |
required |
Returns: A LazyTensor instance of this type.
Source code in src/finch/interface/lazy.py
137 138 139 140 141 142 143 144 145 146 147 148 | |
all(x, /, *, axis=None, keepdims=False, init=None)
Test whether all elements of input array x along given axis are True.
Source code in src/finch/interface/lazy.py
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 | |
any(x, /, *, axis=None, keepdims=False, init=None)
Test whether any element of input array x along given axis is True.
Source code in src/finch/interface/lazy.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | |
asarray(obj, /, *, dtype=None, device=None, copy=None, format=None)
asarray(
obj: np.ndarray,
/,
*,
dtype=None,
device=None,
copy=None,
format: None = None,
) -> BufferizedNDArray
asarray(
obj: sps.spmatrix | sps.sparray,
/,
*,
dtype=None,
device=None,
copy=None,
format: None = None,
) -> FiberTensor
asarray(
obj: Any,
/,
*,
dtype=None,
device=None,
copy=None,
format: FiberTensorFType,
) -> FiberTensor
asarray(
obj: np.generic | complex,
/,
*,
dtype=None,
device=None,
copy=None,
format: None = None,
) -> Scalar
asarray(
obj: Any,
/,
*,
dtype=None,
device=None,
copy=None,
format: TensorFType | None = None,
) -> Tensor
Convert given argument and return wrapper type instance. If input argument is already array type, return unchanged. https://data-apis.org/array-api/latest/API_specification/generated/array_api.asarray.html
Source code in src/finch/interface/lazy.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
broadcast_arrays(*arrays)
Broadcasts one or more arrays against one another.
Source code in src/finch/interface/lazy.py
2626 2627 2628 2629 2630 2631 | |
broadcast_to(tensor, /, shape)
Broadcasts a lazy tensor to a specified shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Any
|
The lazy tensor to broadcast. |
required |
shape
|
tuple
|
The target shape to broadcast to. |
required |
Returns:
| Type | Description |
|---|---|
LazyTensor
|
A new lazy tensor with the specified shape. |
Source code in src/finch/interface/lazy.py
2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 | |
conj(x)
Computes the complex conjugate of the input tensor x.
Parameters
x: LazyTensor The input tensor to compute the complex conjugate of.
Returns
LazyTensor
A new LazyTensor with the complex conjugate of x.
Source code in src/finch/interface/lazy.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 | |
defer(arr)
defer(arr: tuple[Any, ...]) -> tuple[Any, ...]
defer(arr: Any) -> LazyTensor
- defer(arr) -> LazyTensor: Converts an array into a LazyTensor. If the input is already a LazyTensor, it is returned as-is. Otherwise, it creates a LazyTensor representation of the input array.
Parameters: - arr: The input array to be converted into a LazyTensor.
Returns: - LazyTensor: A lazy representation of the input array.
Source code in src/finch/interface/lazy.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
elementwise(f, *args)
elementwise(f, *args) -> LazyTensor:
Applies the function f elementwise to the given arguments, following
broacasting rules.
The function f should be a callable that takes the same number of arguments
as the number of tensors passed to elementwise.
The function will automatically handle broadcasting of the input tensors to
ensure they have compatible shapes. For example, elementwise(ffunc.add,
x, y) is equivalent to x + y.
Parameters: - f: The function to apply elementwise. - *args: The tensors to apply the function to. These tensors should be compatible for broadcasting.
Returns:
- LazyTensor: The tensor, out, of results from applying f elementwise to
the input tensors. After broadcasting the arguments to the same shape, for
each index i, out[*i] = f(args[0][*i], args[1][*i], ...).
Source code in src/finch/interface/lazy.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
expand_dims(x, /, axis=0)
Expands the shape of an array by inserting a new axis (dimension) of size one at the
position specified by axis.
Parameters
x: array
input array.
axis: int
axis position (zero-based). If x has rank (i.e, number of dimensions) N,
a valid axis must reside on the closed-interval [-N-1, N]. If provided a
negative axis, the axis position at which to insert a singleton dimension
must be computed as N + axis + 1. Hence, if provided -1, the resolved
axis position must be N (i.e., a singleton dimension must be appended to the
input array x). If provided -N-1, the resolved axis position must be
0 (i.e., a singleton dimension must be prepended to the input array x).
Returns
out: array
an expanded output array having the same data type as x.
Raises
IndexError
If provided an invalid axis position, an IndexError should be raised.
Source code in src/finch/interface/lazy.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
full(shape, fill_value, *, dtype=None, device=None)
Returns a new array having a specified shape and filled with fill_value.
Parameters: - shape (Union[int, Tuple[int, ...]]): output array shape. - fill_value (Union[bool, int, float, complex]): fill value. - dtype (Optional[dtype]): output array data type. If dtype is None, the output array data type must be inferred from fill_value according to the following rules: * If the fill value is an int, the output array data type must be the default integer data type. * If the fill value is a float, the output array data type must be the default real-valued floating-point data type. * If the fill value is a complex number, the output array data type must be the default complex floating-point data type. * If the fill value is a bool, the output array must have a boolean data type. Default: None.
Returns:
- out (array): an array where every element is equal to fill_value.
Source code in src/finch/interface/lazy.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
is_broadcastable(shape_a, shape_b)
Returns True if shape_a and shape_b are broadcastable according to numpy rules.
Source code in src/finch/interface/lazy.py
1394 1395 1396 1397 1398 1399 1400 1401 | |
is_broadcastable_directional(shape_a, shape_b)
Returns True if shape_a is broadcastable to shape_b according to numpy rules. This is a directional check, so it allows only shape_a to be changed
Source code in src/finch/interface/lazy.py
1404 1405 1406 1407 1408 1409 1410 1411 1412 | |
matmul(x1, x2)
Performs matrix multiplication between two tensors.
Source code in src/finch/interface/lazy.py
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 | |
matrix_transpose(x)
Transposes the input tensor x.
Parameters
x: LazyTensor The input tensor to be transposed. Must have at least 2 dimensions.
Returns
LazyTensor
A new LazyTensor with the axes of x transposed.
Source code in src/finch/interface/lazy.py
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 | |
max(x, /, *, axis=None, keepdims=False, init=None)
Return the maximum of input array arr along given axis.
Source code in src/finch/interface/lazy.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 | |
mean(x, /, *, axis=None, keepdims=False)
Calculates the arithmetic mean of the input array x.
Source code in src/finch/interface/lazy.py
2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 | |
min(x, /, *, axis=None, keepdims=False, init=None)
Return the minimum of input array arr along given axis.
Source code in src/finch/interface/lazy.py
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 | |
moveaxis(x, source, destination)
Moves axes of an array to new positions.
Source code in src/finch/interface/lazy.py
2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 | |
permute_dims(arg, /, axes)
Permutes the axes (dimensions) of an array x.
Parameters
x: array
input array.
axes: Tuple[int, ...]
tuple containing a permutation of (0, 1, ..., N-1) where N is the number
of axes (dimensions) of x.
Returns
out: array
an array containing the axes permutation. The returned array must have the same
data type as x.
Source code in src/finch/interface/lazy.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
reduce(op, x, /, *, axis=None, dtype=None, keepdims=False, init=None)
Reduces the input array x with the binary operator op. Reduces along
the specified axis, with an initial value init.
Parameters
x: array
input array. Should have a numeric data type.
axis: Optional[Union[int, Tuple[int, ...]]]
axis or axes along which reduction must be computed. By default, the reduction
must be computed over the entire array. If a tuple of integers, reductions must
be computed over multiple axes. Default: None.
Optional[dtype]
data type of the returned array. If None, a suitable data type will be
calculated.
bool
if True, the reduced axes (dimensions) must be included in the result as
singleton dimensions, and, accordingly, the result must be compatible with the
input array (see :ref:broadcasting). Otherwise, if False, the reduced axes
(dimensions) must not be included in the result. Default: False.
Optional
Initial value for the reduction. If None, a suitable initial value will be
calculated. The initial value must be compatible with the operation defined by
op. For example, if op is addition, the initial value should be zero; if
op is multiplication, the initial value should be one.
Returns
out: array
If the reduction was computed over the entire array, a zero-dimensional array
containing the reduction; otherwise, a non-zero-dimensional array containing the
reduction. The returned array must have a data type as described by the
dtype parameter above.
Source code in src/finch/interface/lazy.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | |
squeeze(x, /, axis)
Removes singleton dimensions (axes) from x.
Parameters
x: array input array. axis: Union[int, Tuple[int, ...]] axis (or axes) to squeeze.
Returns
out: array
an output array having the same data type and elements as x.
Raises
ValueError
If a specified axis has a size greater than one (i.e., it is not a
singleton dimension), a ValueError should be raised.
Source code in src/finch/interface/lazy.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
std(x, /, *, axis=None, correction=0.0, keepdims=False)
Calculates the standard deviation of the input array x.
Source code in src/finch/interface/lazy.py
2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 | |
tensordot(x1, x2, /, *, axes=2)
Computes the tensordot operation.
Returns a LazyTensor if either x1 or x2 is a LazyTensor. Otherwise, computes the result eagerly.
Source code in src/finch/interface/lazy.py
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 | |
var(x, /, *, axis=None, correction=0.0, keepdims=False)
Calculates the variance of the input array x.
Source code in src/finch/interface/lazy.py
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 | |
vecdot(x1, x2, /, *, axis=-1)
Computes the vector dot product along the specified axis.
Source code in src/finch/interface/lazy.py
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 | |