fill
Static/Dynamic fill values.
Every tensor has a fill value: the background value of a sparse tensor, and the value a newly constructed tensor is filled with. A fill is always a real value, but a tensor's ftype additionally records whether a kernel may specialize on that value:
StaticFill-- compile against this value. It may be folded into generated code.DynamicFill-- do not compile against this value. The value is may change across invocations, so one compiled kernel serves every fill of the same dtype.
AbstractFill
A tensor's fill value, and whether kernels may specialize on it.
Source code in src/finch/algebra/fill.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
ftype
abstractmethod
property
The dtype of the fill value, always known.
value
abstractmethod
property
The fill value itself, always known.
as_dynamic()
This fill, marked so that kernels will not specialize on its value.
Source code in src/finch/algebra/fill.py
53 54 55 | |
DynamicFill
Bases: AbstractFill[FT]
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 dtype only, i.e. two equal DynamicFills may have
different .value's.
Source code in src/finch/algebra/fill.py
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 | |
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.
Source code in src/finch/algebra/fill.py
30 31 32 33 34 35 | |
StaticFill
Bases: AbstractFill[FT]
A fill value which kernels may specialize on. Equality and hashing are by value, so ftypes carrying different static fills are distinct and get distinct kernels.
Source code in src/finch/algebra/fill.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 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 | |
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
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 | |
as_fill(fill)
as_fill(fill: AF) -> AF
as_fill(fill: FTyped[FT]) -> StaticFill[FT]
as_fill(fill: Any) -> StaticFill
Normalize a raw value to a StaticFill, passing an AbstractFill through.
Source code in src/finch/algebra/fill.py
184 185 186 187 188 | |