Mercurial > hg > octave-terminal
changeset 210:7947b7a6b6da
[project @ 1993-11-12 10:51:10 by jwe]
author | jwe |
---|---|
date | Fri, 12 Nov 1993 10:51:33 +0000 |
parents | 5869adaa6aea |
children | 4adbab9c31cd |
files | liboctave/Matrix.cc liboctave/Matrix.h src/builtins.cc src/g-builtins.cc src/g-builtins.h src/tree.h.old |
diffstat | 6 files changed, 269 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Matrix.cc +++ b/liboctave/Matrix.cc @@ -1822,6 +1822,28 @@ } ColumnVector +Matrix::row_min_loc (void) const +{ + ColumnVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nr); + + for (int i = 0; i < nr; i++) + { + int res = 0; + for (int j = 0; j < nc; j++) + if (elem (i, j) < elem (i, res)) + res = j; + result.elem (i) = (double) (res + 1); + } + } + + return result; +} + +ColumnVector Matrix::row_max (void) const { ColumnVector result; @@ -1843,6 +1865,28 @@ return result; } +ColumnVector +Matrix::row_max_loc (void) const +{ + ColumnVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nr); + + for (int i = 0; i < nr; i++) + { + int res = 0; + for (int j = 0; j < nc; j++) + if (elem (i, j) > elem (i, res)) + res = j; + result.elem (i) = (double) (res + 1); + } + } + + return result; +} + RowVector Matrix::column_min (void) const { @@ -1864,6 +1908,28 @@ return result; } +RowVector +Matrix::column_min_loc (void) const +{ + RowVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nc); + + for (int j = 0; j < nc; j++) + { + int res = 0.0; + for (int i = 0; i < nr; i++) + if (elem (i, j) < elem (res, j)) + res = i; + result.elem (j) = (double) (res + 1); + } + } + + return result; +} + RowVector Matrix::column_max (void) const @@ -1887,6 +1953,28 @@ return result; } +RowVector +Matrix::column_max_loc (void) const +{ + RowVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nc); + + for (int j = 0; j < nc; j++) + { + int res = 0; + for (int i = 0; i < nr; i++) + if (elem (i, j) > elem (res, j)) + res = i; + result.elem (j) = (double) (res + 1); + } + } + + return result; +} + ostream& operator << (ostream& os, const Matrix& a) { @@ -4126,6 +4214,32 @@ } ComplexColumnVector +ComplexMatrix::row_min_loc (void) const +{ + ComplexColumnVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nr); + + for (int i = 0; i < nr; i++) + { + Complex res = 0; + double absres = abs (elem (i, 0)); + for (int j = 0; j < nc; j++) + if (abs (elem (i, j)) < absres) + { + res = j; + absres = abs (elem (i, j)); + } + result.elem (i) = res + 1; + } + } + + return result; +} + +ComplexColumnVector ComplexMatrix::row_max (void) const { ComplexColumnVector result; @@ -4151,6 +4265,32 @@ return result; } +ComplexColumnVector +ComplexMatrix::row_max_loc (void) const +{ + ComplexColumnVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nr); + + for (int i = 0; i < nr; i++) + { + Complex res = 0; + double absres = abs (elem (i, 0)); + for (int j = 0; j < nc; j++) + if (abs (elem (i, j)) > absres) + { + res = j; + absres = abs (elem (i, j)); + } + result.elem (i) = res + 1; + } + } + + return result; +} + ComplexRowVector ComplexMatrix::column_min (void) const { @@ -4178,6 +4318,32 @@ } ComplexRowVector +ComplexMatrix::column_min_loc (void) const +{ + ComplexRowVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nc); + + for (int j = 0; j < nc; j++) + { + Complex res = 0; + double absres = abs (elem (0, j)); + for (int i = 0; i < nr; i++) + if (abs (elem (i, j)) < absres) + { + res = i; + absres = abs (elem (i, j)); + } + result.elem (j) = res + 1; + } + } + + return result; +} + +ComplexRowVector ComplexMatrix::column_max (void) const { ComplexRowVector result; @@ -4203,6 +4369,32 @@ return result; } +ComplexRowVector +ComplexMatrix::column_max_loc (void) const +{ + ComplexRowVector result; + + if (nr > 0 && nc > 0) + { + result.resize (nc); + + for (int j = 0; j < nc; j++) + { + Complex res = 0; + double absres = abs (elem (0, j)); + for (int i = 0; i < nr; i++) + if (abs (elem (i, j)) > absres) + { + res = i; + absres = abs (elem (i, j)); + } + result.elem (j) = res + 1; + } + } + + return result; +} + // i/o ostream&
--- a/liboctave/Matrix.h +++ b/liboctave/Matrix.h @@ -512,10 +512,16 @@ ColumnVector diag (int k) const; ColumnVector row_min (void) const; + ColumnVector row_min_loc (void) const; + ColumnVector row_max (void) const; + ColumnVector row_max_loc (void) const; RowVector column_min (void) const; + RowVector column_min_loc (void) const; + RowVector column_max (void) const; + RowVector column_max_loc (void) const; // i/o @@ -1349,10 +1355,16 @@ ComplexColumnVector diag (int k) const; ComplexColumnVector row_min (void) const; + ComplexColumnVector row_min_loc (void) const; + ComplexColumnVector row_max (void) const; + ComplexColumnVector row_max_loc (void) const; ComplexRowVector column_min (void) const; + ComplexRowVector column_min_loc (void) const; + ComplexRowVector column_max (void) const; + ComplexRowVector column_max_loc (void) const; // i/o
--- a/src/builtins.cc +++ b/src/builtins.cc @@ -429,10 +429,6 @@ { "min", 3, 2, builtin_min, "min (x): minimum value(s) of a vector (matrix)", }, - { "get_next_arg", 1, 1, builtin_get_next_arg, - "get_next_arg (): return next argument in function taking varible\n\ -number of parameters", }, - { "npsol", 11, 3, builtin_npsol, #if defined (NPSOL_MISSING) "This function requires NPSOL, which is not freely\n\ @@ -565,6 +561,14 @@ { "syl", 4, 1, builtin_syl, "X = syl (A, B, C): solve the Sylvester equation A X + X B + C = 0", }, + { "va_arg", 1, 1, builtin_va_arg, + "va_arg (): return next argument in function taking varible\n\ +number of parameters", }, + + { "va_start", 1, 0, builtin_va_start, + "va_start (): reset the pointer to the list of optional arguments\n\ +to the beginning", }, + { "warranty", 1, 0, builtin_warranty, "warranty (): describe copying conditions", },
--- a/src/g-builtins.cc +++ b/src/g-builtins.cc @@ -818,35 +818,6 @@ } /* - * Variable argument lists. - */ -tree_constant * -builtin_get_next_arg (const tree_constant *args, int nargin, int nargout) -{ - tree_constant *retval = NULL_TREE_CONST; - if (nargin == 1) - { - if (curr_function != (tree_function *) NULL) - { - if (curr_function->takes_varargs ()) - { - retval = new tree_constant [2]; - retval[0] = curr_function->get_next_arg (); - } - else - error ("next_arg only valid within function taking\ - variable number of arguments"); - } - else - error ("next_arg only valid within function body"); - } - else - print_usage ("get_next_arg"); - - return retval; -} - -/* * Get the value of an environment variable. */ tree_constant * @@ -1688,6 +1659,58 @@ } /* + * Variable argument lists. + */ +tree_constant * +builtin_va_arg (const tree_constant *args, int nargin, int nargout) +{ + tree_constant *retval = NULL_TREE_CONST; + if (nargin == 1) + { + if (curr_function != (tree_function *) NULL) + { + if (curr_function->takes_varargs ()) + { + retval = new tree_constant [2]; + retval[0] = curr_function->va_arg (); + } + else + error ("va_arg only valid within function taking\ + variable number of arguments"); + } + else + error ("va_arg only valid within function body"); + } + else + print_usage ("va_arg"); + + return retval; +} + +tree_constant * +builtin_va_start (const tree_constant *args, int nargin, int nargout) +{ + tree_constant *retval = NULL_TREE_CONST; + if (nargin == 1) + { + if (curr_function != (tree_function *) NULL) + { + if (curr_function->takes_varargs ()) + curr_function->va_start (); + else + error ("va_start only valid within function taking\ + variable number of arguments"); + } + else + error ("va_start only valid within function body"); + } + else + print_usage ("va_start"); + + return retval; +} + +/* * Copying information. */ tree_constant *
--- a/src/g-builtins.h +++ b/src/g-builtins.h @@ -76,7 +76,6 @@ extern tree_constant *builtin_fsolve (const tree_constant *, int, int); extern tree_constant *builtin_fsqp (const tree_constant *, int, int); extern tree_constant *builtin_ftell (const tree_constant *, int, int); -extern tree_constant *builtin_get_next_arg (const tree_constant *, int, int); extern tree_constant *builtin_getenv (const tree_constant *, int, int); extern tree_constant *builtin_givens (const tree_constant *, int, int); extern tree_constant *builtin_hess (const tree_constant *, int, int); @@ -120,6 +119,8 @@ extern tree_constant *builtin_sumsq (const tree_constant *, int, int); extern tree_constant *builtin_svd (const tree_constant *, int, int); extern tree_constant *builtin_syl (const tree_constant *, int, int); +extern tree_constant *builtin_va_arg (const tree_constant *, int, int); +extern tree_constant *builtin_va_start (const tree_constant *, int, int); extern tree_constant *builtin_warranty (const tree_constant *, int, int); extern tree_constant *builtin_zeros (const tree_constant *, int, int);
--- a/src/tree.h.old +++ b/src/tree.h.old @@ -252,7 +252,8 @@ int is_system_m_file (void) const; int takes_varargs (void) const; - tree_constant get_next_arg (void); + void va_start (void); + tree_constant va_arg (void); void stash_function_name (char *s); char *function_name (void); @@ -281,6 +282,7 @@ time_t t_parsed; int system_m_file; int varargs_ok; + int num_named_args; const tree_constant *args_passed; int num_args_passed; int curr_arg_number;