Skip to content

Commit

Permalink
Leverage on dpctl.tensor implementation in dpnp.count_nonzero (#1962)
Browse files Browse the repository at this point in the history
* Leverage on dpctl.tensor implementation of count_nonzero

* Extend dpnp.get_result_array() to accept dpt.usm_ndarray

* Updated dpnp.mean() per review comment

* Add more dpnp tests to cover different use cases cb56101
  • Loading branch information
github-actions[bot] committed Aug 4, 2024
1 parent ac94765 commit b0d1ef6
Show file tree
Hide file tree
Showing 502 changed files with 1,575 additions and 1,558 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 87fcd98015705c959dfb3d670f4dfc1d
config: 4cff48b2f81f644229cb2ad19fa3b056
tags: 645f666f9bcd5a90fca523b33c5a78b7
6 changes: 3 additions & 3 deletions _modules/dpnp/dpnp_array.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_array &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_array &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down
6 changes: 3 additions & 3 deletions _modules/dpnp/dpnp_flatiter.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_flatiter &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_flatiter &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down
10 changes: 6 additions & 4 deletions _modules/dpnp/dpnp_iface.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_iface &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_iface &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down Expand Up @@ -759,7 +759,7 @@ <h1>Source code for dpnp.dpnp_iface</h1><div class="highlight"><pre>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> a : {dpnp_array}</span>
<span class="sd"> a : {dpnp.ndarray, usm_ndarray}</span>
<span class="sd"> Input array.</span>
<span class="sd"> out : {dpnp.ndarray, usm_ndarray}</span>
<span class="sd"> If provided, value of `a` array will be copied into it</span>
Expand All @@ -776,6 +776,8 @@ <h1>Source code for dpnp.dpnp_iface</h1><div class="highlight"><pre>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">if</span> <span class="n">out</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">dpt</span><span class="o">.</span><span class="n">usm_ndarray</span><span class="p">):</span>
<span class="k">return</span> <span class="n">dpnp_array</span><span class="o">.</span><span class="n">_create_from_usm_ndarray</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="k">return</span> <span class="n">a</span>

<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">dpt</span><span class="o">.</span><span class="n">usm_ndarray</span><span class="p">):</span>
Expand Down
6 changes: 3 additions & 3 deletions _modules/dpnp/dpnp_iface_arraycreation.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_iface_arraycreation &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_iface_arraycreation &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down
49 changes: 32 additions & 17 deletions _modules/dpnp/dpnp_iface_counting.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_iface_counting &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_iface_counting &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down Expand Up @@ -136,25 +136,38 @@ <h1>Source code for dpnp.dpnp_iface_counting</h1><div class="highlight"><pre>

<div class="viewcode-block" id="count_nonzero">
<a class="viewcode-back" href="../../reference/generated/dpnp.count_nonzero.html#dpnp.count_nonzero">[docs]</a>
<span class="k">def</span> <span class="nf">count_nonzero</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">count_nonzero</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">out</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Counts the number of non-zero values in the array `a`.</span>

<span class="sd"> For full documentation refer to :obj:`numpy.count_nonzero`.</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> a : {dpnp.ndarray, usm_ndarray}</span>
<span class="sd"> The array for which to count non-zeros.</span>
<span class="sd"> axis : {None, int, tuple}, optional</span>
<span class="sd"> Axis or tuple of axes along which to count non-zeros.</span>
<span class="sd"> Default value means that non-zeros will be counted along a flattened</span>
<span class="sd"> version of `a`.</span>
<span class="sd"> Default: ``None``.</span>
<span class="sd"> keepdims : bool, optional</span>
<span class="sd"> If this is set to ``True``, the axes that are counted are left in the</span>
<span class="sd"> result as dimensions with size one. With this option, the result will</span>
<span class="sd"> broadcast correctly against the input array.</span>
<span class="sd"> Default: ``False``.</span>
<span class="sd"> out : {None, dpnp.ndarray, usm_ndarray}, optional</span>
<span class="sd"> The array into which the result is written. The data type of `out` must</span>
<span class="sd"> match the expected shape and the expected data type of the result.</span>
<span class="sd"> If ``None`` then a new array is returned.</span>
<span class="sd"> Default: ``None``.</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> out : dpnp.ndarray</span>
<span class="sd"> Number of non-zero values in the array along a given axis.</span>
<span class="sd"> Otherwise, a zero-dimensional array with the total number of</span>
<span class="sd"> non-zero values in the array is returned.</span>

<span class="sd"> Limitations</span>
<span class="sd"> -----------</span>
<span class="sd"> Parameters `a` is supported as either :class:`dpnp.ndarray`</span>
<span class="sd"> or :class:`dpctl.tensor.usm_ndarray`.</span>
<span class="sd"> Otherwise ``TypeError`` exception will be raised.</span>
<span class="sd"> Input array data types are limited by supported DPNP :ref:`Data types`.</span>
<span class="sd"> Otherwise, a zero-dimensional array with the total number of non-zero</span>
<span class="sd"> values in the array is returned.</span>

<span class="sd"> See Also</span>
<span class="sd"> --------</span>
Expand All @@ -179,11 +192,13 @@ <h1>Source code for dpnp.dpnp_iface_counting</h1><div class="highlight"><pre>

<span class="sd"> &quot;&quot;&quot;</span>

<span class="c1"># TODO: might be improved by implementing an extension</span>
<span class="c1"># with `count_nonzero` kernel</span>
<span class="n">usm_a</span> <span class="o">=</span> <span class="n">dpnp</span><span class="o">.</span><span class="n">get_usm_ndarray</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="n">usm_a</span> <span class="o">=</span> <span class="n">dpt</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">usm_a</span><span class="p">,</span> <span class="n">dpnp</span><span class="o">.</span><span class="n">bool</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dpnp</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">usm_a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="n">axis</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dpnp</span><span class="o">.</span><span class="n">intp</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="n">keepdims</span><span class="p">)</span></div>
<span class="n">usm_out</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="n">out</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">dpnp</span><span class="o">.</span><span class="n">get_usm_ndarray</span><span class="p">(</span><span class="n">out</span><span class="p">)</span>

<span class="n">usm_res</span> <span class="o">=</span> <span class="n">dpt</span><span class="o">.</span><span class="n">count_nonzero</span><span class="p">(</span>
<span class="n">usm_a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="n">axis</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="n">keepdims</span><span class="p">,</span> <span class="n">out</span><span class="o">=</span><span class="n">usm_out</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">dpnp</span><span class="o">.</span><span class="n">get_result_array</span><span class="p">(</span><span class="n">usm_res</span><span class="p">,</span> <span class="n">out</span><span class="p">)</span></div>

</pre></div>

Expand Down
6 changes: 3 additions & 3 deletions _modules/dpnp/dpnp_iface_histograms.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_iface_histograms &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_iface_histograms &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down
6 changes: 3 additions & 3 deletions _modules/dpnp/dpnp_iface_indexing.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_iface_indexing &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_iface_indexing &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down
6 changes: 3 additions & 3 deletions _modules/dpnp/dpnp_iface_libmath.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dpnp.dpnp_iface_libmath &mdash; Data Parallel Extension for NumPy 0.16.0dev0+98.gd2c623b084 documentation</title>
<title>dpnp.dpnp_iface_libmath &mdash; Data Parallel Extension for NumPy 0.16.0dev0+99.gcb56101780 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

Expand All @@ -23,7 +23,7 @@

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=9459a11b"></script>
<script src="../../_static/documentation_options.js?v=4778e5b8"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script>
Expand All @@ -43,7 +43,7 @@
Data Parallel Extension for NumPy
</a>
<div class="version">
0.16.0dev0+98.gd2c623b084
0.16.0dev0+99.gcb56101780
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down
Loading

0 comments on commit b0d1ef6

Please sign in to comment.