GSoC/GCI Archive
Google Code-in 2010 Parrot Foundation and The Perl Foundation

Add/Subtract other matrix types in NumMatrix2D

completed by: Fernando Brito

mentors: whiteknight

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:

  1. Create a fork of Whiteknight/parrot-linear-algebra.git on Github
  2. 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:
    1. Check that the matrices have compatible dimensions
    2. 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).
    3. Support addition and subtraction using a flag (see add_matrices for an example of this)
  3. Create new overrides of the add and subtract VTABLEs for both ComplexMatrix2D and PMCMatrix2D, calling your new add_matrices_generic function
  4. Add 4 new tests (add/subtract for both input types) to t/pmc/nummatrix2d.t
  5. Open a pull request on Github to have your changes merged

Links:parrot-linear-algebra, complexmatrix2d.pmc