blob: 150d34756c0760cf3ff104c628e523dac67152ef [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta content="Test Utilities" property="og:title">
<meta content="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/og-logo.png" property="og:image">
<meta content="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/og-logo.png" property="og:image:secure_url">
<meta content="Test Utilities" property="og:description"/>
<title>Test Utilities — mxnet documentation</title>
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="../../../_static/basic.css" rel="stylesheet" type="text/css">
<link href="../../../_static/pygments.css" rel="stylesheet" type="text/css">
<link href="../../../_static/mxnet.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="../../../_static/underscore.js" type="text/javascript"></script>
<script src="../../../_static/searchtools_custom.js" type="text/javascript"></script>
<script src="../../../_static/doctools.js" type="text/javascript"></script>
<script src="../../../_static/selectlang.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
<script type="text/javascript"> jQuery(function() { Search.loadIndex("/versions/1.4.1/searchindex.js"); Search.init();}); </script>
<!-- -->
<!-- <script type="text/javascript" src="../../../_static/jquery.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../../../_static/underscore.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../../../_static/doctools.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -->
<!-- -->
<link href="../../../genindex.html" rel="index" title="Index">
<link href="../../../search.html" rel="search" title="Search"/>
<link href="../index.html" rel="up" title="MXNet - Python API"/>
<link href="visualization.html" rel="next" title="Visualization"/>
<link href="../symbol_in_pictures/symbol_in_pictures.html" rel="prev" title="Symbolic Configuration and Execution in Pictures"/>
<link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/>
</link></link></link></meta></meta></meta></head>
<body background="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-background-compressed.jpeg" role="document">
<div class="content-block"><div class="navbar navbar-fixed-top">
<div class="container" id="navContainer">
<div class="innder" id="header-inner">
<h1 id="logo-wrap">
<a href="../../../" id="logo"><img src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet_logo.png"/></a>
</h1>
<nav class="nav-bar" id="main-nav">
<a class="main-nav-link" href="/versions/1.4.1/install/index.html">Install</a>
<span id="dropdown-menu-position-anchor">
<a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Gluon <span class="caret"></span></a>
<ul class="dropdown-menu navbar-menu" id="package-dropdown-menu">
<li><a class="main-nav-link" href="/versions/1.4.1/tutorials/gluon/gluon.html">About</a></li>
<li><a class="main-nav-link" href="https://www.d2l.ai/">Dive into Deep Learning</a></li>
<li><a class="main-nav-link" href="https://gluon-cv.mxnet.io">GluonCV Toolkit</a></li>
<li><a class="main-nav-link" href="https://gluon-nlp.mxnet.io/">GluonNLP Toolkit</a></li>
</ul>
</span>
<span id="dropdown-menu-position-anchor">
<a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">API <span class="caret"></span></a>
<ul class="dropdown-menu navbar-menu" id="package-dropdown-menu">
<li><a class="main-nav-link" href="/versions/1.4.1/api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/clojure/index.html">Clojure</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/java/index.html">Java</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/perl/index.html">Perl</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/scala/index.html">Scala</a></li>
</ul>
</span>
<span id="dropdown-menu-position-anchor-docs">
<a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Docs <span class="caret"></span></a>
<ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-docs">
<li><a class="main-nav-link" href="/versions/1.4.1/faq/index.html">FAQ</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/tutorials/index.html">Tutorials</a>
<li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/1.4.1/example">Examples</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/architecture/index.html">Architecture</a></li>
<li><a class="main-nav-link" href="https://cwiki.apache.org/confluence/display/MXNET/Apache+MXNet+Home">Developer Wiki</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/model_zoo/index.html">Model Zoo</a></li>
<li><a class="main-nav-link" href="https://github.com/onnx/onnx-mxnet">ONNX</a></li>
</li></ul>
</span>
<span id="dropdown-menu-position-anchor-community">
<a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Community <span class="caret"></span></a>
<ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-community">
<li><a class="main-nav-link" href="http://discuss.mxnet.io">Forum</a></li>
<li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/1.4.1">Github</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/community/contribute.html">Contribute</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/community/ecosystem.html">Ecosystem</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/community/powered_by.html">Powered By</a></li>
</ul>
</span>
<span id="dropdown-menu-position-anchor-version" style="position: relative"><a href="#" class="main-nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">1.4.1<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a href="/">master</a></li><li><a href="/versions/1.7.0/">1.7.0</a></li><li><a href=/versions/1.6.0/>1.6.0</a></li><li><a href=/versions/1.5.0/>1.5.0</a></li><li><a href=/versions/1.4.1/>1.4.1</a></li><li><a href=/versions/1.3.1/>1.3.1</a></li><li><a href=/versions/1.2.1/>1.2.1</a></li><li><a href=/versions/1.1.0/>1.1.0</a></li><li><a href=/versions/1.0.0/>1.0.0</a></li><li><a href=/versions/0.12.1/>0.12.1</a></li><li><a href=/versions/0.11.0/>0.11.0</a></li></ul></span></nav>
<script> function getRootPath(){ return "../../../" } </script>
<div class="burgerIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"></a>
<ul class="dropdown-menu" id="burgerMenu">
<li><a href="/versions/1.4.1/install/index.html">Install</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/tutorials/index.html">Tutorials</a></li>
<li class="dropdown-submenu dropdown">
<a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">Gluon</a>
<ul class="dropdown-menu navbar-menu" id="package-dropdown-menu">
<li><a class="main-nav-link" href="/versions/1.4.1/tutorials/gluon/gluon.html">About</a></li>
<li><a class="main-nav-link" href="http://gluon.mxnet.io">The Straight Dope (Tutorials)</a></li>
<li><a class="main-nav-link" href="https://gluon-cv.mxnet.io">GluonCV Toolkit</a></li>
<li><a class="main-nav-link" href="https://gluon-nlp.mxnet.io/">GluonNLP Toolkit</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">API</a>
<ul class="dropdown-menu">
<li><a class="main-nav-link" href="/versions/1.4.1/api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/clojure/index.html">Clojure</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/java/index.html">Java</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/perl/index.html">Perl</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="/versions/1.4.1/api/scala/index.html">Scala</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">Docs</a>
<ul class="dropdown-menu">
<li><a href="/versions/1.4.1/faq/index.html" tabindex="-1">FAQ</a></li>
<li><a href="/versions/1.4.1/tutorials/index.html" tabindex="-1">Tutorials</a></li>
<li><a href="https://github.com/apache/incubator-mxnet/tree/1.4.1/example" tabindex="-1">Examples</a></li>
<li><a href="/versions/1.4.1/architecture/index.html" tabindex="-1">Architecture</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/MXNET/Apache+MXNet+Home" tabindex="-1">Developer Wiki</a></li>
<li><a href="/versions/1.4.1/model_zoo/index.html" tabindex="-1">Gluon Model Zoo</a></li>
<li><a href="https://github.com/onnx/onnx-mxnet" tabindex="-1">ONNX</a></li>
</ul>
</li>
<li class="dropdown-submenu dropdown">
<a aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" role="button" tabindex="-1">Community</a>
<ul class="dropdown-menu">
<li><a href="http://discuss.mxnet.io" tabindex="-1">Forum</a></li>
<li><a href="https://github.com/apache/incubator-mxnet/tree/1.4.1" tabindex="-1">Github</a></li>
<li><a href="/versions/1.4.1/community/contribute.html" tabindex="-1">Contribute</a></li>
<li><a href="/versions/1.4.1/community/ecosystem.html" tabindex="-1">Ecosystem</a></li>
<li><a href="/versions/1.4.1/community/powered_by.html" tabindex="-1">Powered By</a></li>
</ul>
</li>
<li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">1.4.1</a><ul class="dropdown-menu"><li><a tabindex="-1" href=/>master</a></li><li><a tabindex="-1" href=/versions/1.6.0/>1.6.0</a></li><li><a tabindex="-1" href=/versions/1.5.0/>1.5.0</a></li><li><a tabindex="-1" href=/versions/1.4.1/>1.4.1</a></li><li><a tabindex="-1" href=/versions/1.3.1/>1.3.1</a></li><li><a tabindex="-1" href=/versions/1.2.1/>1.2.1</a></li><li><a tabindex="-1" href=/versions/1.1.0/>1.1.0</a></li><li><a tabindex="-1" href=/versions/1.0.0/>1.0.0</a></li><li><a tabindex="-1" href=/versions/0.12.1/>0.12.1</a></li><li><a tabindex="-1" href=/versions/0.11.0/>0.11.0</a></li></ul></li></ul>
</div>
<div class="plusIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"><span aria-hidden="true" class="glyphicon glyphicon-plus"></span></a>
<ul class="dropdown-menu dropdown-menu-right" id="plusMenu"></ul>
</div>
<div id="search-input-wrap">
<form action="../../../search.html" autocomplete="off" class="" method="get" role="search">
<div class="form-group inner-addon left-addon">
<i class="glyphicon glyphicon-search"></i>
<input class="form-control" name="q" placeholder="Search" type="text"/>
</div>
<input name="check_keywords" type="hidden" value="yes">
<input name="area" type="hidden" value="default"/>
</input></form>
<div id="search-preview"></div>
</div>
<div id="searchIcon">
<span aria-hidden="true" class="glyphicon glyphicon-search"></span>
</div>
<!-- <div id="lang-select-wrap"> -->
<!-- <label id="lang-select-label"> -->
<!-- <\!-- <i class="fa fa-globe"></i> -\-> -->
<!-- <span></span> -->
<!-- </label> -->
<!-- <select id="lang-select"> -->
<!-- <option value="en">Eng</option> -->
<!-- <option value="zh">中文</option> -->
<!-- </select> -->
<!-- </div> -->
<!-- <a id="mobile-nav-toggle">
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
</a> -->
</div>
</div>
</div>
<script type="text/javascript">
$('body').css('background', 'white');
</script>
<div class="container">
<div class="row">
<div aria-label="main navigation" class="sphinxsidebar leftsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../../index.html">MXNet APIs</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../c++/index.html">MXNet - C++ API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../clojure/index.html">MXNet - Clojure API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../julia/index.html">MXNet - Julia API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../perl/index.html">MXNet - Perl API</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../index.html">MXNet - Python API</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../index.html#autograd-api">Autograd API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#callback-api">Callback API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#contrib-package">Contrib Package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#gluon-api">Gluon API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#image-api">Image API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#io-api">IO API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#kv-store-api">KV Store API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#metric-api">Metric API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#module-api">Module API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#ndarray-api">NDArray API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#optimization-api">Optimization API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#profiler-api">Profiler API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#run-time-compilation-api">Run-Time Compilation API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#symbol-api">Symbol API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../index.html#symbol-in-pictures-api">Symbol in Pictures API</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="../index.html#tools">Tools</a><ul class="current">
<li class="toctree-l4 current"><a class="current reference internal" href="#">Test Utilities</a></li>
<li class="toctree-l4"><a class="reference internal" href="visualization.html">Visualization</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../r/index.html">MXNet - R API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../scala/index.html">MXNet - Scala API</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/index.html">MXNet Architecture</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../community/index.html">MXNet Community</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../faq/index.html">MXNet FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../gluon/index.html">About Gluon</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/index.html">Installing MXNet</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/index.html#nvidia-jetson-tx-family">Nvidia Jetson TX family</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/index.html#source-download">Source Download</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../model_zoo/index.html">MXNet Model Zoo</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../tutorials/index.html">Tutorials</a></li>
</ul>
</div>
</div>
<div class="content">
<div class="page-tracker"></div>
<!--- Licensed to the Apache Software Foundation (ASF) under one -->
<!--- or more contributor license agreements. See the NOTICE file -->
<!--- distributed with this work for additional information -->
<!--- regarding copyright ownership. The ASF licenses this file -->
<!--- to you under the Apache License, Version 2.0 (the -->
<!--- "License"); you may not use this file except in compliance -->
<!--- with the License. You may obtain a copy of the License at --><!--- http://www.apache.org/licenses/LICENSE-2.0 --><!--- Unless required by applicable law or agreed to in writing, -->
<!--- software distributed under the License is distributed on an -->
<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
<!--- KIND, either express or implied. See the License for the -->
<!--- specific language governing permissions and limitations -->
<!--- under the License. --><div class="section" id="test-utilities">
<span id="test-utilities"></span><h1>Test Utilities<a class="headerlink" href="#test-utilities" title="Permalink to this headline"></a></h1>
<p>This module has a variety of tools that help using and testing MXNet.</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#module-mxnet.test_utils" title="mxnet.test_utils"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.test_utils</span></code></a></td>
<td>Tools for testing.</td>
</tr>
</tbody>
</table>
<div class="section" id="api-reference">
<span id="api-reference"></span><h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline"></a></h2>
<script src="../../../_static/js/auto_module_index.js" type="text/javascript"></script><span class="target" id="module-mxnet.test_utils"></span><p>Tools for testing.</p>
<dl class="function">
<dt id="mxnet.test_utils.default_context">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">default_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#default_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.default_context" title="Permalink to this definition"></a></dt>
<dd><p>Get default context for regression test.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.set_default_context">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">set_default_context</code><span class="sig-paren">(</span><em>ctx</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#set_default_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.set_default_context" title="Permalink to this definition"></a></dt>
<dd><p>Set default context.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.default_dtype">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">default_dtype</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#default_dtype"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.default_dtype" title="Permalink to this definition"></a></dt>
<dd><p>Get default data type for regression test.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_atol">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_atol</code><span class="sig-paren">(</span><em>atol=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_atol"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_atol" title="Permalink to this definition"></a></dt>
<dd><p>Get default numerical threshold for regression test.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_rtol">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_rtol</code><span class="sig-paren">(</span><em>rtol=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_rtol"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_rtol" title="Permalink to this definition"></a></dt>
<dd><p>Get default numerical threshold for regression test.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.random_arrays">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">random_arrays</code><span class="sig-paren">(</span><em>*shapes</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#random_arrays"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.random_arrays" title="Permalink to this definition"></a></dt>
<dd><p>Generate some random numpy arrays.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.random_sample">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">random_sample</code><span class="sig-paren">(</span><em>population</em>, <em>k</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#random_sample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.random_sample" title="Permalink to this definition"></a></dt>
<dd><p>Return a k length list of the elements chosen from the population sequence.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.shuffle_csr_column_indices">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">shuffle_csr_column_indices</code><span class="sig-paren">(</span><em>csr</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#shuffle_csr_column_indices"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.shuffle_csr_column_indices" title="Permalink to this definition"></a></dt>
<dd><p>Shuffle CSR column indices per row
This allows validation of unordered column indices, which is not a requirement
for a valid CSR matrix</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.assign_each">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">assign_each</code><span class="sig-paren">(</span><em>the_input</em>, <em>function</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#assign_each"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.assign_each" title="Permalink to this definition"></a></dt>
<dd><p>Return ndarray composed of passing each array value through some function</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.assign_each2">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">assign_each2</code><span class="sig-paren">(</span><em>input1</em>, <em>input2</em>, <em>function</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#assign_each2"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.assign_each2" title="Permalink to this definition"></a></dt>
<dd><p>Return ndarray composed of passing two array values through some function</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.rand_sparse_ndarray">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">rand_sparse_ndarray</code><span class="sig-paren">(</span><em>shape</em>, <em>stype</em>, <em>density=None</em>, <em>dtype=None</em>, <em>distribution=None</em>, <em>data_init=None</em>, <em>rsp_indices=None</em>, <em>modifier_func=None</em>, <em>shuffle_csr_indices=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#rand_sparse_ndarray"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.rand_sparse_ndarray" title="Permalink to this definition"></a></dt>
<dd><p>Generate a random sparse ndarray. Returns the ndarray, value(np) and indices(np)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>shape</strong> (<em>list</em><em> or </em><em>tuple</em>) – </li>
<li><strong>stype</strong> (<em>str</em>) – valid values: “csr” or “row_sparse”</li>
<li><strong>density</strong> (<em>float</em><em>, </em><em>optional</em>) – should be between 0 and 1</li>
<li><strong>distribution</strong> (<em>str</em><em>, </em><em>optional</em>) – valid values: “uniform” or “powerlaw”</li>
<li><strong>dtype</strong> (<em>numpy.dtype</em><em>, </em><em>optional</em>) – default value is None</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"></p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Result of type CSRNDArray or <a class="reference internal" href="../ndarray/sparse.html#mxnet.ndarray.sparse.RowSparseNDArray" title="mxnet.ndarray.sparse.RowSparseNDArray">RowSparseNDArray</a></p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Below is an example of the powerlaw distribution with csr as the stype.
It calculates the nnz using the shape and density.
It fills up the ndarray with exponentially increasing number of elements.
If there are enough unused_nnzs, n+1th row will have twice more nnzs compared to nth row.
else, remaining unused_nnzs will be used in n+1th row
If number of cols is too small and we have already reached column size it will fill up
all following columns in all followings rows until we reach the required density.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">csr_arr</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">rand_sparse_ndarray</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">16</span><span class="p">),</span> <span class="n">stype</span><span class="o">=</span><span class="s2">"csr"</span><span class="p">,</span>
<span class="go"> density=0.50, distribution="powerlaw")</span>
<span class="gp">>>> </span><span class="n">indptr</span> <span class="o">=</span> <span class="n">csr_arr</span><span class="o">.</span><span class="n">indptr</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">indices</span> <span class="o">=</span> <span class="n">csr_arr</span><span class="o">.</span><span class="n">indices</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="n">csr_arr</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">row2nnz</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">indptr</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span><span class="n">indptr</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">row3nnz</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">indptr</span><span class="p">[</span><span class="mi">2</span><span class="p">]:</span><span class="n">indptr</span><span class="p">[</span><span class="mi">3</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="k">assert</span><span class="p">(</span><span class="n">row3nnz</span> <span class="o">==</span> <span class="mi">2</span><span class="o">*</span><span class="n">row2nnz</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">row4nnz</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">indptr</span><span class="p">[</span><span class="mi">3</span><span class="p">]:</span><span class="n">indptr</span><span class="p">[</span><span class="mi">4</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="k">assert</span><span class="p">(</span><span class="n">row4nnz</span> <span class="o">==</span> <span class="mi">2</span><span class="o">*</span><span class="n">row3nnz</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.create_sparse_array">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">create_sparse_array</code><span class="sig-paren">(</span><em>shape</em>, <em>stype</em>, <em>data_init=None</em>, <em>rsp_indices=None</em>, <em>dtype=None</em>, <em>modifier_func=None</em>, <em>density=0.5</em>, <em>shuffle_csr_indices=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#create_sparse_array"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.create_sparse_array" title="Permalink to this definition"></a></dt>
<dd><p>Create a sparse array, For Rsp, assure indices are in a canonical format</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.create_sparse_array_zd">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">create_sparse_array_zd</code><span class="sig-paren">(</span><em>shape</em>, <em>stype</em>, <em>density</em>, <em>data_init=None</em>, <em>rsp_indices=None</em>, <em>dtype=None</em>, <em>modifier_func=None</em>, <em>shuffle_csr_indices=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#create_sparse_array_zd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.create_sparse_array_zd" title="Permalink to this definition"></a></dt>
<dd><p>Create sparse array, using only rsp_indices to determine density</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.np_reduce">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">np_reduce</code><span class="sig-paren">(</span><em>dat</em>, <em>axis</em>, <em>keepdims</em>, <em>numpy_reduce_func</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#np_reduce"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.np_reduce" title="Permalink to this definition"></a></dt>
<dd><p>Compatible reduce for old version of NumPy.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>dat</strong> (<em>np.ndarray</em>) – Same as NumPy.</li>
<li><strong>axis</strong> (<em>None</em><em> or </em><em>int</em><em> or </em><em>list-like</em>) – Same as NumPy.</li>
<li><strong>keepdims</strong> (<em>bool</em>) – Same as NumPy.</li>
<li><strong>numpy_reduce_func</strong> (<em>function</em>) – A NumPy reducing function like <code class="docutils literal"><span class="pre">np.sum</span></code> or <code class="docutils literal"><span class="pre">np.max</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.find_max_violation">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">find_max_violation</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>rtol=None</em>, <em>atol=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#find_max_violation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.find_max_violation" title="Permalink to this definition"></a></dt>
<dd><p>Finds and returns the location of maximum violation.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.same">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">same</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#same"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.same" title="Permalink to this definition"></a></dt>
<dd><p>Test if two NumPy arrays are the same.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>a</strong> (<em>np.ndarray</em>) – </li>
<li><strong>b</strong> (<em>np.ndarray</em>) – </li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.almost_equal">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">almost_equal</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>rtol=None</em>, <em>atol=None</em>, <em>equal_nan=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#almost_equal"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.almost_equal" title="Permalink to this definition"></a></dt>
<dd><p>Test if two numpy arrays are almost equal.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.assert_almost_equal">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">assert_almost_equal</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>rtol=None</em>, <em>atol=None</em>, <em>names=('a'</em>, <em>'b')</em>, <em>equal_nan=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#assert_almost_equal"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.assert_almost_equal" title="Permalink to this definition"></a></dt>
<dd><p>Test that two numpy arrays are almost equal. Raise exception message if not.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>a</strong> (<em>np.ndarray</em>) – </li>
<li><strong>b</strong> (<em>np.ndarray</em>) – </li>
<li><strong>threshold</strong> (<em>None</em><em> or </em><em>float</em>) – The checking threshold. Default threshold will be used if set to <code class="docutils literal"><span class="pre">None</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.almost_equal_ignore_nan">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">almost_equal_ignore_nan</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>rtol=None</em>, <em>atol=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#almost_equal_ignore_nan"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.almost_equal_ignore_nan" title="Permalink to this definition"></a></dt>
<dd><p>Test that two NumPy arrays are almost equal (ignoring NaN in either array).
Combines a relative and absolute measure of approximate eqality.
If either the relative or absolute check passes, the arrays are considered equal.
Including an absolute check resolves issues with the relative check where all
array values are close to zero.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>a</strong> (<em>np.ndarray</em>) – </li>
<li><strong>b</strong> (<em>np.ndarray</em>) – </li>
<li><strong>rtol</strong> (<em>None</em><em> or </em><em>float</em>) – The relative threshold. Default threshold will be used if set to <code class="docutils literal"><span class="pre">None</span></code>.</li>
<li><strong>atol</strong> (<em>None</em><em> or </em><em>float</em>) – The absolute threshold. Default threshold will be used if set to <code class="docutils literal"><span class="pre">None</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.assert_almost_equal_ignore_nan">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">assert_almost_equal_ignore_nan</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>rtol=None</em>, <em>atol=None</em>, <em>names=('a'</em>, <em>'b')</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#assert_almost_equal_ignore_nan"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.assert_almost_equal_ignore_nan" title="Permalink to this definition"></a></dt>
<dd><p>Test that two NumPy arrays are almost equal (ignoring NaN in either array).
Combines a relative and absolute measure of approximate eqality.
If either the relative or absolute check passes, the arrays are considered equal.
Including an absolute check resolves issues with the relative check where all
array values are close to zero.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>a</strong> (<em>np.ndarray</em>) – </li>
<li><strong>b</strong> (<em>np.ndarray</em>) – </li>
<li><strong>rtol</strong> (<em>None</em><em> or </em><em>float</em>) – The relative threshold. Default threshold will be used if set to <code class="docutils literal"><span class="pre">None</span></code>.</li>
<li><strong>atol</strong> (<em>None</em><em> or </em><em>float</em>) – The absolute threshold. Default threshold will be used if set to <code class="docutils literal"><span class="pre">None</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.assert_exception">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">assert_exception</code><span class="sig-paren">(</span><em>f</em>, <em>exception_type</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#assert_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.assert_exception" title="Permalink to this definition"></a></dt>
<dd><p>Test that function f will throw an exception of type given by <cite>exception_type</cite></p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.retry">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">retry</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#retry"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.retry" title="Permalink to this definition"></a></dt>
<dd><p>Retry n times before failing for stochastic test cases.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.simple_forward">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">simple_forward</code><span class="sig-paren">(</span><em>sym</em>, <em>ctx=None</em>, <em>is_train=False</em>, <em>**inputs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#simple_forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.simple_forward" title="Permalink to this definition"></a></dt>
<dd><p>A simple forward function for a symbol.</p>
<p>Primarily used in doctest to test the functionality of a symbol.
Takes NumPy arrays as inputs and outputs are also converted to NumPy arrays.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>ctx</strong> (<em>Context</em>) – If <code class="docutils literal"><span class="pre">None</span></code>, will take the default context.</li>
<li><strong>inputs</strong> (<em>keyword arguments</em>) – Mapping each input name to a NumPy array.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><ul class="simple">
<li><em>The result as a numpy array. Multiple results will</em></li>
<li><em>be returned as a list of NumPy arrays.</em></li>
</ul>
</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.numeric_grad">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">numeric_grad</code><span class="sig-paren">(</span><em>executor</em>, <em>location</em>, <em>aux_states=None</em>, <em>eps=0.0001</em>, <em>use_forward_train=True</em>, <em>dtype=<type 'numpy.float32'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#numeric_grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.numeric_grad" title="Permalink to this definition"></a></dt>
<dd><p>Calculates a numeric gradient via finite difference method.</p>
<p>Class based on Theano’s <cite>theano.gradient.numeric_grad</cite> [1]</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>executor</strong> (<a class="reference internal" href="../executor/executor.html#mxnet.executor.Executor" title="mxnet.executor.Executor"><em>Executor</em></a>) – Executor that computes the forward pass.</li>
<li><strong>location</strong> (<em>list of numpy.ndarray</em><em> or </em><em>dict of str to numpy.ndarray</em>) – Argument values used as location to compute gradient
Maps the name of arguments to the corresponding numpy.ndarray.
Value of all the arguments must be provided.</li>
<li><strong>aux_states</strong> (<em>None</em><em> or </em><em>list of numpy.ndarray</em><em> or </em><em>dict of str to numpy.ndarray</em><em>, </em><em>optional</em>) – Auxiliary states values used as location to compute gradient
Maps the name of aux_states to the corresponding numpy.ndarray.
Value of all the auxiliary arguments must be provided.</li>
<li><strong>eps</strong> (<em>float</em><em>, </em><em>optional</em>) – Epsilon for the finite-difference method.</li>
<li><strong>use_forward_train</strong> (<em>bool</em><em>, </em><em>optional</em>) – Whether to use <cite>is_train=True</cite> in testing.</li>
<li><strong>dtype</strong> (<em>np.float16</em><em> or </em><em>np.float32</em><em> or </em><em>np.float64</em>) – Datatype for mx.nd.array.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">References</p>
<p>..[1] <a class="reference external" href="https://github.com/Theano/Theano/blob/master/theano/gradient.py">https://github.com/Theano/Theano/blob/master/theano/gradient.py</a></p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.check_numeric_gradient">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">check_numeric_gradient</code><span class="sig-paren">(</span><em>sym</em>, <em>location</em>, <em>aux_states=None</em>, <em>numeric_eps=0.001</em>, <em>rtol=0.01</em>, <em>atol=None</em>, <em>grad_nodes=None</em>, <em>use_forward_train=True</em>, <em>ctx=None</em>, <em>grad_stype_dict=None</em>, <em>dtype=<type 'numpy.float32'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#check_numeric_gradient"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.check_numeric_gradient" title="Permalink to this definition"></a></dt>
<dd><p>Verify an operation by checking backward pass via finite difference method.</p>
<p>Based on Theano’s <cite>theano.gradient.verify_grad</cite> [1]</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>sym</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a>) – Symbol containing op to test</li>
<li><strong>location</strong> (<em>list</em><em> or </em><em>tuple</em><em> or </em><em>dict</em>) – <p>Argument values used as location to compute gradient</p>
<ul>
<li>if type is list of numpy.ndarray, inner elements should have the same order as mxnet.sym.list_arguments().</li>
<li>if type is dict of str -> numpy.ndarray, maps the name of arguments to the corresponding numpy.ndarray.</li>
</ul>
<p><em>In either case, value of all the arguments must be provided.</em></p>
</li>
<li><strong>aux_states</strong> (<em>list</em><em> or </em><em>tuple</em><em> or </em><em>dict</em><em>, </em><em>optional</em>) – The auxiliary states required when generating the executor for the symbol.</li>
<li><strong>numeric_eps</strong> (<em>float</em><em>, </em><em>optional</em>) – Delta for the finite difference method that approximates the gradient.</li>
<li><strong>check_eps</strong> (<em>float</em><em>, </em><em>optional</em>) – relative error eps used when comparing numeric grad to symbolic grad.</li>
<li><strong>grad_nodes</strong> (<em>None</em><em> or </em><em>list</em><em> or </em><em>tuple</em><em> or </em><em>dict</em><em>, </em><em>optional</em>) – Names of the nodes to check gradient on</li>
<li><strong>use_forward_train</strong> (<em>bool</em>) – Whether to use is_train=True when computing the finite-difference.</li>
<li><strong>ctx</strong> (<em>Context</em><em>, </em><em>optional</em>) – Check the gradient computation on the specified device.</li>
<li><strong>grad_stype_dict</strong> (<em>dict of str->str</em><em>, </em><em>optional</em>) – Storage type dictionary for gradient ndarrays.</li>
<li><strong>dtype</strong> (<em>np.float16</em><em> or </em><em>np.float32</em><em> or </em><em>np.float64</em>) – Datatype for mx.nd.array.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">References</p>
<p>[1] <a class="reference external" href="https://github.com/Theano/Theano/blob/master/theano/gradient.py">https://github.com/Theano/Theano/blob/master/theano/gradient.py</a></p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.check_symbolic_forward">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">check_symbolic_forward</code><span class="sig-paren">(</span><em>sym</em>, <em>location</em>, <em>expected</em>, <em>rtol=0.0001</em>, <em>atol=None</em>, <em>aux_states=None</em>, <em>ctx=None</em>, <em>equal_nan=False</em>, <em>dtype=<type 'numpy.float32'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#check_symbolic_forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.check_symbolic_forward" title="Permalink to this definition"></a></dt>
<dd><p>Compares a symbol’s forward results with the expected ones.
Prints error messages if the forward results are not the same as the expected ones.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>sym</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a>) – output symbol</li>
<li><strong>location</strong> (<em>list of np.ndarray</em><em> or </em><em>dict of str to np.ndarray</em>) – <p>The evaluation point</p>
<ul>
<li><dl class="first docutils">
<dt>if type is list of np.ndarray</dt>
<dd>Contains all the numpy arrays corresponding to <cite>sym.list_arguments()</cite>.</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>if type is dict of str to np.ndarray</dt>
<dd>Contains the mapping between argument names and their values.</dd>
</dl>
</li>
</ul>
</li>
<li><strong>expected</strong> (<em>list of np.ndarray</em><em> or </em><em>dict of str to np.ndarray</em>) – <p>The expected output value</p>
<ul>
<li><dl class="first docutils">
<dt>if type is list of np.ndarray</dt>
<dd>Contains arrays corresponding to exe.outputs.</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>if type is dict of str to np.ndarray</dt>
<dd>Contains mapping between sym.list_output() and exe.outputs.</dd>
</dl>
</li>
</ul>
</li>
<li><strong>check_eps</strong> (<em>float</em><em>, </em><em>optional</em>) – Relative error to check to.</li>
<li><strong>aux_states</strong> (<em>list of np.ndarray of dict</em><em>, </em><em>optional</em>) – <ul>
<li><dl class="first docutils">
<dt>if type is list of np.ndarray</dt>
<dd>Contains all the NumPy arrays corresponding to sym.list_auxiliary_states</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>if type is dict of str to np.ndarray</dt>
<dd>Contains the mapping between names of auxiliary states and their values.</dd>
</dl>
</li>
</ul>
</li>
<li><strong>ctx</strong> (<em>Context</em><em>, </em><em>optional</em>) – running context</li>
<li><strong>dtype</strong> (<em>np.float16</em><em> or </em><em>np.float32</em><em> or </em><em>np.float64</em>) – Datatype for mx.nd.array.</li>
<li><strong>equal_nan</strong> (<em>Boolean</em>) – if True, <cite>nan</cite> is a valid value for checking equivalency (ie <cite>nan</cite> == <cite>nan</cite>)</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">lhs</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s1">'lhs'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">rhs</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s1">'rhs'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">sym_dot</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">lhs</span><span class="p">,</span> <span class="n">rhs</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">mat1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">mat2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">ret_expected</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">19</span><span class="p">,</span> <span class="mi">22</span><span class="p">],</span> <span class="p">[</span><span class="mi">43</span><span class="p">,</span> <span class="mi">50</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">check_symbolic_forward</span><span class="p">(</span><span class="n">sym_dot</span><span class="p">,</span> <span class="p">[</span><span class="n">mat1</span><span class="p">,</span> <span class="n">mat2</span><span class="p">],</span> <span class="p">[</span><span class="n">ret_expected</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.check_symbolic_backward">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">check_symbolic_backward</code><span class="sig-paren">(</span><em>sym</em>, <em>location</em>, <em>out_grads</em>, <em>expected</em>, <em>rtol=1e-05</em>, <em>atol=None</em>, <em>aux_states=None</em>, <em>grad_req='write'</em>, <em>ctx=None</em>, <em>grad_stypes=None</em>, <em>equal_nan=False</em>, <em>dtype=<type 'numpy.float32'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#check_symbolic_backward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.check_symbolic_backward" title="Permalink to this definition"></a></dt>
<dd><p>Compares a symbol’s backward results with the expected ones.
Prints error messages if the backward results are not the same as the expected results.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>sym</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a>) – output symbol</li>
<li><strong>location</strong> (<em>list of np.ndarray</em><em> or </em><em>dict of str to np.ndarray</em>) – <p>The evaluation point</p>
<ul>
<li><dl class="first docutils">
<dt>if type is list of np.ndarray</dt>
<dd>Contains all the NumPy arrays corresponding to <code class="docutils literal"><span class="pre">mx.sym.list_arguments</span></code>.</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>if type is dict of str to np.ndarray</dt>
<dd>Contains the mapping between argument names and their values.</dd>
</dl>
</li>
</ul>
</li>
<li><strong>out_grads</strong> (<em>None</em><em> or </em><em>list of np.ndarray</em><em> or </em><em>dict of str to np.ndarray</em>) – <p>NumPys arrays corresponding to sym.outputs for incomming gradient.</p>
<ul>
<li><dl class="first docutils">
<dt>if type is list of np.ndarray</dt>
<dd>Contains arrays corresponding to <code class="docutils literal"><span class="pre">exe.outputs</span></code>.</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>if type is dict of str to np.ndarray</dt>
<dd>contains mapping between mxnet.sym.list_output() and Executor.outputs</dd>
</dl>
</li>
</ul>
</li>
<li><strong>expected</strong> (<em>list of np.ndarray</em><em> or </em><em>dict of str to np.ndarray</em>) – <p>expected gradient values</p>
<ul>
<li><dl class="first docutils">
<dt>if type is list of np.ndarray</dt>
<dd>Contains arrays corresponding to exe.grad_arrays</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>if type is dict of str to np.ndarray</dt>
<dd>Contains mapping between <code class="docutils literal"><span class="pre">sym.list_arguments()</span></code> and exe.outputs.</dd>
</dl>
</li>
</ul>
</li>
<li><strong>check_eps</strong> (<em>float</em><em>, </em><em>optional</em>) – Relative error to check to.</li>
<li><strong>aux_states</strong> (<em>list of np.ndarray</em><em> or </em><em>dict of str to np.ndarray</em>) – </li>
<li><strong>grad_req</strong> (<em>str</em><em> or </em><em>list of str</em><em> or </em><em>dict of str to str</em><em>, </em><em>optional</em>) – Gradient requirements. ‘write’, ‘add’ or ‘null’.</li>
<li><strong>ctx</strong> (<em>Context</em><em>, </em><em>optional</em>) – Running context.</li>
<li><strong>grad_stypes</strong> (<em>dict of str->str</em>) – dictionary of mapping argument name to stype for the gradient</li>
<li><strong>equal_nan</strong> (<em>Boolean</em>) – if True, <cite>nan</cite> is a valid value for checking equivalency (ie <cite>nan</cite> == <cite>nan</cite>)</li>
<li><strong>dtype</strong> (<em>np.float16</em><em> or </em><em>np.float32</em><em> or </em><em>np.float64</em>) – Datatype for mx.nd.array.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">lhs</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s1">'lhs'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">rhs</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s1">'rhs'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">sym_add</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">elemwise_add</span><span class="p">(</span><span class="n">lhs</span><span class="p">,</span> <span class="n">rhs</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">mat1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">mat2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">grad1</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">grad2</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">exec_add</span> <span class="o">=</span> <span class="n">sym_add</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">default_context</span><span class="p">(),</span> <span class="n">args</span><span class="o">=</span><span class="p">{</span><span class="s1">'lhs'</span><span class="p">:</span> <span class="n">mat1</span><span class="p">,</span> <span class="s1">'rhs'</span><span class="p">:</span> <span class="n">mat2</span><span class="p">},</span>
<span class="gp">... </span><span class="n">args_grad</span><span class="o">=</span><span class="p">{</span><span class="s1">'lhs'</span><span class="p">:</span> <span class="n">grad1</span><span class="p">,</span> <span class="s1">'rhs'</span><span class="p">:</span> <span class="n">grad2</span><span class="p">},</span> <span class="n">grad_req</span><span class="o">=</span><span class="p">{</span><span class="s1">'lhs'</span><span class="p">:</span> <span class="s1">'write'</span><span class="p">,</span> <span class="s1">'rhs'</span><span class="p">:</span> <span class="s1">'write'</span><span class="p">})</span>
<span class="gp">>>> </span><span class="n">exec_add</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">is_train</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">ograd</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">grad_expected</span> <span class="o">=</span> <span class="n">ograd</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">check_symbolic_backward</span><span class="p">(</span><span class="n">sym_add</span><span class="p">,</span> <span class="p">[</span><span class="n">mat1</span><span class="p">,</span> <span class="n">mat2</span><span class="p">],</span> <span class="p">[</span><span class="n">ograd</span><span class="p">],</span> <span class="p">[</span><span class="n">grad_expected</span><span class="p">,</span> <span class="n">grad_expected</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.check_speed">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">check_speed</code><span class="sig-paren">(</span><em>sym</em>, <em>location=None</em>, <em>ctx=None</em>, <em>N=20</em>, <em>grad_req=None</em>, <em>typ='whole'</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#check_speed"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.check_speed" title="Permalink to this definition"></a></dt>
<dd><p>Check the running speed of a symbol.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>sym</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a>) – Symbol to run the speed test.</li>
<li><strong>location</strong> (<em>none</em><em> or </em><em>dict of str to np.ndarray</em>) – Location to evaluate the inner executor.</li>
<li><strong>ctx</strong> (<em>Context</em>) – Running context.</li>
<li><strong>N</strong> (<em>int</em><em>, </em><em>optional</em>) – Repeat times.</li>
<li><strong>grad_req</strong> (<em>None</em><em> or </em><em>str</em><em> or </em><em>list of str</em><em> or </em><em>dict of str to str</em><em>, </em><em>optional</em>) – Gradient requirements.</li>
<li><strong>typ</strong> (<em>str</em><em>, </em><em>optional</em>) – <p>“whole” or “forward”</p>
<ul>
<li><dl class="first docutils">
<dt>“whole”</dt>
<dd>Test the forward_backward speed.</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>“forward”</dt>
<dd>Only test the forward speed.</dd>
</dl>
</li>
</ul>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.check_consistency">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">check_consistency</code><span class="sig-paren">(</span><em>sym</em>, <em>ctx_list</em>, <em>scale=1.0</em>, <em>grad_req='write'</em>, <em>arg_params=None</em>, <em>aux_params=None</em>, <em>tol=None</em>, <em>raise_on_err=True</em>, <em>ground_truth=None</em>, <em>equal_nan=False</em>, <em>use_uniform=False</em>, <em>rand_type=<type 'numpy.float64'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#check_consistency"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.check_consistency" title="Permalink to this definition"></a></dt>
<dd><p>Check symbol gives the same output for different running context</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>sym</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a><em> or </em><em>list of Symbols</em>) – Symbol(s) to run the consistency test.</li>
<li><strong>ctx_list</strong> (<em>list</em>) – Running context. See example for more detail.</li>
<li><strong>scale</strong> (<em>float</em><em>, </em><em>optional</em>) – Standard deviation of the inner normal distribution. Used in initialization.</li>
<li><strong>grad_req</strong> (<em>str</em><em> or </em><em>list of str</em><em> or </em><em>dict of str to str</em>) – Gradient requirement.</li>
<li><strong>use_unifrom</strong> (<em>bool</em>) – Optional, When flag set to true,
random input data generated follows uniform distribution,
not normal distribution</li>
<li><strong>rand_type</strong> (<em>np.dtype</em>) – casts the randomly generated data to this type
Optional, when input data is passed via arg_params,
defaults to np.float64 (numpy float default)</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># create the symbol</span>
<span class="gp">>>> </span><span class="n">sym</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">Convolution</span><span class="p">(</span><span class="n">num_filter</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">kernel</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">name</span><span class="o">=</span><span class="s1">'conv'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="c1"># initialize the running context</span>
<span class="gp">>>> </span><span class="n">ctx_list</span> <span class="o">=</span><span class="p">[{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'conv_data'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'conv_data'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'conv_data'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'conv_data'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'conv_data'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'conv_data'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float16</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'conv_data'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'conv_data'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'conv_data'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'conv_data'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">}}]</span>
<span class="gp">>>> </span><span class="n">check_consistency</span><span class="p">(</span><span class="n">sym</span><span class="p">,</span> <span class="n">ctx_list</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">sym</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">Concat</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'concat'</span><span class="p">,</span> <span class="n">num_args</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">ctx_list</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float16</span><span class="p">,</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float16</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">}},</span> <span class="p">{</span><span class="s1">'ctx'</span><span class="p">:</span> <span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="s1">'type_dict'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'concat_arg0'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="s1">'concat_arg1'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">}}]</span>
<span class="gp">>>> </span><span class="n">check_consistency</span><span class="p">(</span><span class="n">sym</span><span class="p">,</span> <span class="n">ctx_list</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.list_gpus">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">list_gpus</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#list_gpus"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.list_gpus" title="Permalink to this definition"></a></dt>
<dd><p>Return a list of GPUs</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">If there are n GPUs, then return a list [0,1,...,n-1]. Otherwise returns
[].</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list of int</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.download">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">download</code><span class="sig-paren">(</span><em>url</em>, <em>fname=None</em>, <em>dirname=None</em>, <em>overwrite=False</em>, <em>retries=5</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#download"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.download" title="Permalink to this definition"></a></dt>
<dd><p>Download an given URL</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>url</strong> (<em>str</em>) – URL to download</li>
<li><strong>fname</strong> (<em>str</em><em>, </em><em>optional</em>) – filename of the downloaded file. If None, then will guess a filename
from url.</li>
<li><strong>dirname</strong> (<em>str</em><em>, </em><em>optional</em>) – output directory name. If None, then guess from fname or use the current
directory</li>
<li><strong>overwrite</strong> (<em>bool</em><em>, </em><em>optional</em>) – Default is false, which means skipping download if the local file
exists. If true, then download the url to overwrite the local file if
exists.</li>
<li><strong>retries</strong> (<em>integer</em><em>, </em><em>default 5</em>) – The number of times to attempt the download in case of failure or non 200 return codes</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The filename of the downloaded file</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_mnist">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_mnist</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_mnist"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_mnist" title="Permalink to this definition"></a></dt>
<dd><p>Download and load the MNIST dataset</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A dict containing the data</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">dict</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_mnist_pkl">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_mnist_pkl</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_mnist_pkl"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_mnist_pkl" title="Permalink to this definition"></a></dt>
<dd><p>Downloads MNIST dataset as a pkl.gz into a directory in the current directory
with the name <cite>data</cite></p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_mnist_ubyte">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_mnist_ubyte</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_mnist_ubyte"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_mnist_ubyte" title="Permalink to this definition"></a></dt>
<dd><p>Downloads ubyte version of the MNIST dataset into a directory in the current directory
with the name <cite>data</cite> and extracts all files in the zip archive to this directory.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_cifar10">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_cifar10</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_cifar10"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_cifar10" title="Permalink to this definition"></a></dt>
<dd><p>Downloads CIFAR10 dataset into a directory in the current directory with the name <cite>data</cite>,
and then extracts all files into the directory <cite>data/cifar</cite>.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_mnist_iterator">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_mnist_iterator</code><span class="sig-paren">(</span><em>batch_size</em>, <em>input_shape</em>, <em>num_parts=1</em>, <em>part_index=0</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_mnist_iterator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_mnist_iterator" title="Permalink to this definition"></a></dt>
<dd><p>Returns training and validation iterators for MNIST dataset</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_zip_data">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_zip_data</code><span class="sig-paren">(</span><em>data_dir</em>, <em>url</em>, <em>data_origin_name</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_zip_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_zip_data" title="Permalink to this definition"></a></dt>
<dd><p>Download and extract zip data.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>data_dir</strong> (<em>str</em>) – Absolute or relative path of the directory name to store zip files</li>
<li><strong>url</strong> (<em>str</em>) – URL to download data from</li>
<li><strong>data_origin_name</strong> (<em>str</em>) – Name of the downloaded zip file</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">get_zip_data</span><span class="p">(</span><span class="s2">"data_dir"</span><span class="p">,</span>
<span class="go"> "http://files.grouplens.org/datasets/movielens/ml-10m.zip",</span>
<span class="go"> "ml-10m.zip")</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_bz2_data">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_bz2_data</code><span class="sig-paren">(</span><em>data_dir</em>, <em>data_name</em>, <em>url</em>, <em>data_origin_name</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_bz2_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_bz2_data" title="Permalink to this definition"></a></dt>
<dd><p>Download and extract bz2 data.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>data_dir</strong> (<em>str</em>) – Absolute or relative path of the directory name to store bz2 files</li>
<li><strong>data_name</strong> (<em>str</em>) – Name of the output file in which bz2 contents will be extracted</li>
<li><strong>url</strong> (<em>str</em>) – URL to download data from</li>
<li><strong>data_origin_name</strong> (<em>str</em>) – Name of the downloaded b2 file</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">get_bz2_data</span><span class="p">(</span><span class="s2">"data_dir"</span><span class="p">,</span> <span class="s2">"kdda.t"</span><span class="p">,</span>
<span class="go"> "https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary/kdda.t.bz2",</span>
<span class="go"> "kdda.t.bz2")</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.set_env_var">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">set_env_var</code><span class="sig-paren">(</span><em>key</em>, <em>val</em>, <em>default_val=''</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#set_env_var"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.set_env_var" title="Permalink to this definition"></a></dt>
<dd><p>Set environment variable</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>key</strong> (<em>str</em>) – Env var to set</li>
<li><strong>val</strong> (<em>str</em>) – New value assigned to the env var</li>
<li><strong>default_val</strong> (<em>str</em><em>, </em><em>optional</em>) – Default value returned if the env var doesn’t exist</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The value of env var before it is set to the new value</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.same_array">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">same_array</code><span class="sig-paren">(</span><em>array1</em>, <em>array2</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#same_array"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.same_array" title="Permalink to this definition"></a></dt>
<dd><p>Check whether two NDArrays sharing the same memory block</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>array1</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – First NDArray to be checked</li>
<li><strong>array2</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – Second NDArray to be checked</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Whether two NDArrays share the same memory</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.discard_stderr">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">discard_stderr</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwds</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#discard_stderr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.discard_stderr" title="Permalink to this definition"></a></dt>
<dd><p>Discards error output of a routine if invoked as:</p>
<dl class="docutils">
<dt>with discard_stderr():</dt>
<dd>...</dd>
</dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.test_utils.DummyIter">
<em class="property">class </em><code class="descclassname">mxnet.test_utils.</code><code class="descname">DummyIter</code><span class="sig-paren">(</span><em>real_iter</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#DummyIter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.DummyIter" title="Permalink to this definition"></a></dt>
<dd><p>A dummy iterator that always returns the same batch of data
(the first data batch of the real data iter). This is usually used for speed testing.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>real_iter</strong> (<em>mx.io.DataIter</em>) – The real data iterator where the first batch of data comes from</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mxnet.test_utils.DummyIter.next">
<code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#DummyIter.next"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.DummyIter.next" title="Permalink to this definition"></a></dt>
<dd><p>Get a data batch from iterator. The first data batch of real iter is always returned.
StopIteration will never be raised.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The data of next batch.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">DataBatch</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.gen_buckets_probs_with_ppf">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">gen_buckets_probs_with_ppf</code><span class="sig-paren">(</span><em>ppf</em>, <em>nbuckets</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#gen_buckets_probs_with_ppf"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.gen_buckets_probs_with_ppf" title="Permalink to this definition"></a></dt>
<dd><dl class="docutils">
<dt>Generate the buckets and probabilities for chi_square test when the ppf (Quantile function)</dt>
<dd>is specified.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>ppf</strong> (<em>function</em>) – The Quantile function that takes a probability and maps it back to a value.
It’s the inverse of the cdf function</li>
<li><strong>nbuckets</strong> (<em>int</em>) – size of the buckets</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><ul class="simple">
<li><strong>buckets</strong> (<em>list of tuple</em>) – The generated buckets</li>
<li><strong>probs</strong> (<em>list</em>) – The generate probabilities</li>
</ul>
</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.mean_check">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">mean_check</code><span class="sig-paren">(</span><em>generator</em>, <em>mu</em>, <em>sigma</em>, <em>nsamples=1000000</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#mean_check"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.mean_check" title="Permalink to this definition"></a></dt>
<dd><p>Test the generator by matching the mean.</p>
<dl class="docutils">
<dt>We test the sample mean by checking if it falls inside the range</dt>
<dd>(mu - 3 * sigma / sqrt(n), mu + 3 * sigma / sqrt(n))</dd>
</dl>
<p>References:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@incollection</span><span class="p">{</span><span class="n">goucher2009beautiful</span><span class="p">,</span>
<span class="n">title</span><span class="o">=</span><span class="p">{</span><span class="n">Beautiful</span> <span class="n">Testing</span><span class="p">:</span> <span class="n">Leading</span> <span class="n">Professionals</span> <span class="n">Reveal</span> <span class="n">How</span> <span class="n">They</span> <span class="n">Improve</span> <span class="n">Software</span><span class="p">},</span>
<span class="n">author</span><span class="o">=</span><span class="p">{</span><span class="n">Goucher</span><span class="p">,</span> <span class="n">Adam</span> <span class="ow">and</span> <span class="n">Riley</span><span class="p">,</span> <span class="n">Tim</span><span class="p">},</span>
<span class="n">year</span><span class="o">=</span><span class="p">{</span><span class="mi">2009</span><span class="p">},</span>
<span class="n">chapter</span><span class="o">=</span><span class="mi">10</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Examples:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">generator</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">x</span><span class="p">)</span>
<span class="n">mean_check_ret</span> <span class="o">=</span> <span class="n">mean_check</span><span class="p">(</span><span class="n">generator</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>generator</strong> (<em>function</em>) – The generator function. It’s expected to generate N i.i.d samples by calling generator(N).</li>
<li><strong>mu</strong> (<em>float</em>) – </li>
<li><strong>sigma</strong> (<em>float</em>) – </li>
<li><strong>nsamples</strong> (<em>int</em>) – </li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>ret</strong> – Whether the mean test succeeds</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.get_im2rec_path">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">get_im2rec_path</code><span class="sig-paren">(</span><em>home_env='MXNET_HOME'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#get_im2rec_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.get_im2rec_path" title="Permalink to this definition"></a></dt>
<dd><p>Get path to the im2rec.py tool</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>home_env</strong> (<em>str</em>) – Env variable that holds the path to the MXNET folder</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The path to im2rec.py</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.var_check">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">var_check</code><span class="sig-paren">(</span><em>generator</em>, <em>sigma</em>, <em>nsamples=1000000</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#var_check"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.var_check" title="Permalink to this definition"></a></dt>
<dd><p>Test the generator by matching the variance.
It will need a large number of samples and is not recommended to use</p>
<dl class="docutils">
<dt>We test the sample variance by checking if it falls inside the range</dt>
<dd>(sigma^2 - 3 * sqrt(2 * sigma^4 / (n-1)), sigma^2 + 3 * sqrt(2 * sigma^4 / (n-1)))</dd>
</dl>
<p>References:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@incollection</span><span class="p">{</span><span class="n">goucher2009beautiful</span><span class="p">,</span>
<span class="n">title</span><span class="o">=</span><span class="p">{</span><span class="n">Beautiful</span> <span class="n">Testing</span><span class="p">:</span> <span class="n">Leading</span> <span class="n">Professionals</span> <span class="n">Reveal</span> <span class="n">How</span> <span class="n">They</span> <span class="n">Improve</span> <span class="n">Software</span><span class="p">},</span>
<span class="n">author</span><span class="o">=</span><span class="p">{</span><span class="n">Goucher</span><span class="p">,</span> <span class="n">Adam</span> <span class="ow">and</span> <span class="n">Riley</span><span class="p">,</span> <span class="n">Tim</span><span class="p">},</span>
<span class="n">year</span><span class="o">=</span><span class="p">{</span><span class="mi">2009</span><span class="p">},</span>
<span class="n">chapter</span><span class="o">=</span><span class="mi">10</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Examples:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">generator</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">x</span><span class="p">)</span>
<span class="n">var_check_ret</span> <span class="o">=</span> <span class="n">var_check</span><span class="p">(</span><span class="n">generator</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>generator</strong> (<em>function</em>) – The generator function. It’s expected to generate N i.i.d samples by calling generator(N).</li>
<li><strong>sigma</strong> (<em>float</em>) – </li>
<li><strong>nsamples</strong> (<em>int</em>) – </li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>ret</strong> – Whether the variance test succeeds</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.chi_square_check">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">chi_square_check</code><span class="sig-paren">(</span><em>generator</em>, <em>buckets</em>, <em>probs</em>, <em>nsamples=1000000</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#chi_square_check"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.chi_square_check" title="Permalink to this definition"></a></dt>
<dd><p>Run the chi-square test for the generator. The generator can be both continuous and discrete.</p>
<p>If the generator is continuous, the buckets should contain tuples of (range_min, range_max) and the probs should be the corresponding ideal probability within the specific ranges. Otherwise, the buckets should be the possible output of the discrete distribution and the probs should be groud-truth probability.</p>
<p>Usually the user is required to specify the probs parameter.</p>
<p>After obtatining the p value, we could further use the standard p > 0.05 threshold to get the final result.</p>
<p>Examples:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">buckets</span><span class="p">,</span> <span class="n">probs</span> <span class="o">=</span> <span class="n">gen_buckets_probs_with_ppf</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">ss</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">5</span><span class="p">)</span>
<span class="n">generator</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">x</span><span class="p">)</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">chi_square_check</span><span class="p">(</span><span class="n">generator</span><span class="o">=</span><span class="n">generator</span><span class="p">,</span> <span class="n">buckets</span><span class="o">=</span><span class="n">buckets</span><span class="p">,</span> <span class="n">probs</span><span class="o">=</span><span class="n">probs</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">p</span> <span class="o">></span> <span class="mf">0.05</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>generator</strong> (<em>function</em>) – A function that is assumed to generate i.i.d samples from a specific distribution.
generator(N) should generate N random samples.</li>
<li><strong>buckets</strong> (<em>list of tuple</em><em> or </em><em>list of number</em>) – The buckets to run the chi-square the test. Make sure that the buckets cover
the whole range of the distribution. Also, the buckets must be in ascending order and have
no intersection</li>
<li><strong>probs</strong> (<em>list</em><em> or </em><em>tuple</em>) – The ground-truth probability of the random value fall in a specific bucket.</li>
<li><strong>nsamples</strong> (<em>int</em>) – The number of samples to generate for the testing</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><ul class="simple">
<li><strong>p</strong> (<em>float</em>) – p value that the generator has the expected distribution.
A higher value indicates a larger confidence</li>
<li><strong>obs_freq</strong> (<em>list</em>) – Observed frequency of buckets</li>
<li><strong>expected_freq</strong> (<em>list</em>) – The expected (ground-truth) frequency of the buckets</li>
</ul>
</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.verify_generator">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">verify_generator</code><span class="sig-paren">(</span><em>generator</em>, <em>buckets</em>, <em>probs</em>, <em>nsamples=1000000</em>, <em>nrepeat=5</em>, <em>success_rate=0.15</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#verify_generator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.verify_generator" title="Permalink to this definition"></a></dt>
<dd><p>Verify whether the generator is correct using chi-square testing.</p>
<dl class="docutils">
<dt>The test is repeated for “nrepeat” times and we check if the success rate is</dt>
<dd>above the threshold (25% by default).</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>generator</strong> (<em>function</em>) – <dl class="docutils">
<dt>A function that is assumed to generate i.i.d samples from a specific distribution.</dt>
<dd>generator(N) should generate N random samples.</dd>
</dl>
</li>
<li><strong>buckets</strong> (<em>list of tuple</em><em> or </em><em>list of number</em>) – <dl class="docutils">
<dt>The buckets to run the chi-square the test. Make sure that the buckets cover</dt>
<dd>the whole range of the distribution. Also, the buckets must be in ascending order and
have no intersection</dd>
</dl>
</li>
<li><strong>probs</strong> (<em>list</em><em> or </em><em>tuple</em>) – The ground-truth probability of the random value fall in a specific bucket.</li>
<li><strong>nsamples</strong> (<em>int</em>) – The number of samples to generate for the testing</li>
<li><strong>nrepeat</strong> (<em>int</em>) – The times to repeat the test</li>
<li><strong>success_rate</strong> (<em>float</em>) – The desired success rate</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>cs_ret_l</strong> – The p values of the chi-square test.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.compare_ndarray_tuple">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">compare_ndarray_tuple</code><span class="sig-paren">(</span><em>t1</em>, <em>t2</em>, <em>rtol=None</em>, <em>atol=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#compare_ndarray_tuple"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.compare_ndarray_tuple" title="Permalink to this definition"></a></dt>
<dd><p>Compare ndarray tuple.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.test_utils.compare_optimizer">
<code class="descclassname">mxnet.test_utils.</code><code class="descname">compare_optimizer</code><span class="sig-paren">(</span><em>opt1</em>, <em>opt2</em>, <em>shape</em>, <em>dtype</em>, <em>w_stype='default'</em>, <em>g_stype='default'</em>, <em>rtol=0.0001</em>, <em>atol=1e-05</em>, <em>compare_states=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#compare_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.compare_optimizer" title="Permalink to this definition"></a></dt>
<dd><p>Compare opt1 and opt2.</p>
</dd></dl>
<dl class="class">
<dt id="mxnet.test_utils.EnvManager">
<em class="property">class </em><code class="descclassname">mxnet.test_utils.</code><code class="descname">EnvManager</code><span class="sig-paren">(</span><em>key</em>, <em>val</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/test_utils.html#EnvManager"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.test_utils.EnvManager" title="Permalink to this definition"></a></dt>
<dd><p>Environment variable setter and unsetter via with idiom</p>
</dd></dl>
<script>auto_index("api-reference");</script></div>
</div>
</div>
</div>
<div aria-label="main navigation" class="sphinxsidebar rightsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../../../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Test Utilities</a><ul>
<li><a class="reference internal" href="#api-reference">API Reference</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div><div class="footer">
<div class="section-disclaimer">
<div class="container">
<div>
<img height="60" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/apache_incubator_logo.png"/>
<p>
Apache MXNet is an effort undergoing incubation at The Apache Software Foundation (ASF), <strong>sponsored by the <i>Apache Incubator</i></strong>. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
</p>
<p>
"Copyright © 2017-2018, The Apache Software Foundation
Apache MXNet, MXNet, Apache, the Apache feather, and the Apache MXNet project logo are either registered trademarks or trademarks of the Apache Software Foundation."
</p>
</div>
</div>
</div>
</div> <!-- pagename != index -->
</div>
<script crossorigin="anonymous" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../../../_static/js/sidebar.js" type="text/javascript"></script>
<script src="../../../_static/js/search.js" type="text/javascript"></script>
<script src="../../../_static/js/navbar.js" type="text/javascript"></script>
<script src="../../../_static/js/clipboard.min.js" type="text/javascript"></script>
<script src="../../../_static/js/copycode.js" type="text/javascript"></script>
<script src="../../../_static/js/page.js" type="text/javascript"></script>
<script src="../../../_static/js/docversion.js" type="text/javascript"></script>
<script type="text/javascript">
$('body').ready(function () {
$('body').css('visibility', 'visible');
});
</script>
</body>
</html>