-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Support various filtering functions in OpenVINO #21836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
445b6c0
162f6df
ec0b030
315334d
958ef56
36d35de
f1e10e5
0b366b6
194c6f0
7332a03
c8d6807
ab2eca7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -545,16 +545,61 @@ def average(x, axis=None, weights=None): | |
|
|
||
|
|
||
| def bartlett(x): | ||
| raise NotImplementedError( | ||
| "`bartlett` is not supported with openvino backend" | ||
| x = get_ov_output(x) | ||
| zero_const = ov_opset.constant(0, Type.i64) | ||
| one_const = ov_opset.constant(1, Type.i64) | ||
| two_const = ov_opset.constant(2, Type.i64) | ||
| two_const_f64 = ov_opset.constant(2.0, Type.f64) | ||
| if x.get_element_type() != Type.i64: | ||
| x = ov_opset.convert(x, Type.i64) | ||
| half = ov_opset.convert( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
||
| ov_opset.divide(ov_opset.subtract(x, one_const), two_const), Type.f64 | ||
| ) | ||
| n = ov_opset.range(zero_const, x, one_const, Type.f64) | ||
| condition = ov_opset.less_equal(n, half) | ||
| first_half = ov_opset.divide( | ||
| ov_opset.multiply(two_const_f64, n), | ||
| ov_opset.convert(ov_opset.subtract(x, one_const), Type.f64), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Instead, use a float version of |
||
| ) | ||
| second_half = ov_opset.subtract(two_const_f64, first_half) | ||
| window = ov_opset.select(condition, first_half, second_half) | ||
| window = ov_opset.convert(window, OPENVINO_DTYPES[config.floatx()]).output( | ||
| 0 | ||
| ) | ||
| return OpenVINOKerasTensor(window) | ||
|
|
||
|
|
||
| def hamming(x): | ||
| raise NotImplementedError( | ||
| "`hamming` is not supported with openvino backend" | ||
| m = get_ov_output(x) | ||
|
|
||
| m_i64 = ( | ||
| m if m.get_element_type() == Type.i64 else ov_opset.convert(m, Type.i64) | ||
| ) | ||
|
|
||
| start = ov_opset.constant(0, Type.i64) | ||
| step = ov_opset.constant(1, Type.i64) | ||
| n = ov_opset.range(start, m_i64, step, Type.f64) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Tensorflow, there is some special handling for odd vs. even numbers of elements, maybe you need this: |
||
|
|
||
| one_i64 = ov_opset.constant(1, Type.i64) | ||
| denom_i64 = ov_opset.subtract(m_i64, one_i64) | ||
| denom = ov_opset.convert(denom_i64, Type.f64) | ||
|
|
||
| two_pi = ov_opset.constant(2.0 * np.pi, Type.f64) | ||
| two_pi_over_m_minus_1 = ov_opset.divide(two_pi, denom) | ||
|
|
||
| x = ov_opset.multiply(two_pi_over_m_minus_1, n) | ||
| c = ov_opset.cos(x) | ||
|
|
||
| # 0.54 - 0.46 * cos(...) | ||
| a = ov_opset.constant(0.54, Type.f64) | ||
| b = ov_opset.constant(0.46, Type.f64) | ||
| hamming_window = ov_opset.subtract(a, ov_opset.multiply(b, c)) | ||
| hamming_window = ov_opset.convert( | ||
| hamming_window, OPENVINO_DTYPES[config.floatx()] | ||
| ) | ||
|
|
||
| return OpenVINOKerasTensor(hamming_window.output(0)) | ||
|
|
||
|
|
||
| def heaviside(x1, x2): | ||
| x1 = get_ov_output(x1) | ||
|
|
@@ -624,9 +669,30 @@ def bincount(x, weights=None, minlength=0, sparse=False): | |
|
|
||
|
|
||
| def blackman(x): | ||
danielenricocahall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| raise NotImplementedError( | ||
| "`blackman` is not supported with openvino backend" | ||
| x = get_ov_output(x) | ||
| zero_const = ov_opset.constant(0, Type.i64) | ||
| one_const = ov_opset.constant(1, Type.i64) | ||
| two_pi = ov_opset.constant(2.0 * np.pi, Type.f64) | ||
| term_1 = ov_opset.constant(0.42, Type.f64) | ||
| term_2 = ov_opset.constant(0.5, Type.f64) | ||
| term_3 = ov_opset.constant(0.08, Type.f64) | ||
| if x.get_element_type() != Type.i64: | ||
| x = ov_opset.convert(x, Type.i64) | ||
| n = ov_opset.range(zero_const, x, one_const, Type.f64) | ||
| n_minus_1 = ov_opset.subtract( | ||
| ov_opset.convert(x, Type.f64), ov_opset.constant(1.0, Type.f64) | ||
| ).output(0) | ||
| angle_2pi = ov_opset.divide(ov_opset.multiply(two_pi, n), n_minus_1) | ||
| angle_4pi = ov_opset.multiply(angle_2pi, ov_opset.constant(2.0, Type.f64)) | ||
| cos_2pi = ov_opset.cos(angle_2pi) | ||
| cos_4pi = ov_opset.cos(angle_4pi) | ||
| term_2_final = ov_opset.multiply(term_2, cos_2pi) | ||
| term_3_final = ov_opset.multiply(term_3, cos_4pi) | ||
| window = ov_opset.add(ov_opset.subtract(term_1, term_2_final), term_3_final) | ||
| window = ov_opset.convert(window, OPENVINO_DTYPES[config.floatx()]).output( | ||
| 0 | ||
| ) | ||
| return OpenVINOKerasTensor(window) | ||
|
|
||
|
|
||
| def broadcast_to(x, shape): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.