Mercurial > hg > octave-lojdl
changeset 6518:952c8b00525e
[project @ 2007-04-11 20:50:22 by jwe]
author | jwe |
---|---|
date | Wed, 11 Apr 2007 20:50:23 +0000 |
parents | a1ec359aef37 |
children | edadfd12ce53 |
files | doc/ChangeLog doc/interpreter/container.txi scripts/ChangeLog scripts/control/util/axis2dlim.m scripts/miscellaneous/Makefile.in scripts/miscellaneous/not.m src/ChangeLog src/data.cc src/ov.h |
diffstat | 9 files changed, 321 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,14 @@ +2007-04-11 Søren Hauberg <hauberg@gmail.com> + + * interpreter/container.txi: Document indexing with (). + +2007-04-11 David Bateman <dbateman@free.fr> + + * interpreter/linalg.txi (Techniques used for Linear Algebra): + New node. + * interpreter/octave.texi: Include it in menu. + * interpreter/sparse.txi: Delete discusion of matrix_type. + 2007-04-11 Søren Hauberg <hauberg@gmail.com> * interpreter/container.txi: Improve cell array documentation.
--- a/doc/interpreter/container.txi +++ b/doc/interpreter/container.txi @@ -163,8 +163,10 @@ a cell array, because it might not be possible to represent all elements with a single variable as is the case with numerical arrays. -Accessing multiple elements of a cell array will result in a list of all -the requested elements. This list can then form the basis of a new +Accessing multiple elements of a cell array with the @samp{@{} and +@samp{@{} operators will result in a comma-seperated list of all +the requested elements. This list can then be used anywhere where a +comma-seperated list is used, such as in the creation of a new numerical array or cell array, or be passed as arguments to a function. If all the accessed elements of a cell array are scalars or column vectors, they can be concatenated into a new column vector @@ -178,9 +180,25 @@ 1 2 3 4 @end example -In much the same way, a new cell array containing the accessed elements -can be created. By surrounding the list with @samp{@{} and @samp{@}} a -new cell array will be created, like the following example illustrates +It is also possible to pass the accessed elements directly to a +function. The list of elements from the cell array will be passed as an +argument list to a given function as if it is called with the elements as +arguments. The two calls to @code{printf} in the following example are +identical but the latter is more simple and handles more situations + +@example +c = @{"GNU", "Octave", "is", "Free", "Software"@}; +printf ("%s ", c@{1@}, c@{2@}, c@{3@}, c@{4@}, c@{5@}); + @print{} GNU Octave is Free Software +printf ("%s ", c@{:@}); + @print{} GNU Octave is Free Software +@end example + +Just like it is possible to create a numerical array from selected +elements of a cell array, it is possible to create a new cell array +containing the selected elements. By surrounding the list with +@samp{@{} and @samp{@}} a new cell array will be created, like the +following example illustrates @example a = @{1, rand(2, 2), "three"@}; @@ -192,18 +210,22 @@ @} @end example -It is also possible to pass the accessed elements directly to a -function. The list of elements from the cell array will be passed as an -argument list to a given function if it is called with the elements as -arguments. The two calls to @code{printf} in the following example are -identical but the latter is more simple and handles more situations +@noindent +This syntax is however a bit cumbersome, and since this is a common +operation, it is possible to achieve the same using the @samp{(} +and @samp{)} operators for indexing. When a cell array is indexed +using the @samp{(} and @samp{)} operators a new cell array containing +the selected elements. Using this syntax, the previous example can +be simplified into the following @example -c = @{"GNU", "Octave", "is", "Free", "Software"@}; -printf ("%s ", c@{1@}, c@{2@}, c@{3@}, c@{4@}, c@{5@}); - @print{} GNU Octave is Free Software -printf ("%s ", c@{:@}); - @print{} GNU Octave is Free Software +a = @{1, rand(2, 2), "three"@}; +b = a( [1, 3] ) + @result{} b = + @{ + [1,1] = 1 + [1,2] = three + @} @end example @node Cell Arrays of Strings
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,13 @@ +2007-04-11 John W. Eaton <jwe@octave.org> + + * miscellaneous/not.m: Delete. + * miscellaneous/Makefile.in (SOURCES): Delete it from the list. + +2007-04-11 A. S. Hodel <a.s.hodel@eng.auburn.edu> + + * control/util/axis2dlim.m: Try harder to handle min and max vals + that are close but not exactly equal. + 2007-04-11 David Bateman <dbateman@free.fr> * general/bitcmp.m: Make it work again.
--- a/scripts/control/util/axis2dlim.m +++ b/scripts/control/util/axis2dlim.m @@ -59,10 +59,12 @@ endif else ## they're at least one-dimensional + tolv = max(1e-8, 1e-8*abs(midv)); + if(abs(delv(1)) >= tolv(1)) if(delv(1) != 0) axdel(1:2) = 1.1*[-delv(1),delv(1)]; endif - if(delv(2) != 0) + if(abs(delv(2)) >= tolv(2)) axdel(3:4) = 1.1*[-delv(2),delv(2)]; endif endif
--- a/scripts/miscellaneous/Makefile.in +++ b/scripts/miscellaneous/Makefile.in @@ -26,7 +26,7 @@ fileattrib.m fileparts.m flops.m fullfile.m getfield.m gunzip.m \ inputname.m ispc.m isunix.m license.m list_primes.m ls.m \ ls_command.m menu.m mex.m mexext.m mkoctfile.m movefile.m \ - news.m not.m orderfields.m pack.m paren.m parseparams.m \ + news.m orderfields.m pack.m paren.m parseparams.m \ semicolon.m setfield.m single.m substruct.m tar.m \ tempdir.m tempname.m texas_lotto.m unix.m unpack.m untar.m \ unzip.m ver.m version.m warning_ids.m xor.m zip.m
deleted file mode 100644 --- a/scripts/miscellaneous/not.m +++ /dev/null @@ -1,34 +0,0 @@ -## Copyright (C) 2004 John W. Eaton -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} not (@var{val}) -## Return the logical negation of val. This function is equivalent to -## @code{! val}. -## @end deftypefn - -function retval = not (val) - - if (nargin == 1) - retval = ! val; - else - print_usage (); - endif - -endfunction
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2007-04-11 John W. Eaton <jwe@octave.org> + + * data.cc (Fnot, Fuplus, Fuminus, Ftranspose, Fctranspose, Fplus, + Fminus, Fmtimes, Fmrdivide, Fmpower, Fmldivide, Flt, Fle, Feq, + Fge, Fgt, Fne, Ftimes, Frdivide, Fpower, Fldivide, Fand, For): + New functions. + 2007-04-09 John W. Eaton <jwe@octave.org> * graphics.cc (line::line_properties::markeredgecolor,
--- a/src/data.cc +++ b/src/data.cc @@ -2656,6 +2656,234 @@ return retval; } +#define UNARY_OP_DEFUN_BODY(F) \ + \ + octave_value retval; \ + \ + if (args.length () == 1) \ + retval = F (args(0)); \ + else \ + print_usage (); \ + \ + return retval + +DEFUN (not, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} not (@var{x})\n\ +This function is equivalent to @code{! x}.\n\ +@end deftypefn") +{ + UNARY_OP_DEFUN_BODY (op_not); +} + +DEFUN (uplus, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} uplus (@var{x})\n\ +This function is equivalent to @code{+ x}.\n\ +@end deftypefn") +{ + UNARY_OP_DEFUN_BODY (op_uplus); +} + +DEFUN (uminus, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} uminus (@var{x})\n\ +This function is equivalent to @code{- x}.\n\ +@end deftypefn") +{ + UNARY_OP_DEFUN_BODY (op_uminus); +} + +DEFUN (transpose, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} transpose (@var{x})\n\ +This function is equivalent to @code{x.'}.\n\ +@end deftypefn") +{ + UNARY_OP_DEFUN_BODY (op_transpose); +} + +DEFUN (ctranspose, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} ctranspose (@var{x})\n\ +This function is equivalent to @code{x'}.\n\ +@end deftypefn") +{ + UNARY_OP_DEFUN_BODY (op_hermitian); +} + +#define BINARY_OP_DEFUN_BODY(F) \ + \ + octave_value retval; \ + \ + if (args.length () == 2) \ + retval = F (args(0), args(1)); \ + else \ + print_usage (); \ + \ + return retval + +DEFUN (plus, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} plus (@var{x}, @var{y})\n\ +This function is equivalent to @code{x + y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_add); +} + +DEFUN (minus, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} minus (@var{x}, @var{y})\n\ +This function is equivalent to @code{x - y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_sub); +} + +DEFUN (mtimes, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} mtimes (@var{x}, @var{y})\n\ +This function is equivalent to @code{x * y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_mul); +} + +DEFUN (mrdivide, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} mrdivide (@var{x}, @var{y})\n\ +This function is equivalent to @code{x / y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_div); +} + +DEFUN (mpower, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} mpower (@var{x}, @var{y})\n\ +This function is equivalent to @code{x ^ y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_pow); +} + +DEFUN (mldivide, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} mldivide (@var{x}, @var{y})\n\ +This function is equivalent to @code{x \\ y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_ldiv); +} + +DEFUN (lt, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} lt (@var{x}, @var{y})\n\ +This function is equivalent to @code{x < y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_lt); +} + +DEFUN (le, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} le (@var{x}, @var{y})\n\ +This function is equivalent to @code{x <= y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_le); +} + +DEFUN (eq, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} eq (@var{x}, @var{y})\n\ +This function is equivalent to @code{x == y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_eq); +} + +DEFUN (ge, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} ge (@var{x}, @var{y})\n\ +This function is equivalent to @code{x >= y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_ge); +} + +DEFUN (gt, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} gt (@var{x}, @var{y})\n\ +This function is equivalent to @code{x > y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_gt); +} + +DEFUN (ne, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} ne (@var{x}, @var{y})\n\ +This function is equivalent to @code{x != y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_ne); +} + +DEFUN (times, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} times (@var{x}, @var{y})\n\ +This function is equivalent to @code{x .* y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_el_mul); +} + +DEFUN (rdivide, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} rdivide (@var{x}, @var{y})\n\ +This function is equivalent to @code{x ./ y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_el_div); +} + +DEFUN (power, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} power (@var{x}, @var{y})\n\ +This function is equivalent to @code{x .\\ y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_el_pow); +} + +DEFUN (ldivide, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} ldivide (@var{x}, @var{y})\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_el_ldiv); +} + +DEFUN (and, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} and (@var{x}, @var{y})\n\ +This function is equivalent to @code{x & y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_el_and); +} + +DEFUN (or, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} or (@var{x}, @var{y})\n\ +This function is equivalent to @code{x | y}.\n\ +@end deftypefn") +{ + BINARY_OP_DEFUN_BODY (op_el_or); +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/ov.h +++ b/src/ov.h @@ -70,11 +70,11 @@ enum unary_op { - op_not, - op_uplus, - op_uminus, - op_transpose, - op_hermitian, + op_not, // not + op_uplus, // uplus + op_uminus, // uminus + op_transpose, // transpose + op_hermitian, // ctranspose op_incr, op_decr, num_unary_ops, @@ -83,26 +83,26 @@ enum binary_op { - op_add, - op_sub, - op_mul, - op_div, - op_pow, - op_ldiv, + op_add, // plus + op_sub, // minus + op_mul, // mtimes + op_div, // mrdivide + op_pow, // mpower + op_ldiv, // mldivide op_lshift, op_rshift, - op_lt, - op_le, - op_eq, - op_ge, - op_gt, - op_ne, - op_el_mul, - op_el_div, - op_el_pow, - op_el_ldiv, - op_el_and, - op_el_or, + op_lt, // lt + op_le, // le + op_eq, // eq + op_ge, // ge + op_gt, // gt + op_ne, // ne + op_el_mul, // times + op_el_div, // rdivide + op_el_pow, // power + op_el_ldiv, // ldivide + op_el_and, // and + op_el_or, // or op_struct_ref, num_binary_ops, unknown_binary_op @@ -881,6 +881,7 @@ OV_UNOP_OP (name, op) OV_UNOP_FN_OP (op_not, !) +OV_UNOP_FN_OP (op_uplus, +) OV_UNOP_FN_OP (op_uminus, -) OV_UNOP_FN (op_transpose)