Closed mreineck closed 2 months ago
What would you expect nanobind to do with a long double
? That type is inherently non-portable. Python does not provide functionality to convert a C long double
into a Python float
, or vice versa. The only thing one could do is to drop the long
part silently, which seems bug-prone and a bad default behavior.
Well, there is numpy.longdouble
... I know that it is not guaranteed to be any longer than numpy.double
, but it worked flawlessly with pybind11
whenever the type existed on the target architecture.
In the big picture it's not something I absolutely need in my applications, but scipy.fft
, for example, relies on this feature, and that would mean that pocketfft
(which is used internally by scipy
) cannot be ported to nanobind
.
Quick example (on x86_64):
import numpy as np
import scipy
print (scipy.fft.fftn(np.zeros(10,dtype=np.longdouble)).dtype)
This will print complex256
.
There is a big difference between nanobind and pybind11 here:
pybind11 had NumPy integration. For this, it communicated (at runtime) with the low-level NumPy API, which in turn required NumPy to be installed.
nanobind does not have a dependency on any particular Tensor API. It implements a generic ndarray
type that can talk to many different libraries, but without making any assumption about such low-level bits. A long double unfortunately cannot be passed through these interfaces.
You will need to create a wrapper that casts numeric types before binding them with nanobind. I will close this issue, since there isn't an obvious solution.
Thanks for the explanation!
Problem description
I'm trying to port an existing pybind11-dependent project to
nanobind
, with generally good success. But I'm encountering an issue where thedtype
ofstd::complex<long double>
is taken: the compiler warns that a constant of 256 (bit size?) is cast to 0, and the subsequent unit tests fail. Here is an excerpt of the compiler output:Is this something that should be working, or am I using
nanobind
incorrectly? I'm happy to work on a small reproducer if this is helpful.Reproducible example code
No response