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
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 235 236 237 238 239 240 | |
LazyTensor
Bases: OverrideTensor
Source code in src/finch/interface/lazy.py
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 367 368 369 370 371 372 | |
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
362 363 364 365 366 367 368 369 | |
__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
335 336 337 338 339 340 341 342 | |
__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
344 345 346 347 348 349 350 351 | |
__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
353 354 355 356 357 358 359 360 | |
LazyTensorFType
Bases: TensorFType
Source code in src/finch/interface/lazy.py
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 168 169 170 171 172 173 | |
__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
143 144 145 146 147 148 149 150 151 152 153 154 | |
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
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 | |
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
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 | |
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
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 522 523 524 525 526 527 | |
broadcast_arrays(*arrays)
Broadcasts one or more arrays against one another.
Source code in src/finch/interface/lazy.py
2670 2671 2672 2673 2674 2675 | |
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
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 | |
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
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 | |
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
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
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
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | |
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
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 759 760 761 762 763 764 765 766 767 768 769 | |
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
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 594 595 596 597 598 599 600 601 602 603 604 | |
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
1435 1436 1437 1438 1439 1440 1441 1442 | |
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
1445 1446 1447 1448 1449 1450 1451 1452 1453 | |
matmul(x1, x2)
Performs matrix multiplication between two tensors.
Source code in src/finch/interface/lazy.py
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 | |
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
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 | |
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
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 | |
mean(x, /, *, axis=None, keepdims=False)
Calculates the arithmetic mean of the input array x.
Source code in src/finch/interface/lazy.py
2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 | |
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
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 | |
moveaxis(x, source, destination)
Moves axes of an array to new positions.
Source code in src/finch/interface/lazy.py
2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 | |
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
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
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
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 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 | |
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
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 806 807 808 809 810 811 812 813 814 815 816 | |
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
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 | |
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
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 | |
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
2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 | |
vecdot(x1, x2, /, *, axis=-1)
Computes the vector dot product along the specified axis.
Source code in src/finch/interface/lazy.py
1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 | |