changeset 14123:2f742be03f90 stable

doc: mention how scalar broadcasting is a special case of broadcasting
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 29 Dec 2011 15:36:59 -0500
parents c299bb9f0ad0
children 4b07db9dd976
files doc/interpreter/vectorize.txi
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/vectorize.txi
+++ b/doc/interpreter/vectorize.txi
@@ -341,6 +341,11 @@
 broadcast into matrices of size @code{[3 3]} before ordinary matrix
 subtraction takes place.
 
+A special case of broadcasting that may be familiar is when all
+dimensions of the array being broadcast are 1, i.e. the array is a
+scalar. Thus for example, operations like @code{x - 42} and @code{max
+(x, 2)} are basic examples of broadcasting.
+
 For a higher-dimensional example, suppose @code{img} is an RGB image of
 size @code{[m n 3]} and we wish to multiply each color by a different
 scalar.  The following code accomplishes this with broadcasting,
@@ -409,7 +414,7 @@
 For matrices @var{a} and @var{b}, consider the following:
 
 @example
-c = sum (permute (a, [1, 3, 2]) .* permute (b, [3, 2, 1]), 3);
+@var{c} = sum (permute (@var{a}, [1, 3, 2]) .* permute (@var{b}, [3, 2, 1]), 3);
 @end example
 
 @noindent
@@ -417,7 +422,7 @@
 across each other during elementwise multiplication in order to obtain a
 larger 3-D array, and this array is then summed along the third dimension.
 A moment of thought will prove that this operation is simply the much
-faster ordinary matrix multiplication, @code{c = a*b;}.
+faster ordinary matrix multiplication, @code{@var{c} = @var{a}*@var{b};}.
 
 A note on terminology: ``broadcasting'' is the term popularized by the
 Numpy numerical environment in the Python programming language.  In other
@@ -462,6 +467,10 @@
 warning ("error", "Octave:broadcast");
 @end example
 
+@noindent
+For broadcasting on scalars that worked in previous versions of Octave,
+this warning will not be emitted.
+
 @node Function Application
 @section Function Application
 @cindex map
@@ -652,7 +661,7 @@
   ## this will be two columns, the first is the difference and
   ## the second the mean of the two elements used for the diff.
   B(i,:) = [A(i+1)-A(i), (A(i+1) + A(i))/2)];
-end
+endfor
 @end group
 @end example