Add other matrix types in ComplexMatrix2D
completed by: David Czech
mentors: whiteknight
Task Description: Parrot-Linear-Algebra (PLA) is a linear algebra package for the Parrot virtual machine. PLA adds several matrix types including ComplexMatrix2D, a 2-D matrix type with complex values. It also provides other types NumMatrix2D and PMCMatrix2D to hold values with other types.
ComplexMatrix2D's add VTABLE contains logic to add two matrices together. However, this VTABLE only supports adding in other ComplexMatrix2D, not NumMatrix2D or PMCMatrix2D. We should have the ability to add any type of matrix to a ComplexMatrix2D.
Steps to Complete:
- Create a fork of Whiteknight/parrot-linear-algebra.git on Github
- Create a new function in src/pmc/complexmatrix2d.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 real part of the ComplexMatrix2D (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 NumMatrix2D and PMCMatrix2D, calling your new add_matrices_generic function
- Add 4 new tests (add/subtract for both input types) to t/pmc/complexmatrix2d.t
- Open a pull request on Github to have your changes merged