/*
 * call-seq: rows(array)
 *
 * Create a matrix using the elements of +array+ as rows.
 *
 *   DMatrix.rows(array)
 *
 * is equivalent to
 *
 *   DMatrix.new(array.size, array[0].size) { |i,j| array[i][j] }
 *
 * +DimensionError+ is raised if +array+ is not rectangular.
 *
 */
VALUE rb_dmatrix_s_rows( VALUE klass, VALUE array )
{
    int i ;
    int j ;
    int vsize ;
    int hsize ;

    VALUE* ptr ;
    VALUE crow ;

    DMatrix* a = 0 ;
    VALUE ra ;

    if( TYPE(array) != T_ARRAY )
    {
        raise_bad_array() ;
    }

    ptr = RARRAY_PTR(array) ;
    vsize = RARRAY_LEN(array) ;

    if( vsize < 1 || TYPE(ptr[0]) != T_ARRAY )
    {
        raise_bad_array() ;
    }
    if( (hsize = RARRAY_LEN(ptr[0])) == 0 )
    {
        raise_bad_array() ;
    }
    
    a = DMatrix_new(vsize, hsize) ;
    ra = wrap_dmatrix(a) ;
    
    for( i = 0 ; i != vsize ; ++i )
    {
        crow = ptr[i] ;

        if( TYPE(crow) != T_ARRAY )
        {
            raise_bad_array() ;
        }

        if( RARRAY_LEN(crow) != hsize )
        {
            raise_bad_array() ;
        }

        for( j = 0 ; j != hsize ; j++ )
        {
            a->data[i + j*a->vsize] = NUM2DBL(RARRAY_PTR(crow)[j]) ;
        }
    }

    return ra ;
}