# torchcts/exactref architecture

> Architecture diagram of the GitHub repository torchcts/exactref, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/torchcts/exactref
- Repository: https://github.com/torchcts/exactref

## Overview

ExactRef is a numerical-reference library: callers provide operands and an operation, then inspect a correctly rounded exact answer, certified bounds, tolerances, or an emulated accumulation. The graph preserves the documented operation families and the distinct attention forward/backward stages. Shared array, format, operand, rounding, and result layers support those operations; the native gateway exposes C kernels. Some operation implementations and C units were not excerpted, so their internal call relationships are omitted unless documented or visible in the index.

Main entry points: [`src/exactref/_native.py`](https://github.com/torchcts/exactref/blob/main/src/exactref/_native.py) (C extension gateway), [`src/exactref/__init__.py`](https://github.com/torchcts/exactref/blob/main/src/exactref/__init__.py) (ExactRef API), [`src/exactref/ops/_product_core.py`](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/_product_core.py) (Products and GEMM), [`src/exactref/ops/attention/_forward.py`](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_forward.py) (Attention forward)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public interface"]
  node_api["ExactRef API<br/>[__init__.py]"]
end

subgraph group_operations["Numerical operations"]
  node_products["Products and GEMM<br/>[_product_core.py]"]
  node_elementwise["Arithmetic and reduction<br/>[elementwise.py]"]
  node_fft["Fourier transform<br/>[fft.py]"]
  node_matrixexp["Matrix functions<br/>[matrix_exp.py]"]
end

subgraph group_attention["Attention analysis"]
  node_attnproblem["Attention problem<br/>[_problem.py]"]
  node_attnforward["Attention forward<br/>[_forward.py]"]
  node_attnbackward["Attention backward<br/>[_backward.py]"]
  node_attnalgorithms["Attention algorithms<br/>[_algorithms.py]"]
end

subgraph group_core["Shared numerical core"]
  node_inputs["Input conversion<br/>[convert.py]"]
  node_arrays["Array storage<br/>[array.py]"]
  node_formats["Element formats<br/>[formats.py]"]
  node_accumulation["Accumulation models<br/>[accumulation.py]"]
  node_boundaries["Rounding boundaries<br/>[boundaries.py]"]
  node_operands["Operand handling<br/>[_operands.py]"]
  node_result["Bounds and results<br/>[result.py]"]
end

subgraph group_native["Native kernels"]
  node_native["C extension gateway<br/>[_native.py]"]
  node_cproduct["Product kernels<br/>[product.c]"]
  node_cattention["Attention kernels<br/>[attention.c]"]
  node_cfft["FFT kernels<br/>[fft.c]"]
  node_cmatrixexp["Matrix exponential kernel<br/>[matrix_exp.c]"]
end

node_caller(("Numerical-code tester"))

node_caller -->|"requests reference"| node_api
node_api -->|"converts inputs"| node_inputs
node_api -->|"exposes products"| node_products
node_api -->|"exposes arithmetic"| node_elementwise
node_api -->|"exposes FFT"| node_fft
node_api -->|"exposes matrix functions"| node_matrixexp
node_api -->|"exposes attention"| node_attnforward
node_inputs -->|"creates arrays"| node_arrays
node_arrays -->|"stores typed values"| node_formats
node_products -->|"normalizes operands"| node_operands
node_products -->|"calls product kernels"| node_native
node_elementwise -->|"calls arithmetic kernels"| node_native
node_fft -->|"calls FFT kernels"| node_native
node_matrixexp -.->|"uses native routines"| node_native
node_attnforward -->|"prepares inputs"| node_attnproblem
node_attnbackward -->|"prepares inputs"| node_attnproblem
node_attnforward -->|"uses backward support"| node_attnbackward
node_attnalgorithms -->|"selects forward method"| node_attnforward
node_attnalgorithms -->|"selects backward method"| node_attnbackward
node_products -->|"models summation order"| node_accumulation
node_products -->|"builds operation result"| node_result
node_elementwise -->|"builds operation result"| node_result
node_fft -->|"builds operation result"| node_result
node_attnforward -->|"returns bounds"| node_result
node_attnbackward -->|"returns bounds"| node_result
node_boundaries -->|"describes rounding"| node_accumulation
node_native -->|"exposes product routines"| node_cproduct
node_native -->|"exposes attention routines"| node_cattention
node_native -->|"exposes FFT routines"| node_cfft
node_native -->|"exposes matrix routines"| node_cmatrixexp

click node_api "https://github.com/torchcts/exactref/blob/main/src/exactref/__init__.py"
click node_inputs "https://github.com/torchcts/exactref/blob/main/src/exactref/convert.py"
click node_arrays "https://github.com/torchcts/exactref/blob/main/src/exactref/array.py"
click node_formats "https://github.com/torchcts/exactref/blob/main/src/exactref/formats.py"
click node_products "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/_product_core.py"
click node_elementwise "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/elementwise.py"
click node_fft "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/fft.py"
click node_matrixexp "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/matrix_exp.py"
click node_attnproblem "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_problem.py"
click node_attnforward "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_forward.py"
click node_attnbackward "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_backward.py"
click node_attnalgorithms "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_algorithms.py"
click node_accumulation "https://github.com/torchcts/exactref/blob/main/src/exactref/accumulation.py"
click node_boundaries "https://github.com/torchcts/exactref/blob/main/src/exactref/boundaries.py"
click node_operands "https://github.com/torchcts/exactref/blob/main/src/exactref/ops/_operands.py"
click node_result "https://github.com/torchcts/exactref/blob/main/src/exactref/result.py"
click node_native "https://github.com/torchcts/exactref/blob/main/src/exactref/_native.py"
click node_cproduct "https://github.com/torchcts/exactref/blob/main/csrc/product.c"
click node_cattention "https://github.com/torchcts/exactref/blob/main/csrc/attention.c"
click node_cfft "https://github.com/torchcts/exactref/blob/main/csrc/fft.c"
click node_cmatrixexp "https://github.com/torchcts/exactref/blob/main/csrc/matrix_exp.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api toneBlue
class node_products,node_elementwise,node_fft,node_matrixexp toneAmber
class node_attnproblem,node_attnforward,node_attnbackward,node_attnalgorithms toneMint
class node_inputs,node_arrays,node_formats,node_accumulation,node_boundaries,node_operands,node_result toneRose
class node_native,node_cproduct,node_cattention,node_cfft,node_cmatrixexp,node_caller toneIndigo
```

## Components

### Public interface

- [ExactRef API](https://github.com/torchcts/exactref/blob/main/src/exactref/__init__.py): `src/exactref/__init__.py`

### Numerical operations

- [Products and GEMM](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/_product_core.py): `src/exactref/ops/_product_core.py`
- [Arithmetic and reduction](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/elementwise.py): `src/exactref/ops/elementwise.py`
- [Fourier transform](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/fft.py): `src/exactref/ops/fft.py`
- [Matrix functions](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/matrix_exp.py): `src/exactref/ops/matrix_exp.py`

### Attention analysis

- [Attention problem](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_problem.py): `src/exactref/ops/attention/_problem.py`
- [Attention forward](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_forward.py): `src/exactref/ops/attention/_forward.py`
- [Attention backward](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_backward.py): `src/exactref/ops/attention/_backward.py`
- [Attention algorithms](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/attention/_algorithms.py): `src/exactref/ops/attention/_algorithms.py`

### Shared numerical core

- [Input conversion](https://github.com/torchcts/exactref/blob/main/src/exactref/convert.py): `src/exactref/convert.py`
- [Array storage](https://github.com/torchcts/exactref/blob/main/src/exactref/array.py): `src/exactref/array.py`
- [Element formats](https://github.com/torchcts/exactref/blob/main/src/exactref/formats.py): `src/exactref/formats.py`
- [Accumulation models](https://github.com/torchcts/exactref/blob/main/src/exactref/accumulation.py): `src/exactref/accumulation.py`
- [Rounding boundaries](https://github.com/torchcts/exactref/blob/main/src/exactref/boundaries.py): `src/exactref/boundaries.py`
- [Operand handling](https://github.com/torchcts/exactref/blob/main/src/exactref/ops/_operands.py): `src/exactref/ops/_operands.py`
- [Bounds and results](https://github.com/torchcts/exactref/blob/main/src/exactref/result.py): `src/exactref/result.py`

### Native kernels

- [C extension gateway](https://github.com/torchcts/exactref/blob/main/src/exactref/_native.py): `src/exactref/_native.py`
- [Product kernels](https://github.com/torchcts/exactref/blob/main/csrc/product.c): `csrc/product.c`
- [Attention kernels](https://github.com/torchcts/exactref/blob/main/csrc/attention.c): `csrc/attention.c`
- [FFT kernels](https://github.com/torchcts/exactref/blob/main/csrc/fft.c): `csrc/fft.c`
- [Matrix exponential kernel](https://github.com/torchcts/exactref/blob/main/csrc/matrix_exp.c): `csrc/matrix_exp.c`

### Other components

- **Numerical-code tester**

## Connections

- Numerical-code tester → ExactRef API: requests reference (evidence: `README.md`)
- ExactRef API → Input conversion: converts inputs (evidence: `src/exactref/__init__.py`)
- ExactRef API → Products and GEMM: exposes products (evidence: `README.md`)
- ExactRef API → Arithmetic and reduction: exposes arithmetic (evidence: `README.md`)
- ExactRef API → Fourier transform: exposes FFT (evidence: `README.md`)
- ExactRef API → Matrix functions: exposes matrix functions (evidence: `README.md`)
- ExactRef API → Attention forward: exposes attention (evidence: `README.md`)
- Input conversion → Array storage: creates arrays (evidence: `src/exactref/convert.py`)
- Array storage → Element formats: stores typed values (evidence: `src/exactref/array.py`)
- Products and GEMM → Operand handling: normalizes operands (evidence: `src/exactref/ops/_product_core.py`)
- Products and GEMM → C extension gateway: calls product kernels (evidence: `src/exactref/ops/matmul.py`)
- Arithmetic and reduction → C extension gateway: calls arithmetic kernels (evidence: `src/exactref/ops/elementwise.py`)
- Fourier transform → C extension gateway: calls FFT kernels (evidence: `src/exactref/ops/fft.py`)
- Matrix functions → C extension gateway: uses native routines
- Attention forward → Attention problem: prepares inputs (evidence: `src/exactref/ops/attention/_forward.py`)
- Attention backward → Attention problem: prepares inputs (evidence: `src/exactref/ops/attention/_backward.py`)
- Attention forward → Attention backward: uses backward support (evidence: `src/exactref/ops/attention/_forward.py`)
- Attention algorithms → Attention forward: selects forward method (evidence: `src/exactref/ops/attention/_algorithms.py`)
- Attention algorithms → Attention backward: selects backward method (evidence: `src/exactref/ops/attention/_algorithms.py`)
- Products and GEMM → Accumulation models: models summation order (evidence: `src/exactref/ops/matmul.py`)
- Products and GEMM → Bounds and results: builds operation result (evidence: `src/exactref/ops/_product_core.py`)
- Arithmetic and reduction → Bounds and results: builds operation result (evidence: `src/exactref/ops/elementwise.py`)
- Fourier transform → Bounds and results: builds operation result (evidence: `src/exactref/ops/fft.py`)
- Attention forward → Bounds and results: returns bounds (evidence: `src/exactref/ops/attention/_forward.py`)
- Attention backward → Bounds and results: returns bounds (evidence: `src/exactref/ops/attention/_backward.py`)
- Rounding boundaries → Accumulation models: describes rounding (evidence: `src/exactref/boundaries.py`)
- C extension gateway → Product kernels: exposes product routines (evidence: `src/exactref/_native.py`)
- C extension gateway → Attention kernels: exposes attention routines (evidence: `src/exactref/_native.py`)
- C extension gateway → FFT kernels: exposes FFT routines (evidence: `src/exactref/_native.py`)
- C extension gateway → Matrix exponential kernel: exposes matrix routines (evidence: `src/exactref/_native.py`)
