mixin.register
Registration of structural mixin operations for AxisFuzzy core classes.
This module registers mtype-agnostic structural and container operations that
extend the functionality of axisfuzzy.core.fuzznums.Fuzznum and
axisfuzzy.core.fuzzarray.Fuzzarray with NumPy-like capabilities.
The registered functions focus on shape manipulation, view operations, and common container utilities that work uniformly across all fuzzy number types without requiring mtype-specific dispatch logic.
Architecture
The registration follows a three-layer pattern:
Implementation Layer (
axisfuzzy.mixin.factory): Contains the actual function implementations that operate on the SoA (Struct-of-Arrays) backend.Registration Layer (this module): Uses
axisfuzzy.mixin.registry.register_mixin()decorator to declare how each function should be exposed (instance method, top-level function, or both).Injection Layer (
axisfuzzy.mixin.registry): Dynamically attaches the registered functions to target classes and the module namespace during library initialization.
Registered Functions
This module registers the following categories of mixin functions:
- Shape Manipulation Functions:
_reshape_impl: Delegates tofactory._reshape_factory()to give arrays new shapes without changing data_flatten_impl: Delegates tofactory._flatten_factory()to collapse arrays into 1D_squeeze_impl: Delegates tofactory._squeeze_factory()to remove single-dimensional entries_ravel_impl: Delegates tofactory._ravel_factory()to return contiguous flattened arrays
- Transformation Functions:
_transpose_impl: Delegates tofactory._transpose_factory()to transpose array dimensions_T_impl: Property wrapper for transpose operation, provides.Tattribute access_broadcast_to_impl: Delegates tofactory._broadcast_to_factory()to broadcast arrays to new shapes
- Data Access Functions:
_copy_impl: Delegates tofactory._copy_factory()to create deep copies of fuzzy objects_item_impl: Delegates tofactory._item_factory()to extract scalar items from arrays
- Container Operations:
_concat_impl: Delegates tofactory._concat_factory()to join arrays along existing axes_stack_impl: Delegates tofactory._stack_factory()to stack arrays along new axes_append_impl: Delegates tofactory._append_factory()to append elements to arrays_pop_impl: Delegates tofactory._pop_factory()to remove and return elements from arrays
- Boolean Testing Functions:
_any_impl: Delegates tofactory._any_factory()to test if any array elements are truthy_all_impl: Delegates tofactory._all_factory()to test if all array elements are truthy
Injection Types
Functions are registered with different injection types to control their exposure:
‘both’: Available as both instance methods (e.g.,
arr.reshape(2, 3)) and top-level functions (e.g.,axisfuzzy.reshape(arr, 2, 3)). Used for most operations.‘top_level_function’: Only available as module-level functions (e.g.,
axisfuzzy.copy(obj)).‘instance_function’: Only available as bound methods on target classes (e.g.,
arr.T).
Key Differences from Extension System
Mixin System: mtype-agnostic, focuses on structural operations like reshape, flatten, transpose that work the same way for any fuzzy number type.
Extension System: mtype-sensitive, provides specialized implementations for different fuzzy types (e.g., distance calculation varies between qrofn and ivfn).
Registration Pattern
All functions follow a consistent registration pattern:
@register_mixin(name='function_name',
target_classes=['Fuzznum', 'Fuzzarray'],
injection_type='both')
def _function_name_impl(self, *args, **kwargs):
return _function_name_factory(self, *args, **kwargs)
This pattern ensures:
- Uniform naming convention (_function_name_impl for registration wrappers)
- Consistent delegation to factory implementations
- Proper metadata attachment for injection
- Complete documentation inheritance from factory functions
Notes
All registered functions delegate to factory implementations in
axisfuzzy.mixin.factoryfor actual computation.Injection happens at library initialization via
axisfuzzy.mixin.registry.MixinFunctionRegistry.build_and_inject().Functions are designed to work with the SoA backend architecture of
Fuzzarray.Registration order does not affect functionality but follows logical grouping for maintainability.
See also
axisfuzzy.mixin.factoryImplementation layer for mixin operations.
axisfuzzy.mixin.registryRegistration and injection infrastructure.
axisfuzzy.core.fuzzarrayPrimary target class for structural operations.
axisfuzzy.core.fuzznumsSecondary target class for scalar operations.
Examples
After library initialization, registered functions are available as both instance methods and top-level functions:
from axisfuzzy.core import fuzznum, fuzzarray
from axisfuzzy import reshape, copy # top-level functions
# Create sample data
a = fuzznum((0.6, 0.3), mtype='qrofn')
arr = fuzzarray([a, a, a, a])
# Instance methods (injected via mixin system)
reshaped = arr.reshape(2, 2)
flattened = arr.flatten()
copied = arr.copy()
# Top-level functions (also injected via mixin system)
reshaped2 = reshape(arr, 2, 2)
copied2 = copy(arr)
References
Backend architecture: axisfuzzy.core.backend