Mercurial > hg > octave-terminal
changeset 3418:ca92c9d3f882
[project @ 2000-01-12 03:07:47 by jwe]
author | jwe |
---|---|
date | Wed, 12 Jan 2000 03:07:52 +0000 |
parents | cb56e4bd79ca |
children | e71b3d1dd327 |
files | scripts/ChangeLog scripts/linear-algebra/cross.m scripts/polynomial/polyfit.m scripts/signal/autocov.m scripts/statistics/distributions/discrete_rnd.m scripts/statistics/distributions/hypergeometric_rnd.m src/ChangeLog src/DLD-FUNCTIONS/filter.cc src/DLD-FUNCTIONS/find.cc src/DLD-FUNCTIONS/minmax.cc src/DLD-FUNCTIONS/sort.cc src/DLD-FUNCTIONS/svd.cc src/data.cc src/dirfns.cc src/oct-obj.h src/ov-cx-mat.cc src/ov-cx-mat.h src/ov-re-mat.cc src/ov-re-mat.h src/ov.cc src/ov.h |
diffstat | 21 files changed, 152 insertions(+), 154 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,15 @@ +2000-01-11 John W. Eaton <jwe@bevo.che.wisc.edu> + + * linear-algebra/cross.m: Only return a row vector if both args + are row vectors. + * polynomial/polyfit.m: Likewise. + + * signal/autocov.m: Don't reset prefer_column_vectors. + + * statistics/distributions/discrete_rnd.m: + Always generate a row vector. + * statistics/distributions/hypergeometric_rnd.m: Likewise. + 2000-01-11 Ben Sapp <bsapp@nua.lampf.lanl.gov> * strings/upper.m: Add missing `-*- texinfo -*-' tag to doc string.
--- a/scripts/linear-algebra/cross.m +++ b/scripts/linear-algebra/cross.m @@ -17,7 +17,10 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} cross (@var{x}, @var{y}) ## Computes the vector cross product of the two 3-dimensional vectors -## @var{x} and @var{y}. For example, +## @var{x} and @var{y}. +## +## A row vector is returned if @var{x} and @var{y} are both row vectors; +## otherwise, a column vector is returned. ## ## @example ## @group @@ -44,8 +47,7 @@ x_nr = rows (x); y_nr = rows (y); - if ((x_nr == y_nr && x_nr == 1) - || (x_nr != y_nr && ! prefer_column_vectors)) + if (x_nr == y_nr && x_nr == 1) z = z.'; endif
--- a/scripts/polynomial/polyfit.m +++ b/scripts/polynomial/polyfit.m @@ -32,6 +32,10 @@ ## @code{sumsq (p(x(i)) - y(i))}, ## @end ifinfo ## to best fit the data in the least squares sense. +## +## The polynomial coefficients are returned in a row vector if @var{x} +## and @var{y} are both row vectors; otherwise, they are returned in a +## column vector. ## ## If two output arguments are requested, the second contains the values of ## the polynomial for each value of @var{x}. @@ -76,8 +80,8 @@ p = flipud (p); - if (! prefer_column_vectors) - p = p.'; + if (y_is_row_vector && rows (x) == 1) + p = p'; endif endfunction
--- a/scripts/signal/autocov.m +++ b/scripts/signal/autocov.m @@ -42,19 +42,8 @@ retval = zeros (h + 1, c); - unwind_protect - - oldpcv = prefer_column_vectors; - prefer_column_vectors = "false"; - - for i = 0 : h - retval(i+1, :) = diag (X(i+1:n, :).' * conj (X(1:n-i, :))) / n; - endfor - - unwind_protect_cleanup - - prefer_column_vectors = oldpcv; - - end_unwind_protect + for i = 0 : h + retval(i+1, :) = diag (X(i+1:n, :).' * conj (X(1:n-i, :))) / n; + endfor endfunction
--- a/scripts/statistics/distributions/discrete_rnd.m +++ b/scripts/statistics/distributions/discrete_rnd.m @@ -16,8 +16,9 @@ ## usage: discrete_rnd (N, V, P) ## -## Generate a random sample of size N from the univariate distribution -## which assumes the values in V with probabilities P. +## Generate a row vector containing a random sample of size N from the +## univariate distribution which assumes the values in V with +## probabilities P. ## ## Currently, N must be a scalar. @@ -30,7 +31,7 @@ usage ("discrete_rnd (N, V, P)"); endif - if !is_scalar (N) + if (! is_scalar (N)) error ("discrete_rnd: N must be a scalar"); endif @@ -47,9 +48,5 @@ s = reshape (cumsum (P / sum (P)), m, 1); rnd = V (1 + sum ((s * ones (1, N)) <= ((ones (m, 1) * u)))); - - if (prefer_column_vectors) - rnd = rnd'; - endif endfunction
--- a/scripts/statistics/distributions/hypergeometric_rnd.m +++ b/scripts/statistics/distributions/hypergeometric_rnd.m @@ -14,8 +14,8 @@ ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -## Generate a random sample of size N from the hypergeometric -## distribution with parameters m, t, and n. +## Generate a row vector containing a random sample of size N from the +## hypergeometric distribution with parameters m, t, and n. ## ## The parameters m, t, and n must positive integers with m and n not ## greater than t. @@ -28,11 +28,7 @@ if ((m < 0) | (t < 0) | (n <= 0) | (m != round (m)) | (t != round (t)) | (n != round (n)) | (m > t) | (n > t)) - if (prefer_column_vectors) - rnd = NaN * ones (N, 1) - else - rnd = NaN * ones (1, N) - endif + rnd = NaN * ones (1, N) else rnd = discrete_rnd (N, 0 : n, hypergeometric_pdf (0 : n, m, t, n)); endif
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,24 @@ +2000-01-11 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ov.cc (Vprefer_column_vectors): Now static. + * ov.h (octave_value (const ComplexRowVector&), + octave_value (const ComplexColumnVector&), + octave_value (const RowVector&), octave_value (const ColumnVector&)): + Delete second arg. Change all callers. + * oct-obj.h (octave_value_list (const RowVector&), + octave_value_list (const ColumnVector&), + octave_value_list (const ComplexRowVector&), + octave_value_list (const ComplexColumnVector&)): Likewise. + * ov-cx-mat.h, ov-cx-mat.cc + (octave_complex_matrix (const ComplexRowVector&), + (octave_complex_matrix (const ComplexColumnVector&)): + Delete second arg, simply create object with orientation + corresponding to vector arg. Move constructors to class decl. + * ov-re-mat.h, ov-re-mat.cc (octave_matrix (const RowVector&), + (octave_matrix (const ColumnVector&)): + Delete second arg, simply create object with orientation + corresponding to vector arg. Move constructors to class decl. + 2000-01-07 Ben Sapp <bsapp@nua.lampf.lanl.gov> * mappers.cc (Fconj, Ferf, Ferfc, Fgamma, Fimag, Flgamma, Flog10,
--- a/src/DLD-FUNCTIONS/filter.cc +++ b/src/DLD-FUNCTIONS/filter.cc @@ -257,10 +257,9 @@ const char *errmsg = "filter: arguments must be vectors"; - int x_is_vector = (args(2).rows () == 1 || args(2).columns () == 1); + bool x_is_row_vector = (args(2).rows () == 1); - int si_is_vector = (nargin == 4 - && (args(3).rows () == 1 || args(3).columns () == 1)); + bool si_is_row_vector = (nargin == 4 && args(3).rows () == 1); if (args(0).is_complex_type () || args(1).is_complex_type () @@ -293,16 +292,16 @@ if (nargout == 2) { - if (si_is_vector) - retval (1) = octave_value (si, (args(3).columns () == 1)); + if (si_is_row_vector) + retval(1) = si.transpose (); else - retval (1) = si; + retval(1) = si; } - if (x_is_vector) - retval (0) = octave_value (y, (args(2).columns () == 1)); + if (x_is_row_vector) + retval(0) = y.transpose (); else - retval (0) = y; + retval(0) = y; } else error (errmsg); @@ -338,16 +337,16 @@ if (nargout == 2) { - if (si_is_vector) - retval (1) = octave_value (si, (args(3).columns () == 1)); + if (si_is_row_vector) + retval(1) = si.transpose (); else - retval (1) = si; + retval(1) = si; } - if (x_is_vector) - retval (0) = octave_value (y, (args(2).columns () == 1)); + if (x_is_row_vector) + retval(0) = y.transpose (); else - retval (0) = y; + retval(0) = y; } else error (errmsg);
--- a/src/DLD-FUNCTIONS/find.cc +++ b/src/DLD-FUNCTIONS/find.cc @@ -29,6 +29,19 @@ #include "gripes.h" #include "oct-obj.h" +#define DO_FIND_OP(T) \ + do \ + { \ + T tmp (count); \ + \ + for (int i = 0; i < count; i++) \ + tmp (i) = nr * (j_idx (i) - 1.0) + i_idx (i); \ + \ + retval(0) = tmp; \ + } \ + while (0) + + static octave_value_list find_to_fortran_idx (const ColumnVector i_idx, const ColumnVector j_idx, const octave_value& val, int nr, int nargout) @@ -40,15 +53,15 @@ case 0: case 1: { - int count = i_idx.length (); - ColumnVector tmp (count); - for (int i = 0; i < count; i++) - tmp (i) = nr * (j_idx (i) - 1.0) + i_idx (i); - // If the original argument was a row vector, force a row // vector of indices to be returned. - retval(0) = octave_value (tmp, (nr != 1)); + int count = i_idx.length (); + + if (nr == 1) + DO_FIND_OP(RowVector); + else + DO_FIND_OP(ColumnVector); } break; @@ -57,15 +70,8 @@ // Fall through! case 2: - retval(1) = octave_value (j_idx, 1); - retval(0) = octave_value (i_idx, 1); - - // If you want this to work more like Matlab, use - // - // retval(0) = octave_value (i_idx, (nr != 1)); - // - // instead of the previous statement. - + retval(1) = j_idx; + retval(0) = i_idx; break; default: @@ -112,8 +118,7 @@ } } - octave_value tmp (v, 1); - return find_to_fortran_idx (i_idx, j_idx, tmp, m_nr, nargout); + return find_to_fortran_idx (i_idx, j_idx, octave_value (v), m_nr, nargout); } static octave_value_list @@ -152,8 +157,7 @@ } } - octave_value tmp (v, 1); - return find_to_fortran_idx (i_idx, j_idx, tmp, m_nr, nargout); + return find_to_fortran_idx (i_idx, j_idx, octave_value (v), m_nr, nargout); } DEFUN_DLD (find, args, nargout,
--- a/src/DLD-FUNCTIONS/minmax.cc +++ b/src/DLD-FUNCTIONS/minmax.cc @@ -315,7 +315,7 @@ if (m.rows () == 1) retval(0) = m.row_min (); else - retval(0) = octave_value (m.column_min (), 0); + retval(0) = m.column_min (); } } else if (arg1.is_complex_type ()) @@ -327,7 +327,7 @@ if (m.rows () == 1) retval(0) = m.row_min (); else - retval(0) = octave_value (m.column_min (), 0); + retval(0) = m.column_min (); } } else @@ -348,7 +348,7 @@ if (m.rows () == 1) retval(0) = m.row_min (index); else - retval(0) = octave_value (m.column_min (index), 0); + retval(0) = m.column_min (index); } } else if (arg1.is_complex_type ()) @@ -362,7 +362,7 @@ if (m.rows () == 1) retval(0) = m.row_min (index); else - retval(0) = octave_value (m.column_min (index), 0); + retval(0) = m.column_min (index); } } else @@ -381,7 +381,7 @@ ? octave_NaN : static_cast<double> (tmp); } - retval(1) = octave_value (idx, 0); + retval(1) = idx; } } else if (nargin == 2) @@ -529,7 +529,7 @@ if (m.rows () == 1) retval(0) = m.row_max (); else - retval(0) = octave_value (m.column_max (), 0); + retval(0) = m.column_max (); } } else if (arg1.is_complex_type ()) @@ -541,7 +541,7 @@ if (m.rows () == 1) retval(0) = m.row_max (); else - retval(0) = octave_value (m.column_max (), 0); + retval(0) = m.column_max (); } } else @@ -562,7 +562,7 @@ if (m.rows () == 1) retval(0) = m.row_max (index); else - retval(0) = octave_value (m.column_max (index), 0); + retval(0) = m.column_max (index); } } else if (arg1.is_complex_type ()) @@ -576,7 +576,7 @@ if (m.rows () == 1) retval(0) = m.row_max (index); else - retval(0) = octave_value (m.column_max (index), 0); + retval(0) = m.column_max (index); } } else @@ -595,7 +595,7 @@ ? octave_NaN : static_cast<double> (tmp); } - retval(1) = octave_value (idx, 0); + retval(1) = idx; } } else if (nargin == 2)
--- a/src/DLD-FUNCTIONS/sort.cc +++ b/src/DLD-FUNCTIONS/sort.cc @@ -164,8 +164,8 @@ if (nr == 1 && nc > 0) { - retval (1) = Matrix (nr, nc, 1.0); - retval (0) = m; + retval(1) = Matrix (nr, nc, 1.0); + retval(0) = m; return retval; } @@ -181,8 +181,8 @@ } } - retval (1) = idx; - retval (0) = ms; + retval(1) = idx; + retval(0) = ms; return retval; } @@ -199,8 +199,8 @@ if (n == 1) { - retval (1) = RowVector (n, 1.0); - retval (0) = v; + retval(1) = RowVector (n, 1.0); + retval(0) = v; return retval; } @@ -213,8 +213,8 @@ VECTOR_CREATE_RETURN_VALUES (vs, v); } - retval (1) = octave_value (idx, 0); - retval (0) = octave_value (vs, 0); + retval(1) = idx; + retval(0) = vs; return retval; } @@ -232,8 +232,8 @@ if (nr == 1 && nc > 0) { - retval (1) = Matrix (nr, nc, 1.0); - retval (0) = cm; + retval(1) = Matrix (nr, nc, 1.0); + retval(0) = cm; return retval; } @@ -259,8 +259,8 @@ } } - retval (1) = idx; - retval (0) = cms; + retval(1) = idx; + retval(0) = cms; return retval; } @@ -277,8 +277,8 @@ if (n == 1) { - retval (1) = RowVector (n, 1.0); - retval (0) = cv; + retval(1) = RowVector (n, 1.0); + retval(0) = cv; return retval; } @@ -301,8 +301,8 @@ VECTOR_CREATE_RETURN_VALUES (cvs, cv); } - retval (1) = octave_value (idx, 0); - retval (0) = octave_value (cvs, 0); + retval(1) = idx; + retval(0) = cvs; return retval; }
--- a/src/DLD-FUNCTIONS/svd.cc +++ b/src/DLD-FUNCTIONS/svd.cc @@ -158,7 +158,7 @@ if (nargout == 0 || nargout == 1) { - retval(0) = octave_value (sigma.diag (), 1); + retval(0) = sigma.diag (); } else { @@ -187,7 +187,7 @@ if (nargout == 0 || nargout == 1) { - retval(0) = octave_value (sigma.diag (), 1); + retval(0) = sigma.diag (); } else {
--- a/src/data.cc +++ b/src/data.cc @@ -1136,7 +1136,7 @@ the value of @code{prefer_column_vectors}.\n\ @end deftypefn") { - octave_value_list retval; + octave_value retval; int nargin = args.length (); @@ -1166,7 +1166,7 @@ ComplexRowVector rv = linspace (x1, x2, npoints); if (! error_state) - retval (0) = octave_value (rv, 0); + retval = rv; } } else @@ -1179,7 +1179,7 @@ RowVector rv = linspace (x1, x2, npoints); if (! error_state) - retval (0) = octave_value (rv, 0); + retval = rv; } } }
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -491,7 +491,7 @@ for (int i = 0; i < n; i++) result(i) = tmp(i); - retval = octave_value (result, true); + retval = result; } } else
--- a/src/oct-obj.h +++ b/src/oct-obj.h @@ -58,11 +58,11 @@ octave_value_list (const DiagMatrix& d) : data (1, octave_value (d)) { } - octave_value_list (const RowVector& v, int pcv) - : data (1, octave_value (v, pcv)) { } + octave_value_list (const RowVector& v) + : data (1, octave_value (v)) { } - octave_value_list (const ColumnVector& v, int pcv) - : data (1, octave_value (v, pcv)) { } + octave_value_list (const ColumnVector& v) + : data (1, octave_value (v)) { } octave_value_list (const Complex& c) : data (1, octave_value (c)) { } @@ -73,11 +73,11 @@ octave_value_list (const ComplexDiagMatrix& d) : data (1, octave_value (d)) { } - octave_value_list (const ComplexRowVector& v, int pcv) - : data (1, octave_value (v, pcv)) { } + octave_value_list (const ComplexRowVector& v) + : data (1, octave_value (v)) { } - octave_value_list (const ComplexColumnVector& v, int pcv) - : data (1, octave_value (v, pcv)) { } + octave_value_list (const ComplexColumnVector& v) + : data (1, octave_value (v)) { } octave_value_list (const char *s) : data (1, octave_value (s)) { }
--- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -51,20 +51,6 @@ DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex_matrix, "complex matrix"); -octave_complex_matrix::octave_complex_matrix (const ComplexRowVector& v, - int pcv) - : octave_base_matrix<ComplexMatrix> (((pcv < 0 && Vprefer_column_vectors) - || pcv) - ? ComplexMatrix (v.transpose ()) - : ComplexMatrix (v)) { } - -octave_complex_matrix::octave_complex_matrix (const ComplexColumnVector& v, - int pcv) - : octave_base_matrix<ComplexMatrix> (((pcv < 0 && Vprefer_column_vectors) - || pcv) - ? ComplexMatrix (v) - : ComplexMatrix (v.transpose ())) { } - octave_value * octave_complex_matrix::try_narrowing_conversion (void) {
--- a/src/ov-cx-mat.h +++ b/src/ov-cx-mat.h @@ -63,9 +63,11 @@ octave_complex_matrix (const ComplexDiagMatrix& d) : octave_base_matrix<ComplexMatrix> (d) { } - octave_complex_matrix (const ComplexRowVector& v, int pcv = -1); + octave_complex_matrix (const ComplexRowVector& v) + : octave_base_matrix<ComplexMatrix> (ComplexMatrix (v)) { } - octave_complex_matrix (const ComplexColumnVector& v, int pcv = -1); + octave_complex_matrix (const ComplexColumnVector& v) + : octave_base_matrix<ComplexMatrix> (ComplexMatrix (v)) { } octave_complex_matrix (const octave_complex_matrix& cm) : octave_base_matrix<ComplexMatrix> (cm) { }
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -52,14 +52,6 @@ DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_matrix, "matrix"); -octave_matrix::octave_matrix (const RowVector& v, int pcv) - : octave_base_matrix<Matrix> ((pcv < 0 && Vprefer_column_vectors) || pcv - ? Matrix (v.transpose ()) : Matrix (v)) { } - -octave_matrix::octave_matrix (const ColumnVector& v, int pcv) - : octave_base_matrix<Matrix> ((pcv < 0 && Vprefer_column_vectors) || pcv - ? Matrix (v) : Matrix (v.transpose ())) { } - octave_value * octave_matrix::try_narrowing_conversion (void) {
--- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -63,9 +63,11 @@ octave_matrix (const DiagMatrix& d) : octave_base_matrix<Matrix> (d) { } - octave_matrix (const RowVector& v, int pcv = -1); + octave_matrix (const RowVector& v) + : octave_base_matrix<Matrix> (Matrix (v)) { } - octave_matrix (const ColumnVector& v, int pcv = -1); + octave_matrix (const ColumnVector& v) + : octave_base_matrix<Matrix> (Matrix (v)) { } octave_matrix (const octave_matrix& m) : octave_base_matrix<Matrix> (m) { }
--- a/src/ov.cc +++ b/src/ov.cc @@ -96,7 +96,7 @@ // // (for A undefined). Only matters when resize_on_range_error is also // TRUE. -bool Vprefer_column_vectors; +static bool Vprefer_column_vectors; // If TRUE, print the name along with the value. bool Vprint_answer_id_name; @@ -356,15 +356,15 @@ maybe_mutate (); } -octave_value::octave_value (const RowVector& v, int pcv) - : rep (new octave_matrix (v, pcv)) +octave_value::octave_value (const RowVector& v) + : rep (new octave_matrix (v)) { rep->count = 1; maybe_mutate (); } -octave_value::octave_value (const ColumnVector& v, int pcv) - : rep (new octave_matrix (v, pcv)) +octave_value::octave_value (const ColumnVector& v) + : rep (new octave_matrix (v)) { rep->count = 1; maybe_mutate (); @@ -391,15 +391,15 @@ maybe_mutate (); } -octave_value::octave_value (const ComplexRowVector& v, int pcv) - : rep (new octave_complex_matrix (v, pcv)) +octave_value::octave_value (const ComplexRowVector& v) + : rep (new octave_complex_matrix (v)) { rep->count = 1; maybe_mutate (); } -octave_value::octave_value (const ComplexColumnVector& v, int pcv) - : rep (new octave_complex_matrix (v, pcv)) +octave_value::octave_value (const ComplexColumnVector& v) + : rep (new octave_complex_matrix (v)) { rep->count = 1; maybe_mutate ();
--- a/src/ov.h +++ b/src/ov.h @@ -156,13 +156,13 @@ octave_value (const Cell& m); octave_value (const Matrix& m); octave_value (const DiagMatrix& d); - octave_value (const RowVector& v, int pcv = -1); - octave_value (const ColumnVector& v, int pcv = -1); + octave_value (const RowVector& v); + octave_value (const ColumnVector& v); octave_value (const Complex& C); octave_value (const ComplexMatrix& m); octave_value (const ComplexDiagMatrix& d); - octave_value (const ComplexRowVector& v, int pcv = -1); - octave_value (const ComplexColumnVector& v, int pcv = -1); + octave_value (const ComplexRowVector& v); + octave_value (const ComplexColumnVector& v); octave_value (bool b); octave_value (const boolMatrix& bm); octave_value (char c); @@ -662,14 +662,6 @@ // means it should be considered an error. extern int Vok_to_lose_imaginary_part; -// If TRUE, create column vectors when doing assignments like: -// -// octave> A(1) = 3; A(2) = 5 -// -// (for A undefined). Only matters when resize_on_range_error is also -// TRUE. -extern bool Vprefer_column_vectors; - // If TRUE, print the name along with the value. extern bool Vprint_answer_id_name;