Skip to content

Commit ef27f73

Browse files
committed
Adding more functions
1 parent e522f0d commit ef27f73

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

src/blosc2/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ def _raise(exc):
330330
are_partitions_behaved,
331331
arange,
332332
broadcast_to,
333-
bitwise_xor,
334333
linspace,
335334
eye,
336335
asarray,
@@ -440,6 +439,9 @@ def _raise(exc):
440439
atan,
441440
atan2,
442441
atanh,
442+
bitwise_invert,
443+
bitwise_or,
444+
bitwise_xor,
443445
conj,
444446
contains,
445447
cos,
@@ -459,12 +461,15 @@ def _raise(exc):
459461
mean,
460462
min,
461463
multiply,
464+
pow,
462465
prod,
463466
real,
464467
sin,
465468
sinh,
466469
sqrt,
470+
square,
467471
std,
472+
subtract,
468473
sum,
469474
tan,
470475
tanh,
@@ -543,6 +548,8 @@ def _raise(exc):
543548
"atan",
544549
"atan2",
545550
"atanh",
551+
"bitwise_invert",
552+
"bitwise_or",
546553
"bitwise_xor",
547554
"broadcast_to",
548555
"clib_info",
@@ -611,6 +618,7 @@ def _raise(exc):
611618
"pack_tensor",
612619
"permute_dims",
613620
"postfilter_funcs",
621+
"pow",
614622
"prefilter_funcs",
615623
"print_versions",
616624
"prod",
@@ -628,9 +636,11 @@ def _raise(exc):
628636
"set_nthreads",
629637
"set_releasegil",
630638
"sort",
639+
"square",
631640
"stack",
632641
"storage_dflts",
633642
"sum",
643+
"subtract",
634644
"tan",
635645
"tanh",
636646
"tensordot",

src/blosc2/ndarray.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
887887
np.conj: "conj",
888888
np.real: "real",
889889
np.imag: "imag",
890-
np.bitwise_not: "~",
890+
np.bitwise_invert: "~",
891891
np.isnan: "isnan",
892892
np.isfinite: "isfinite",
893893
np.isinf: "isinf",
@@ -2429,6 +2429,12 @@ def __matmul__(self, other):
24292429
def __xor__(self, other):
24302430
return bitwise_xor(self, other)
24312431

2432+
def __or__(self, other):
2433+
return bitwise_or(self, other)
2434+
2435+
def __invert__(self):
2436+
return bitwise_invert(self)
2437+
24322438

24332439
def array_from_ffi_ptr(array_ptr) -> NDArray:
24342440
"""
@@ -3547,6 +3553,9 @@ def pow(
35473553
x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr
35483554
First input array. May have any data type.
35493555
3556+
x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr
3557+
Second input array. Must be compatible with x1. May have any data type.
3558+
35503559
Returns
35513560
-------
35523561
out LazyExpr
@@ -3572,6 +3581,9 @@ def bitwise_xor(
35723581
x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr
35733582
First input array. May have any data type.
35743583
3584+
x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr
3585+
Second input array. Must be compatible with x1. May have any data type.
3586+
35753587
Returns
35763588
-------
35773589
out LazyExpr
@@ -3584,6 +3596,57 @@ def bitwise_xor(
35843596
return x1 ^ x2
35853597

35863598

3599+
def bitwise_or(
3600+
x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex,
3601+
x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex,
3602+
) -> blosc2.LazyExpr:
3603+
"""
3604+
Computes the value of x1_i | x2_i for each element x1_i of the input array x1 and x2_i
3605+
of x2.
3606+
3607+
Parameters
3608+
-----------
3609+
x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr
3610+
First input array. May have any data type.
3611+
3612+
x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr
3613+
Second input array. Must be compatible with x1. May have any data type.
3614+
3615+
Returns
3616+
-------
3617+
out LazyExpr
3618+
A LazyArray containing the element-wise results.
3619+
3620+
References
3621+
----------
3622+
`np.bitwise_or <https://numpy.org/doc/stable/reference/generated/numpy.bitwise_or.html#numpy.bitwise_or>`_
3623+
"""
3624+
return x1 | x2
3625+
3626+
3627+
def bitwise_invert(
3628+
x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex,
3629+
) -> blosc2.LazyExpr:
3630+
"""
3631+
Computes the value of ~x1_i for each element x1_i of the input array x1.
3632+
3633+
Parameters
3634+
-----------
3635+
x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr
3636+
First input array. May have any data type.
3637+
3638+
Returns
3639+
-------
3640+
out LazyExpr
3641+
A LazyArray containing the element-wise results.
3642+
3643+
References
3644+
----------
3645+
`np.bitwise_invert <https://numpy.org/doc/stable/reference/generated/numpy.bitwise_invert.html#numpy.bitwise_invert>`_
3646+
"""
3647+
return ~x1
3648+
3649+
35873650
def where(
35883651
condition: blosc2.LazyExpr | NDArray,
35893652
x: NDArray | NDField | np.ndarray | int | float | complex | bool | str | bytes | None = None,

0 commit comments

Comments
 (0)