sgn.transforms
¶
Transforms elements and related utilities for the SGN framework.
CallableTransform
dataclass
¶
Bases: InputPull
A transform element that takes a mapping of {(input, combinations) -> callable}, each of which is mapped to a unique output pad.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callmap
|
dict[str, Callable]
|
dict[str, Callable], a mapping of output pad names to callables |
dict()
|
depmap
|
dict[str, tuple[str, ...]]
|
dict[str, tuple[str, ...]], mapping of output pad names to input combinations |
dict()
|
Source code in sgn/transforms.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 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 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 |
|
__post_init__()
¶
Setup callable mappings and name associated source pads.
Source code in sgn/transforms.py
51 52 53 54 55 56 57 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 112 113 114 115 |
|
from_callable(name, callable, output_pad_name, sink_pad_names)
staticmethod
¶
Create a CallableTransform from a single callable that will be applied to all inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str, the name of the CallableTransform |
required |
callable
|
Callable
|
Callable, the callable to use for the transform |
required |
output_pad_name
|
str
|
str, the name of the output pad |
required |
sink_pad_names
|
list[str]
|
list[str], the names of the sink pads (input pads) |
required |
Returns:
Type | Description |
---|---|
CallableTransform, the created CallableTransform |
Source code in sgn/transforms.py
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 |
|
from_combinations(name, combos, sink_pad_names=None, source_pad_names=None)
staticmethod
¶
Create a CallableTransform from a list of combinations where each combination is.
(input_keys, func, output_name)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str, the name of the CallableTransform |
required |
combos
|
Iterable[tuple[tuple[str, ...], Callable, str]]
|
Sequence[tuple[tuple[str, ...], Callable, str]], a list of combinations to create the CallableTransform, where each combination is a tuple of the input keys, the callable, and the output name |
required |
sink_pad_names
|
Optional[Sequence[str]]
|
Optional[list[str]], the names of the sink pads (input pads). If not specified, inferred from the combos |
None
|
source_pad_names
|
Optional[Sequence[str]]
|
Optional[list[str]], the names of the source pads (output pads). If not specified, inferred from the combos |
None
|
Returns:
Type | Description |
---|---|
CallableTransform, the created CallableTransform |
Source code in sgn/transforms.py
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 |
|
new(pad)
¶
Apply the callable associated to the pad to the corresponding inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pad
|
SourcePad
|
SourcePad, The source pad through which the frame is passed |
required |
Returns:
Type | Description |
---|---|
Frame
|
Frame, the output frame |
Source code in sgn/transforms.py
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 |
|
InputPull
dataclass
¶
Bases: TransformElement
Input Pull mixin class for Transforms creates a dictionary of inputs and a pull method to populate the dictionary.
The new method remains abstract and must be implemented in the subclass.
Source code in sgn/transforms.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
pull(pad, frame)
¶
Pull a frame into the transform element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pad
|
SinkPad
|
SinkPad, The sink pad that is receiving the frame |
required |
frame
|
Frame
|
Frame, the frame to pull into the pad. |
required |
Source code in sgn/transforms.py
23 24 25 26 27 28 29 30 31 32 |
|