Index
AbstractFill
¶
Bases: FTyped[AbstractFillFType], ABC
A tensor's fill value. Its ftype says whether kernels may specialize on it.
Source code in src/finch/algebra/fill.py
AbstractFillFType
¶
The fill of a format: the element type of its fill, and whether kernels may specialize on the value of the fill.
Source code in src/finch/algebra/fill.py
DynamicFill
¶
Bases: AbstractFill
A fill value which kernels must not specialize on. The value is known and is bound to the kernel at call time.
Equality and hashing are by element type only, i.e. two equal
DynamicFills may have different .value's.
Source code in src/finch/algebra/fill.py
DynamicFillError
¶
Bases: Exception
Raised when a fill value must be specialized on at compile time but the fill is Dynamic. Callers may catch this to fall back to value-specialized compilation.
DynamicFillFType
¶
Bases: AbstractFillFType
The fill of a format which kernels must not specialize on, so only its element type is part of the format. Each tensor holds its own fill value, which is bound to the kernel at call time.
Source code in src/finch/algebra/fill.py
FType
¶
Bases: ABC
Source code in src/finch/algebra/ftypes.py
__call__(val)
abstractmethod
¶
Perform type conversion or construction with the given value.
For numeric/scalar types, this converts the value to this type. For composite types, this may construct an instance of this type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
Any
|
The value to convert or use for construction |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The converted/constructed value |
Source code in src/finch/algebra/ftypes.py
FTyped
¶
SingletonOperatorFType
¶
Bases: ImmutableStructFType, FinchOperatorFType
A stateless callable type with one canonical operator value.
Source code in src/finch/algebra/algebra.py
StaticFill
¶
Bases: AbstractFill
A fill value which kernels may specialize on. Equality and hashing are by
value, matching StaticFillFType.
Source code in src/finch/algebra/fill.py
StaticFillFType
¶
Bases: AbstractFillFType
The fill of a format which kernels may specialize on, so its value is part of the format. Equality and hashing are by element type and value, so formats with different static fills are distinct and get distinct kernels.
Source code in src/finch/algebra/fill.py
StructFType
¶
Source code in src/finch/algebra/ftypes.py
__call__(*args, **kwargs)
¶
Construct a struct instance from the given fields.
Can be called with positional arguments matching struct_fields order, or keyword arguments matching field names.
Source code in src/finch/algebra/ftypes.py
Tensor
¶
Bases: FTyped[TensorFType[FT]], ABC
Abstract base class for tensor-like data structures. Tensors are multi-dimensional arrays that can be used to represent data in various formats. They support operations such as indexing, slicing, and reshaping, and can be used in mathematical computations. This class provides the basic interface for tensors to be used with lazy ops in Finch, though more advanced interfaces may be required for different backends.
Source code in src/finch/algebra/tensor.py
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 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 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
element_type
property
¶
The element type of the tensor. The element type is the scalar type of the elements in a tensor, which may be different from the data type of the tensor.
fill
property
¶
The fill of the tensor: its fill value, and whether kernels may specialize on it. Its ftype is the fill of the tensor's format.
fill_value
property
¶
The fill value for the tensor. The fill value is the default value for a tensor when it is created with a given shape and dtype, as well as the background value for sparse tensors. Note: this is the raw value NOT the AbstractFill. A tensor whose fill is dynamic holds its own fill value.
ftype
abstractmethod
property
¶
FType of the tensor, which may include metadata about the tensor.
ndim
property
¶
Number of dimensions of the tensor.
shape
abstractmethod
property
¶
Shape of the tensor.
shape_type
property
¶
Shape type of the tensor. The shape type is a tuple of the index types in the tensor. It's the type of each element in tns.shape. It should be an actual tuple, rather than a tupleftype, so that it can hold e.g. dtypes, formats, or types, and so that we can easily index it.
item()
abstractmethod
¶
Return the Python scalar stored in a zero-dimensional tensor.
Indexing tensor objects must keep returning tensor-like values, including for
zero-dimensional results. item() is the explicit escape hatch for code that
needs the underlying Python scalar value. Implementations should raise
ValueError when called on a non-scalar tensor.
Source code in src/finch/algebra/tensor.py
to_numpy()
abstractmethod
¶
to_scipy()
abstractmethod
¶
with_fill(fill_value)
¶
An equivalent tensor carrying fill_value as its fill.
TensorFType
¶
Bases: FType, ABC, Generic[FT]
Source code in src/finch/algebra/tensor.py
element_type
abstractmethod
property
¶
Data type of the tensor elements.
fill_type
abstractmethod
property
¶
The fill of the format, either static or dynamic.
ndim
property
¶
Number of dimensions of the tensor.
shape_type
abstractmethod
property
¶
Shape type of the tensor. The shape type is a tuple of the index types in the tensor. It's the type of each element in tns.shape. It should be an actual tuple, rather than a tuple type, so that it can hold e.g. dtypes, formats, or types, and so that we can easily index it.
construct(shape)
abstractmethod
¶
Create a tensor instance with the given shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple
|
The shape of the tensor to create. |
required |
Returns: A tensor instance with the specified shape.
Source code in src/finch/algebra/tensor.py
default_protocols()
¶
The protocol which a loop reads each dimension of the tensor with, when the access gives none, or none if the tensor reads every dimension the same way under any protocol.
Source code in src/finch/algebra/tensor.py
protocols()
¶
The protocols which a loop can read each dimension of the tensor with, or none if it reads them only with the default.
with_fill(fill_type)
¶
This ftype carrying fill_type as its fill.
TupleFType
¶
Bases: ImmutableStructFType, FDType
FType for Python tuples, with a struct-compatible interface.
Source code in src/finch/algebra/ftypes.py
803 804 805 806 807 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 891 892 893 894 | |
apply_fill(op, *fills)
¶
Compute the fill value of mapping op over tensors with fills fills.
A fill stays static only while its value is one the algebra can act on. Combining static fills computes an arbitrary value -- adding 1 repeatedly walks a fill through 1, 2, 3, ... -- and a static fill is compared by value, so keeping those static would key a kernel per distinct value and make a loop cost a compilation per iteration.
Source code in src/finch/algebra/fill.py
apply_fill_type(op, *fill_types)
¶
The fill of the format which results from mapping op over tensors whose
formats have the fills fill_types. This is the format of apply_fill.
Source code in src/finch/algebra/fill.py
as_fill(fill)
¶
Normalize a raw value to a StaticFill, passing an AbstractFill through.
cansplitpush(op)
¶
Whether a reduction can split-push through the same operator expression.
fisinstance(x, f)
¶
fixpoint_type(op, z, t)
¶
Determines the fixpoint type after repeated calling the given operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
CallableFType
|
The operation to evaluate. |
required |
z
|
AbstractFillFType
|
The fill format of the initial value. |
required |
t
|
FType
|
The type to evaluate against. |
required |
Returns:
| Type | Description |
|---|---|
FType
|
The fixpoint type. |
Source code in src/finch/algebra/algebra.py
ftype(x)
¶
Return the corresponding FType for a given object. Recognizes numpy, Python builtins, and Python tuples. Sometimes recognizes types. Override .ftype to customize the ftype of an object.
Source code in src/finch/algebra/ftypes.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 | |
is_specializable_value(val)
¶
A constant is only worth specializing on if some operator's identity or
annihilator rule can fire against it; see SPECIALIZABLE_VALUES.
Source code in src/finch/algebra/algebra.py
isdtype(dtype, kind)
¶
Check if a dtype belongs to an Array API dtype kind.
Source code in src/finch/algebra/ftypes.py
promote_type(T1, T2)
¶
Returns the data type with the smallest size and smallest scalar kind to which both type1 and type2 may be safely cast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T1
|
FDType
|
The first type to promote. |
required |
T2
|
FDType
|
The second type to promote. |
required |
Returns:
| Type | Description |
|---|---|
FDType
|
The common type of the given arguments. |
Source code in src/finch/algebra/ftypes.py
repeat_operator(op)
¶
If there exists an operator g such that f(x, x, ..., x) (n times) is equal to g(x, n), then return g.
resolve_fill(fill_type, fill=None)
¶
The fill of a new tensor of a format whose fill is fill_type. A given
fill takes the element type of the format, and decides whether the fill of
the new tensor is dynamic. Otherwise the fill of the format must be static.