1
+ <!DOCTYPE html>
2
+ < html class ="writer-html5 " lang ="en " data-content_root ="../../ ">
3
+ < head >
4
+ < meta charset ="utf-8 " />
5
+ <!-- Google tag (gtag.js) -->
6
+ < script async src ="https://www.googletagmanager.com/gtag/js?id=G-554F8VNE28 "> </ script >
7
+ < script >
8
+ window . dataLayer = window . dataLayer || [ ] ;
9
+ function gtag ( ) { dataLayer . push ( arguments ) ; }
10
+ gtag ( 'js' , new Date ( ) ) ;
11
+ gtag ( 'config' , 'G-554F8VNE28' ) ;
12
+ </ script >
13
+
14
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
15
+ < title > dpnp.dpnp_iface_counting — Data Parallel Extension for NumPy 0.13.1dev3+10.gc1f6f16c4a documentation</ title >
16
+ < link rel ="stylesheet " type ="text/css " href ="../../_static/pygments.css?v=fa44fd50 " />
17
+ < link rel ="stylesheet " type ="text/css " href ="../../_static/css/theme.css?v=19f00094 " />
18
+
19
+
20
+ <!--[if lt IE 9]>
21
+ <script src="../../_static/js/html5shiv.min.js"></script>
22
+ <![endif]-->
23
+
24
+ < script src ="../../_static/jquery.js?v=5d32c60e "> </ script >
25
+ < script src ="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c "> </ script >
26
+ < script src ="../../_static/documentation_options.js?v=eada3fc1 "> </ script >
27
+ < script src ="../../_static/doctools.js?v=888ff710 "> </ script >
28
+ < script src ="../../_static/sphinx_highlight.js?v=dc90522c "> </ script >
29
+ < script src ="../../_static/js/theme.js "> </ script >
30
+ < link rel ="index " title ="Index " href ="../../genindex.html " />
31
+ < link rel ="search " title ="Search " href ="../../search.html " />
32
+ </ head >
33
+
34
+ < body class ="wy-body-for-nav ">
35
+ < div class ="wy-grid-for-nav ">
36
+ < nav data-toggle ="wy-nav-shift " class ="wy-nav-side ">
37
+ < div class ="wy-side-scroll ">
38
+ < div class ="wy-side-nav-search " >
39
+
40
+
41
+
42
+ < a href ="../../index.html " class ="icon icon-home ">
43
+ Data Parallel Extension for NumPy
44
+ </ a >
45
+ < div class ="version ">
46
+ 0.13.1dev3+10.gc1f6f16c4a
47
+ </ div >
48
+ < div role ="search ">
49
+ < form id ="rtd-search-form " class ="wy-form " action ="../../search.html " method ="get ">
50
+ < input type ="text " name ="q " placeholder ="Search docs " aria-label ="Search docs " />
51
+ < input type ="hidden " name ="check_keywords " value ="yes " />
52
+ < input type ="hidden " name ="area " value ="default " />
53
+ </ form >
54
+ </ div >
55
+ </ div > < div class ="wy-menu wy-menu-vertical " data-spy ="affix " role ="navigation " aria-label ="Navigation menu ">
56
+ < ul >
57
+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../overview.html "> Overview</ a > </ li >
58
+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../quick_start_guide.html "> Quick Start Guide</ a > </ li >
59
+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../reference/index.html "> API Reference</ a > </ li >
60
+ </ ul >
61
+ < p class ="caption " role ="heading "> < span class ="caption-text "> Development information</ span > </ p >
62
+ < ul >
63
+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../dpnp_backend_api.html "> C++ backend API Reference</ a > </ li >
64
+ </ ul >
65
+
66
+ </ div >
67
+ </ div >
68
+ </ nav >
69
+
70
+ < section data-toggle ="wy-nav-shift " class ="wy-nav-content-wrap "> < nav class ="wy-nav-top " aria-label ="Mobile navigation menu " >
71
+ < i data-toggle ="wy-nav-top " class ="fa fa-bars "> </ i >
72
+ < a href ="../../index.html "> Data Parallel Extension for NumPy</ a >
73
+ </ nav >
74
+
75
+ < div class ="wy-nav-content ">
76
+ < div class ="rst-content ">
77
+ < div role ="navigation " aria-label ="Page navigation ">
78
+ < ul class ="wy-breadcrumbs ">
79
+ < li > < a href ="../../index.html " class ="icon icon-home " aria-label ="Home "> </ a > </ li >
80
+ < li class ="breadcrumb-item "> < a href ="../index.html "> Module code</ a > </ li >
81
+ < li class ="breadcrumb-item active "> dpnp.dpnp_iface_counting</ li >
82
+ < li class ="wy-breadcrumbs-aside ">
83
+ </ li >
84
+ </ ul >
85
+ < hr />
86
+ </ div >
87
+ < div role ="main " class ="document " itemscope ="itemscope " itemtype ="http://schema.org/Article ">
88
+ < div itemprop ="articleBody ">
89
+
90
+ < h1 > Source code for dpnp.dpnp_iface_counting</ h1 > < div class ="highlight "> < pre >
91
+ < span > </ span > < span class ="c1 "> # cython: language_level=3</ span >
92
+ < span class ="c1 "> # distutils: language = c++</ span >
93
+ < span class ="c1 "> # -*- coding: utf-8 -*-</ span >
94
+ < span class ="c1 "> # *****************************************************************************</ span >
95
+ < span class ="c1 "> # Copyright (c) 2016-2024, Intel Corporation</ span >
96
+ < span class ="c1 "> # All rights reserved.</ span >
97
+ < span class ="c1 "> #</ span >
98
+ < span class ="c1 "> # Redistribution and use in source and binary forms, with or without</ span >
99
+ < span class ="c1 "> # modification, are permitted provided that the following conditions are met:</ span >
100
+ < span class ="c1 "> # - Redistributions of source code must retain the above copyright notice,</ span >
101
+ < span class ="c1 "> # this list of conditions and the following disclaimer.</ span >
102
+ < span class ="c1 "> # - Redistributions in binary form must reproduce the above copyright notice,</ span >
103
+ < span class ="c1 "> # this list of conditions and the following disclaimer in the documentation</ span >
104
+ < span class ="c1 "> # and/or other materials provided with the distribution.</ span >
105
+ < span class ="c1 "> #</ span >
106
+ < span class ="c1 "> # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"</ span >
107
+ < span class ="c1 "> # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</ span >
108
+ < span class ="c1 "> # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</ span >
109
+ < span class ="c1 "> # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE</ span >
110
+ < span class ="c1 "> # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</ span >
111
+ < span class ="c1 "> # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</ span >
112
+ < span class ="c1 "> # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</ span >
113
+ < span class ="c1 "> # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN</ span >
114
+ < span class ="c1 "> # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)</ span >
115
+ < span class ="c1 "> # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF</ span >
116
+ < span class ="c1 "> # THE POSSIBILITY OF SUCH DAMAGE.</ span >
117
+ < span class ="c1 "> # *****************************************************************************</ span >
118
+
119
+ < span class ="sd "> """</ span >
120
+ < span class ="sd "> Interface of the counting function of the dpnp</ span >
121
+
122
+ < span class ="sd "> Notes</ span >
123
+ < span class ="sd "> -----</ span >
124
+ < span class ="sd "> This module is a face or public interface file for the library</ span >
125
+ < span class ="sd "> it contains:</ span >
126
+ < span class ="sd "> - Interface functions</ span >
127
+ < span class ="sd "> - documentation for the functions</ span >
128
+ < span class ="sd "> - The functions parameters check</ span >
129
+
130
+ < span class ="sd "> """</ span >
131
+
132
+ < span class ="kn "> import</ span > < span class ="nn "> dpnp</ span >
133
+
134
+ < span class ="n "> __all__</ span > < span class ="o "> =</ span > < span class ="p "> [</ span > < span class ="s2 "> "count_nonzero"</ span > < span class ="p "> ]</ span >
135
+
136
+
137
+ < div class ="viewcode-block " id ="count_nonzero ">
138
+ < a class ="viewcode-back " href ="../../reference/generated/dpnp.count_nonzero.html#dpnp.count_nonzero "> [docs]</ a >
139
+ < 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 >
140
+ < span class ="w "> </ span > < span class ="sd "> """</ span >
141
+ < span class ="sd "> Counts the number of non-zero values in the array `a`.</ span >
142
+
143
+ < span class ="sd "> For full documentation refer to :obj:`numpy.count_nonzero`.</ span >
144
+
145
+ < span class ="sd "> Returns</ span >
146
+ < span class ="sd "> -------</ span >
147
+ < span class ="sd "> out : dpnp.ndarray</ span >
148
+ < span class ="sd "> Number of non-zero values in the array along a given axis.</ span >
149
+ < span class ="sd "> Otherwise, a zero-dimensional array with the total number of</ span >
150
+ < span class ="sd "> non-zero values in the array is returned.</ span >
151
+
152
+ < span class ="sd "> Limitations</ span >
153
+ < span class ="sd "> -----------</ span >
154
+ < span class ="sd "> Parameters `a` is supported as either :class:`dpnp.ndarray`</ span >
155
+ < span class ="sd "> or :class:`dpctl.tensor.usm_ndarray`.</ span >
156
+ < span class ="sd "> Otherwise ``TypeError`` exception will be raised.</ span >
157
+ < span class ="sd "> Input array data types are limited by supported DPNP :ref:`Data types`.</ span >
158
+
159
+ < span class ="sd "> See Also</ span >
160
+ < span class ="sd "> --------</ span >
161
+ < span class ="sd "> :obj:`dpnp.nonzero` : Return the coordinates of all the non-zero values.</ span >
162
+
163
+ < span class ="sd "> Examples</ span >
164
+ < span class ="sd "> --------</ span >
165
+ < span class ="sd "> >>> import dpnp as np</ span >
166
+ < span class ="sd "> >>> np.count_nonzero(np.eye(4))</ span >
167
+ < span class ="sd "> array(4)</ span >
168
+ < span class ="sd "> >>> a = np.array([[0, 1, 7, 0],</ span >
169
+ < span class ="sd "> [3, 0, 2, 19]])</ span >
170
+ < span class ="sd "> >>> np.count_nonzero(a)</ span >
171
+ < span class ="sd "> array(5)</ span >
172
+ < span class ="sd "> >>> np.count_nonzero(a, axis=0)</ span >
173
+ < span class ="sd "> array([1, 1, 2, 1])</ span >
174
+ < span class ="sd "> >>> np.count_nonzero(a, axis=1)</ span >
175
+ < span class ="sd "> array([2, 3])</ span >
176
+ < span class ="sd "> >>> np.count_nonzero(a, axis=1, keepdims=True)</ span >
177
+ < span class ="sd "> array([[2],</ span >
178
+ < span class ="sd "> [3]])</ span >
179
+
180
+ < span class ="sd "> """</ span >
181
+
182
+ < span class ="c1 "> # TODO: might be improved by implementing an extension with `count_nonzero` kernel</ span >
183
+ < span class ="n "> a</ span > < span class ="o "> =</ span > < span class ="n "> dpnp</ span > < span class ="o "> .</ span > < span class ="n "> astype</ span > < span class ="p "> (</ span > < span class ="n "> 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 >
184
+ < span class ="k "> return</ span > < span class ="n "> a</ span > < span class ="o "> .</ span > < span class ="n "> sum</ 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 >
185
+
186
+ </ pre > </ div >
187
+
188
+ </ div >
189
+ </ div >
190
+ < footer >
191
+
192
+ < hr />
193
+
194
+ < div role ="contentinfo ">
195
+ < p > © Copyright 2020-2024, Intel Corporation.</ p >
196
+ </ div >
197
+
198
+ Built with < a href ="https://www.sphinx-doc.org/ "> Sphinx</ a > using a
199
+ < a href ="https://github.com/readthedocs/sphinx_rtd_theme "> theme</ a >
200
+ provided by < a href ="https://readthedocs.org "> Read the Docs</ a > .
201
+
202
+
203
+ </ footer >
204
+ </ div >
205
+ </ div >
206
+ </ section >
207
+ </ div >
208
+ < script >
209
+ jQuery ( function ( ) {
210
+ SphinxRtdTheme . Navigation . enable ( true ) ;
211
+ } ) ;
212
+ </ script >
213
+
214
+ </ body >
215
+ </ html >
0 commit comments