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:

  1. Implementation Layer (axisfuzzy.mixin.factory): Contains the actual function implementations that operate on the SoA (Struct-of-Arrays) backend.

  2. 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).

  3. 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 to factory._reshape_factory() to give arrays new shapes without changing data

  • _flatten_impl: Delegates to factory._flatten_factory() to collapse arrays into 1D

  • _squeeze_impl: Delegates to factory._squeeze_factory() to remove single-dimensional entries

  • _ravel_impl: Delegates to factory._ravel_factory() to return contiguous flattened arrays

Transformation Functions:
  • _transpose_impl: Delegates to factory._transpose_factory() to transpose array dimensions

  • _T_impl: Property wrapper for transpose operation, provides .T attribute access

  • _broadcast_to_impl: Delegates to factory._broadcast_to_factory() to broadcast arrays to new shapes

Data Access Functions:
  • _copy_impl: Delegates to factory._copy_factory() to create deep copies of fuzzy objects

  • _item_impl: Delegates to factory._item_factory() to extract scalar items from arrays

Container Operations:
  • _concat_impl: Delegates to factory._concat_factory() to join arrays along existing axes

  • _stack_impl: Delegates to factory._stack_factory() to stack arrays along new axes

  • _append_impl: Delegates to factory._append_factory() to append elements to arrays

  • _pop_impl: Delegates to factory._pop_factory() to remove and return elements from arrays

Boolean Testing Functions:
  • _any_impl: Delegates to factory._any_factory() to test if any array elements are truthy

  • _all_impl: Delegates to factory._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

See also

axisfuzzy.mixin.factory

Implementation layer for mixin operations.

axisfuzzy.mixin.registry

Registration and injection infrastructure.

axisfuzzy.core.fuzzarray

Primary target class for structural operations.

axisfuzzy.core.fuzznums

Secondary 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