"y \= scalar" fails
John W. Eaton
jwe at bevo.che.wisc.edu
Mon Mar 3 15:29:15 CST 2008
On 3-Mar-2008, Jaroslav Hajek wrote:
| OK, no problem. In my eyes, matrix \= scalar is confusing. Perhaps
| just because I've never seen it (because it does not work). Anyway, I
| think such an extension would be easy to implement. I'd even volunteer
| to do it if more people are interested.
| Does anyone else share Rolf's opinion?
If you want M \ s (and presumably s / M) to work, then I think for
consistency with the rest of the Octave internals, we should implement
this by introducing new xleftdiv and xdiv functions that take double
and Complex scalar values as arguments so that things like
DEFBINOP (ldiv, matrix, scalar)
{
CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
Matrix m1 = v1.matrix_value ();
Matrix m2 = v2.matrix_value ();
MatrixType typ = v1.matrix_type ();
Matrix ret = xleftdiv (m1, m2, typ);
v1.matrix_type (typ);
return ret;
}
can be rewritten as
DEFBINOP (ldiv, matrix, scalar)
{
CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
Matrix ret = xleftdiv (v1.matrix_value (), v2.scalar_value (),
v1.matrix_type ());
v1.matrix_type (typ);
return ret;
}
This leaves the original xleftdiv and xdiv functions alone and only
working for conforming matrix dimensions. This is consistent with
other internal functions in Octave which do not do special things when
(for example) a Matrix object happens to have only one element.
You'll also need to handle the sparse cases.
jwe
More information about the Bug-octave
mailing list