From c89209450db22079533ad9ea8950e288a851e38f Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Thu, 5 Nov 2020 10:29:22 +0800 Subject: [PATCH] ci(mge): remove blank line for windows doctest GitOrigin-RevId: 09cf6518e8cf96113f455a6222ba17f271143bb4 --- imperative/python/megengine/functional/tensor.py | 41 +++++++----------------- imperative/python/megengine/module/embedding.py | 33 ++++--------------- 2 files changed, 19 insertions(+), 55 deletions(-) diff --git a/imperative/python/megengine/functional/tensor.py b/imperative/python/megengine/functional/tensor.py index 7bcc0c69..60ccf66b 100644 --- a/imperative/python/megengine/functional/tensor.py +++ b/imperative/python/megengine/functional/tensor.py @@ -208,25 +208,16 @@ def broadcast_to(inp: Tensor, shape: Union[int, Iterable[int]]) -> Tensor: from megengine import tensor import megengine.functional as F - data = tensor(np.arange(0, 6, dtype=np.float32).reshape(2, 3)) - out = F.broadcast_to(data, (4, 2, 3)) + data = tensor(np.arange(0, 3, dtype=np.float32).reshape(3)) + out = F.broadcast_to(data, (2, 3)) print(out.numpy()) Outputs: .. testoutput:: - [[[0. 1. 2.] - [3. 4. 5.]] - - [[0. 1. 2.] - [3. 4. 5.]] - - [[0. 1. 2.] - [3. 4. 5.]] - - [[0. 1. 2.] - [3. 4. 5.]]] + [[0. 1. 2.] + [0. 1. 2.]] """ return _broadcast(inp, shape) @@ -298,8 +289,8 @@ def stack(inps, axis=0, device=None): from megengine import tensor import megengine.functional as F - x1 = tensor(np.arange(0, 6, dtype=np.float32).reshape((2, 3))) - x2 = tensor(np.arange(6, 12, dtype=np.float32).reshape((2, 3))) + x1 = tensor(np.arange(0, 3, dtype=np.float32).reshape((3))) + x2 = tensor(np.arange(6, 9, dtype=np.float32).reshape((3))) out = F.stack([x1, x2], axis=0) print(out.numpy()) @@ -307,11 +298,8 @@ def stack(inps, axis=0, device=None): .. testoutput:: - [[[ 0. 1. 2.] - [ 3. 4. 5.]] - - [[ 6. 7. 8.] - [ 9. 10. 11.]]] + [[0. 1. 2.] + [6. 7. 8.]] """ if len(inps) > 0 and not isinstance(inps[0].shape, inps[0].__class__): @@ -751,21 +739,16 @@ def reshape(inp: Tensor, target_shape: Iterable[int]) -> Tensor: from megengine import tensor import megengine.functional as F x = tensor(np.arange(12, dtype=np.int32)) - out = F.reshape(x, (3, 2, 2)) + out = F.reshape(x, (3, 4)) print(out.numpy()) Outputs: .. testoutput:: - [[[ 0 1] - [ 2 3]] - - [[ 4 5] - [ 6 7]] - - [[ 8 9] - [10 11]]] + [[ 0 1 2 3] + [ 4 5 6 7] + [ 8 9 10 11]] """ return inp.reshape(target_shape) diff --git a/imperative/python/megengine/module/embedding.py b/imperative/python/megengine/module/embedding.py index 21bda708..fb7bfa39 100644 --- a/imperative/python/megengine/module/embedding.py +++ b/imperative/python/megengine/module/embedding.py @@ -38,10 +38,10 @@ class Embedding(Module): import numpy as np import megengine as mge import megengine.module as M - weight = mge.tensor(np.array([(1.2,2.3,3.4,4.5,5.6),(0.1,1.1,2.1,3.1,4.1)], dtype=np.float32)) - data = mge.tensor(np.array([(0,1,1),(1,0,1),(0,0,1)], dtype=np.int32)) + weight = mge.tensor(np.array([(1.2,2.3,3.4,4.5,5.6)], dtype=np.float32)) + data = mge.tensor(np.array([(0,0)], dtype=np.int32)) - embedding = M.Embedding(2, 5, initial_weight=weight) + embedding = M.Embedding(1, 5, initial_weight=weight) output = embedding(data) with np.printoptions(precision=6): print(output.numpy()) @@ -51,16 +51,7 @@ class Embedding(Module): .. testoutput:: [[[1.2 2.3 3.4 4.5 5.6] - [0.1 1.1 2.1 3.1 4.1] - [0.1 1.1 2.1 3.1 4.1]] - - [[0.1 1.1 2.1 3.1 4.1] - [1.2 2.3 3.4 4.5 5.6] - [0.1 1.1 2.1 3.1 4.1]] - - [[1.2 2.3 3.4 4.5 5.6] - [1.2 2.3 3.4 4.5 5.6] - [0.1 1.1 2.1 3.1 4.1]]] + [1.2 2.3 3.4 4.5 5.6]]] """ @@ -134,8 +125,8 @@ class Embedding(Module): import numpy as np import megengine as mge import megengine.module as M - weight = mge.tensor(np.array([(1.2,2.3,3.4,4.5,5.6),(0.1,1.1,2.1,3.1,4.1)], dtype=np.float32)) - data = mge.tensor(np.array([(0,1,1),(1,0,1),(0,0,1)], dtype=np.int32)) + weight = mge.tensor(np.array([(1.2,2.3,3.4,4.5,5.6)], dtype=np.float32)) + data = mge.tensor(np.array([(0,0)], dtype=np.int32)) embedding = M.Embedding.from_pretrained(weight, freeze=False) output = embedding(data) @@ -146,17 +137,7 @@ class Embedding(Module): .. testoutput:: [[[1.2 2.3 3.4 4.5 5.6] - [0.1 1.1 2.1 3.1 4.1] - [0.1 1.1 2.1 3.1 4.1]] - - [[0.1 1.1 2.1 3.1 4.1] - [1.2 2.3 3.4 4.5 5.6] - [0.1 1.1 2.1 3.1 4.1]] - - [[1.2 2.3 3.4 4.5 5.6] - [1.2 2.3 3.4 4.5 5.6] - [0.1 1.1 2.1 3.1 4.1]]] - + [1.2 2.3 3.4 4.5 5.6]]] """ embeddings_shape = embeddings.shape