Skip to content

Commit

Permalink
regenerate the manual
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Aug 19, 2015
1 parent 42fffd7 commit 4adfd31
Show file tree
Hide file tree
Showing 19 changed files with 7,924 additions and 3,611 deletions.
104 changes: 57 additions & 47 deletions doc/devdocs/cartesian.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,72 +138,82 @@ Macro reference

.. function:: @nloops N itersym rangeexpr bodyexpr

::
@nloops N itersym rangeexpr preexpr bodyexpr
@nloops N itersym rangeexpr preexpr postexpr bodyexpr

Generate ``N`` nested loops, using ``itersym`` as the prefix for
the iteration variables. ``rangeexpr`` may be an
anonymous-function expression, or a simple symbol ``var`` in which
case the range is ``1:size(var,d)`` for dimension ``d``.

Optionally, you can provide "pre" and "post" expressions. These
get executed first and last, respectively, in the body of each
loop. For example,
::

@nloops 2 i A d->j_d=min(i_d,5) begin
s += @nref 2 A j
end

would generate
::

for i_2 = 1:size(A, 2)
j_2 = min(i_2, 5)
for i_1 = 1:size(A, 1)
j_1 = min(i_1, 5)
s += A[j_1,j_2]
end
end

If you want just a post-expression, supply
``nothing`` for the pre-expression. Using parenthesis and
semicolons, you can supply multi-statement expressions.
.. Docstring generated from Julia source
.. code-block:: julia
@nloops N itersym rangeexpr bodyexpr
@nloops N itersym rangeexpr preexpr bodyexpr
@nloops N itersym rangeexpr preexpr postexpr bodyexpr
Generate ``N`` nested loops, using ``itersym`` as the prefix for the iteration variables. ``rangeexpr`` may be an anonymous-function expression, or a simple symbol ``var`` in which case the range is ``1:size(var,d)`` for dimension ``d``\ .

Optionally, you can provide "pre" and "post" expressions. These get executed first and last, respectively, in the body of each loop. For example, :

.. code-block:: julia
@nloops 2 i A d->j_d=min(i_d,5) begin
s += @nref 2 A j
end
would generate :

.. code-block:: julia
for i_2 = 1:size(A, 2)
j_2 = min(i_2, 5)
for i_1 = 1:size(A, 1)
j_1 = min(i_1, 5)
s += A[j_1,j_2]
end
end
If you want just a post-expression, supply ``nothing`` for the pre-expression. Using parenthesis and semicolons, you can supply multi-statement expressions.

.. function:: @nref N A indexexpr

Generate expressions like ``A[i_1,i_2,...]``. ``indexexpr`` can
either be an iteration-symbol prefix, or an anonymous-function
expression.
.. Docstring generated from Julia source
.. code-block:: julia
@nref N A indexexpr
Generate expressions like ``A[i_1,i_2,...]``\ . ``indexexpr`` can either be an iteration-symbol prefix, or an anonymous-function expression.

.. function:: @nexprs N expr

Generate ``N`` expressions. ``expr`` should be an
anonymous-function expression.
.. Docstring generated from Julia source
.. code-block:: julia
@nexprs N expr
Generate ``N`` expressions. ``expr`` should be an anonymous-function expression.

.. function:: @ntuple N expr

Generates an ``N``-tuple. ``@ntuple 2 i`` would generate ``(i_1, i_2)``, and ``@ntuple 2 k->k+1`` would generate ``(2,3)``.
.. Docstring generated from Julia source
.. code-block:: julia
@ntuple N expr
Generates an ``N``\ -tuple. ``@ntuple 2 i`` would generate ``(i_1, i_2)``\ , and ``@ntuple 2 k->k+1`` would generate ``(2,3)``\ .

.. function:: @nall N expr

``@nall 3 d->(i_d > 1)`` would generate the expression
``(i_1 > 1 && i_2 > 1 && i_3 > 1)``. This can be convenient for
bounds-checking.
.. Docstring generated from Julia source
.. code-block:: julia
@nall N expr
``@nall 3 d->(i_d > 1)`` would generate the expression ``(i_1 > 1 && i_2 > 1 && i_3 > 1)``\ . This can be convenient for bounds-checking.

.. function:: @nif N conditionexpr expr

::
@nif N conditionexpr expr elseexpr
.. Docstring generated from Julia source
.. code-block:: julia
@nif N conditionexpr expr
@nif N conditionexpr expr elseexpr
Generates a sequence of ``if ... elseif ... else ... end`` statements. For example::
Generates a sequence of ``if ... elseif ... else ... end`` statements. For example:

@nif 3 d->(i_d >= size(A,d)) d->(error("Dimension ", d, " too big")) d->println("All OK")
.. code-block:: julia
@nif 3 d->(i_d >= size(A,d)) d->(error("Dimension ", d, " too big")) d->println("All OK")
would generate::
would generate:

if i_1 > size(A, 1)
.. code-block:: julia
if i_1 > size(A, 1)
error("Dimension ", 1, " too big")
elseif i_2 > size(A, 2)
Expand Down
Loading

0 comments on commit 4adfd31

Please sign in to comment.