Skip to content

Fix MB01XX test signatures (43 failing tests in PR #258) #264

@jamestjsp

Description

@jamestjsp

Fix MB01XX Test Signatures

Problem Summary

PR #258 has 43 failing tests due to function signature mismatches. Tests were generated with incorrect LLM prompt and are missing required parameters.

Root Cause:

  • Tests call MB01XX functions with wrong argument count/types
  • Missing workspace arrays (dwork_obj)
  • Mode parameters correctly use integers (0/1) per design
  • Reference documentation created: MB01XX_SIGNATURE_REFERENCE.md

Example Issue:

# Python wrapper expects (11 args):
mb01ld(uplo, trans, m, n, k, alpha, beta, r_obj, a_obj, x_obj, dwork_obj)

# Test incorrectly calls (8 args):
mb01ld(0, 0, n, k, alpha, beta, B, A)  # Missing: m, r_obj, x_obj, dwork_obj

Key Findings

  1. 3 functions have NO Python wrappers: MB01KD, MB01MD, MB01ND
  2. 7 non-existent functions in tests: mb01kx, mb01lx, mb01mx, mb01nx, mb01ox, mb01px, mb01qx
  3. Mode parameters use integers: UPLO=0/1, TRANS=0/1 (not strings - this is intentional design)
  4. Workspace arrays required for most functions (exceptions: MB01SD, MB01SS, MB01XD, MB01XY)
  5. 11 functions exist in wrapper but not tested: mb01oc, mb01oe, mb01oh, mb01oo, mb01os, mb01ot, mb01rb, mb01rh, mb01rt, mb01rw, mb01ry

Reference Document: MB01XX_SIGNATURE_REFERENCE.md contains complete signature analysis


Multi-Phase Fix Plan

Phase 1: Audit and Cleanup (Foundation)

Goal: Remove invalid tests, document scope

Tasks:

  • Remove tests for 7 non-existent functions (mb01kx, mb01lx, mb01mx, mb01nx, mb01ox, mb01px, mb01qx)
  • Skip tests for 3 unwrapped functions (MB01KD, MB01MD, MB01ND) with @pytest.mark.skip("No Python wrapper")
  • Create test inventory and group by function family

Deliverable: Clean test file with ~33 valid tests


Phase 2: Fix Simple Functions (No Workspace)

Goal: Fix 4 functions without workspace requirements

Functions:

  • MB01SD - Row/column scaling: mb01sd(jobs, m, n, a_obj, r_obj, c_obj)a_obj
  • MB01SS - Symmetric scaling: mb01ss(jobs, uplo, n, a_obj, d_obj)a_obj
  • MB01XD - Matrix inversion: mb01xd(uplo, n, a_obj)(a_obj, info)
  • MB01XY - Matrix inversion (variant): mb01xy(uplo, n, a_obj)(a_obj, info)

Test Data: Extract from SLICOT-Reference/doc/MB01{SD,SS,XD,XY}.html

Deliverable: 4+ passing tests


Phase 3: Fix Scaling/Normalization Functions

Goal: Fix matrix scaling utilities

Functions:

  • MB01PD - Safe range scaling: 9 parameters including block structure (nbl, nrows_obj)
  • MB01QD - Scale by CTO/CFROM: 10 parameters

Challenges: Block structure parameters, matrix type codes

Deliverable: 2+ passing tests


Phase 4: Fix Symmetric/Skew-symmetric Transformations

Goal: Fix similarity transformation functions

Functions:

  • MB01LD - Skew-symmetric similarity (workspace: required)
  • MB01RD - Symmetric similarity (workspace: M*N)
  • MB01RU - Symmetric similarity simplified (workspace: M*N)
  • MB01RX - Symmetric matrix operation (no workspace)

Test Strategy:

# Allocate workspace
dwork = np.zeros(m*n, dtype=np.float64, order='F')
r_obj, x_obj, info = slicutlet.mb01rd(uplo, trans, m, n, alpha, beta, r_obj, a_obj, x_obj, dwork)

Deliverable: 4+ passing tests


Phase 5: Fix Hessenberg Operations

Goal: Fix Hessenberg matrix multiplication/transformation

Functions:

  • MB01OD - Combined Hessenberg+triangular (workspace: N*N)
  • MB01TD - Quasi-triangular product (workspace: N-1)
  • MB01UD - Hessenberg multiply (no workspace)
  • MB01UW - Hessenberg with workspace
  • MB01UX - Triangular-Hessenberg (real)
  • MB01UY - Triangular-Hessenberg (variant)

Test Strategy: Create Hessenberg matrices (upper triangular + one subdiagonal)

Deliverable: 6+ passing tests


Phase 6: Fix Special Operations

Goal: Fix specialized functions

Functions:

  • MB01VD - Kronecker-like product (returns dimensions: c_obj, mc, nc, info)
  • MB01WD - Lyapunov-like operation (DICO: 0=Continuous, 1=Discrete)
  • MB01YD - Symmetric rank-k-l update
  • MB01ZD - Triangular-Hessenberg solve (DIAG: 0=Non-unit, 1=Unit)

Deliverable: 4+ passing tests


Phase 7: Fix Complex Function

Goal: Fix the only complex MB01XX function

Function:

  • MB01UZ - Complex triangular-Hessenberg
    • alpha: Python complex type (1.0 + 0.5j)
    • Arrays: dtype=np.complex128
    • Workspace: zwork = np.zeros(..., dtype=np.complex128)

Deliverable: 1+ passing test


Phase 8: Validation and PR Update

Goal: Ensure all tests pass, update PR

Tasks:

  • Run full test suite: pytest python/tests/test_mb01xx.py -v
  • Verify test count: ~33 passing (43 - 7 nonexistent - 3 unwrapped)
  • Add coverage for 11 missing wrapped functions (optional)
  • Commit: REFACTOR: Fix MB01XX test signatures (Phases 1-8)
  • Push to fix/mb01xx-test-signatures branch
  • Update PR ENH: Add translations of MB01XX family #258 description

Deliverable: Clean PR with all valid tests passing


Mode Parameter Design (CRITICAL)

From CLAUDE.md Translation Conventions:

Mode parameters (CHARACTER*1 in Fortran) → const i32 in C (deliberate design):

  • Avoid string handling in C
  • Use integer values: 0, 1, 2
  • Python tests pass integers, not strings

Mapping:

  • UPLO: 0=Upper, 1=Lower
  • TRANS: 0=NoTranspose, 1=Transpose, 2=ConjugateTranspose
  • SIDE: 0=Left, 1=Right
  • DIAG: 0=Non-unit, 1=Unit
  • JOBS: Function-specific
  • TYPE: 0=General, 1=Lower, 2=Upper, 3=Hessenberg, 4/5/6=Band
  • SCUN: 0=Scale, 1=Unscale
  • DICO: 0=Continuous, 1=Discrete

Example Flow:

Python Test: uplo=0 → Wrapper: int uplo → C: const i32 uplo → BLAS: "U" (ternary)

C code converts to strings only when calling BLAS/LAPACK:

SLC_DSYR2K((uplo ? "L" : "U"), (trans ? "T" : "N"), ...);

Test Data Approach

For each function:

  1. Read SLICOT-Reference/doc/MBXXXX.html "Example" section
  2. Find Fortran READ statements to understand data format
  3. Extract "Program Data" (column-major Fortran convention)
  4. Extract "Program Results" for expected outputs
  5. Write Python test with assert_allclose(result, expected, rtol=1e-14)

Workspace Sizing Patterns:

  • M*N for general transformations
  • N*N for square matrix operations
  • N-1 for quasi-triangular
  • Check HTML "Arguments" section for LDWORK requirements

Open Questions

  1. Should we add tests for 11 unwrapped functions in extension_mb.c?
  2. Should we create wrappers for MB01KD, MB01MD, MB01ND?
  3. Test tolerance: rtol=1e-14 or looser (1e-10)?
  4. Execute sequentially (one PR) or in parallel (multiple PRs per phase)?

References

  • Signature Reference: MB01XX_SIGNATURE_REFERENCE.md
  • SLICOT Docs: SLICOT-Reference/doc/MB*.html
  • Python Wrappers: python/extensions/extension_mb.c
  • C Implementations: src/MB/mb*.c
  • Current PR: ENH: Add translations of MB01XX family #258
  • Fix Branch: fix/mb01xx-test-signatures

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions