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

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:

  1. Create a fork of Whiteknight/parrot-linear-algebra.git on Github
  2. 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:
    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 real part of the ComplexMatrix2D (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 NumMatrix2D and PMCMatrix2D, calling your new add_matrices_generic function
  4. Add 4 new tests (add/subtract for both input types) to t/pmc/complexmatrix2d.t
  5. Open a pull request on Github to have your changes merged

Links:parrot-linear-algebra, complexmatrix2d.pmc