Skip to content

Commit

Permalink
Added eval(...) to Symbol class (apache#5300)
Browse files Browse the repository at this point in the history
* python -> Python (fixed capitalization typo)

* flavours -> flavors for internal consistency with American spellings. Changed 'good flabors' to specify imperative and symbolic programming, better not to tease the reader

* Improved writing of 'History' section

* Improved writing of 'History' section

* fixed symbol.md doc which previously used deprecated / incorrect mxnet.sym.var instead of the real/working mxnet.sym.Variable

* fixed typos and readability in parts of the README.md

* removed awkward phrasing about 'flavours'

* typo cleanup

* Update NEWS.md

Fixed typos

* adding eval function for combining  with , makes for quicker introspection in interactive interpreters

* fixed docstrig

* fixed docstring, cleaned up whitespace

* clean up

* Changed code to work with **kwargs, doesn't require dictionary explicitly. This also removes need for clumsy code to handle the case where there are no arguments

* fixed too-long lines in the docstring

* Update symbol.py
  • Loading branch information
zackchase authored and piiswrong committed Mar 18, 2017
1 parent 39776a3 commit 47b3b7a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion python/mxnet/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .base import c_array, c_str, mx_uint, py_str, string_types, mx_real_t
from .base import NDArrayHandle, ExecutorHandle, SymbolHandle
from .base import check_call, MXNetError
from .context import Context
from .context import Context, cpu
from .ndarray import NDArray, zeros as _nd_zeros, _DTYPE_NP_TO_MX, _DTYPE_MX_TO_NP
from .executor import Executor
from . import _symbol_internal as _internal
Expand Down Expand Up @@ -1025,6 +1025,39 @@ def grad(self, wrt):
return Symbol(handle)
# pylint: enable= no-member

def eval(self, ctx=cpu(), **kwargs):
"""Evaluate a symbol given arguments
The `eval` method combines a call to `bind` (which returns an executor)
with a call to `forward` (executor method).
For the common use case, where you might repeatedly evaluate with same arguments,
eval is slow.
In that case, you should call `bind` once and then repeatedly call forward.
Eval allows simpler syntax for less cumbersome introspection.
Parameters
----------
ctx : Context
The device context the generated executor to run on.
kwargs : list of NDArray or dict of str to NDArray
Input arguments to the symbol.
- If type is list of NDArray, the position is in the same order of list_arguments.
- If type is dict of str to NDArray, then it maps the name of arguments
to the corresponding NDArray.
- In either case, all the arguments must be provided.
Returns
----------
result : a list of NDArrays corresponding to the values
taken by each symbol when evaluated on given args.
When called on a single symbol (not a group),
the result will be a list with one element.
"""
return self.bind(ctx, kwargs).forward()



def var(name, attr=None, shape=None, lr_mult=None, wd_mult=None, dtype=None, init=None):
"""Create a symbolic variable with specified name.
Expand Down

0 comments on commit 47b3b7a

Please sign in to comment.