Skip to content

Axis parameter is a u8 magic number in from_iterator and related APIs #461

Description

@genefold-ai

Problem

DenseMatrix::from_iterator(iter, nrows, ncols, axis: u8) (and related axis-taking APIs) use u8 magic numbers: 0 = row-major fill, 1 = column-major fill.

Two failure modes observed downstream (genefold test suite):

  1. Accidental transposition — passing 1 where 0 was meant silently transposes the matrix; dimensions still match, values are wrong. This actually happened across fixtures in the same codebase.
  2. Undocumented convention — the meaning of 0/1 is only discoverable from source; nothing in the type prevents 2.

Proposal

pub enum Axis { Row = 0, Col = 1 }

impl DenseMatrix<T> {
    pub fn from_iterator_axis(iter: I, nrows: usize, ncols: usize, axis: Axis) -> Result<Self, Failed>;
}
  • New enum-taking methods first (no breakage of existing u8 signatures, deprecate later);
  • TryFrom<u8> for Axis so stringly/CLI boundaries convert with an error instead of a wrong-number bug.

A repo-wide grep shows the axis: u8 convention repeats across other constructors/iterators — worth treating uniformly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions