mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-04-30 12:00:39 +00:00
16 lines
1.3 KiB
Markdown
16 lines
1.3 KiB
Markdown
|
|
# Semantic Description of `obiutils` Matrix Functionality
|
||
|
|
|
||
|
|
The `package obiutils` provides a generic, type-safe matrix abstraction in Go with core utility methods for construction and querying.
|
||
|
|
|
||
|
|
- **`Make2DArray[T]()`**: A generic constructor that initializes a 2D slice (matrix) of type `Matrix[T]`, with specified numbers of rows and columns. All elements are zero-initialized (e.g., `0` for integers, empty string for strings, default struct values).
|
||
|
|
|
||
|
|
- **`.Column(colIndex int)`**: Extracts and returns a single column (as `[]T`) from the matrix at the given 0-based index, preserving element order across rows.
|
||
|
|
|
||
|
|
- **`.Rows(indices ...int)`**: Returns a new matrix composed of only the specified row indices (0-based), supporting single-row, multi-row, or empty selections.
|
||
|
|
|
||
|
|
- **`.Dim() (rows, cols int)`**: Returns the dimensions of the matrix as `(number_of_rows, number_of_columns)`. Handles edge cases: `nil`, empty (`{}`), and jagged or zero-column matrices safely (e.g., `{ { } }` yields `(1, 0)`).
|
||
|
|
|
||
|
|
All functionality is implemented as methods on the `Matrix[T]` type (implicitly defined via slices of slices), leveraging Go generics for compile-time safety and runtime efficiency.
|
||
|
|
|
||
|
|
The package includes comprehensive unit tests validating correctness across types (`int`, `string`, custom structs) and boundary conditions.
|