# petewebbo/momath architecture

> Architecture diagram of the GitHub repository petewebbo/momath, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/petewebbo/momath
- Repository: https://github.com/petewebbo/momath

## Overview

##### Main Components
- Math Core Modules:
- Vector Module (src/vector)
- Contains dynamic/static vector implementations and vector operations (mo_vector.hpp, mo_vector_ops.hpp).
- Matrix Module (src/matrix)
- Provides matrix implementations (static/dynamic), matrix operations, and higher-level linear algebra operations using OpenBLAS (files like mo_matrix.hpp, mo_matrix_ops.hpp).
- Types Module (src/types)
- Defines basic and specialized types for DSP, FFT, matrix, and vector operations.
- FFT Engine (src/fft)
- Acts as a unified interface (mo_fft.hpp) to different FFT implementations.
- Contains submodules for each FFT library:
- FFTW (src/fft/fftw)
- NE10 (src/fft/ne10)
- PocketFFT (src/fft/pocket)
- Splitradix (src/fft/splitradix)
- Utility Module (src/util)
- Provides general utility functions (assertions, file IO, math utilities, printing) to support common operations across modules.
- Error Handling
- Managed via a dedicated header (src/mo_errors.hpp) to capture error definitions and handling, ensuring robustness.

##### Relationships and Interactions Between Components
- The Vector and Matrix modules both use the Types module for consistent type definitions.
- The FFT module is designed with multiple strategies – the library selected depends on compile-time flags. Therefore, the system design should denote an abstraction layer where a generic FFT interface is provided, while concrete implementations (ne10, fftw, pocket, splitradix) are interchangeable.
- The Matrix module interfaces with the OpenBLAS-based linear algebra routines (under src/matrix/linalg/openblas) for operations such as matrix multiplication and SVD.
- Utility functions form a cross-cutting layer that supports all modules, e.g., for debugging, assertions, and file I/O.
- There is a test suite organized in the test directory that validates each of these functional areas (FFT, matrix, vector).

##### Architectural Patterns and Design Principles
- Modularity: Each mathematical operation domain (vector, matrix, FFT) is compartmentalized for ease of maintenance and extension.
- Abstraction and Strategy: Especially in the FFT Engine – a single interface (mo_fft.hpp) allows multiple underlying implementations to be swapped via build-time flags.
- Separation of Concerns: Distinguishing between core math functionality, utility functions, and external library interactions (such as OpenBLAS) keeps the design clear and testable.

##### Instructed Elements
- Clear labels for each component (e.g., “Vector Module”, “Matrix Module”, “FFT Engine – Splitradix”, “FFT Engine – FFTW”, “Types”, “Utility”, “Linear Algebra via OpenBLAS”).
- Data flows from the FFT abstract interface to its specific implementations.
- Dependencies, such as the Matrix module relying on the Types and OpenBLAS modules.
- Interactions where utility functions support the main modules.
- Core logic components (Vector, Matrix, FFT)
- Supporting/shared modules (Types, Util, Error Handling)
- External dependencies (OpenBLAS)
- Build configuration/strategy (highlighting the use of CMake flags for selecting FFT libraries)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Math Modules
    subgraph "Math Core Modules"
        VectorModule["Vector Module"]:::core
        MatrixModule["Matrix Module"]:::core
        FFTAbstract["FFT Engine (Abstract)"]:::core
    end

    %% FFT Implementations
    subgraph "FFT Implementations"
        FFTW["FFT Engine - FFTW"]:::core
        NE10["FFT Engine - NE10"]:::core
        PocketFFT["FFT Engine - PocketFFT"]:::core
        Splitradix["FFT Engine - Splitradix"]:::core
    end

    %% Supporting and External Modules
    TypesModule["Types Module"]:::support
    UtilityModule["Utility Module"]:::support
    ErrorHandling["Error Handling"]:::support
    OpenBLAS["Linear Algebra via OpenBLAS"]:::external
    TestSuite["Test Suite"]:::test

    %% Relationships between Core Modules and Supporting Modules
    VectorModule -->|"uses"| TypesModule
    MatrixModule -->|"uses"| TypesModule
    MatrixModule -->|"calls"| OpenBLAS
    FFTAbstract -->|"selects"| FFTW
    FFTAbstract -->|"selects"| NE10
    FFTAbstract -->|"selects"| PocketFFT
    FFTAbstract -->|"selects"| Splitradix

    UtilityModule -->|"supports"| VectorModule
    UtilityModule -->|"supports"| MatrixModule
    UtilityModule -->|"supports"| FFTAbstract

    ErrorHandling -->|"handles"| VectorModule
    ErrorHandling -->|"handles"| MatrixModule
    ErrorHandling -->|"handles"| FFTAbstract

    TestSuite -->|"tests"| VectorModule
    TestSuite -->|"tests"| MatrixModule
    TestSuite -->|"tests"| FFTAbstract

    %% Click Events for Component Mappings
    click VectorModule "https://github.com/petewebbo/momath/blob/main/src/vector/mo_vector.hpp"
    click VectorModule "https://github.com/petewebbo/momath/blob/main/src/vector/mo_vector_ops.hpp"

    click MatrixModule "https://github.com/petewebbo/momath/blob/main/src/matrix/mo_matrix.hpp"
    click MatrixModule "https://github.com/petewebbo/momath/blob/main/src/matrix/mo_matrix_ops.hpp"

    click OpenBLAS "https://github.com/petewebbo/momath/blob/main/src/matrix/linalg/openblas/mo_linalg.hpp"

    click TypesModule "https://github.com/petewebbo/momath/blob/main/src/types/mo_basic_types.hpp"
    click TypesModule "https://github.com/petewebbo/momath/blob/main/src/types/mo_dspvector_types.hpp"
    click TypesModule "https://github.com/petewebbo/momath/blob/main/src/types/mo_fft_types.hpp"
    click TypesModule "https://github.com/petewebbo/momath/blob/main/src/types/mo_matrix_types.hpp"
    click TypesModule "https://github.com/petewebbo/momath/blob/main/src/types/mo_vector_types.hpp"

    click FFTAbstract "https://github.com/petewebbo/momath/blob/main/src/fft/mo_fft.hpp"

    click FFTW "https://github.com/petewebbo/momath/blob/main/src/fft/fftw/mo_fft_fftw.hpp"
    click NE10 "https://github.com/petewebbo/momath/blob/main/src/fft/ne10/mo_fft_ne10.hpp"
    click PocketFFT "https://github.com/petewebbo/momath/blob/main/src/fft/pocket/mo_fft_pocket.hpp"
    click Splitradix "https://github.com/petewebbo/momath/blob/main/src/fft/splitradix/mo_fft_splitradix.hpp"

    click UtilityModule "https://github.com/petewebbo/momath/blob/main/src/util/mo_assert.hpp"
    click UtilityModule "https://github.com/petewebbo/momath/blob/main/src/util/mo_fileio.hpp"
    click UtilityModule "https://github.com/petewebbo/momath/blob/main/src/util/mo_math_utils.hpp"
    click UtilityModule "https://github.com/petewebbo/momath/blob/main/src/util/mo_print.hpp"

    click ErrorHandling "https://github.com/petewebbo/momath/blob/main/src/mo_errors.hpp"

    click TestSuite "https://github.com/petewebbo/momath/tree/main/test/"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef support fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef test fill:#FFA500,stroke:#000,stroke-width:2px;
```
