GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MAINT: Vendor npymath as git submodule and vendor npyrandom directly by lysnikolaou · Pull Request #19638 · scipy/scipy

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented Dec 5, 2023 •
edited by rgommers
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Closes gh-17498

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rgommers reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@lysnikolaou lysnikolaou changed the title Vendor libnpymath Vendor stand-alone libnpymath Dec 5, 2023
@lucascolley lucascolley added the maintenance Items related to regular maintenance tasks label Dec 5, 2023
@lysnikolaou
lysnikolaou force-pushed the vendor-libnpymath branch from d86d9fe to e74a1a6 Compare December 5, 2023 14:37
@lucascolley

lucascolley commented Dec 5, 2023

Copy link
Copy Markdown
Member

x-ref gh-17498

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lucascolley lucascolley added this to the 1.13.0 milestone Dec 6, 2023
@rgommers rgommers mentioned this pull request Dec 8, 2023
WIP: BLD: build libnpymath and libnpyrandom as Meson subprojects #18030
Closed
@rgommers

rgommers commented Dec 8, 2023

Copy link
Copy Markdown
Member

The CI failures are looking like:

stats/_biasedurn.cpython-310d-x86_64-linux-gnu.so: undefined symbol: npy_log1p

The problem here will be with statically linking libnpyrandom, since that expects the old libnpymath library and that is now replaced with the new version with renamed symbols. Hence the code for random can no longer find npy_log1p. That's why I included both libraries in gh-18030. I'm not sure whether that's the correct resolution here though. The design in numpy isn't great, it'd be much better to have a regular shared library interface for Cython. Let's discuss that on numpy/numpy#20880.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers

rgommers commented Dec 8, 2023

Copy link
Copy Markdown
Member

If we look at what we're actually using from libnpyrandom, it's fairly minimal. There are two Cython files, stats/_biasedurn.pyx and stats/_rcont/rcont.pyx, which need it. Both need the bitgen_t struct, which is a struct of pointers (see https://numpy.org/doc/stable/reference/random/extending.html#new-bit-generators):

typedef struct bitgen {
  void *state;
  uint64_t (*next_uint64)(void *st);
  uint32_t (*next_uint32)(void *st);
  double (*next_double)(void *st);
  uint64_t (*next_raw)(void *st);
} bitgen_t;

And then _biasedurn.pyx needs the random_normal function. If you look at the sources for that, you'll find that that's pretty much all pure C as well, except for it using npy_log1p. Which is simply an alias for C99's log1p.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers rgommers mentioned this pull request Dec 8, 2023
ENH: Future of npymath library numpy/numpy#20880
Open
@lysnikolaou

lysnikolaou commented Dec 13, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I've removed the libnpymath (it's not needed at all) and libnpyrandom (no need for a static library, just the sources) dependencies altogether and tested this against numpy/numpy#25390, which in turn removes any dependency on numpy from npyrandom, and it seems like everything's okay. @rgommers Do you think this is a sensible way forward?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers

rgommers commented Dec 14, 2023

Copy link
Copy Markdown
Member

Those source files aren't shipped by NumPy yet, so that cannot work I think - as also indicated by CI failures:

 scipy/meson.build:80:30: ERROR: File ../test/lib/python3.9/site-packages/numpy/core/include/../../random/src/distributions/distributions.c does not exist.

We are supporting ~4 numpy versions back, so rather than trying to ship the C sources as part of NumPy, they should be vendored somehow (either directly or via a submodule). I was suggesting above that what we need is so minimal (one struct, one function) that it may be possible to vendor the relevant bits directly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou
MAINT: Remove npymath dependency and vendor npyrandom
38e763a
@lysnikolaou
lysnikolaou force-pushed the vendor-libnpymath branch from 793319d to 38e763a Compare December 15, 2023 13:55
@lysnikolaou lysnikolaou changed the title Vendor stand-alone libnpymath MAINT: Remove npymath dependency and vendor npyrandom Dec 15, 2023
@lysnikolaou
lysnikolaou marked this pull request as ready for review December 15, 2023 13:56
@lysnikolaou
lysnikolaou requested review from person142, rgommers and steppi as code owners December 15, 2023 13:56
rgommers
rgommers reviewed Dec 15, 2023
View reviewed changes
Comment thread scipy/special/meson.build Resolved

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou added 2 commits December 15, 2023 15:32
@lysnikolaou
Add libnpymath back in
d27bad6
@lysnikolaou
Do not install npymath
4829d69
@lysnikolaou lysnikolaou changed the title MAINT: Remove npymath dependency and vendor npyrandom MAINT: Vendor npymath as git submodule and vendor npyrandom directly Dec 18, 2023
@lysnikolaou
Pull in npymath changes made for numpy
f129c8d
@carlkl

carlkl commented Dec 20, 2023

Copy link
Copy Markdown
Member

I got successfully (locally) Windows 32-bit build with lysnikolaou@4829d69 out of the box!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@matthew-brett

matthew-brett commented Dec 20, 2023

Copy link
Copy Markdown
Contributor

I got successfully (locally) Windows 32-bit build with lysnikolaou@4829d69 out of the box!

Ah - excellent - but I guess with the same ndimage test failures as before?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@carlkl

carlkl commented Dec 20, 2023

Copy link
Copy Markdown
Member

The same failures unfortunately. Not related to this PR however.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou added 3 commits January 11, 2024 12:48
@lysnikolaou
Remove lysnikolaou/libnpymath subproject
5477f17
@lysnikolaou
Add numpy/libnpymath submodule
2183954
@lysnikolaou
Merge branch 'main' into vendor-libnpymath
89468a0
@lysnikolaou

lysnikolaou commented Jan 11, 2024

Copy link
Copy Markdown
Contributor Author

This is now updated to use numpy/libnpymath, instead of my test repo. A round of review would be nice, so that we can merge it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lucascolley

lucascolley commented Jan 11, 2024

Copy link
Copy Markdown
Member

The cp311 (build sdist + wheel), full, no pythran fail is unrelated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lucascolley
lucascolley removed request for person142 and steppi January 11, 2024 12:52
@lysnikolaou

lysnikolaou commented Jan 11, 2024

Copy link
Copy Markdown
Contributor Author

So is the Meson build (3.12, false) as far as I can tell.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rgommers
rgommers reviewed Jan 12, 2024
View reviewed changes

@rgommers rgommers left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This looks quite good! Only one nontrivial comment so far. I'll have a closer look at the included C code, but should be safe since it's a sync from numpy code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread meson.build Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread scipy/stats/_rcont/_rcont.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rgommers

rgommers commented Jan 12, 2024

Copy link
Copy Markdown
Member

If you push another commit, could you include [wheel build] in the first line of your commit message? That way we run all wheel builds too, and ensure that's all green.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou added 4 commits January 12, 2024 17:15
@lysnikolaou
Add libnpyrandom README and use subproject in meson [wheel build]
ab50e0b
@lysnikolaou
Merge branch 'main' into vendor-libnpymath
9de3b8b
@lysnikolaou
Update libnpymath to fix features.h detection
6e89940
@lysnikolaou
Update libnpymath to use numpy types and usage of npy*
9b7b336
@lysnikolaou
lysnikolaou requested a review from perimosocordiae as a code owner February 27, 2024 15:26
lysnikolaou added 3 commits February 27, 2024 16:54
@lysnikolaou
Merge branch 'main' into vendor-libnpymath
905623f
@lysnikolaou
Remove numpyconfig include
b819e98
@lysnikolaou
More renames to npymath_*
8e9de83
@lysnikolaou
lysnikolaou force-pushed the vendor-libnpymath branch from d37b134 to 8e9de83 Compare February 27, 2024 18:03
@tylerjereddy

tylerjereddy commented Mar 12, 2024

Copy link
Copy Markdown
Contributor

@lysnikolaou can you summarize for me the relationship (if any) between this change and NumPy 2.0.0? As I recall, Ralf wanted this merged a few release ago, but then things got tricky with various discussion upstream.

I'm thinking of branching for 1.13.0 (NumPy 2.0.0 support release) ~Sunday the 17th.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou

lysnikolaou commented Mar 13, 2024

Copy link
Copy Markdown
Contributor Author

@lysnikolaou can you summarize for me the relationship (if any) between this change and NumPy 2.0.0? As I recall, Ralf wanted this merged a few release ago, but then things got tricky with various discussion upstream.

I'm thinking of branching for 1.13.0 (NumPy 2.0.0 support release) ~Sunday the 17th.

TL;DR This is not needed for 2.0 compatibility.

The bigger picture is that we want to eventually stop shipping static libraries with NumPy. We're working with the assumption that SciPy is one of the few, if not the only, downstream user of the static libraries, hence this PR that adds support for the new way of doing things.

However, this change did not make it into 2.0 because of challenges with complex numbers. I'm actively working on a solution for these problems, and hope that everything will be ready for 2.1. In case that goes well, npymath will be moved out of the NumPy source tree and it will be maintained in a separate repo. NumPy will still ship with the npymath static library for backwards-compatibility reasons, although we would like to eventually sunset that, and the best way to go forward for downstream would be to vendor npymath as a git submodule instead of relying on NumPy for it.

For npyrandom, the purpose of this PR is to remove any dependency on it, and instead vendor the few needed files directly. This way, we can start figuring out a plan on how to stop shipping the npyrandom static library as well.

rgommers reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tylerjereddy tylerjereddy modified the milestones: 1.13.0, 1.14.0 Mar 13, 2024
@lysnikolaou lysnikolaou mentioned this pull request Apr 8, 2024
MAINT: Vendor npyrandom instead of using static library #20413
Merged
@rgommers

rgommers commented Apr 15, 2024

Copy link
Copy Markdown
Member

The libnpyrandom part of this PR was split off and merged in gh-20413. The rest accumulated quite a few conflicts. With all the code rewrites into C++ going on in scipy.special, some of the complex type related issues there may have already been solved.

For a next step here, I'd recommend another PR splitting off whatever is mergeable next. I think it the removal of libnpymath does not have to be all at once, right? If so, then just adding the new subproject with the changes to sparsetools and ndimage would work. Although - that code doesn't use libnpymath but only npy_math.h - so is that actually a useful/necessary change?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers rgommers removed this from the 1.14.0 milestone May 25, 2024
@lucascolley lucascolley mentioned this pull request Jul 22, 2024
META: vendored code tracker #21232
Open
@ev-br

ev-br commented Sep 6, 2024

Copy link
Copy Markdown
Member

A gentle ping, as this seems to have slipped on everyone's radar. Would be great to move this along.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou

lysnikolaou commented Sep 17, 2024

Copy link
Copy Markdown
Contributor Author

@ev-br Thanks for the ping! This fell further down my priority list and I haven't had time to work on it for a while. I think we first need to clear up how NumPy will handle libnpymath going forward (how the split to a different repo will happen and how all the different piece will interact), before we can move on with this.

Hopefully I'll be able to find some time to work on this soon-ish.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lucascolley lucascolley mentioned this pull request Mar 11, 2026
MAINT: special: Remove npymath dep #24788
Merged
@ilayn ilayn modified the milestone: 1.18.0 Mar 12, 2026
@ilayn ilayn closed this in #24788 Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rgommers rgommers rgommers left review comments
@perimosocordiae perimosocordiae Awaiting requested review from perimosocordiae perimosocordiae is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

maintenance Items related to regular maintenance tasks

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BLD: Remove use of libnpymath and libnpyrandom

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@lysnikolaou @lucascolley @rgommers @carlkl @matthew-brett @tylerjereddy @ev-br @ilayn
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.