diff options
author | Richard Burton <richard.burton@arm.com> | 2020-04-08 16:39:05 +0100 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2020-04-10 16:11:09 +0000 |
commit | dc0c6ed9f8b993e63f492f203d7d7080ab4c835c (patch) | |
tree | ea8541990b13ebf1a038009aa6b8b4b1ea8c3f55 /python/pyarmnn/test/test_tensor_shape.py | |
parent | fe5a24beeef6e9a41366e694f41093565e748048 (diff) | |
download | armnn-dc0c6ed9f8b993e63f492f203d7d7080ab4c835c.tar.gz |
Add PyArmNN to work with ArmNN API of 20.02
* Add Swig rules for generating python wrapper
* Add documentation
* Add tests and testing data
Change-Id: If48eda08931514fa21e72214dfead2835f07237c
Signed-off-by: Richard Burton <richard.burton@arm.com>
Signed-off-by: Derek Lamberti <derek.lamberti@arm.com>
Diffstat (limited to 'python/pyarmnn/test/test_tensor_shape.py')
-rw-r--r-- | python/pyarmnn/test/test_tensor_shape.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/python/pyarmnn/test/test_tensor_shape.py b/python/pyarmnn/test/test_tensor_shape.py new file mode 100644 index 0000000000..c6f731fb43 --- /dev/null +++ b/python/pyarmnn/test/test_tensor_shape.py @@ -0,0 +1,78 @@ +# Copyright © 2020 Arm Ltd. All rights reserved. +# SPDX-License-Identifier: MIT +import pytest +import pyarmnn as ann + + +def test_tensor_shape_tuple(): + tensor_shape = ann.TensorShape((1, 2, 3)) + + assert 3 == tensor_shape.GetNumDimensions() + assert 6 == tensor_shape.GetNumElements() + + +def test_tensor_shape_one(): + tensor_shape = ann.TensorShape((10,)) + assert 1 == tensor_shape.GetNumDimensions() + assert 10 == tensor_shape.GetNumElements() + + +def test_tensor_shape_empty(): + with pytest.raises(RuntimeError) as err: + ann.TensorShape(()) + + assert "Tensor numDimensions must be greater than 0" in str(err.value) + + +def test_tensor_shape_tuple_mess(): + tensor_shape = ann.TensorShape((1, "2", 3.0)) + + assert 3 == tensor_shape.GetNumDimensions() + assert 6 == tensor_shape.GetNumElements() + + +def test_tensor_shape_list(): + + with pytest.raises(TypeError) as err: + ann.TensorShape([1, 2, 3]) + + assert "Argument is not a tuple" in str(err.value) + + +def test_tensor_shape_tuple_mess_fail(): + + with pytest.raises(TypeError) as err: + ann.TensorShape((1, "two", 3.0)) + + assert "All elements must be numbers" in str(err.value) + + +def test_tensor_shape_varags(): + with pytest.raises(TypeError) as err: + ann.TensorShape(1, 2, 3) + + assert "__init__() takes 2 positional arguments but 4 were given" in str(err.value) + + +def test_tensor_shape__get_item_out_of_bounds(): + tensor_shape = ann.TensorShape((1, 2, 3)) + with pytest.raises(ValueError) as err: + for i in range(4): + tensor_shape[i] + + assert "Invalid dimension index: 3 (number of dimensions is 3)" in str(err.value) + + +def test_tensor_shape__set_item_out_of_bounds(): + tensor_shape = ann.TensorShape((1, 2, 3)) + with pytest.raises(ValueError) as err: + for i in range(4): + tensor_shape[i] = 1 + + assert "Invalid dimension index: 3 (number of dimensions is 3)" in str(err.value) + + +def test_tensor_shape___str__(): + tensor_shape = ann.TensorShape((1, 2, 3)) + + assert str(tensor_shape) == "TensorShape{Shape(1, 2, 3), NumDimensions: 3, NumElements: 6}" |