py21cmfast.wrapper.inputs.InputStruct¶
- class py21cmfast.wrapper.inputs.InputStruct¶
A convenient interface to create a C structure with defaults specified.
It is provided for the purpose of creating C structures in Python to be passed to C functions, where sensible defaults are available. Structures which are created within C and passed back do not need to be wrapped.
This provides a fully initialised structure, and will fail if not all fields are specified with defaults.
Note
The actual C structure is gotten by calling an instance. This is auto-generated when called, based on the parameters in the class.
Warning
This class will not deal well with parameters of the struct which are pointers. All parameters should be primitive types, except for strings, which are dealt with specially.
- Parameters:
ffi (cffi object) – The ffi object from any cffi-wrapped library.
- classmethod __init_subclass__()¶
Store each subclass for easy access.
- Return type:
None
- __str__()¶
Human-readable string representation of the object.
- Return type:
str
- asdict()¶
Return a dict representation of the instance.
Examples
This dict should be such that doing the following should work, i.e. it can be used exactly to construct a new instance of the same object:
>>> inp = InputStruct(**params) >>> newinp =InputStruct(**inp.asdict()) >>> inp == newinp
- Return type:
dict
- clone(**kwargs)¶
Make a fresh copy of the instance with arbitrary parameters updated.
- classmethod from_subdict(dct, safe=True)¶
Construct an instance of a parameter structure from a dictionary.
- classmethod new(x=None, **kwargs)¶
Create a new instance of the struct.
- Parameters:
x (dict | InputStruct | None) – Initial values for the struct. If x is a dictionary, it should map field names to their corresponding values. If x is an instance of this class, its attributes will be used as initial values. If x is None, the struct will be initialised with default values.
- Other Parameters:
All other parameters should be passed as if directly to the class constructor
(i.e. as parameter names).
- Parameters:
x (dict | Self | None)
Examples
>>> up = SimulationOptions({'HII_DIM': 250}) >>> up.HII_DIM 250 >>> up = SimulationOptions(up) >>> up.HII_DIM 250 >>> up = SimulationOptions() >>> up.HII_DIM 200 >>> up = SimulationOptions(HII_DIM=256) >>> up.HII_DIM 256
- property cdict: dict¶
A python dictionary containing the properties of the wrapped C-struct.
The memory pointed to by this dictionary is not owned by the wrapped C-struct, but is rather just a python dict. However, in contrast to
asdict(), this method transforms the properties to what they should be in C (e.g. linear space vs. log-space) before putting them into the dict.This dict also contains only the properties of the wrapped C-struct, rather than all properties of the
InputStructinstance (some attributes of the python instance are there only to guide setting of defaults, and don’t appear in the C-struct at all).- Return type:
dict
- property cstruct: py21cmfast.wrapper.structs.StructWrapper¶
The object pointing to the memory accessed by C-code for this struct.
- Return type:
- property struct: py21cmfast.wrapper.structs.StructWrapper¶
The python-wrapped struct associated with this input object.
- Return type: