furax
Top-level public API re-exported from the furax namespace.
Modules:
-
core– -
distributed– -
exceptions– -
interfaces– -
io– -
linalg– -
mapmaking– -
math– -
obs– -
tree–
Classes:
-
AbstractLinearOperator–Base class for linear operators.
-
IdentityOperator–Operator that returns its input unchanged: I(x) = x.
-
HomothetyOperator–Operator that multiplies its input by a scalar: H(x) = k * x.
-
MoveAxisOperator–Operator that moves axes of pytree leaves: y = jnp.moveaxis(x, source, destination).
-
RavelOperator–Operator that flattens pytree leaves: y = x.ravel().
-
ReshapeOperator–Operator that reshapes pytree leaves: y = x.reshape(shape).
-
BlockRowOperator–Operator that horizontally concatenates block operators: [A | B | C].
-
BlockDiagonalOperator–Operator with independent diagonal blocks: diag(A, B, C).
-
BlockColumnOperator–Operator that vertically stacks block operators: [A; B; C].
-
DenseBlockDiagonalOperator–Operator that applies block diagonal dense matrices via einsum.
-
BroadcastDiagonalOperator–Operator that performs element-wise multiplication with broadcasting.
-
DiagonalOperator–Operator that performs element-wise multiplication: D(x) = d * x.
-
IndexOperator–Operator that extracts elements by indexing: y = x[indices].
-
MaskOperator–Operator that zeros out values according to a boolean mask: M(x) = x * mask.
-
SumOperator–Operator that sums pytree leaves along specified axes.
-
FourierOperator–Operator that applies a frequency-domain kernel via FFT.
-
SymmetricBandToeplitzOperator–Operator for symmetric band Toeplitz convolution.
-
TreeOperator–Operator defined by a generalized matrix as a pytree of pytrees.
-
OperatorTag–Flags representing properties of linear operators.
-
Config–
Functions:
-
asoperator–Wraps a function into an operator.
-
as_lineax_operator–Wrap a furax operator for use with lineax solvers.
-
square–Mark an operator as square.
-
symmetric–Mark an operator as symmetric (implies square).
-
orthogonal–Mark an operator as orthogonal (implies square).
-
diagonal–Mark an operator as diagonal (implies symmetric, which implies square).
-
tridiagonal–Mark an operator as tridiagonal (implies square).
-
lower_triangular–Mark an operator as lower triangular (implies square).
-
upper_triangular–Mark an operator as upper triangular (implies square).
-
positive_semidefinite–Mark an operator as positive semi-definite (implies square).
-
negative_semidefinite–Mark an operator as negative semi-definite (implies square).
-
idempotent–Mark an operator as idempotent, i.e. P @ P = P (implies square).
furax.AbstractLinearOperator
dataclass
Bases: ABC
Base class for linear operators.
Methods:
-
__init_subclass__– -
__post_init__– -
__call__– -
__matmul__– -
__add__– -
__sub__– -
__mul__– -
__rmul__– -
__truediv__– -
__pos__– -
__neg__– -
mv– -
reduce–Returns a linear operator with a reduced structure.
-
as_matrix–Returns the operator as a dense matrix.
-
transpose– -
inverse– -
__init__–
Attributes:
-
class_tags(OperatorTag) – -
in_structure(PyTree[ShapeDtypeStruct]) – -
tags(OperatorTag) –Get the tags for this operator instance.
-
is_square(bool) – -
is_symmetric(bool) – -
is_orthogonal(bool) – -
is_diagonal(bool) – -
is_tridiagonal(bool) – -
is_lower_triangular(bool) – -
is_upper_triangular(bool) – -
is_positive_semidefinite(bool) – -
is_negative_semidefinite(bool) – -
is_idempotent(bool) – -
T(AbstractLinearOperator) – -
I(AbstractLinearOperator) – -
out_structure(PyTree[ShapeDtypeStruct]) – -
in_size(int) –The number of elements in the input PyTree.
-
out_size(int) –The number of elements in the output PyTree.
-
in_promoted_dtype(DType[Any]) –Returns the promoted data type of the operator's input leaves.
-
out_promoted_dtype(DType[Any]) –Returns the promoted data type of the operator's output leaves.
Source code in src/furax/core/_base.py
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 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 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 | |
class_tags = OperatorTag.NONE
class-attribute
in_structure = field(kw_only=True, metadata={'static': True}, default=None)
class-attribute
instance-attribute
tags
property
Get the tags for this operator instance.
is_square
property
is_symmetric
property
is_orthogonal
property
is_diagonal
property
is_tridiagonal
property
is_lower_triangular
property
is_upper_triangular
property
is_positive_semidefinite
property
is_negative_semidefinite
property
is_idempotent
property
T
property
I
property
out_structure
property
in_size
property
The number of elements in the input PyTree.
out_size
property
The number of elements in the output PyTree.
in_promoted_dtype
property
Returns the promoted data type of the operator's input leaves.
out_promoted_dtype
property
Returns the promoted data type of the operator's output leaves.
__init_subclass__(**kwargs)
__post_init__()
__call__(x=None, **keywords)
Source code in src/furax/core/_base.py
__matmul__(other)
Source code in src/furax/core/_base.py
__add__(other)
Source code in src/furax/core/_base.py
__sub__(other)
Source code in src/furax/core/_base.py
__mul__(other)
__rmul__(other)
Source code in src/furax/core/_base.py
__truediv__(other)
Source code in src/furax/core/_base.py
__pos__()
__neg__()
mv(x)
abstractmethod
reduce()
as_matrix()
Returns the operator as a dense matrix.
Input and output PyTrees are flattened and concatenated.
Source code in src/furax/core/_base.py
transpose()
inverse()
__init__(*, in_structure=None)
furax.IdentityOperator
dataclass
Bases: AbstractLinearOperator
Operator that returns its input unchanged: I(x) = x.
The identity operator is diagonal, orthogonal and positive semi-definite. Its transpose and inverse are itself.
Examples:
>>> I = IdentityOperator(in_structure=jax.ShapeDtypeStruct((3,), jnp.float32))
>>> x = jnp.array([1.0, 2.0, 3.0])
>>> I(x)
Array([1., 2., 3.], dtype=float32)
Methods:
-
__matmul__– -
mv– -
as_matrix–
Source code in src/furax/core/_base.py
__matmul__(other)
mv(x)
furax.HomothetyOperator
dataclass
Bases: AbstractLinearOperator
Operator that multiplies its input by a scalar: H(x) = k * x.
The homothety operator is diagonal, symmetric and positive semi-definite (for positive values). Two consecutive homotheties compose by multiplying their scalars: H(k1) @ H(k2) = H(k1 * k2).
Attributes:
Examples:
>>> H = HomothetyOperator(2.0, in_structure=jax.ShapeDtypeStruct((3,), jnp.float32))
>>> x = jnp.array([1.0, 2.0, 3.0])
>>> H(x)
Array([2., 4., 6.], dtype=float32)
>>> H.I(x) # Inverse: divides by 2
Array([0.5, 1. , 1.5], dtype=float32)
Methods:
-
__matmul__– -
mv– -
inverse– -
as_matrix–
Source code in src/furax/core/_base.py
value
instance-attribute
__matmul__(other)
mv(x)
inverse()
furax.MoveAxisOperator
Bases: AbstractLinearOperator
Operator that moves axes of pytree leaves: y = jnp.moveaxis(x, source, destination).
This operator is orthogonal: its transpose and inverse are the reverse axis move.
Attributes:
-
source(tuple[int, ...]) –The source axis or axes to move.
-
destination(tuple[int, ...]) –The destination axis or axes.
Examples:
>>> in_structure = jax.ShapeDtypeStruct((2, 3), jnp.float32)
>>> op = MoveAxisOperator(0, 1, in_structure=in_structure)
>>> op(jnp.array([[1., 1, 1], [2, 2, 2]]))
Array([[1., 2.],
[1., 2.],
[1., 2.]], dtype=float32)
Methods:
Source code in src/furax/core/_axes.py
source = field(metadata={'static': True})
class-attribute
instance-attribute
destination = field(metadata={'static': True})
class-attribute
instance-attribute
inverse = transpose
class-attribute
instance-attribute
__init__(source, destination, *, in_structure)
Source code in src/furax/core/_axes.py
mv(x)
furax.RavelOperator
dataclass
Bases: AbstractRavelOrReshapeOperator
Operator that flattens pytree leaves: y = x.ravel().
By default, all dimensions are flattened. Use first_axis and last_axis
to flatten only a subset of contiguous axes.
This operator is orthogonal: its transpose restores the original shape.
Attributes:
-
first_axis(int) –The first axis to flatten (default: 0).
-
last_axis(int) –The last axis to flatten (default: -1).
Examples:
To flatten the leaves of a pytree:
>>> in_structure = jax.ShapeDtypeStruct((2, 3), jnp.float32)
>>> op = RavelOperator(in_structure=in_structure)
>>> op.out_structure
ShapeDtypeStruct(shape=(6,), dtype=float32)
To flatten the first two axes of the leaves of a pytree:
>>> import furax as fx
>>> x = [jnp.ones((2, 2)), jnp.ones((2, 2, 8))]
>>> op = RavelOperator(0, 1, in_structure=fx.tree.as_structure(x))
>>> op.out_structure
[ShapeDtypeStruct(shape=(4,), dtype=float32),
ShapeDtypeStruct(shape=(4, 8), dtype=float32)]
To flatten the last two axes of the leaves of a pytree:
>>> import furax as fx
>>> x = [jnp.ones((2, 2, 3)), jnp.ones((2, 8))]
>>> op = RavelOperator(-2, -1, in_structure=fx.tree.as_structure(x))
>>> op.out_structure
[ShapeDtypeStruct(shape=(2, 6), dtype=float32),
ShapeDtypeStruct(shape=(16,), dtype=float32)]
Methods:
-
__post_init__– -
mv–
Source code in src/furax/core/_axes.py
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 | |
first_axis = field(default=0, metadata={'static': True})
class-attribute
instance-attribute
last_axis = field(default=(-1), metadata={'static': True})
class-attribute
instance-attribute
__post_init__()
Source code in src/furax/core/_axes.py
mv(x)
Source code in src/furax/core/_axes.py
furax.ReshapeOperator
dataclass
Bases: AbstractRavelOrReshapeOperator
Operator that reshapes pytree leaves: y = x.reshape(shape).
This operator is orthogonal: its transpose restores the original shape.
Attributes:
Methods:
-
__post_init__– -
mv–
Source code in src/furax/core/_axes.py
shape = field(metadata={'static': True})
class-attribute
instance-attribute
__post_init__()
Source code in src/furax/core/_axes.py
furax.BlockRowOperator
Bases: AbstractBlockOperator
Operator that horizontally concatenates block operators: [A | B | C].
Applies each block to the corresponding part of a pytree input and sums the results. All blocks must have the same output structure.
Transpose: BlockRowOperator.T = BlockColumnOperator
Attributes:
-
blocks(PyTree[AbstractLinearOperator]) –A pytree of operators (all with identical output structure).
Examples:
>>> x = jnp.array([1, 2], jnp.float32)
>>> I = IdentityOperator(in_structure=jax.ShapeDtypeStruct((2,), jnp.float32))
>>> op_list = BlockRowOperator([I, 2*I, 3*I])
>>> op_list.as_matrix()
Array([[1., 0., 2., 0., 3., 0.],
[0., 1., 0., 2., 0., 3.]], dtype=float32)
>>> op_list([x, x, x])
Array([ 6., 12.], dtype=float32)
>>> op_dict = BlockRowOperator({'a': I, 'b': 2*I, 'c': 3*I})
>>> op_dict({'a': x, 'b': x, 'c': x})
Array([ 6., 12.], dtype=float32)
Methods:
Source code in src/furax/core/_blocks.py
out_structure
property
__init__(blocks)
Source code in src/furax/core/_blocks.py
mv(x)
Source code in src/furax/core/_blocks.py
transpose()
furax.BlockDiagonalOperator
Bases: AbstractBlockOperator
Operator with independent diagonal blocks: diag(A, B, C).
Applies each block independently to the corresponding part of a pytree input. No constraints on block input/output structures.
The inverse is the block diagonal of individual inverses (if all blocks are square).
Attributes:
-
blocks(PyTree[AbstractLinearOperator]) –A pytree of operators.
Examples:
>>> x = jnp.array([1, 2], jnp.float32)
>>> H = DenseBlockDiagonalOperator(
... jnp.array([[0, 1], [1, 0]]),
... jax.ShapeDtypeStruct((2,), jnp.float32)
... )
>>> H.as_matrix()
Array([[0., 1.],
[1., 0.]], dtype=float32)
>>> op_list = BlockDiagonalOperator([H, 2*H, 3*H])
>>> op_list.as_matrix()
Array([[0., 1., 0., 0., 0., 0.],
[1., 0., 0., 0., 0., 0.],
[0., 0., 0., 2., 0., 0.],
[0., 0., 2., 0., 0., 0.],
[0., 0., 0., 0., 0., 3.],
[0., 0., 0., 0., 3., 0.]], dtype=float32)
>>> op_list([x, x, x])
[Array([2., 1.], dtype=float32),
Array([4., 2.], dtype=float32),
Array([6., 3.], dtype=float32)]
>>> op_dict = BlockDiagonalOperator({'a': H, 'b': 2*H, 'c': 3*H})
>>> op_dict({'a': x, 'b': x, 'c': x})
{'a': Array([2., 1.], dtype=float32),
'b': Array([4., 2.], dtype=float32),
'c': Array([6., 3.], dtype=float32)}
Methods:
Source code in src/furax/core/_blocks.py
__init__(blocks)
mv(vector)
transpose()
inverse()
Source code in src/furax/core/_blocks.py
as_matrix()
reduce()
BlockDiagonalOperator([I, I, ...]) -> I.
Source code in src/furax/core/_blocks.py
furax.BlockColumnOperator
Bases: AbstractBlockOperator
Operator that vertically stacks block operators: [A; B; C].
Applies each block to the same input and returns a pytree of outputs. All blocks must have the same input structure.
Transpose: BlockColumnOperator.T = BlockRowOperator
Attributes:
-
blocks(PyTree[AbstractLinearOperator]) –A pytree of operators (all with identical input structure).
Examples:
>>> x = jnp.array([1, 2], jnp.float32)
>>> I = IdentityOperator(in_structure=jax.ShapeDtypeStruct((2,), jnp.float32))
>>> op_list = BlockColumnOperator([I, I, I])
>>> op_list.as_matrix()
Array([[1., 0.],
[0., 1.],
[1., 0.],
[0., 1.],
[1., 0.],
[0., 1.]], dtype=float32)
>>> op_list(x)
[Array([1., 2.], dtype=float32),
Array([1., 2.], dtype=float32),
Array([1., 2.], dtype=float32)]
>>> op_dict = BlockColumnOperator({'a': I, 'b': I, 'c': I})
>>> op_dict(x)
{'a': Array([1., 2.], dtype=float32),
'b': Array([1., 2.], dtype=float32),
'c': Array([1., 2.], dtype=float32)}
Methods:
Source code in src/furax/core/_blocks.py
__init__(blocks)
Source code in src/furax/core/_blocks.py
mv(vector)
transpose()
furax.DenseBlockDiagonalOperator
dataclass
Bases: AbstractLinearOperator
Operator that applies block diagonal dense matrices via einsum.
Only the diagonal blocks are stored, making this more memory-efficient than a full dense matrix. The operation is defined by einsum subscripts.
Attributes:
-
blocks(Inexact[Array, ...]) –The dense blocks as an array (at least 2D).
-
subscripts(str) –Einsum subscripts defining the operation (default: 'ij...,j...->i...').
Examples:
For a matrix made of three 2x4 diagonal blocks, and input block columns of three blocks of four elements each, the operator can be written as:
>>> blocks = jnp.arange(24).reshape(3, 2, 4)
>>> op = DenseBlockDiagonalOperator(
... blocks, jax.ShapeDtypeStruct((3, 4), jnp.int32), 'imn,in->im')
>>> op.as_matrix()
Array([[ 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0],
[ 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 8, 9, 10, 11, 0, 0, 0, 0],
[ 0, 0, 0, 0, 12, 13, 14, 15, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 16, 17, 18, 19],
[ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23]], dtype=int32)
The axes along which the operator is block diagonal can be non-leading dimensions. As a matter of fact, by default, the diagonal axes are assumed to be "on the right". The notion of block diagonality should be understood in a tensor context. The representation of this operator as a 2d matrix, which relies on the row-major layout, may not be block diagonal.
>>> blocks = jnp.arange(24).reshape(3, 2, 4)
>>> op = DenseBlockDiagonalOperator(blocks, jax.ShapeDtypeStruct((2, 4), jnp.int32))
>>> op.as_matrix()
Array([[ 0, 0, 0, 0, 4, 0, 0, 0],
[ 0, 1, 0, 0, 0, 5, 0, 0],
[ 0, 0, 2, 0, 0, 0, 6, 0],
[ 0, 0, 0, 3, 0, 0, 0, 7],
[ 8, 0, 0, 0, 12, 0, 0, 0],
[ 0, 9, 0, 0, 0, 13, 0, 0],
[ 0, 0, 10, 0, 0, 0, 14, 0],
[ 0, 0, 0, 11, 0, 0, 0, 15],
[16, 0, 0, 0, 20, 0, 0, 0],
[ 0, 17, 0, 0, 0, 21, 0, 0],
[ 0, 0, 18, 0, 0, 0, 22, 0],
[ 0, 0, 0, 19, 0, 0, 0, 23]], dtype=int32)
Methods:
-
__post_init__– -
mv– -
transpose–
Source code in src/furax/core/_dense.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 | |
blocks
instance-attribute
subscripts = field(default='ij...,j...->i...', metadata={'static': True})
class-attribute
instance-attribute
__post_init__()
Source code in src/furax/core/_dense.py
mv(x)
Source code in src/furax/core/_dense.py
furax.BroadcastDiagonalOperator
Bases: AbstractLinearOperator
Operator that performs element-wise multiplication with broadcasting.
Unlike DiagonalOperator, this operator can change the output shape through
broadcasting, making it non-square. Depending on the broadcasting direction:
- Left broadcasting (extending dimensions on the left): equivalent to a block row operator with diagonal blocks.
- Right broadcasting (extending dimensions on the right): equivalent to a block diagonal operator with column blocks.
Attributes:
-
diagonal(Inexact[Array, ...]) –The diagonal values.
-
axis_destination(int | tuple[int, ...]) –The axes along which the generalized diagonal values are applied to the input. If the type is a sequence, there should be as many axes as the number of dimensions in the
diagonalinput. If the type is a non-negative scalar integer, the dimensions will be(axis, ..., axis + diagonal.ndim - 1). If the type is a negative scalar integer, the dimensions will be(axis - diagonal.ndim, ..., axis).
Examples:
>>> import furax as fx
>>> import jax.numpy as jnp
>>> from numpy.testing import assert_allclose
>>> x = jnp.array([1, 2, 3])
>>> values = jnp.array([[1, 1, 1], [2, 1, 0]])
>>> op = BroadcastDiagonalOperator(
... values, in_structure=fx.tree.as_structure(x), axis_destination=-1
... )
>>> assert_allclose(op(x), jnp.array([[1, 2, 3], [2, 2, 0]]))
>>> op.as_matrix()
Array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[2, 0, 0],
[0, 1, 0],
[0, 0, 0]], dtype=int32)
>>> x = jnp.array([1, 2])
>>> values = jnp.array([[2, 3, 1], [1, 0, 1]])
>>> op = BroadcastDiagonalOperator(
... values, in_structure=fx.tree.as_structure(x), axis_destination=0
... )
>>> assert_allclose(op(x), jnp.array([[2, 3, 1], [2, 0, 2]]))
>>> op.as_matrix()
Array([[2, 0],
[3, 0],
[1, 0],
[0, 1],
[0, 0],
[0, 1]], dtype=int32)
>>> x = jnp.array([[0, 1, 2], [2, 3, 4]])
>>> values = jnp.array([2, 1])
>>> op = BroadcastDiagonalOperator(
... values, in_structure=fx.tree.as_structure(x), axis_destination=0
... )
>>> assert_allclose(op(x), jnp.array([[0, 2, 4], [2, 3, 4]]))
>>> op.as_matrix()
Array([[2, 0, 0, 0, 0, 0],
[0, 2, 0, 0, 0, 0],
[0, 0, 2, 0, 0, 0],
[0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1]], dtype=int32)
Methods:
Source code in src/furax/core/_diagonal.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 | |
axis_destination = field(default=(-1), kw_only=True, metadata={'static': True})
class-attribute
instance-attribute
diagonal
property
__init__(diagonal, *, axis_destination=-1, in_structure=None)
Source code in src/furax/core/_diagonal.py
mv(x)
Source code in src/furax/core/_diagonal.py
furax.DiagonalOperator
Bases: BroadcastDiagonalOperator
Operator that performs element-wise multiplication: D(x) = d * x.
The diagonal operator is symmetric and square. Its inverse divides by the diagonal values (zeros are handled by returning zero).
The multiplication axes can be specified via axis_destination:
- axis_destination=0: diagonal[:, None] * x (multiply along first axis)
- axis_destination=-1: diagonal * x (standard broadcasting, default)
Attributes:
-
diagonal(Inexact[Array, ...]) –The diagonal values.
-
axis_destination(int | tuple[int, ...]) –The axes along which the diagonal values are applied to the input. If the type is a sequence, there should be as many axes as the number of dimensions in the
diagonalinput. If the type is a non-negative scalar integer, the dimensions will be(axis, ..., axis + diagonal.ndim - 1). If the type is a negative scalar integer, the dimensions will be(axis - diagonal.ndim, ..., axis).
Examples:
>>> import furax as fx
>>> from numpy.testing import assert_allclose
>>> key_gain, key_tod, key_common = jax.random.split(jax.random.PRNGKey(0), 3)
>>> detector_count = 3
>>> sample_count = 10
>>> x = {
... 'tod': jax.random.normal(key_tod, (detector_count, sample_count)),
... 'ground': jax.random.normal(key_common, (detector_count,)),
... }
>>> detector_gains = jax.random.normal(key_gain, (detector_count,)) / 100 + 1
>>> op = DiagonalOperator(
... detector_gains, axis_destination=0, in_structure=fx.tree.as_structure(x)
... )
>>> y = op(x)
>>> assert_allclose(x['tod'] * detector_gains[:, None], y['tod'])
>>> assert_allclose(x['ground'] * detector_gains, y['ground'])
Methods:
Source code in src/furax/core/_diagonal.py
__init__(diagonal, *, axis_destination=-1, in_structure=None)
Source code in src/furax/core/_diagonal.py
inverse()
as_matrix()
Source code in src/furax/core/_diagonal.py
furax.IndexOperator
Bases: AbstractLinearOperator
Operator that extracts elements by indexing: y = x[indices].
Supports integer indices, slices, boolean masks, and advanced indexing. When indices are unique, the operator satisfies: I @ I.T = Identity.
Attributes:
-
indices(tuple[int | slice | Bool[Array, ...] | Integer[Array, ...] | EllipsisType, ...]) –The indexing tuple (integers, slices, arrays, or Ellipsis).
-
unique_indices(bool) –Whether the indices select unique elements (enables optimizations).
Examples:
To extract the second element of the first axis:
To extract values from the penultimate axis given an array of indices:
>>> indices = jax.numpy.array([2, 4, 4, 5, 7])
>>> in_structure = jax.ShapeDtypeStruct((9, 8, 3), jax.numpy.float32)
>>> op = IndexOperator((..., indices, slice(None)), in_structure=in_structure)
In order to extract values using a boolean mask, it is required to specify an output structure:
>>> indices = jax.numpy.array([True, False, True, False])
>>> in_structure = jax.ShapeDtypeStruct((4,), jax.numpy.float32)
>>> out_structure = jax.ShapeDtypeStruct((2,), jax.numpy.float32)
>>> op = IndexOperator(indices, in_structure=in_structure, out_structure=out_structure)
So it is usually better to specify an index mask:
Methods:
Source code in src/furax/core/_indices.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 | |
indices
instance-attribute
unique_indices = field(metadata={'static': True})
class-attribute
instance-attribute
out_structure
property
indexed_axes
property
Returns the list of axes for which an indexing is performed.
for an indexing of (slice(None), 3, ..., jnp.array([1, 2])),
it returns [1, -1].
__init__(indices, *, in_structure, out_structure=None, unique_indices=None, _out_structure=None)
Source code in src/furax/core/_indices.py
mv(x)
furax.MaskOperator
dataclass
Bases: AbstractLinearOperator
Operator that zeros out values according to a boolean mask: M(x) = x * mask.
The mask is symmetric and idempotent (M @ M = M). A True value means the data point is valid and preserved; False values are set to zero.
The mask is bit-packed internally to save memory. Use from_boolean_mask()
to create from a standard boolean array.
Attributes:
-
mask(PyTree[UInt8[Array, ...]]) –Bit-packed mask as a pytree matching
in_structure.
Methods:
-
__post_init__– -
from_boolean_mask–Create a MaskOperator from a boolean mask.
-
to_boolean_mask–Return the unpacked boolean mask as a pytree matching
in_structure. -
complement–Return the complementary mask: valid where this one is invalid, and vice versa.
-
restrict–Return a new MaskOperator with samples additionally masked out where
conditionis False. -
mv–
Source code in src/furax/core/_mask.py
mask
instance-attribute
Bit-packed sample mask as a pytree matching in_structure.
__post_init__()
Source code in src/furax/core/_mask.py
from_boolean_mask(boolean_mask, *, in_structure)
classmethod
Create a MaskOperator from a boolean mask.
Parameters:
-
boolean_mask(PyTree[Bool[Array, ...]]) –Either a single boolean array (broadcast to all leaves of
in_structure) or a pytree of boolean arrays matching the structure ofin_structure. -
in_structure(PyTree[ShapeDtypeStruct]) –The pytree structure of the operator's input.
Source code in src/furax/core/_mask.py
to_boolean_mask()
Return the unpacked boolean mask as a pytree matching in_structure.
Source code in src/furax/core/_mask.py
complement()
Return the complementary mask: valid where this one is invalid, and vice versa.
Computed directly on the packed bytes via bitwise NOT (no unpack/repack). Padding bits in
the last byte are flipped too, but to_boolean_mask discards them (it truncates to the
sample count), so they never surface.
Source code in src/furax/core/_mask.py
restrict(condition)
Return a new MaskOperator with samples additionally masked out where condition is False.
A scalar condition gates the whole operator on or off.
Source code in src/furax/core/_mask.py
furax.SumOperator
dataclass
Bases: AbstractLinearOperator
Operator that sums pytree leaves along specified axes.
Follows NumPy conventions for axis specification
None: sum all dimensionsint: sum a single axis(): no reduction (identity)tuple[int, ...]: sum multiple axes
The axis specification can be a pytree matching the input structure to apply different reductions to different leaves.
Attributes:
Examples:
To sum along every dimension of all leaves:
>>> from furax.tree import as_structure
>>> x = {'a': jnp.array([[0, 0, 0], [1, 1, 1]]),
... 'b': jnp.array([[1, 1, 1], [2, 2, 2]])}
>>> op = SumOperator(axis=None, in_structure=as_structure(x))
>>> op(x)
{'a': Array(3, dtype=int32), 'b': Array(9, dtype=int32)}
To sum along every dimension of only one leaf:
>>> op = SumOperator(axis={'a': None, 'b': ()}, in_structure=as_structure(x))
>>> op(x)
{'a': Array(3, dtype=int32), 'b': Array([[1, 1, 1], [2, 2, 2]], dtype=int32)}
To sum the leaves along different axes:
>>> op = SumOperator(axis={'a': 0, 'b': 1}, in_structure=as_structure(x))
>>> op(x)
{'a': Array([1, 1, 1], dtype=int32), 'b': Array([3, 6], dtype=int32)}
Methods:
-
mv–
Source code in src/furax/core/_sum.py
axis = field(metadata={'static': True})
class-attribute
instance-attribute
mv(x)
Source code in src/furax/core/_sum.py
furax.FourierOperator
Bases: AbstractLinearOperator
Operator that applies a frequency-domain kernel via FFT.
Performs element-wise multiplication in Fourier space: Y = IFFT(FFT(x) * kernel). The filter is applied along the last axis. Supports optional apodization to reduce edge artifacts.
Attributes:
-
kernel_func(Callable[[Array], Array]) –Function that returns the kernel given frequencies.
-
sample_rate(float) –Sample rate of the input signal [Hz].
-
apodize(bool) –Whether to apply Hamming window apodization.
-
fft_size(int) –Size of the FFT (power of 2 for efficiency).
Examples:
>>> import jax.numpy as jnp
>>> n = 1000
>>> fs = 200.0 # sampling frequency
>>> cutoff = 10.0 # cutoff frequency
>>> op = FourierOperator(
... lambda f: f < cutoff, # low-pass filter
... in_structure=jax.ShapeDtypeStruct((n,), float),
... sample_rate=fs,
... )
>>> signal = jnp.ones(n)
>>> filtered = op(signal)
Methods:
-
__init__–Create a FourierOperator.
-
mv–Apply Fourier kernel to input array.
-
get_kernel– -
as_matrix–Returns the operator as a dense matrix.
-
create_bandpass_operator–Creates a bandpass filtering operator.
Source code in src/furax/core/_fourier.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 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 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 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
kernel_func = field(metadata={'static': True})
class-attribute
instance-attribute
fft_size = field(metadata={'static': True})
class-attribute
instance-attribute
apodize = field(metadata={'static': True})
class-attribute
instance-attribute
padding_width = field(metadata={'static': True})
class-attribute
instance-attribute
sample_rate
instance-attribute
__init__(kernel_func, *, in_structure, sample_rate=1.0, apodize=False, padding_width=None)
Parameters:
-
kernel_func(Callable[[Float[Array, ...]], Inexact[Array, ...]]) –Function that generates the Fourier kernel as a function of frequency.
-
in_structure(PyTree[ShapeDtypeStruct]) –Input structure of the operator.
-
sample_rate(float, default:1.0) –Sample rate of the input signal [Hz]. Important if the kernel function depends on physical frequency units.
-
apodize(bool, default:False) –Pad and apply Hamming window to both ends to reduce edge artifacts.
-
padding_width(int | None, default:None) –Padding width in samples on each end. Defaults is 5% of data length (rounded up).
Source code in src/furax/core/_fourier.py
mv(x)
Apply Fourier kernel to input array.
For multidimensional inputs, the filter is applied along the last axis.
Source code in src/furax/core/_fourier.py
get_kernel()
as_matrix()
Returns the operator as a dense matrix.
Warning: This can be memory-intensive for large inputs.
Source code in src/furax/core/_fourier.py
create_bandpass_operator(f_low, f_high, sample_rate, in_structure, *, filter_type='square', apodize=True)
classmethod
Creates a bandpass filtering operator.
Examples:
>>> import jax.numpy as jnp
>>> tod = jnp.sin(2 * jnp.pi * 10 * jnp.linspace(0, 1, 1000))
>>> op = FourierOperator.create_bandpass_operator(
... f_low=5.0,
... f_high=15.0,
... sample_rate=1000.0,
... in_structure=jax.ShapeDtypeStruct(tod.shape, tod.dtype)
... )
>>> filtered = op(tod)
Parameters:
-
f_low(float) –Lower frequency cutoff (inclusive) [Hz].
-
f_high(float) –Upper frequency cutoff (inclusive) [Hz].
-
sample_rate(float) –Sampling rate of the input signal [Hz].
-
in_structure(PyTree[ShapeDtypeStruct]) –Input structure specification.
-
filter_type(str, default:'square') –Filter shape type. Options: 'square', 'butter4', 'cos2'. Default: 'square'. - 'square': Sharp cutoff (ideal brick-wall filter) - 'butter4': 4th-order Butterworth filter (smooth rolloff) - 'cos2': Cosine-squared transition (smooth rolloff)
-
apodize(bool, default:True) –Apply Hamming window to reduce edge artifacts.
Returns:
-
FourierOperator–FourierOperator configured with bandpass kernel.
Raises:
-
ValueError–If frequency parameters or filter_type are invalid.
Source code in src/furax/core/_fourier.py
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 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 | |
furax.SymmetricBandToeplitzOperator
Bases: AbstractLinearOperator
Operator for symmetric band Toeplitz convolution.
A Toeplitz matrix has constant diagonals. This operator is symmetric and exploits the band structure for efficient computation. For multidimensional band values, the operator is block diagonal.
Available methods (N = matrix size, K = number of bands):
- dense: dense matrix multiplication
- direct: direct convolution
- fft: FFT on the whole input
- overlap_save_sequential: sequential FFT on chunks
- overlap_save_parallel: batched FFT on chunks (default)
============================ ========= ======
Method Time Memory
============================ ========= ======
dense O(N^2) N^2
direct O(NK) 2N
fft O(N log N) 3N
overlap_save_sequential O(N log K) 2N
overlap_save_parallel O(N log K) 4N
============================ ========= ======
Attributes:
-
band_values(Float[Array, ...]) –The band values (first element is the diagonal).
-
method(str) –The computation method.
-
fft_size(int | None) –FFT size for the fft and overlap methods.
Examples:
>>> tod = jnp.ones((2, 5))
>>> op = SymmetricBandToeplitzOperator(
... jnp.array([[1., 0.5], [1, 0.25]]),
... in_structure=jax.ShapeDtypeStruct(tod.shape, tod.dtype))
>>> op(tod)
Array([[1.5 , 2. , 2. , 2. , 1.5 ],
[1.25, 1.5 , 1.5 , 1.5 , 1.25]], dtype=float64)
>>> op.as_matrix()
Array([[1. , 0.5 , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0.5 , 1. , 0.5 , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0.5 , 1. , 0.5 , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0.5 , 1. , 0.5 , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0.5 , 1. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 1. , 0.25, 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0.25, 1. , 0.25, 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0.25, 1. , 0.25, 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.25, 1. , 0.25],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.25, 1. ]], dtype=float64)
Methods:
Source code in src/furax/core/_toeplitz.py
22 23 24 25 26 27 28 29 30 31 32 33 34 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 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 248 249 250 251 252 253 254 255 256 257 | |
METHODS = ('dense', 'direct', 'fft', 'overlap_save_parallel', 'overlap_save_sequential')
class-attribute
band_values
instance-attribute
method = field(metadata={'static': True})
class-attribute
instance-attribute
fft_size = field(metadata={'static': True})
class-attribute
instance-attribute
__init__(band_values, *, in_structure, method='overlap_save_parallel', fft_size=None)
Source code in src/furax/core/_toeplitz.py
mv(x)
as_matrix()
Source code in src/furax/core/_toeplitz.py
furax.TreeOperator
Bases: AbstractLinearOperator
Operator defined by a generalized matrix as a pytree of pytrees.
More memory-efficient than dense matrices when the structure allows XLA optimizations (symmetries, zeros, shared elements, broadcasting).
The structure of the generalized matrix is the tree product: outer_treedef x inner_treedef, analogous to a matrix where rows are represented by an outer tree and columns by the inner tree.
Leaves within the same row must be broadcastable; no such constraint applies across rows.
Attributes:
-
tree(PyTree[Array]) –The generalized matrix as a pytree of pytrees.
-
outer_treedef(PyTreeDef) –PyTreeDef for rows.
-
inner_treedef(PyTreeDef) –PyTreeDef for columns.
-
tree_shape(tuple[int, int]) –(num_rows, num_cols) in terms of tree leaves.
Examples:
To represent the Mueller Matrix of a quarter-wave plate with a vertical fast-axis:
>>> from furax.obs.stokes import StokesIQUV
>>> op = TreeOperator(
... StokesIQUV(
StokesIQUV(1, 0, 0, 0),
StokesIQUV(0, 1, 0, 0),
StokesIQUV(0, 0, 0, -1),
StokesIQUV(0, 0, 1, 0),
),
in_structure=StokesIQUV.structure_for((), jnp.float32)
... )
>>> op.as_matrix()
Array([[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 0., -1.],
[ 0., 0., 1., 0.]], dtype=float32)
>>> op(StokesIQUV(1., 1., 1., 1.))
StokesIQUV(i=1.0, q=1.0, u=-1.0, v=1.0)
Methods:
Source code in src/furax/core/_trees.py
tree
instance-attribute
inner_treedef = field(metadata={'static': True})
class-attribute
instance-attribute
outer_treedef = field(metadata={'static': True})
class-attribute
instance-attribute
tree_shape
property
Return the number of leaves of the outer and inner structures.
__init__(tree, *, in_structure, inner_treedef=None, outer_treedef=None)
Source code in src/furax/core/_trees.py
mv(x)
transpose()
inverse()
Source code in src/furax/core/_trees.py
furax.OperatorTag
Bases: IntFlag
Flags representing properties of linear operators.
Attributes:
-
NONE– -
SQUARE– -
SYMMETRIC– -
ORTHOGONAL– -
DIAGONAL– -
TRIDIAGONAL– -
LOWER_TRIANGULAR– -
UPPER_TRIANGULAR– -
POSITIVE_SEMIDEFINITE– -
NEGATIVE_SEMIDEFINITE– -
IDEMPOTENT–
Source code in src/furax/core/_base.py
NONE = 0
class-attribute
instance-attribute
SQUARE = auto()
class-attribute
instance-attribute
SYMMETRIC = auto()
class-attribute
instance-attribute
ORTHOGONAL = auto()
class-attribute
instance-attribute
DIAGONAL = auto()
class-attribute
instance-attribute
TRIDIAGONAL = auto()
class-attribute
instance-attribute
LOWER_TRIANGULAR = auto()
class-attribute
instance-attribute
UPPER_TRIANGULAR = auto()
class-attribute
instance-attribute
POSITIVE_SEMIDEFINITE = auto()
class-attribute
instance-attribute
NEGATIVE_SEMIDEFINITE = auto()
class-attribute
instance-attribute
IDEMPOTENT = auto()
class-attribute
instance-attribute
furax.Config
Methods:
Source code in src/furax/_config.py
__init__(**kwargs)
__str__()
__enter__()
__exit__(exc_type, exc_val, exc_tb)
furax.asoperator(func, *, in_structure, **keywords)
Wraps a function into an operator.
Parameters:
-
func(Callable[..., Any]) –The function to wrap.
-
in_structure(PyTree[ShapeDtypeStruct]) –The structure (shapes and dtypes) of the operator's input.
-
**keywords(Any, default:{}) –Keyword arguments to pass to the function.
Usage
op = asoperator(lambda x: 2*x, in_structure=jax.ShapeDtypeStruct((), jnp.float32)) op.I(1.) Array(0.5, dtype=float32)
Returns:
-
AbstractLinearOperator–An operator wrapping the function.
Source code in src/furax/core/_base.py
furax.as_lineax_operator(operator, tags=OperatorTag.NONE)
Wrap a furax operator for use with lineax solvers.
This function creates a lineax-compatible wrapper that stores the furax operator as a pytree field, ensuring JIT compatibility. Tags from the furax operator are automatically copied.
Parameters:
-
operator(AbstractLinearOperator) –A furax AbstractLinearOperator instance
-
tags(OperatorTag, default:NONE) –Extra operator tags to attach to the wrapper, combined with those copied from the furax operator.
Returns:
-
AbstractLinearOperator–A lineax AbstractLinearOperator that wraps the furax operator
Examples:
>>> import furax as fx
>>> import lineax as lx
>>> import jax.numpy as jnp
>>> op = fx.IdentityOperator(in_structure=fx.tree.as_structure(jnp.ones(10)))
>>> lx_op = fx.as_lineax_operator(op)
>>> solution = lx.linear_solve(lx_op, jnp.ones(10))
Source code in src/furax/interfaces/lineax.py
furax.square(cls)
Mark an operator as square.
furax.symmetric(cls)
Mark an operator as symmetric (implies square).
furax.orthogonal(cls)
Mark an operator as orthogonal (implies square).
furax.diagonal(cls)
Mark an operator as diagonal (implies symmetric, which implies square).
furax.tridiagonal(cls)
furax.lower_triangular(cls)
furax.upper_triangular(cls)
furax.positive_semidefinite(cls)
Mark an operator as positive semi-definite (implies square).
furax.negative_semidefinite(cls)
Mark an operator as negative semi-definite (implies square).