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
LazyTensor
¶
Bases: OverrideTensor
Source code in src/finch/interface/lazy.py
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 373 | |
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
__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
__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
__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
LazyTensorFType
¶
Bases: TensorFType
Source code in src/finch/interface/lazy.py
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 174 | |
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
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
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
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
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 528 | |
broadcast_arrays(*arrays)
¶
Broadcasts one or more arrays against one another.
Source code in src/finch/interface/lazy.py
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
conj(x)
¶
defer(arr)
¶
- 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
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
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
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
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
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
matmul(x1, x2)
¶
Performs matrix multiplication between two tensors.
Source code in src/finch/interface/lazy.py
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
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
mean(x, /, *, axis=None, keepdims=False)
¶
Calculates the arithmetic mean of the input array x.
Source code in src/finch/interface/lazy.py
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
moveaxis(x, source, destination)
¶
Moves axes of an array to new positions.
Source code in src/finch/interface/lazy.py
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
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
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 914 915 916 917 918 919 920 | |
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
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
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
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 1727 1728 1729 1730 1731 1732 1733 | |
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
vecdot(x1, x2, /, *, axis=-1)
¶
Computes the vector dot product along the specified axis.