Mercurial > hg > octave-lyh
comparison doc/interpreter/expr.txi @ 14116:951eacaf9381 stable
Initial documentation for broadcasting and general vectorization guidelines
* vectorize.txi: New file.
* NEWS: Update with location of broadcasting documentation.
* Makefile.am: Add vectorize.texi
* arith.txi: Move accumarray and accumdim docstring to vectorize.txi
* container.txi: Move structfun docstring to vectorize.txi
* expr.txi: Mention broadcasting where relevant.
* func.txi: Move vectorize docstring to vectorize.txi
* matrix.txi: Move function application section to vectorize.txi
* octave.texi: Add vectorize.txi and its menu options
* sparse.txi: Move spfun to vectorize.txi
* tips.txi: Move and rewrite coding tips section in vectorize.txi
* bsxfun.h (is_valid_bsxfun, is_valid_inplace_bsxfun): Rename warning
to "Octave:broadcast"
* accumdim.m: Reformat to use @example in lieu of @smallexample
* warning_ids.m: Add Octave:broadcast
* bsxfun.cc: Reword docstring to mention broadcasting
* cellfun.cc: Move comment about efficiency from tips.txi
* version.h.in: Add a big startup warning about broadcasting
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 27 Dec 2011 15:15:41 -0500 |
parents | b0cdd60db5e5 |
children | 94e2a76f1e5a |
comparison
equal
deleted
inserted
replaced
14115:0b3518c1228a | 14116:951eacaf9381 |
---|---|
510 @cindex Hermitian operator | 510 @cindex Hermitian operator |
511 @cindex transpose, complex-conjugate | 511 @cindex transpose, complex-conjugate |
512 @cindex complex-conjugate transpose | 512 @cindex complex-conjugate transpose |
513 | 513 |
514 The following arithmetic operators are available, and work on scalars | 514 The following arithmetic operators are available, and work on scalars |
515 and matrices. | 515 and matrices. They element-by-element operators and functions broadcast |
516 (@pxref{Broadcasting}). | |
516 | 517 |
517 @table @asis | 518 @table @asis |
518 @item @var{x} + @var{y} | 519 @item @var{x} + @var{y} |
519 @opindex + | 520 @opindex + |
520 Addition. If both operands are matrices, the number of rows and columns | 521 Addition. If both operands are matrices, the number of rows and columns |
713 such as equality. They are written using | 714 such as equality. They are written using |
714 @emph{relational operators}. | 715 @emph{relational operators}. |
715 | 716 |
716 All of Octave's comparison operators return a value of 1 if the | 717 All of Octave's comparison operators return a value of 1 if the |
717 comparison is true, or 0 if it is false. For matrix values, they all | 718 comparison is true, or 0 if it is false. For matrix values, they all |
718 work on an element-by-element basis. For example: | 719 work on an element-by-element basis. Broadcasting rules apply. |
720 @xref{Broadcasting}. For example: | |
719 | 721 |
720 @example | 722 @example |
721 @group | 723 @group |
722 [1, 2; 3, 4] == [1, 3; 2, 4] | 724 [1, 2; 3, 4] == [1, 3; 2, 4] |
723 @result{} 1 0 | 725 @result{} 1 0 |
724 0 1 | 726 0 1 |
725 @end group | 727 @end group |
726 @end example | 728 @end example |
727 | 729 |
728 If one operand is a scalar and the other is a matrix, the scalar is | 730 According to broadcasting rules, if one operand is a scalar and the |
729 compared to each element of the matrix in turn, and the result is the | 731 other is a matrix, the scalar is compared to each element of the matrix |
730 same size as the matrix. | 732 in turn, and the result is the same size as the matrix. |
731 | 733 |
732 @table @code | 734 @table @code |
733 @item @var{x} < @var{y} | 735 @item @var{x} < @var{y} |
734 @opindex < | 736 @opindex < |
735 True if @var{x} is less than @var{y}. | 737 True if @var{x} is less than @var{y}. |
860 @opindex ! | 862 @opindex ! |
861 Each element of the result is true if the corresponding element of | 863 Each element of the result is true if the corresponding element of |
862 @var{boolean} is false. | 864 @var{boolean} is false. |
863 @end table | 865 @end table |
864 | 866 |
865 For matrix operands, these operators work on an element-by-element | 867 These operators work on an element-by-element basis. For example, the |
866 basis. For example, the expression | 868 expression |
867 | 869 |
868 @example | 870 @example |
869 [1, 0; 0, 1] & [1, 0; 2, 3] | 871 [1, 0; 0, 1] & [1, 0; 2, 3] |
870 @end example | 872 @end example |
871 | 873 |
872 @noindent | 874 @noindent |
873 returns a two by two identity matrix. | 875 returns a two by two identity matrix. |
874 | 876 |
875 For the binary operators, the dimensions of the operands must conform if | 877 For the binary operators, broadcasting rules apply. @xref{Broadcasting}. |
876 both are matrices. If one of the operands is a scalar and the other a | 878 In particular, if one of the operands is a scalar and the other a |
877 matrix, the operator is applied to the scalar and each element of the | 879 matrix, the operator is applied to the scalar and each element of the |
878 matrix. | 880 matrix. |
879 | 881 |
880 For the binary element-by-element boolean operators, both subexpressions | 882 For the binary element-by-element boolean operators, both subexpressions |
881 @var{boolean1} and @var{boolean2} are evaluated before computing the | 883 @var{boolean1} and @var{boolean2} are evaluated before computing the |