[Numpy-discussion] Meson - C extension - Finding numpy includes in virtual env

2023-11-25 Thread Doug Turnbull
I am converting a Numpy C extension Python project from distutils to meson.
I've been following along the meson-python instructions (
https://meson-python.readthedocs.io/en/latest/tutorials/introduction.html)

I've installed meson / ninja (and everything else...) into a virtualenv
(python -m venv venv). Running Python 3.11

Unfortunately the following command fails:

incdir_numpy = run_command(py,
  ['-c', 'import numpy; print(numpy.get_include())'],
  capture: true,
  check: false,
).stdout().strip()

Capturing stderr, gives the error:

>   ModuleNotFoundError: No module named 'numpy' does not exist.

But If I hardcode incdir_numpy to my actual location, it works fine

incdir_numpy = 'venv/lib/python3.11/site-packages/numpy/core/include'

I've tried deactivating / activating the venv and rebuilding, no such luck.

I feel like I'm missing something obvious about meson / numpy and virtual
environments?

My changes are here

https://github.com/softwaredoug/np-sims/compare/meson?expand=1#diff-30d8f6be6320feeacf686be94f48c70869b52630e01ea625f0f15adc0d57c3e4R5
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] savetxt() has fmt='%.18e' as default, but fmt='%.16e' is always sufficient

2023-11-25 Thread Jeppe Dakin
Double-precision numbers need at most 17 significant decimal digits to be 
serialised losslessly. Yet, savetxt() uses 19 by default, meaning that most 
files produced with savetxt() takes up about 9% more disk space than they need 
to, without any benefit. I have described the problem more detailed on 
Stackoverflow:
https://stackoverflow.com/questions/77535380/minimum-number-of-digits-for-exact-double-precision-and-the-fmt-18e-of-numpy

Is there any reason behind the default choice of savetxt(..., fmt='%.18e')? If 
not, why not reduce it to savetxt(..., fmt='%.16e')?
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: savetxt() has fmt='%.18e' as default, but fmt='%.16e' is always sufficient

2023-11-25 Thread Robert Kern
On Sat, Nov 25, 2023 at 11:18 AM Jeppe Dakin 
wrote:

> Double-precision numbers need at most 17 significant decimal digits to be
> serialised losslessly. Yet, savetxt() uses 19 by default, meaning that most
> files produced with savetxt() takes up about 9% more disk space than they
> need to, without any benefit. I have described the problem more detailed on
> Stackoverflow:
>
> https://stackoverflow.com/questions/77535380/minimum-number-of-digits-for-exact-double-precision-and-the-fmt-18e-of-numpy
>
> Is there any reason behind the default choice of savetxt(...,
> fmt='%.18e')? If not, why not reduce it to savetxt(..., fmt='%.16e')?
>

A long time ago when `savetxt()` was written, we did not use the reliable
Dragon4 string representation algorithm that guarantees that floating point
numbers are written out with the minimum number of decimal digits needed to
reproduce the number. We may even have relied on the platform's floating
point to string conversion routines, which were of variable quality. The
extra digits accounted for that unreliability.

It probably could be changed now, but I'd want more aggressive testing of
the assertion of correctness (`random()`, as used in that StackOverflow
demonstration, does *not* exercise a lot of the important edge cases in the
floating point format). But if your true concern is that 9% of disk space,
you probably don't want to be using `savetxt()` in any case.

-- 
Robert Kern
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Meson - C extension - Finding numpy includes in virtual env

2023-11-25 Thread Stefan van der Walt via NumPy-Discussion
Hi Doug,

On Sat, Nov 25, 2023, at 07:14, Doug Turnbull wrote:
> Unfortunately the following command fails:
> 
> incdir_numpy = run_command(py,
>   ['-c', 'import numpy; print(numpy.get_include())'],
>   capture: true,
>   check: false,
> ).stdout().strip()

In your repo it says stderr, but the version above (stdout) works for me.

Perhaps you are using a different Python than the one in your virtual env, 
because meson was installed onto your path previously? Try `python -m pip 
install meson` and then invoking the meson binary directly from your 
virtualenv: venv/bin/meson.

Stéfan
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com