/*
 * call-seq: premul!(a)
 *
 * In-place multiply
 *
 *   c = a * b
 *
 * is equivalent to
 *
 *   c = b.premul!(a)
 *
 * with
 *
 *   b.object_id == c.object_id
 *
 * Note this implies +a+ must be square.  +DimensionError+ is raised
 * otherwise.
 *
 */
VALUE rb_dmatrix_premul_inplace(VALUE self, VALUE ra)
{
    DMatrix* b ;
    get_dmatrix(b, self) ;

    if( rb_obj_is_kind_of(ra, rb_cDMatrix) )
    {
        DMatrix* a ;
        DMatrix* c ;
        
        get_dmatrix(a, ra) ;
        
        if( a->hsize != b->vsize ||
            a->vsize != a->hsize )
        {
            raise_dim_error() ;
        }
        
        c = DMatrix_new(a->vsize, b->hsize) ;
        DMatrix_mul(c, a, b) ;
        DMatrix_swap(b, c) ;
        DMatrix_free(c) ;
    }
    else
    {
        DMatrix_mul_scalar(b, NUM2DBL(ra)) ;
    }

    return self ;
}