utils
utils
¤
csafelog = ComplexSafeLog.apply
module-attribute
¤
safelog = SafeLog.apply
module-attribute
¤
ComplexSafeLog
¤
Bases: Function
Source code in cirkit/backend/torch/utils.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
backward(ctx, grad_output)
staticmethod
¤
Source code in cirkit/backend/torch/utils.py
44 45 46 47 | |
forward(x)
staticmethod
¤
Source code in cirkit/backend/torch/utils.py
33 34 35 | |
setup_context(ctx, inputs, output)
staticmethod
¤
Source code in cirkit/backend/torch/utils.py
37 38 39 40 41 42 | |
SafeLog
¤
Bases: Function
Source code in cirkit/backend/torch/utils.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
backward(ctx, grad_output)
staticmethod
¤
Source code in cirkit/backend/torch/utils.py
22 23 24 25 | |
forward(x)
staticmethod
¤
Source code in cirkit/backend/torch/utils.py
11 12 13 | |
setup_context(ctx, inputs, output)
staticmethod
¤
Source code in cirkit/backend/torch/utils.py
15 16 17 18 19 20 | |
flatten_dims(x, /, *, dims)
¤
Flatten the given dims in the input.
If the dims are not continuous, they will be permuted and flattened to the position of the first element in dims.
Intended to be used as a helper for some torch functions that can only work on one dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The tensor to be flattened. |
required |
dims
|
Sequence[int]
|
The dimensions to flatten along, expected to be sorted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The flattened tensor. |
Source code in cirkit/backend/torch/utils.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
unflatten_dims(x, /, *, dims, shape)
¤
Unflatten the first dim in dims in the input to get a given shape.
This is the inverse transformation of flatten_dims, provided a correspondimg shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The tensor to be unflattened. |
required |
dims
|
Sequence[int]
|
The dimensions to unflatten to, should be the same as flatten_dims. |
required |
shape
|
Sequence[int]
|
The shape to unflatten to, can be either the shape for dims, or the whole shape for the output. If the latter, the shape will not be checked for consistency outside dims. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The unflattened tensor. |
Source code in cirkit/backend/torch/utils.py
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 | |