Add/Subtract other matrix types in NumMatrix2D
completed by: Fernando Brito
Task Description: Parrot-Linear-Algebra (PLA) is a linear algebra package for the Parrot virtual machine. PLA adds several matrix types including NumMatrix2D, a 2-D matrix type with numeric values. It also provides other types ComplexMatrix2D and PMCMatrix2D to hold values with other types.
NumMatrix2D's add and subtract VTABLEs contain logic to add two matrices together. However, these VTABLEs only support adding in other NumMatrix2D, not ComplexMatrix2D or PMCMatrix2D. We should have the ability to add any type of matrix to a NumMatrix2D.
Steps to Complete:
- Create a fork of Whiteknight/parrot-linear-algebra.git on Github
- Create a new function in src/pmc/nummatrix2d.pmc called add_matrices_generic. (see add_matrices function for example). In this new function, you should:
- Check that the matrices have compatible dimensions
- Iterate over all elements in the matrix, using VTABLE_get_number on the other matrix and adding that result to the item in the NumMatrix2D (SELF).
- Support addition and subtraction using a flag (see add_matrices for an example of this)
- Create new overrides of the add and subtract VTABLEs for both ComplexMatrix2D and PMCMatrix2D, calling your new add_matrices_generic function
- Add 4 new tests (add/subtract for both input types) to t/pmc/nummatrix2d.t
- Open a pull request on Github to have your changes merged