octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dim-vector.h


From: rik
Subject: dim-vector.h
Date: Wed, 13 May 2015 14:04:07 -0700

5/13/15

All,

I was reviewing bug #45100 where the documentation for using a dim_vector
object in an oct-file is incorrect.  The documentation is:

-- Start DOC --
Define the dimensions of the matrix or array with a dim_vector which has
the same characteristics as the vector returned from size. For example:

dim_vector dv (2);
dv(0) = 2; dv(1) = 3;  // 2 rows, 3 columns
Matrix a (dv);

This can be used on all matrix and array types.
-- End DOC --

First, there is no single argument constructor in dim-vector.h to create a
dim_vector with the requested number of dimensions.  Why don't we have this
constructor?  It seems like it would be useful.  The only possible
confusion is that people coming from m-files might think that it is
equivalent to ones (N) which creates an NxN value.

There are already multiple argument input forms so the line

dim_vector dv (2, 3);

will create a dimension vector with two dimensions and the appropriate
sizes for a matrix with 2 rows and 3 columns.  That was the fix that was
made in the documentation.

But I also tried the following code

dim_vector dv;
dv.resize (2);
dv(0) = 2; dv(1) = 3;

This fails because there is no operator overload for () indexing.  Instead
one has to write

dv.elem (0) = 2; dv.elem (1) = 3;

Is there any reason we don't have that operator overload as we do for Array
and Matrix classes?  Is it just oversight?  Because it otherwise feels like
a natural way to manipulate the dim_vector object.

Cheers,
Rik




reply via email to

[Prev in Thread] Current Thread [Next in Thread]