Skip to content

Commit f5171b3

Browse files
authored
Implement blackman function in keras.ops (#21235)
* Add blackman for ops * Add numpy test for blackman * Add excluded_concrete_tests for blackman * Add NotImplementedError for openvino
1 parent ce95589 commit f5171b3

File tree

12 files changed

+96
-0
lines changed

12 files changed

+96
-0
lines changed

keras/api/_tf_keras/keras/ops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
from keras.src.ops.numpy import bitwise_or as bitwise_or
145145
from keras.src.ops.numpy import bitwise_right_shift as bitwise_right_shift
146146
from keras.src.ops.numpy import bitwise_xor as bitwise_xor
147+
from keras.src.ops.numpy import blackman as blackman
147148
from keras.src.ops.numpy import broadcast_to as broadcast_to
148149
from keras.src.ops.numpy import ceil as ceil
149150
from keras.src.ops.numpy import clip as clip

keras/api/_tf_keras/keras/ops/numpy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from keras.src.ops.numpy import bitwise_or as bitwise_or
3737
from keras.src.ops.numpy import bitwise_right_shift as bitwise_right_shift
3838
from keras.src.ops.numpy import bitwise_xor as bitwise_xor
39+
from keras.src.ops.numpy import blackman as blackman
3940
from keras.src.ops.numpy import broadcast_to as broadcast_to
4041
from keras.src.ops.numpy import ceil as ceil
4142
from keras.src.ops.numpy import clip as clip

keras/api/ops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
from keras.src.ops.numpy import bitwise_or as bitwise_or
145145
from keras.src.ops.numpy import bitwise_right_shift as bitwise_right_shift
146146
from keras.src.ops.numpy import bitwise_xor as bitwise_xor
147+
from keras.src.ops.numpy import blackman as blackman
147148
from keras.src.ops.numpy import broadcast_to as broadcast_to
148149
from keras.src.ops.numpy import ceil as ceil
149150
from keras.src.ops.numpy import clip as clip

keras/api/ops/numpy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from keras.src.ops.numpy import bitwise_or as bitwise_or
3737
from keras.src.ops.numpy import bitwise_right_shift as bitwise_right_shift
3838
from keras.src.ops.numpy import bitwise_xor as bitwise_xor
39+
from keras.src.ops.numpy import blackman as blackman
3940
from keras.src.ops.numpy import broadcast_to as broadcast_to
4041
from keras.src.ops.numpy import ceil as ceil
4142
from keras.src.ops.numpy import clip as clip

keras/src/backend/jax/numpy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ def right_shift(x, y):
474474
return bitwise_right_shift(x, y)
475475

476476

477+
def blackman(x):
478+
x = convert_to_tensor(x)
479+
return jnp.blackman(x)
480+
481+
477482
def broadcast_to(x, shape):
478483
x = convert_to_tensor(x)
479484
return jnp.broadcast_to(x, shape)

keras/src/backend/numpy/numpy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ def right_shift(x, y):
390390
return bitwise_right_shift(x, y)
391391

392392

393+
def blackman(x):
394+
x = convert_to_tensor(x)
395+
return np.blackman(x).astype(config.floatx())
396+
397+
393398
def broadcast_to(x, shape):
394399
return np.broadcast_to(x, shape)
395400

keras/src/backend/openvino/excluded_concrete_tests.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ NumpyDtypeTest::test_any
99
NumpyDtypeTest::test_argpartition
1010
NumpyDtypeTest::test_array
1111
NumpyDtypeTest::test_bartlett
12+
NumpyDtypeTest::test_blackman
1213
NumpyDtypeTest::test_bitwise
1314
NumpyDtypeTest::test_ceil
1415
NumpyDtypeTest::test_concatenate
@@ -76,6 +77,7 @@ NumpyOneInputOpsCorrectnessTest::test_any
7677
NumpyOneInputOpsCorrectnessTest::test_argpartition
7778
NumpyOneInputOpsCorrectnessTest::test_array
7879
NumpyOneInputOpsCorrectnessTest::test_bartlett
80+
NumpyOneInputOpsCorrectnessTest::test_blackman
7981
NumpyOneInputOpsCorrectnessTest::test_bitwise_invert
8082
NumpyOneInputOpsCorrectnessTest::test_conj
8183
NumpyOneInputOpsCorrectnessTest::test_correlate
@@ -152,4 +154,5 @@ NumpyTwoInputOpsCorrectnessTest::test_vdot
152154
NumpyTwoInputOpsCorrectnessTest::test_where
153155
NumpyOneInputOpsDynamicShapeTest::test_angle
154156
NumpyOneInputOpsDynamicShapeTest::test_bartlett
157+
NumpyOneInputOpsDynamicShapeTest::test_blackman
155158
NumpyOneInputOpsStaticShapeTest::test_angle

keras/src/backend/openvino/numpy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ def bincount(x, weights=None, minlength=0, sparse=False):
509509
return OpenVINOKerasTensor(final_output)
510510

511511

512+
def blackman(x):
513+
raise NotImplementedError(
514+
"`blackman` is not supported with openvino backend"
515+
)
516+
517+
512518
def broadcast_to(x, shape):
513519
assert isinstance(shape, (tuple, list)), (
514520
"`broadcast_to` is supported only for tuple and list `shape`"

keras/src/backend/tensorflow/numpy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,18 @@ def right_shift(x, y):
10581058
return bitwise_right_shift(x, y)
10591059

10601060

1061+
def blackman(x):
1062+
dtype = config.floatx()
1063+
x = tf.cast(x, dtype)
1064+
n = tf.range(x, dtype=dtype)
1065+
n_minus_1 = tf.cast(x - 1, dtype)
1066+
term1 = 0.42
1067+
term2 = -0.5 * tf.cos(2 * np.pi * n / n_minus_1)
1068+
term3 = 0.08 * tf.cos(4 * np.pi * n / n_minus_1)
1069+
window = term1 + term2 + term3
1070+
return window
1071+
1072+
10611073
def broadcast_to(x, shape):
10621074
return tf.broadcast_to(x, shape)
10631075

keras/src/backend/torch/numpy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@ def right_shift(x, y):
515515
return bitwise_right_shift(x, y)
516516

517517

518+
def blackman(x):
519+
x = convert_to_tensor(x)
520+
return torch.signal.windows.blackman(x)
521+
522+
518523
def broadcast_to(x, shape):
519524
x = convert_to_tensor(x)
520525
return torch.broadcast_to(x, shape)

0 commit comments

Comments
 (0)