/*
 * call-seq: to_a
 *
 * Create an array from the matrix
 *
 *   a = m.to_a
 *
 * is equivalent to
 *
 *   a = Array.new(m.vsize) { Array.new(m.hsize) }
 *   m.each_index { |i,j|
 *      a[i][j] = m[i,j]
 *   }
 *
 */
VALUE rb_dmatrix_to_a(VALUE self)
{
    int i ;
    int j ;
    VALUE arr ;
    VALUE row ;
    DMatrix* a ;
    get_dmatrix(a, self) ;

    arr = rb_ary_new2(a->vsize) ;

    for( i = 0 ; i != a->vsize ; ++i )
    {
        row = rb_ary_new2(a->hsize) ;

        for( j = 0 ; j != a->hsize ; ++j )
        {
            rb_ary_store(row,
                         j,
                         rb_float_new(a->data[i + j*a->vsize])) ;
        }

        rb_ary_store(arr, i, row) ;
    }

    return arr ;
}