[incubator-mxnet] 17/42: Fix (#15188)
This is an automated email from the ASF dual-hosted git repository. haoj pushed a commit to branch numpy in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git commit ab38acbdc38b12a05061411e7b1b8d7fbb913ea1 Author: reminisce AuthorDate: Sun Jun 9 08:56:16 2019 -0700 Fix (#15188) --- example/numpy/numpy_semantics.ipynb| 308 + python/mxnet/gluon/data/dataloader.py | 10 +- python/mxnet/gluon/data/vision/datasets.py | 5 +- python/mxnet/numpy/multiarray.py | 19 +- python/mxnet/numpy_extension/__init__.py | 7 +- python/mxnet/util.py | 47 +++-- 6 files changed, 369 insertions(+), 27 deletions(-) diff --git a/example/numpy/numpy_semantics.ipynb b/example/numpy/numpy_semantics.ipynb new file mode 100644 index 000..1cec51f --- /dev/null +++ b/example/numpy/numpy_semantics.ipynb @@ -0,0 +1,308 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"# How to Use NumPy Semantics in MXNet with `mxnet.numpy` Module\n", +"\n", +"## NumPy Shape Semantics\n", +"\n", +"### Example \n", +"\n", +"| Shape Example | MXNet (before) | MXNet/NumPy |\n", +"|:---:|:---:|:---:|\n", +"| `()` | unknown | Scalar tensor |\n", +"| `(2, 0, 1)` | Second dimension unknown | Zero-size tensor |\n", +"| `None`(Python) | N/A | Unknown |\n", +"| `(2, -1, 0)`(C++) | N/A | Second dim uknown|\n", +"\n", +"### Affected modules\n", +"- Shape inference: imperative, symbolic, Gluon\n", +"- Legacy operators (not recommended to use)\n", +"- MXNet/NumPy operators\n", +"\n", +"## NumPy Array Semantics\n", +"**Definition:** The type of created ndarrays is `mxnet.numpy.ndarray`/`mxnet.symbol.numpy._Symbol`, instead of `mxnet.ndarray.NDArray`/`mxnet.symbol.Symbol` (only affects Gluon modules).\n", +"- Block/HybridBlock\n", +"- Parameter creation and initialization.\n", +"- Inputs/outputs (symbol/ndarray) of `__call__`/`forward`/`hybrid_forward`.\n", +"- Computational graph construction.\n", +"- Dataloader\n", +"\n", +"## Dependency of Two Types of Semantics\n", +"- It is required to keep NumPy shape semantics active while activating NumPy array semantics.\n", +"- Deactivating NumPy shape semantics while NumPy array semantics is still active is not allowed." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"import logging\n", +"import mxnet as mx\n", +"from mxnet import np, npx, gluon\n", +"\n", +"logging.basicConfig(level=logging.INFO)\n", +"\n", +"try:\n", +"npx.set_np(shape=False, array=True)\n", +"except ValueError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"## How to Enable NumPy Shape semantics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"a = mx.nd.random.uniform(shape=())\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"c = np.random.uniform()\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"npx.set_np(shape=True, array=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"a = mx.nd.random.uniform(shape=())\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"c = np.random.uniform()\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"\n", +"print('type(a) =', type(a))\n", +"print('a.shape = ', a.shape)\n", +"print('a.size = ', a.size)\n", +"\n", +"print('type(b) =', type(b))\n", +"print('b.shape = ', b.shape)\n", +"print('b.size = ', b.size)\n", +"\n", +"print('type(c) =', type(c))\n", +"print('c.shape = ', c.shape)\n", +"print('c.size = ', c.size)\n", +"\n", +"print('type(d) =', type(d))\n", +"print('d.shape = ', d.shape)\n", +"print('d.size = ', d.size)" + ] + }, + { + "cell_type": "markdown", +
[incubator-mxnet] 17/42: Fix (#15188)
This is an automated email from the ASF dual-hosted git repository. haoj pushed a commit to branch numpy in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git commit ddc8b58e1d85a1297e18b8f9d1c55bbbc6aad467 Author: reminisce AuthorDate: Sun Jun 9 08:56:16 2019 -0700 Fix (#15188) --- example/numpy/numpy_semantics.ipynb| 308 + python/mxnet/gluon/data/dataloader.py | 10 +- python/mxnet/gluon/data/vision/datasets.py | 5 +- python/mxnet/numpy/multiarray.py | 19 +- python/mxnet/numpy_extension/__init__.py | 7 +- python/mxnet/util.py | 47 +++-- 6 files changed, 369 insertions(+), 27 deletions(-) diff --git a/example/numpy/numpy_semantics.ipynb b/example/numpy/numpy_semantics.ipynb new file mode 100644 index 000..1cec51f --- /dev/null +++ b/example/numpy/numpy_semantics.ipynb @@ -0,0 +1,308 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"# How to Use NumPy Semantics in MXNet with `mxnet.numpy` Module\n", +"\n", +"## NumPy Shape Semantics\n", +"\n", +"### Example \n", +"\n", +"| Shape Example | MXNet (before) | MXNet/NumPy |\n", +"|:---:|:---:|:---:|\n", +"| `()` | unknown | Scalar tensor |\n", +"| `(2, 0, 1)` | Second dimension unknown | Zero-size tensor |\n", +"| `None`(Python) | N/A | Unknown |\n", +"| `(2, -1, 0)`(C++) | N/A | Second dim uknown|\n", +"\n", +"### Affected modules\n", +"- Shape inference: imperative, symbolic, Gluon\n", +"- Legacy operators (not recommended to use)\n", +"- MXNet/NumPy operators\n", +"\n", +"## NumPy Array Semantics\n", +"**Definition:** The type of created ndarrays is `mxnet.numpy.ndarray`/`mxnet.symbol.numpy._Symbol`, instead of `mxnet.ndarray.NDArray`/`mxnet.symbol.Symbol` (only affects Gluon modules).\n", +"- Block/HybridBlock\n", +"- Parameter creation and initialization.\n", +"- Inputs/outputs (symbol/ndarray) of `__call__`/`forward`/`hybrid_forward`.\n", +"- Computational graph construction.\n", +"- Dataloader\n", +"\n", +"## Dependency of Two Types of Semantics\n", +"- It is required to keep NumPy shape semantics active while activating NumPy array semantics.\n", +"- Deactivating NumPy shape semantics while NumPy array semantics is still active is not allowed." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"import logging\n", +"import mxnet as mx\n", +"from mxnet import np, npx, gluon\n", +"\n", +"logging.basicConfig(level=logging.INFO)\n", +"\n", +"try:\n", +"npx.set_np(shape=False, array=True)\n", +"except ValueError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"## How to Enable NumPy Shape semantics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"a = mx.nd.random.uniform(shape=())\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"c = np.random.uniform()\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"npx.set_np(shape=True, array=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"a = mx.nd.random.uniform(shape=())\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"c = np.random.uniform()\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"\n", +"print('type(a) =', type(a))\n", +"print('a.shape = ', a.shape)\n", +"print('a.size = ', a.size)\n", +"\n", +"print('type(b) =', type(b))\n", +"print('b.shape = ', b.shape)\n", +"print('b.size = ', b.size)\n", +"\n", +"print('type(c) =', type(c))\n", +"print('c.shape = ', c.shape)\n", +"print('c.size = ', c.size)\n", +"\n", +"print('type(d) =', type(d))\n", +"print('d.shape = ', d.shape)\n", +"print('d.size = ', d.size)" + ] + }, + { + "cell_type": "markdown", +
[incubator-mxnet] 17/42: Fix (#15188)
This is an automated email from the ASF dual-hosted git repository. haoj pushed a commit to branch numpy in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git commit 49feb63c1b21d9665ae1d53264b4ae0d6f869958 Author: reminisce AuthorDate: Sun Jun 9 08:56:16 2019 -0700 Fix (#15188) --- example/numpy/numpy_semantics.ipynb| 308 + python/mxnet/gluon/data/dataloader.py | 10 +- python/mxnet/gluon/data/vision/datasets.py | 5 +- python/mxnet/numpy/multiarray.py | 19 +- python/mxnet/numpy_extension/__init__.py | 7 +- python/mxnet/util.py | 47 +++-- 6 files changed, 369 insertions(+), 27 deletions(-) diff --git a/example/numpy/numpy_semantics.ipynb b/example/numpy/numpy_semantics.ipynb new file mode 100644 index 000..1cec51f --- /dev/null +++ b/example/numpy/numpy_semantics.ipynb @@ -0,0 +1,308 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"# How to Use NumPy Semantics in MXNet with `mxnet.numpy` Module\n", +"\n", +"## NumPy Shape Semantics\n", +"\n", +"### Example \n", +"\n", +"| Shape Example | MXNet (before) | MXNet/NumPy |\n", +"|:---:|:---:|:---:|\n", +"| `()` | unknown | Scalar tensor |\n", +"| `(2, 0, 1)` | Second dimension unknown | Zero-size tensor |\n", +"| `None`(Python) | N/A | Unknown |\n", +"| `(2, -1, 0)`(C++) | N/A | Second dim uknown|\n", +"\n", +"### Affected modules\n", +"- Shape inference: imperative, symbolic, Gluon\n", +"- Legacy operators (not recommended to use)\n", +"- MXNet/NumPy operators\n", +"\n", +"## NumPy Array Semantics\n", +"**Definition:** The type of created ndarrays is `mxnet.numpy.ndarray`/`mxnet.symbol.numpy._Symbol`, instead of `mxnet.ndarray.NDArray`/`mxnet.symbol.Symbol` (only affects Gluon modules).\n", +"- Block/HybridBlock\n", +"- Parameter creation and initialization.\n", +"- Inputs/outputs (symbol/ndarray) of `__call__`/`forward`/`hybrid_forward`.\n", +"- Computational graph construction.\n", +"- Dataloader\n", +"\n", +"## Dependency of Two Types of Semantics\n", +"- It is required to keep NumPy shape semantics active while activating NumPy array semantics.\n", +"- Deactivating NumPy shape semantics while NumPy array semantics is still active is not allowed." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"import logging\n", +"import mxnet as mx\n", +"from mxnet import np, npx, gluon\n", +"\n", +"logging.basicConfig(level=logging.INFO)\n", +"\n", +"try:\n", +"npx.set_np(shape=False, array=True)\n", +"except ValueError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"## How to Enable NumPy Shape semantics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"a = mx.nd.random.uniform(shape=())\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"c = np.random.uniform()\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"npx.set_np(shape=True, array=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"a = mx.nd.random.uniform(shape=())\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"c = np.random.uniform()\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"\n", +"print('type(a) =', type(a))\n", +"print('a.shape = ', a.shape)\n", +"print('a.size = ', a.size)\n", +"\n", +"print('type(b) =', type(b))\n", +"print('b.shape = ', b.shape)\n", +"print('b.size = ', b.size)\n", +"\n", +"print('type(c) =', type(c))\n", +"print('c.shape = ', c.shape)\n", +"print('c.size = ', c.size)\n", +"\n", +"print('type(d) =', type(d))\n", +"print('d.shape = ', d.shape)\n", +"print('d.size = ', d.size)" + ] + }, + { + "cell_type": "markdown", +
[incubator-mxnet] 17/42: Fix (#15188)
This is an automated email from the ASF dual-hosted git repository. haoj pushed a commit to branch numpy in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git commit 64abcf4dd13b39200e9f4af28d5e39a5f24c4b13 Author: reminisce AuthorDate: Sun Jun 9 08:56:16 2019 -0700 Fix (#15188) --- example/numpy/numpy_semantics.ipynb| 308 + python/mxnet/gluon/data/dataloader.py | 10 +- python/mxnet/gluon/data/vision/datasets.py | 5 +- python/mxnet/numpy/multiarray.py | 19 +- python/mxnet/numpy_extension/__init__.py | 7 +- python/mxnet/util.py | 47 +++-- 6 files changed, 369 insertions(+), 27 deletions(-) diff --git a/example/numpy/numpy_semantics.ipynb b/example/numpy/numpy_semantics.ipynb new file mode 100644 index 000..1cec51f --- /dev/null +++ b/example/numpy/numpy_semantics.ipynb @@ -0,0 +1,308 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"# How to Use NumPy Semantics in MXNet with `mxnet.numpy` Module\n", +"\n", +"## NumPy Shape Semantics\n", +"\n", +"### Example \n", +"\n", +"| Shape Example | MXNet (before) | MXNet/NumPy |\n", +"|:---:|:---:|:---:|\n", +"| `()` | unknown | Scalar tensor |\n", +"| `(2, 0, 1)` | Second dimension unknown | Zero-size tensor |\n", +"| `None`(Python) | N/A | Unknown |\n", +"| `(2, -1, 0)`(C++) | N/A | Second dim uknown|\n", +"\n", +"### Affected modules\n", +"- Shape inference: imperative, symbolic, Gluon\n", +"- Legacy operators (not recommended to use)\n", +"- MXNet/NumPy operators\n", +"\n", +"## NumPy Array Semantics\n", +"**Definition:** The type of created ndarrays is `mxnet.numpy.ndarray`/`mxnet.symbol.numpy._Symbol`, instead of `mxnet.ndarray.NDArray`/`mxnet.symbol.Symbol` (only affects Gluon modules).\n", +"- Block/HybridBlock\n", +"- Parameter creation and initialization.\n", +"- Inputs/outputs (symbol/ndarray) of `__call__`/`forward`/`hybrid_forward`.\n", +"- Computational graph construction.\n", +"- Dataloader\n", +"\n", +"## Dependency of Two Types of Semantics\n", +"- It is required to keep NumPy shape semantics active while activating NumPy array semantics.\n", +"- Deactivating NumPy shape semantics while NumPy array semantics is still active is not allowed." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"import logging\n", +"import mxnet as mx\n", +"from mxnet import np, npx, gluon\n", +"\n", +"logging.basicConfig(level=logging.INFO)\n", +"\n", +"try:\n", +"npx.set_np(shape=False, array=True)\n", +"except ValueError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"## How to Enable NumPy Shape semantics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"a = mx.nd.random.uniform(shape=())\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"c = np.random.uniform()\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"npx.set_np(shape=True, array=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"a = mx.nd.random.uniform(shape=())\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"c = np.random.uniform()\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"\n", +"print('type(a) =', type(a))\n", +"print('a.shape = ', a.shape)\n", +"print('a.size = ', a.size)\n", +"\n", +"print('type(b) =', type(b))\n", +"print('b.shape = ', b.shape)\n", +"print('b.size = ', b.size)\n", +"\n", +"print('type(c) =', type(c))\n", +"print('c.shape = ', c.shape)\n", +"print('c.size = ', c.size)\n", +"\n", +"print('type(d) =', type(d))\n", +"print('d.shape = ', d.shape)\n", +"print('d.size = ', d.size)" + ] + }, + { + "cell_type": "markdown", +
[incubator-mxnet] 17/42: Fix (#15188)
This is an automated email from the ASF dual-hosted git repository. haoj pushed a commit to branch numpy in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git commit 7bcddcf2c2e9a93a5b0058400fb6e7cc39476408 Author: reminisce AuthorDate: Sun Jun 9 08:56:16 2019 -0700 Fix (#15188) --- example/numpy/numpy_semantics.ipynb| 308 + python/mxnet/gluon/data/dataloader.py | 10 +- python/mxnet/gluon/data/vision/datasets.py | 5 +- python/mxnet/numpy/multiarray.py | 19 +- python/mxnet/numpy_extension/__init__.py | 7 +- python/mxnet/util.py | 47 +++-- 6 files changed, 369 insertions(+), 27 deletions(-) diff --git a/example/numpy/numpy_semantics.ipynb b/example/numpy/numpy_semantics.ipynb new file mode 100644 index 000..1cec51f --- /dev/null +++ b/example/numpy/numpy_semantics.ipynb @@ -0,0 +1,308 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"# How to Use NumPy Semantics in MXNet with `mxnet.numpy` Module\n", +"\n", +"## NumPy Shape Semantics\n", +"\n", +"### Example \n", +"\n", +"| Shape Example | MXNet (before) | MXNet/NumPy |\n", +"|:---:|:---:|:---:|\n", +"| `()` | unknown | Scalar tensor |\n", +"| `(2, 0, 1)` | Second dimension unknown | Zero-size tensor |\n", +"| `None`(Python) | N/A | Unknown |\n", +"| `(2, -1, 0)`(C++) | N/A | Second dim uknown|\n", +"\n", +"### Affected modules\n", +"- Shape inference: imperative, symbolic, Gluon\n", +"- Legacy operators (not recommended to use)\n", +"- MXNet/NumPy operators\n", +"\n", +"## NumPy Array Semantics\n", +"**Definition:** The type of created ndarrays is `mxnet.numpy.ndarray`/`mxnet.symbol.numpy._Symbol`, instead of `mxnet.ndarray.NDArray`/`mxnet.symbol.Symbol` (only affects Gluon modules).\n", +"- Block/HybridBlock\n", +"- Parameter creation and initialization.\n", +"- Inputs/outputs (symbol/ndarray) of `__call__`/`forward`/`hybrid_forward`.\n", +"- Computational graph construction.\n", +"- Dataloader\n", +"\n", +"## Dependency of Two Types of Semantics\n", +"- It is required to keep NumPy shape semantics active while activating NumPy array semantics.\n", +"- Deactivating NumPy shape semantics while NumPy array semantics is still active is not allowed." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"import logging\n", +"import mxnet as mx\n", +"from mxnet import np, npx, gluon\n", +"\n", +"logging.basicConfig(level=logging.INFO)\n", +"\n", +"try:\n", +"npx.set_np(shape=False, array=True)\n", +"except ValueError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ +"## How to Enable NumPy Shape semantics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"a = mx.nd.random.uniform(shape=())\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"c = np.random.uniform()\n", +"except mx.MXNetError as e:\n", +"print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"try:\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"except mx.MXNetError as e:\n", +"print(e) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"npx.set_np(shape=True, array=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ +"a = mx.nd.random.uniform(shape=())\n", +"b = mx.nd.random.uniform(shape=(2, 0, 1))\n", +"c = np.random.uniform()\n", +"d = np.random.uniform(size=(2, 0, 1))\n", +"\n", +"print('type(a) =', type(a))\n", +"print('a.shape = ', a.shape)\n", +"print('a.size = ', a.size)\n", +"\n", +"print('type(b) =', type(b))\n", +"print('b.shape = ', b.shape)\n", +"print('b.size = ', b.size)\n", +"\n", +"print('type(c) =', type(c))\n", +"print('c.shape = ', c.shape)\n", +"print('c.size = ', c.size)\n", +"\n", +"print('type(d) =', type(d))\n", +"print('d.shape = ', d.shape)\n", +"print('d.size = ', d.size)" + ] + }, + { + "cell_type": "markdown", +