Skip to content
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

Add 2D signal b-splines to cupyx.scipy.signal #7721

Merged
merged 7 commits into from
Sep 8, 2023

Conversation

andfoy
Copy link
Contributor

@andfoy andfoy commented Jul 13, 2023

See #7403
Depends on #7715

@andfoy andfoy changed the title Add 2d signal b-splines to cupyx.scipy.signal Add 2D signal b-splines to cupyx.scipy.signal Jul 13, 2023
@emcastillo emcastillo added cat:feature New features/APIs prio:medium labels Jul 14, 2023
intype = Iin.dtype.char
hcol = cupy.asarray([1.0, 4.0, 1.0], 'f') / 6.0
if intype in ['F', 'D']:
Iin = Iin.astype('F')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange (both here and in scipy) : why does it only work in single precision complex.

Also below, is there a major reason sepfir2d cannot natively support complex inputs?

Copy link
Contributor Author

@andfoy andfoy Jul 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mention it, this is directly copied from SciPy, no modifications so far. We would need to research more about the sepfir implementation.

My guess is that (from what I've seen), all the implementations in _splines_mod.c.in (Or that template file in SciPy) only define functions for floating point numbers and not for other data types

EDIT: CuPy sepfir2 does support complex dtypes

@mergify
Copy link
Contributor

mergify bot commented Aug 2, 2023

This pull request is now in conflicts. Could you fix it @andfoy? 🙏

@andfoy andfoy force-pushed the add_2d_signal_splines branch from f1b1298 to 467eb1f Compare August 3, 2023 12:30
@andfoy andfoy marked this pull request as ready for review August 3, 2023 12:31
@takagi
Copy link
Member

takagi commented Aug 22, 2023

/test mini

@@ -393,3 406,111 @@ def qspline1d_eval(cj, newx, dx=1.0, x0=0):
result = cj[indj] * _quadratic(newx - thisj)
res[cond3] = result
return res


def cspline2d(signal, lamb=0.0, precision=-1.0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that scipy uses lambda for the name of the second argument. Any reason to choose lamb here?
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.cspline2d.html

Copy link
Contributor Author

@andfoy andfoy Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As lambda is a reserved keyword in Python, then it is not possible to use it. Since SciPy is generating the signature from C, I think it would be possible to declare lambda as a parameter in the exported function. However in the practice, any use of lambda will trigger a SyntaxError. https://github.com/scipy/scipy/blob/897d811c616ec380df4000e117034e0c4cb2815c/scipy/signal/_splinemodule.c#L22

This is a bug in SciPy

return out


def qspline2d(signal, lamb=0.0, precision=-1.0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto (lambda?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@takagi
Copy link
Member

takagi commented Aug 22, 2023

Some tests seem to have mismatched values. Would you check them?

@andfoy
Copy link
Contributor Author

andfoy commented Aug 22, 2023

The numerical errors were caused after 9cc8dc2 in #7651, I'm debugging any call to result_type that might got affected

@andfoy
Copy link
Contributor Author

andfoy commented Aug 22, 2023

The culprit is cupy._r, which now is ignoring floating point arguments and instead casting them to integer. Specific to one of the failing tests:
imagen

When it was passing:
imagen

I don't know if this is a new behaviour or a regression caused after #7651

@andfoy
Copy link
Contributor Author

andfoy commented Aug 22, 2023

I can confirm the tests are fixed after #7815

@mergify
Copy link
Contributor

mergify bot commented Sep 6, 2023

This pull request is now in conflicts. Could you fix it @andfoy? 🙏

@andfoy andfoy force-pushed the add_2d_signal_splines branch from 467eb1f to 42c706a Compare September 6, 2023 16:42
@takagi
Copy link
Member

takagi commented Sep 7, 2023

/test full

@takagi takagi added this to the v13.0.0rc1 milestone Sep 7, 2023
@takagi takagi merged commit 5f6b487 into cupy:main Sep 8, 2023
@takagi
Copy link
Member

takagi commented Sep 8, 2023

Thanks, @andfoy!

@andfoy andfoy deleted the add_2d_signal_splines branch September 8, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants