Skip to content

Commit b811f5a

Browse files
committed
Update links and add more examples with dpnp.binary_repr
1 parent a475f09 commit b811f5a

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

dpnp/dpnp_iface_bitwise.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ def binary_repr(num, width=None):
165165
:obj:`dpnp.logical_and` : Compute the truth value of ``x1`` AND ``x2`` element-wise.
166166
:obj:`dpnp.bitwise_or`: Compute the bit-wise OR of two arrays element-wise.
167167
:obj:`dpnp.bitwise_xor` : Compute the bit-wise XOR of two arrays element-wise.
168+
:obj:`dpnp.binary_repr` : Return the binary representation of the input number
169+
as a string.
168170
169171
Examples
170172
--------
171173
>>> import dpnp as np
172174
>>> x1 = np.array([2, 5, 255])
173-
>>> x2 = np.array([3,14,16])
175+
>>> x2 = np.array([3, 14, 16])
174176
>>> np.bitwise_and(x1, x2)
175-
[2, 4, 16]
177+
array([ 2, 4, 16])
176178
177179
>>> a = np.array([True, True])
178180
>>> b = np.array([False, True])
@@ -184,6 +186,16 @@ def binary_repr(num, width=None):
184186
185187
>>> x1 & x2
186188
array([ 2, 4, 16])
189+
190+
The number 13 is represented by ``00001101``. Likewise, 17 is represented by
191+
``00010001``. The bit-wise AND of 13 and 17 is therefore ``000000001``, or 1:
192+
193+
>>> np.bitwise_and(np.array(14), 13)
194+
array(12)
195+
>>> np.binary_repr(12)
196+
'1100'
197+
>>> np.bitwise_and(np.array([14, 3]), 13)
198+
array([12, 1])
187199
"""
188200

189201
bitwise_and = DPNPBinaryFunc(
@@ -234,6 +246,8 @@ def binary_repr(num, width=None):
234246
:obj:`dpnp.logical_or` : Compute the truth value of ``x1`` OR ``x2`` element-wise.
235247
:obj:`dpnp.bitwise_and`: Compute the bit-wise AND of two arrays element-wise.
236248
:obj:`dpnp.bitwise_xor` : Compute the bit-wise XOR of two arrays element-wise.
249+
:obj:`dpnp.binary_repr` : Return the binary representation of the input number
250+
as a string.
237251
238252
Examples
239253
--------
@@ -248,6 +262,15 @@ def binary_repr(num, width=None):
248262
249263
>>> x1 | x2
250264
array([ 6, 5, 255])
265+
266+
The number 13 has the binary representation ``00001101``. Likewise, 16 is
267+
represented by ``00010000``. The bit-wise OR of 13 and 16 is then ``00011101``,
268+
or 29:
269+
270+
>>> np.bitwise_or(np.array(13), 16)
271+
array(29)
272+
>>> np.binary_repr(29)
273+
'11101'
251274
"""
252275

253276
bitwise_or = DPNPBinaryFunc(
@@ -298,6 +321,8 @@ def binary_repr(num, width=None):
298321
:obj:`dpnp.logical_xor` : Compute the truth value of ``x1`` XOR `x2`, element-wise.
299322
:obj:`dpnp.bitwise_and`: Compute the bit-wise AND of two arrays element-wise.
300323
:obj:`dpnp.bitwise_or` : Compute the bit-wise OR of two arrays element-wise.
324+
:obj:`dpnp.binary_repr` : Return the binary representation of the input number
325+
as a string.
301326
302327
Examples
303328
--------
@@ -317,6 +342,14 @@ def binary_repr(num, width=None):
317342
318343
>>> a ^ b
319344
array([ True, False])
345+
346+
The number 13 is represented by ``00001101``. Likewise, 17 is represented by
347+
``00010001``. The bit-wise XOR of 13 and 17 is therefore ``00011100``, or 28:
348+
349+
>>> np.bitwise_xor(np.array(13), 17)
350+
array(28)
351+
>>> np.binary_repr(28)
352+
'11100'
320353
"""
321354

322355
bitwise_xor = DPNPBinaryFunc(
@@ -365,13 +398,21 @@ def binary_repr(num, width=None):
365398
:obj:`dpnp.bitwise_or` : Compute the bit-wise OR of two arrays element-wise.
366399
:obj:`dpnp.bitwise_xor` : Compute the bit-wise XOR of two arrays element-wise.
367400
:obj:`dpnp.logical_not` : Compute the truth value of NOT x element-wise.
401+
:obj:`dpnp.binary_repr` : Return the binary representation of the input number
402+
as a string.
368403
369404
Examples
370405
--------
371406
>>> import dpnp as np
407+
408+
The number 13 is represented by ``00001101``. The invert or bit-wise NOT of 13
409+
is then:
410+
372411
>>> x = np.array([13])
373412
>>> np.invert(x)
374-
-14
413+
array([-14])
414+
>>> np.binary_repr(-14, width=8)
415+
'11110010'
375416
376417
>>> a = np.array([True, False])
377418
>>> np.invert(a)
@@ -382,6 +423,7 @@ def binary_repr(num, width=None):
382423
383424
>>> ~a
384425
array([False, True])
426+
385427
"""
386428

387429
invert = DPNPUnaryFunc(
@@ -435,6 +477,8 @@ def binary_repr(num, width=None):
435477
See Also
436478
--------
437479
:obj:`dpnp.right_shift` : Shift the bits of an integer to the right.
480+
:obj:`dpnp.binary_repr` : Return the binary representation of the input number
481+
as a string.
438482
439483
Examples
440484
--------
@@ -449,6 +493,13 @@ def binary_repr(num, width=None):
449493
450494
>>> x1 << x2
451495
array([10, 20, 40])
496+
497+
>>> np.binary_repr(5)
498+
'101'
499+
>>> np.left_shift(np.array(5), 2)
500+
array(20)
501+
>>> np.binary_repr(20)
502+
'10100'
452503
"""
453504

454505
left_shift = DPNPBinaryFunc(
@@ -501,6 +552,8 @@ def binary_repr(num, width=None):
501552
See Also
502553
--------
503554
:obj:`dpnp.left_shift` : Shift the bits of an integer to the left.
555+
:obj:`dpnp.binary_repr` : Return the binary representation of the input number
556+
as a string.
504557
505558
Examples
506559
--------
@@ -515,6 +568,13 @@ def binary_repr(num, width=None):
515568
516569
>>> x1 >> x2
517570
array([5, 2, 1])
571+
572+
>>> np.binary_repr(10)
573+
'1010'
574+
>>> np.right_shift(np.array(10), 1)
575+
array(5)
576+
>>> np.binary_repr(5)
577+
'101'
518578
"""
519579

520580
right_shift = DPNPBinaryFunc(

0 commit comments

Comments
 (0)