Parma Polyhedra Library requirements
Internal rectangular coefficient matrices

Internal rectangular coefficient matrices

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-000361

For Row equal to Dense_Row or Sparse_Row, Matrix<Row> shall represent a rectangular coefficient array with independent row and column counts. Every retained row shall have exactly the matrix column count; entry Mij shall be the row coefficient at index j. Zero rows, zero columns and zero-by-zero shape shall all be admitted and remain distinct shapes. The raw row contracts shall follow 🔗 1. Internal coefficient-row values and valid use. No affine, constraint or generator interpretation shall be imposed by the matrix.

Calls shall require live valid matrices, valid positions/iterators, admitted nonoverflowing size calculations and sufficient resources. Mutable row access shall require clients to restore the common width before a call requiring matrix validity. Initialization, numerical and synchronization prerequisites shall follow 🔗 1. Internal coefficient-row values and valid use. Failed construction shall release storage owned by the incomplete matrix. Recoverable mutation failure may propagate; unchanged sources shall survive and modified targets shall remain destructible without a universal rectangular-state or rollback guarantee.

Matrix shape and coordinate identity must remain meaningful even when one dimension is zero.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Compare complete independent rectangular arrays and shapes, including both zero extents. Inspect mutable-row lifetime, initialization, failure cleanup and numerical prerequisites.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal

Internal source header: Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member declarations below apply to this template with Row equal to Dense_Row or Sparse_Row.

template <typename Row> class Matrix;
SW_SPEC
2
PPL-SPEC-000362
PPL-SPEC-000362
Zero-filled square and rectangular matrix construction

Default construction shall produce zero-by-zero shape. Square construction shall produce n rows and columns. Rectangular construction shall preserve both requested counts, including zero in either count. Every coefficient shall initially be zero, and sparse rows shall initially have no stored entries. Construction shall use the row type selected by the template.

Zero initialization supplies a defined array before individual entries are assigned.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Enumerate small rectangular and square shapes, zero-row/nonzero-width matrices and nonzero-row/zero-width matrices against independent zero arrays.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
explicit Matrix<Row>::Matrix(dimension_type n = 0);
Matrix<Row>::Matrix(dimension_type num_rows, dimension_type num_columns);
SW_SPEC
3
PPL-SPEC-000363
PPL-SPEC-000363
Owning matrix copies, assignment and whole-matrix swaps

Implicit copy construction/assignment shall preserve shape and all entries, produce independent row owners, admit self-assignment and return the target from assignment. A copy shall survive its source mutation/destruction. Implicit moves shall transfer the source entry value to the target and leave the source valid for destruction and reassignment, with unspecified shape and entries. Member/free swaps shall exchange full matrix values and dimensions, including self-swap. Destruction shall release row and coefficient storage owned by the matrix. Failure shall follow 🔗 1. Internal rectangular coefficient matrices and valid use.

Copying a row container must preserve each coefficient independently of another matrix lifetime.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check source destruction/mutation, self and chained assignments, empty and unequal shapes, moves with source reuse and both swap forms.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
Matrix<Row>::Matrix(const Matrix<Row>& y); // Implicitly declared.
Matrix<Row>& Matrix<Row>::operator=(const Matrix<Row>& y); // Implicitly declared.
Matrix<Row>::Matrix(Matrix<Row>&& y); // Implicitly declared.
Matrix<Row>& Matrix<Row>::operator=(Matrix<Row>&& y); // Implicitly declared.
Matrix<Row>::~Matrix(); // Implicitly declared.
void Matrix<Row>::m_swap(Matrix<Row>& y);
template <typename Row> void swap(Matrix<Row>& x, Matrix<Row>& y);
SW_SPEC
4
PPL-SPEC-000364
PPL-SPEC-000364
Matrix shape, row capacity and reservation

Shape queries shall report logical row and column counts independently of allocated capacity. has_no_rows() shall mean row count zero, including a nonzero column count. capacity() shall report reserved row slots at least as large as row count. reserve_rows(n) shall retain shape and values and provide at least n row slots; a request no larger than current capacity shall retain capacity. Reallocation may invalidate row references/iterators. max_num_rows() shall return std::vector<Row>().max_size() and max_num_columns() shall return Row::max_size(). These reported limits shall not guarantee that every allocation below them succeeds.

Reserved row storage and logical dimensions answer different questions.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check shape queries and capacity lower bounds through reservation and reuse; retain every entry and distinguish no rows from zero columns without attempting infeasible allocations.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
dimension_type Matrix<Row>::num_rows() const;
dimension_type Matrix<Row>::num_columns() const;
bool Matrix<Row>::has_no_rows() const;
dimension_type Matrix<Row>::capacity() const;
void Matrix<Row>::reserve_rows(dimension_type n);
static dimension_type Matrix<Row>::max_num_rows();
static dimension_type Matrix<Row>::max_num_columns();
SW_SPEC
5
PPL-SPEC-000365
PPL-SPEC-000365
Matrix resizing, prefix preservation and clear

Resizing shall set the requested rectangular shape, preserve every entry in the common old/new row-and-column rectangle, discard removed entries and initialize newly introduced entries to zero. Removed values shall not reappear on regrowth. The one-argument form shall set a square shape. clear() shall produce zero rows and columns; it need not release reserved row capacity. Successful resizing shall restore every retained row to the common width. Existing iterators/references shall be invalidated as specified by changes to the row vector and row storage.

Shape changes must preserve coordinate associations and remove stale values outside the retained rectangle.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Compare mixed shrink/grow histories in both dimensions and all zero extents with independent array slicing/zero extension, including later regrowth and square resizing.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::resize(dimension_type n);
void Matrix<Row>::resize(dimension_type num_rows, dimension_type num_columns);
void Matrix<Row>::clear();
SW_SPEC
6
PPL-SPEC-000366
PPL-SPEC-000366
Appending zero rows and columns

add_zero_rows(n) and add_zero_columns(m) shall require positive counts and admitted resulting shapes. They shall append exactly that many zero rows or columns, retaining all old entries at their old coordinates. The combined form shall require both positive counts and append both zero blocks. Zero columns in old/new rows shall follow the selected raw row representation.

Appending empty storage must not shift or reinterpret existing matrix entries.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check independent rectangle extension with zero/nonzero initial extents, both storage types and row-capacity reuse versus growth.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::add_zero_rows(dimension_type n);
void Matrix<Row>::add_zero_columns(dimension_type m);
void Matrix<Row>::add_zero_rows_and_columns(dimension_type n, dimension_type m);
SW_SPEC
7
PPL-SPEC-000367
PPL-SPEC-000367
Copy-appending a row with source independence

add_row(x) shall require x.size() == num_columns() and an admitted additional row. It shall append an owned copy of the source entry value, preserve all old rows/width and preserve an external source. The source may be a row borrowed from the target matrix; its entry value shall be captured before growth can invalidate that reference. Mutating the appended row shall not modify its source. Existing matrix-row iterators may be invalidated.

A copied target-owned row must remain valid as an input even when append reallocates row storage.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check external and borrowed rows with spare/full row capacity, zero-width rows and independently mutated appended/source rows.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::add_row(const Row& x);
SW_SPEC
8
PPL-SPEC-000368
PPL-SPEC-000368
Recycling an external row into a matrix

add_recycled_row(x) shall require a live row of matching column count that is not a row of the matrix, plus admitted additional row count. It shall append the source entry vector while preserving all old matrix values. On success, the donor shall be a valid all-zero row of the same column count; its capacity shall be unspecified. The operation may transfer owned storage rather than copy coefficient values. Violations of matching-width or independent-donor preconditions need not be detected in release builds. Borrowed matrix-row iterators may be invalidated by append.

A transferred donor needs an explicit residual state and independence rule to avoid ownership aliasing.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check matching external dense/sparse donors with varying capacities and zero/nonzero widths, source zero state, transferred coefficient ownership and existing matrix values. Inspect/debug-check excluded borrowed or wrong-width donors.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::add_recycled_row(Row& x);
SW_SPEC
9
PPL-SPEC-000369
PPL-SPEC-000369
Removing contiguous or trailing matrix rows

Trailing-row removal shall require n <= num_rows() and remove exactly the last n rows while retaining column count. Iterator-range removal shall require a valid ordered half-open range in the same matrix, including an empty range; it shall retain the unselected rows in their original order and keep column count. Removing every row shall retain the declared width. Removed row storage shall be released; later appended zero rows shall not recover old coefficients.

Row removal changes sequence positions without altering the coordinate width or values of surviving rows.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Enumerate all row windows and trailing lengths against independent sequence erasure, including zero-width, empty, full removal and later zero-row append.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::remove_trailing_rows(dimension_type n);
void Matrix<Row>::remove_rows(iterator first, iterator last);
SW_SPEC
10
PPL-SPEC-000370
PPL-SPEC-000370
Inserting and removing matrix columns

add_zero_columns(n,i) shall require i <= num_columns() and an admitted nonoverflowing result shape. It shall insert n zero columns before i and shift all old columns at or after i up by n; zero insertion shall preserve the array. remove_column(i) shall require an in-width column, erase it from every row and shift later indices down by one. Trailing-column removal shall require n <= num_columns() and remove just the last n columns. Row count shall be retained, including zero rows. These transformations shall preserve every surviving coefficient association.

All rows must undergo the same coordinate renumbering even when they store different sparse supports.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Enumerate front/interior/end insertion, all individual and trailing removals, zero-width/no-row shapes and later regrowth against independent row-wise vector edits.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::add_zero_columns(dimension_type n, dimension_type i);
void Matrix<Row>::remove_column(dimension_type i);
void Matrix<Row>::remove_trailing_columns(dimension_type n);
SW_SPEC
11
PPL-SPEC-000371
PPL-SPEC-000371
Column swaps and encoded nonzero-index permutation cycles

Column swaps shall require two in-width indices and exchange their entries in every row; index zero and self-swaps shall be admitted. Encoded permutation cycles shall require a nonempty vector containing complete disjoint cycles of length at least two, each terminated by zero. Every listed index shall be nonzero and strictly below column count. The final element shall be a zero terminator. For each cycle, the old coefficient at each listed column shall move to the following listed column, with the last wrapping to the first. Unlisted columns, especially column zero, shall remain unchanged. Both operations shall retain shape; row-level borrowed positions may be invalidated.

Zero is an encoding delimiter for cycles rather than a permutable coordinate in that interface.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check swaps including zero, disjoint two/long cycles, wrapping orientation, zero-valued cycle entries and untouched column zero in both row types. Apply only complete valid encodings.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::swap_columns(dimension_type i, dimension_type j);
void Matrix<Row>::permute_columns(const std::vector<dimension_type>& cycles);
SW_SPEC
12
PPL-SPEC-000372
PPL-SPEC-000372
Borrowed matrix rows and row-sequence iterators

Indexed access shall require i < num_rows() and borrow the corresponding row. Const access shall not modify sparse support. Mutable access shall permit coefficient updates within common width; changing a borrowed row's size shall require restoring rectangularity under 🔗 1. Internal rectangular coefficient matrices and valid use. Row iterators shall enumerate every retained row in order, including zero-width rows, using the standard random-access vector position semantics of Swapping_Vector. Const/mutable positions shall agree; prefix/postfix advancement shall retain the usual advanced/entry-position results. Borrowed rows and iterators shall not outlive the matrix or survive invalidating row-vector operations.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

Borrowed row access supports efficient coefficient updates while keeping matrix width a caller-maintained invariant.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check row address identity, indexed/forward/reverse/random-access correspondence, prefix/postfix positions, const reads, zero-width rows and entry mutation through borrowed rows. Check lvalue admission and temporary-owner rejection with compile-time client expressions. Preserve temporary iterator/view use and lvalue storage identity in runtime checks.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc. tests/rowstoragespec1.cc.

CPP
Internal
typedef typename Swapping_Vector<Row>::iterator Matrix<Row>::iterator;
typedef typename Swapping_Vector<Row>::const_iterator Matrix<Row>::const_iterator;
Row& Matrix<Row>::operator[](dimension_type i) &;
const Row& Matrix<Row>::operator[](dimension_type i) const &;
Matrix<Row>::iterator Matrix<Row>::begin() &;
Matrix<Row>::iterator Matrix<Row>::end() &;
Matrix<Row>::const_iterator Matrix<Row>::begin() const &;
Matrix<Row>::const_iterator Matrix<Row>::end() const &;
SW_SPEC
13
PPL-SPEC-000373
PPL-SPEC-000373
Matrix equality includes both dimensions and every entry

Matrix equality shall return true exactly when both logical dimensions and all corresponding row coefficient vectors agree. Extra zero rows or columns shall affect equality. Row capacity, allocation identity and explicit versus implicit sparse zeroes shall not affect equality. Inequality shall be its Boolean negation. Comparison shall not modify either operand.

Equal empty storage does not imply equal declared matrix shape.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check Boolean inequality expressions in both operand orders through C++20 equality rewriting, retaining the stated equality and mismatch behavior. Check unchanged/copy/self equality, altered entries, different zero extents, reserved capacity and explicit sparse zeroes.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
template <typename Row>
bool operator==(const Matrix<Row>& x, const Matrix<Row>& y);
// Inequality uses C++20 rewriting of operator==.
SW_SPEC
14
PPL-SPEC-000374
PPL-SPEC-000374
Matrix ASCII reload validates rectangular row sizes

ASCII export shall emit r x c followed by a newline and the compatible row-type ASCII representation of each retained row in order. Loading a complete compatible representation shall replace both dimensions and every entry and return true only for a valid rectangular result. Zero-row/nonzero- column and nonzero-row/zero-column representations shall be admitted. Malformed/missing shape tokens or row encodings, including a row size that differs from the declared width, shall return false. Trailing input shall remain available for further parsing. The dimensions shall fit the container limits and any limits supplied by the enclosing record. Matrix row storage shall grow as the rows are decoded. Failure need not roll back prior changes; owned storage and surviving target destruction shall follow 🔗 1. Internal rectangular coefficient matrices and valid use. Diagnostic dump/print forms shall emit this same reloadable representation.

A reload success must restore a rectangular array rather than accepting a header that disagrees with its rows.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Round-trip complete independent arrays and both zero extents, check exact header/row ordering, malformed/truncated fields, mismatched row widths, retries and preserved trailing input.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
void Matrix<Row>::ascii_dump(std::ostream& s) const;
void Matrix<Row>::ascii_dump() const;
void Matrix<Row>::print() const;
bool Matrix<Row>::ascii_load(std::istream& s);
SW_SPEC
15
PPL-SPEC-000375
PPL-SPEC-000375
Matrix rectangularity inspection and memory accounting

OK() shall report whether every retained row's logical size equals the matrix column count; no-row matrices shall satisfy that width invariant for any declared admitted column count. It shall not replace the separate raw-row invariant queries. Memory queries shall preserve matrix values. Total memory shall equal sizeof(matrix) + external; external memory shall include reserved row-vector slots and external storage owned by each live row. The returned count shall be a storage-accounting estimate, with no promise of exact allocator overhead or future allocation success.

Common row width and the invariants of each row are separate conditions; storage accounting must include both levels of ownership.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check matching/mismatched/restored borrowed row widths, empty matrices with nonzero width, accounting identities for reserved rows and unchanged entries through const queries.

src/Matrix_defs.hh; src/Matrix_inlines.hh; src/Matrix_templates.hh; src/Swapping_Vector_defs.hh; src/Swapping_Vector_inlines.hh; tests/matrixspec1.cc; tests/matrix1.cc.

CPP
Internal
bool Matrix<Row>::OK() const;
memory_size_type Matrix<Row>::external_memory_in_bytes() const;
memory_size_type Matrix<Row>::total_memory_in_bytes() const;