-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2319 from mikedh/test/iteration
Release: Iteration Tests
- Loading branch information
Showing
20 changed files
with
191 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ requires = ["setuptools >= 61.0", "wheel"] | |
[project] | ||
name = "trimesh" | ||
requires-python = ">=3.8" | ||
version = "4.5.2" | ||
version = "4.5.3" | ||
authors = [{name = "Michael Dawson-Haggerty", email = "[email protected]"}] | ||
license = {file = "LICENSE.md"} | ||
description = "Import, export, process, analyze and view triangular meshes." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from functools import reduce | ||
|
||
import numpy as np | ||
|
||
from trimesh.iteration import chain, reduce_cascade | ||
|
||
|
||
def test_reduce_cascade(): | ||
# the multiply will explode quickly past the integer maximum | ||
def both(operation, items): | ||
""" | ||
Run our cascaded reduce and regular reduce. | ||
""" | ||
|
||
b = reduce_cascade(operation, items) | ||
|
||
if len(items) > 0: | ||
assert b == reduce(operation, items) | ||
|
||
return b | ||
|
||
for i in range(20): | ||
data = np.arange(i) | ||
c = both(items=data, operation=lambda a, b: a + b) | ||
|
||
if i == 0: | ||
assert c is None | ||
else: | ||
assert c == np.arange(i).sum() | ||
|
||
# try a multiply | ||
data = np.arange(i) | ||
c = both(items=data, operation=lambda a, b: a * b) | ||
|
||
if i == 0: | ||
assert c is None | ||
else: | ||
assert c == np.prod(data) | ||
|
||
# try a multiply | ||
data = np.arange(i)[1:] | ||
c = both(items=data, operation=lambda a, b: a * b) | ||
if i <= 1: | ||
assert c is None | ||
else: | ||
assert c == np.prod(data) | ||
|
||
data = ["a", "b", "c", "d", "e", "f", "g"] | ||
print("# reduce_pairwise\n-----------") | ||
r = both(operation=lambda a, b: a + b, items=data) | ||
|
||
assert r == "abcdefg" | ||
|
||
|
||
def test_chain(): | ||
# should work on iterables the same as `itertools.chain` | ||
assert np.allclose(chain([1, 3], [4]), [1, 3, 4]) | ||
# should work with non-iterable single values | ||
assert np.allclose(chain([1, 3], 4), [1, 3, 4]) | ||
# should filter out `None` arguments | ||
assert np.allclose(chain([1, 3], None, 4, None), [1, 3, 4]) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_reduce_cascade() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from . import blender, gmsh | ||
|
||
# add to __all__ as per pep8 | ||
__all__ = ["gmsh", "blender"] | ||
__all__ = ["blender", "gmsh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.