diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | docs/numpy.ipynb | 10 | ||||
-rw-r--r-- | pint/numpy_func.py | 2 | ||||
-rw-r--r-- | pint/testsuite/test_numpy.py | 16 |
5 files changed, 27 insertions, 6 deletions
@@ -5,6 +5,7 @@ __pycache__ .DS_Store docs/_build/ .idea +.vscode build/ dist/ MANIFEST @@ -4,8 +4,8 @@ Pint Changelog 0.11 (unreleased) ----------------- -- Nothing changed yet. - +- Added additional NumPy function implementations (allclose, intersect1d) + (Issue #979, Thanks Jon Thielen) 0.10.1 (2020-01-07) ------------------- diff --git a/docs/numpy.ipynb b/docs/numpy.ipynb index 8a66c64..2dc6078 100644 --- a/docs/numpy.ipynb +++ b/docs/numpy.ipynb @@ -301,7 +301,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['alen', 'all', 'amax', 'amin', 'any', 'append', 'argmax', 'argmin', 'argsort', 'around', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'average', 'block', 'broadcast_to', 'clip', 'column_stack', 'compress', 'concatenate', 'copy', 'copyto', 'count_nonzero', 'cross', 'cumprod', 'cumproduct', 'cumsum', 'diagonal', 'diff', 'dot', 'dstack', 'ediff1d', 'einsum', 'empty_like', 'expand_dims', 'fix', 'flip', 'full_like', 'gradient', 'hstack', 'insert', 'interp', 'isclose', 'iscomplex', 'isin', 'isreal', 'linalg.solve', 'linspace', 'mean', 'median', 'meshgrid', 'moveaxis', 'nan_to_num', 'nanargmax', 'nanargmin', 'nancumprod', 'nancumsum', 'nanmax', 'nanmean', 'nanmedian', 'nanmin', 'nanpercentile', 'nanstd', 'nansum', 'nanvar', 'ndim', 'nonzero', 'ones_like', 'pad', 'percentile', 'ptp', 'ravel', 'reshape', 'resize', 'result_type', 'rollaxis', 'rot90', 'round_', 'searchsorted', 'shape', 'size', 'sort', 'squeeze', 'stack', 'std', 'sum', 'swapaxes', 'tile', 'transpose', 'trapz', 'trim_zeros', 'unwrap', 'var', 'vstack', 'where', 'zeros_like']\n" + "['alen', 'all', 'allclose', 'amax', 'amin', 'any', 'append', 'argmax', 'argmin', 'argsort', 'around', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'average', 'block', 'broadcast_to', 'clip', 'column_stack', 'compress', 'concatenate', 'copy', 'copyto', 'count_nonzero', 'cross', 'cumprod', 'cumproduct', 'cumsum', 'diagonal', 'diff', 'dot', 'dstack', 'ediff1d', 'einsum', 'empty_like', 'expand_dims', 'fix', 'flip', 'full_like', 'gradient', 'hstack', 'insert', 'interp', 'intersect1d', 'isclose', 'iscomplex', 'isin', 'isreal', 'linalg.solve', 'linspace', 'mean', 'median', 'meshgrid', 'moveaxis', 'nan_to_num', 'nanargmax', 'nanargmin', 'nancumprod', 'nancumsum', 'nanmax', 'nanmean', 'nanmedian', 'nanmin', 'nanpercentile', 'nanstd', 'nansum', 'nanvar', 'ndim', 'nonzero', 'ones_like', 'pad', 'percentile', 'ptp', 'ravel', 'reshape', 'resize', 'result_type', 'rollaxis', 'rot90', 'round_', 'searchsorted', 'shape', 'size', 'sort', 'squeeze', 'stack', 'std', 'sum', 'swapaxes', 'tile', 'transpose', 'trapz', 'trim_zeros', 'unwrap', 'var', 'vstack', 'where', 'zeros_like']\n" ] } ], @@ -522,7 +522,7 @@ "</svg>\n" ], "text/plain": [ - "<graphviz.dot.Digraph at 0x7fe7030a9208>" + "<graphviz.dot.Digraph at 0x7f68cc084208>" ] }, "execution_count": 13, @@ -636,15 +636,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "<COO: shape=(100, 100, 100), dtype=float64, nnz=99897, fill_value=0.0> meter\n", + "<COO: shape=(100, 100, 100), dtype=float64, nnz=99598, fill_value=0.0> meter\n", "\n", - "0.09488747484058625 meter\n" + "0.09462606529121113 meter\n" ] } ], "source": [ "from sparse import COO\n", "\n", + "np.random.seed(80243963)\n", + "\n", "x = np.random.random((100, 100, 100))\n", "x[x < 0.9] = 0 # fill most of the array with zeros\n", "s = COO(x)\n", diff --git a/pint/numpy_func.py b/pint/numpy_func.py index 2eda4fa..1fd7d8c 100644 --- a/pint/numpy_func.py +++ b/pint/numpy_func.py @@ -772,6 +772,8 @@ for func_str, unit_arguments, wrap_output in [ ("insert", ["arr", "values"], True), ("resize", "a", True), ("reshape", "a", True), + ("allclose", ["a", "b"], False), + ("intersect1d", ["ar1", "ar2"], True), ]: implement_consistent_units_by_argument(func_str, unit_arguments, wrap_output) diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py index 13a773f..0efb476 100644 --- a/pint/testsuite/test_numpy.py +++ b/pint/testsuite/test_numpy.py @@ -1153,6 +1153,22 @@ class TestNumpyUnclassified(TestNumpyMethods): ), ) # Note: Does not support Quantity pad_with vectorized callable use + @helpers.requires_array_function_protocol() + def test_allclose(self): + self.assertTrue( + np.allclose([1e10, 1e-8] * self.ureg.m, [1.00001e10, 1e-9] * self.ureg.m) + ) + self.assertFalse( + np.allclose([1e10, 1e-8] * self.ureg.m, [1.00001e10, 1e-9] * self.ureg.mm) + ) + + @helpers.requires_array_function_protocol() + def test_intersect1d(self): + self.assertQuantityEqual( + np.intersect1d([1, 3, 4, 3] * self.ureg.m, [3, 1, 2, 1] * self.ureg.m), + [1, 3] * self.ureg.m, + ) + @unittest.skip class TestBitTwiddlingUfuncs(TestUFuncs): |