Skip to content

DEV: Reimplement RectArray and Matrix/SquareMatrix #546

@tturocy

Description

@tturocy

The rectangular array class RectArray (and by extension the Matrix and SquareMatrix classes) is one of the few remaining places in which Gambit directly handles memory allocation/deallocation via new/delete.

We want to modernise the implementation of these classes.

  1. The current implementation of RectArray is a pointer-to-pointer setup, with the index into the first pointer being the row and the second being the column. This should be replaced with a single std::vector, in which the contents are "raveled" and we handle the offset arithmetic to find the appropriate element rather than relying on C-style pointer arithmetic. (Note that helpfully our RectArray is actually not resizeable at present; there was a resizeable version of this historically but it's no longer needed, which makes re-implementation a bit easier).

2.. Based on similar experience with the parallel one-dimensional Array and Vector classes, Matrix should not be derived from RectArray but instead a Matrix should just have a RectArray as a data member. This refactoring should be done.

  1. Classes which represent a row and a column of the RectArray should be created and provided. These should be useful in simplifying (and making more efficient) some of the operations currently provided in getting/setting rows and columns of the RectArray. For example, there are cases in which GetRow and GetColumn is filling an Array or Vector simply so the resulting data can be used in that container, but actually the calling code could be more generic and use a class which presents a slice of the RectArray as a one-dimensional object, which would eliminate unnecessary copying. it may be beyond the scope of this issue fully to change all such uses, but the re-design of the class should set up such access.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++Items which involve writing in C++hackathonIssues potentially suitable for a hackathon exercise

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions