Commit 16d16df7 authored by L.S. Cook's avatar L.S. Cook Committed by Scott Cyphers

. helping people document code more efficiently (#1090)

parent 6b84c5e6
# nGraph Code Examples
`You are at: ngraph/doc/examples/README.md`
The code examples in this folder are for documentation purposes.
Any modifications to the code or comments on example programs
in this directory have DOCUMENTATION BREAKING IMPLICATIONS. You
are welcome to refactor these code examples, if you think they
can be made more clear; however, you must also find and update
all `.rst` documentation files affected by your change(s). Every
example file added to this directory must be accompanied separate
and proper documentation files formatted in `.rst`, as per the
specification in our [doc contributor README] file.
[doc contributor README](http://ngraph.nervanasys.com/docs/latest/project/doc-contributor-README.html)
...@@ -77,7 +77,7 @@ We begin by building the graph, starting with the input parameter ...@@ -77,7 +77,7 @@ We begin by building the graph, starting with the input parameter
``X``. We define a fully-connected layer, including a parameter for ``X``. We define a fully-connected layer, including a parameter for
weights and bias. weights and bias.
.. literalinclude:: ../../../examples/mnist_mlp.cpp .. literalinclude:: ../../../examples/mnist_mlp/mnist_mlp.cpp
:language: cpp :language: cpp
:lines: 124-136 :lines: 124-136
...@@ -85,7 +85,7 @@ weights and bias. ...@@ -85,7 +85,7 @@ weights and bias.
We repeat the process for the next layer, which we We repeat the process for the next layer, which we
normalize with a ``softmax``. normalize with a ``softmax``.
.. literalinclude:: ../../../examples/mnist_mlp.cpp .. literalinclude:: ../../../examples/mnist_mlp/mnist_mlp.cpp
:language: cpp :language: cpp
:lines: 138-149 :lines: 138-149
...@@ -99,7 +99,7 @@ We use cross-entropy to compute the loss. nGraph does not currenty ...@@ -99,7 +99,7 @@ We use cross-entropy to compute the loss. nGraph does not currenty
have a cross-entropy op, so we implement it directly, adding clipping have a cross-entropy op, so we implement it directly, adding clipping
to prevent underflow. to prevent underflow.
.. literalinclude:: ../../../examples/mnist_mlp.cpp .. literalinclude:: ../../../examples/mnist_mlp/mnist_mlp.cpp
:language: cpp :language: cpp
:lines: 151-166 :lines: 151-166
...@@ -116,7 +116,7 @@ interpreted frameworks. In nGraph, we augment the loss computation ...@@ -116,7 +116,7 @@ interpreted frameworks. In nGraph, we augment the loss computation
with computations for the weight adjustments. This allows the with computations for the weight adjustments. This allows the
calculations for the adjustments to be further optimized. calculations for the adjustments to be further optimized.
.. literalinclude:: ../../../examples/mnist_mlp.cpp .. literalinclude:: ../../../examples/mnist_mlp/mnist_mlp.cpp
:language: cpp :language: cpp
:lines: 172-175 :lines: 172-175
...@@ -131,7 +131,7 @@ update computation for ``N`` will be given by the node ...@@ -131,7 +131,7 @@ update computation for ``N`` will be given by the node
The different update nodes will share intermediate computations. So to The different update nodes will share intermediate computations. So to
get the updated values for the weights we just say: get the updated values for the weights we just say:
.. literalinclude:: ../../../examples/mnist_mlp.cpp .. literalinclude:: ../../../examples/mnist_mlp/mnist_mlp.cpp
:language: cpp :language: cpp
:lines: 177-217 :lines: 177-217
...@@ -151,7 +151,7 @@ use the same nodes in different functions, nGraph currently does not ...@@ -151,7 +151,7 @@ use the same nodes in different functions, nGraph currently does not
allow the same nodes to be compiled in different functions, so we allow the same nodes to be compiled in different functions, so we
compile clones of the nodes. compile clones of the nodes.
.. literalinclude:: ../../../examples/mnist_mlp.cpp .. literalinclude:: ../../../examples/mnist_mlp/mnist_mlp.cpp
:language: cpp :language: cpp
:lines: 220-226 :lines: 220-226
...@@ -71,7 +71,7 @@ They receive their values from outside of the graph, so they have no inputs. ...@@ -71,7 +71,7 @@ They receive their values from outside of the graph, so they have no inputs.
They have attributes for the element type and the shape of the tensor that will They have attributes for the element type and the shape of the tensor that will
be passed to them. be passed to them.
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 25-29 :lines: 25-29
...@@ -81,7 +81,7 @@ shape ``(2, 3)`` and a row-major element layout. ...@@ -81,7 +81,7 @@ shape ``(2, 3)`` and a row-major element layout.
To create a graph for ``(a + b) * c``, first make an ``op::Add`` node with inputs To create a graph for ``(a + b) * c``, first make an ``op::Add`` node with inputs
from ``a`` and ``b``, and an ``op::Multiply`` node from the add node and ``c``: from ``a`` and ``b``, and an ``op::Multiply`` node from the add node and ``c``:
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 31-32 :lines: 31-32
...@@ -94,7 +94,7 @@ type and shape of its unique output. ...@@ -94,7 +94,7 @@ type and shape of its unique output.
Once the graph is built, we need to package it in a ``Function``: Once the graph is built, we need to package it in a ``Function``:
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 35-36 :lines: 35-36
...@@ -131,7 +131,7 @@ for additional details. ...@@ -131,7 +131,7 @@ for additional details.
To continue with our original example and select the ``"CPU"`` backend: To continue with our original example and select the ``"CPU"`` backend:
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 38-39 :lines: 38-39
...@@ -168,7 +168,7 @@ Backends are responsible for managing storage. If the storage is off-CPU, caches ...@@ -168,7 +168,7 @@ Backends are responsible for managing storage. If the storage is off-CPU, caches
are used to minimize copying between device and CPU. We can allocate storage for are used to minimize copying between device and CPU. We can allocate storage for
the three parameters and the return value as follows: the three parameters and the return value as follows:
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 41-46 :lines: 41-46
...@@ -186,7 +186,7 @@ Initialize the inputs ...@@ -186,7 +186,7 @@ Initialize the inputs
Next we need to copy some data into the tensors. Next we need to copy some data into the tensors.
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 48-55 :lines: 48-55
...@@ -201,7 +201,7 @@ Invoke the computation ...@@ -201,7 +201,7 @@ Invoke the computation
To invoke the function, we simply pass argument and resultant tensors to the To invoke the function, we simply pass argument and resultant tensors to the
call frame: call frame:
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 57-58 :lines: 57-58
...@@ -213,7 +213,7 @@ Access the outputs ...@@ -213,7 +213,7 @@ Access the outputs
We can use the ``read`` method to access the result: We can use the ``read`` method to access the result:
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 60-77 :lines: 60-77
...@@ -222,7 +222,7 @@ We can use the ``read`` method to access the result: ...@@ -222,7 +222,7 @@ We can use the ``read`` method to access the result:
Put it all together Put it all together
=================== ===================
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:linenos: :linenos:
:caption: "The (a + b) * c example for executing a computation on nGraph" :caption: "The (a + b) * c example for executing a computation on nGraph"
......
...@@ -149,7 +149,7 @@ specify the relative path to the location of the ``.onnx`` file. ...@@ -149,7 +149,7 @@ specify the relative path to the location of the ``.onnx`` file.
Enable ONNX and load an ONNX file from disk Enable ONNX and load an ONNX file from disk
-------------------------------------------- --------------------------------------------
.. literalinclude:: ../../../examples/onnx_example.py .. literalinclude:: ../../../examples/onnx/onnx_example.py
:language: python :language: python
:lines: 17-19 :lines: 17-19
...@@ -157,7 +157,7 @@ Enable ONNX and load an ONNX file from disk ...@@ -157,7 +157,7 @@ Enable ONNX and load an ONNX file from disk
Convert an ONNX model to an ngraph model Convert an ONNX model to an ngraph model
------------------------------------------- -------------------------------------------
.. literalinclude:: ../../../examples/onnx_example.py .. literalinclude:: ../../../examples/onnx/onnx_example.py
:language: python :language: python
:lines: 22-23 :lines: 22-23
...@@ -184,7 +184,7 @@ input parameters for the computation which generates the output. ...@@ -184,7 +184,7 @@ input parameters for the computation which generates the output.
Using ngraph_api, create a callable computation object Using ngraph_api, create a callable computation object
------------------------------------------------------- -------------------------------------------------------
.. literalinclude:: ../../../examples/onnx_example.py .. literalinclude:: ../../../examples/onnx/onnx_example.py
:language: python :language: python
:lines: 27-29 :lines: 27-29
...@@ -192,14 +192,14 @@ Using ngraph_api, create a callable computation object ...@@ -192,14 +192,14 @@ Using ngraph_api, create a callable computation object
Load or create an image Load or create an image
------------------------ ------------------------
.. literalinclude:: ../../../examples/onnx_example.py .. literalinclude:: ../../../examples/onnx/onnx_example.py
:language: python :language: python
:lines: 32-33 :lines: 32-33
Run ResNet inference on picture Run ResNet inference on picture
--------------------------------- ---------------------------------
.. literalinclude:: ../../../examples/onnx_example.py .. literalinclude:: ../../../examples/onnx/onnx_example.py
:language: python :language: python
:lines: 36-37 :lines: 36-37
...@@ -207,7 +207,7 @@ Run ResNet inference on picture ...@@ -207,7 +207,7 @@ Run ResNet inference on picture
Put it all together Put it all together
=================== ===================
.. literalinclude:: ../../../examples/onnx_example.py .. literalinclude:: ../../../examples/onnx/onnx_example.py
:language: python :language: python
:lines: 17-37 :lines: 17-37
:caption: "Demo sample code to run inference with nGraph" :caption: "Demo sample code to run inference with nGraph"
......
...@@ -10,13 +10,13 @@ building of graphs. ...@@ -10,13 +10,13 @@ building of graphs.
Several C++ operators are overloaded to simplify graph construction. Several C++ operators are overloaded to simplify graph construction.
For example, the following: For example, the following:
.. literalinclude:: ../../../examples/abc.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 32-32 :lines: 32-32
can be simplified to: can be simplified to:
.. literalinclude:: ../../../examples/abc_operator.cpp .. literalinclude:: ../../../examples/abc_operator/abc_operator.cpp
:language: cpp :language: cpp
:lines: 31 :lines: 31
......
...@@ -15,7 +15,7 @@ An example from C++ ...@@ -15,7 +15,7 @@ An example from C++
Let's start with a simple C++ example, a function ``count`` that Let's start with a simple C++ example, a function ``count`` that
returns how many times it has already been called: returns how many times it has already been called:
.. literalinclude:: ../../../examples/update.cpp .. literalinclude:: ../../../examples/update/update.cpp
:language: cpp :language: cpp
:lines: 20-24 :lines: 20-24
:caption: update.cpp :caption: update.cpp
...@@ -27,13 +27,13 @@ convert this to use a stateless function, define a function that ...@@ -27,13 +27,13 @@ convert this to use a stateless function, define a function that
takes the current value of ``counter`` as an argument and returns the takes the current value of ``counter`` as an argument and returns the
updated value. updated value.
.. literalinclude:: ../../../examples/update.cpp .. literalinclude:: ../../../examples/update/update.cpp
:language: cpp :language: cpp
:lines: 26-29 :lines: 26-29
To use this version of counting, To use this version of counting,
.. literalinclude:: ../../../examples/update.cpp .. literalinclude:: ../../../examples/update/update.cpp
:language: cpp :language: cpp
:lines: 36-48 :lines: 36-48
......
...@@ -55,14 +55,14 @@ source file: ...@@ -55,14 +55,14 @@ source file:
:: ::
.. literalinclude:: ../../../../src/ngraph/descriptor/primary_tensor_view.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 20-31 :lines: 20-31
And the raw code will render as follows And the raw code will render as follows
.. literalinclude:: ../../../../src/ngraph/descriptor/primary_tensor_view.cpp .. literalinclude:: ../../../examples/abc/abc.cpp
:language: cpp :language: cpp
:lines: 20-31 :lines: 20-31
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment