You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/devdocs/cartesian.rst
+57-47Lines changed: 57 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -138,72 +138,82 @@ Macro reference
138
138
139
139
.. function:: @nloops N itersym rangeexpr bodyexpr
140
140
141
-
::
142
-
@nloops N itersym rangeexpr preexpr bodyexpr
143
-
@nloops N itersym rangeexpr preexpr postexpr bodyexpr
144
-
145
-
Generate ``N`` nested loops, using ``itersym`` as the prefix for
146
-
the iteration variables. ``rangeexpr`` may be an
147
-
anonymous-function expression, or a simple symbol ``var`` in which
148
-
case the range is ``1:size(var,d)`` for dimension ``d``.
149
-
150
-
Optionally, you can provide "pre" and "post" expressions. These
151
-
get executed first and last, respectively, in the body of each
152
-
loop. For example,
153
-
::
154
-
155
-
@nloops 2 i A d->j_d=min(i_d,5) begin
156
-
s += @nref 2 A j
157
-
end
158
-
159
-
would generate
160
-
::
161
-
162
-
for i_2 = 1:size(A, 2)
163
-
j_2 = min(i_2, 5)
164
-
for i_1 = 1:size(A, 1)
165
-
j_1 = min(i_1, 5)
166
-
s += A[j_1,j_2]
167
-
end
168
-
end
169
-
170
-
If you want just a post-expression, supply
171
-
``nothing`` for the pre-expression. Using parenthesis and
172
-
semicolons, you can supply multi-statement expressions.
141
+
.. Docstring generated from Julia source
142
+
.. code-block:: julia
143
+
@nloops N itersym rangeexpr bodyexpr
144
+
@nloops N itersym rangeexpr preexpr bodyexpr
145
+
@nloops N itersym rangeexpr preexpr postexpr bodyexpr
146
+
147
+
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``\ .
148
+
149
+
Optionally, you can provide "pre" and "post" expressions. These get executed first and last, respectively, in the body of each loop. For example, :
150
+
151
+
.. code-block:: julia
152
+
@nloops 2 i A d->j_d=min(i_d,5) begin
153
+
s += @nref 2 A j
154
+
end
155
+
156
+
would generate :
157
+
158
+
.. code-block:: julia
159
+
for i_2 = 1:size(A, 2)
160
+
j_2 = min(i_2, 5)
161
+
for i_1 = 1:size(A, 1)
162
+
j_1 = min(i_1, 5)
163
+
s += A[j_1,j_2]
164
+
end
165
+
end
166
+
167
+
If you want just a post-expression, supply ``nothing`` for the pre-expression. Using parenthesis and semicolons, you can supply multi-statement expressions.
173
168
174
169
.. function:: @nref N A indexexpr
175
170
176
-
Generate expressions like ``A[i_1,i_2,...]``. ``indexexpr`` can
177
-
either be an iteration-symbol prefix, or an anonymous-function
178
-
expression.
171
+
.. Docstring generated from Julia source
172
+
.. code-block:: julia
173
+
@nref N A indexexpr
174
+
175
+
Generate expressions like ``A[i_1,i_2,...]``\ . ``indexexpr`` can either be an iteration-symbol prefix, or an anonymous-function expression.
179
176
180
177
.. function:: @nexprs N expr
181
178
182
-
Generate ``N`` expressions. ``expr`` should be an
183
-
anonymous-function expression.
179
+
.. Docstring generated from Julia source
180
+
.. code-block:: julia
181
+
@nexprs N expr
182
+
183
+
Generate ``N`` expressions. ``expr`` should be an anonymous-function expression.
184
184
185
185
.. function:: @ntuple N expr
186
186
187
-
Generates an ``N``-tuple. ``@ntuple 2 i`` would generate ``(i_1, i_2)``, and ``@ntuple 2 k->k+1`` would generate ``(2,3)``.
187
+
.. Docstring generated from Julia source
188
+
.. code-block:: julia
189
+
@ntuple N expr
190
+
191
+
Generates an ``N``\ -tuple. ``@ntuple 2 i`` would generate ``(i_1, i_2)``\ , and ``@ntuple 2 k->k+1`` would generate ``(2,3)``\ .
188
192
189
193
.. function:: @nall N expr
190
194
191
-
``@nall 3 d->(i_d > 1)`` would generate the expression
192
-
``(i_1 > 1 && i_2 > 1 && i_3 > 1)``. This can be convenient for
193
-
bounds-checking.
195
+
.. Docstring generated from Julia source
196
+
.. code-block:: julia
197
+
@nall N expr
198
+
199
+
``@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.
194
200
195
201
.. function:: @nif N conditionexpr expr
196
202
197
-
::
198
-
@nif N conditionexpr expr elseexpr
203
+
.. Docstring generated from Julia source
204
+
.. code-block:: julia
205
+
@nif N conditionexpr expr
206
+
@nif N conditionexpr expr elseexpr
199
207
200
-
Generates a sequence of ``if ... elseif ... else ... end`` statements. For example::
208
+
Generates a sequence of ``if ... elseif ... else ... end`` statements. For example:
0 commit comments