symforce.ops.impl.dataclass_storage_ops module#

class DataclassStorageOps[source]#

Bases: object

StorageOps implementation for dataclasses

Supports nested types. If any of the fields are of unknown size (e.g. sequences), the relevant functions expect to be passed an instance instead of the type. However, the length of sequences can be specified using field metadata, allowing for StorageOps functions such as storage_dim, from_storage, and symbolic to be passed the dataclass type rather than an instance. Adding a sequence of length 10, for example, would look like:

@dataclass
class ExampleDataclass:
    example_list: T.Sequence[ExampleType] = field(metadata={"length": 10})
static storage_dim(a)[source]#
Parameters:

a (Dataclass | Type[Dataclass]) –

Return type:

int

static to_storage(a)[source]#
Parameters:

a (Dataclass) –

Return type:

List[float]

static from_storage(a, elements)[source]#
Parameters:
Return type:

Dataclass

static symbolic(a, name, **kwargs)[source]#

Return a symbolic instance of a Dataclass

Names are chosen by creating each field with symbolic name {name}.{field_name}. If the name argument is not given, that part is left off, and fields are created with just {field_name}.

Parameters:
Return type:

Dataclass