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

Support array types in arithmetic for ComplexMatrix2D

completed by: Kristaba

mentors: whiteknight

Task Description: Parrot-Linear-Algebra (PLA) is a plugin library that adds linear algebra (matrix and vector) support for the Parrot virtual machine. ComplexMatrix2D is a Parrot data type that acts as a 2D matrix of complex values. ComplexMatrix2D can perform arithmetic operations with scalars, such as adding a single value to every element in the matrix. However, not all possible input data types are supported.

Inputs which are strings are currently parsed into Complex values in the function get_complex_value_from_pmc() (src/lib/math_common.c). We would like the ability to treat 2-element arrays as complex values too. The first element in the array would be the real part, and the second element would be the imaginary part.

The student should:

  1. Create a fork of PLA on github
  2. Modify the function src/lib/math_common.c:get_complex_value_from_pmc() to pull a complex value out of a 2-element array (longer arrays should not be handled. 1-element or 0-element array behavior is up to the discretion of the student)
  3. Add tests to t/methods/complexmatrix2d/gemm.t to show that the parameters Alpha and Beta can both be passed as arrays without triggering errors
  4. Add at least 10 tests for the new behavior, spread out among any of the following files:
    1. t/methods/complexmatrix2d/fill.t
    2. t/methods/complexmatrix2d/item_at.t
    3. t/methods/complexmatrix2d/initialize_from_args.t
    4. t/methods/complexmatrix2d/initialize_from_array.t
    5. t/pmc/complexmatrix2d.t (set_pmc_keyed and set_pmc_keyed_int VTABLEs)
  5. Open a pull request at github to merge in the new features.

Benefits: Right now complex values can only be specified using either a String or a Complex PMC (usually initialized from a string). Adding in the ability to specify Complex values using array types adds much flexibility to the interface and allows the ComplexMatrix2D PMC type to be more useful to it's users.