Skip to content

Commit

Permalink
nanobind: fix adapt_c_buffer on windows (we can use precisely sized t…
Browse files Browse the repository at this point in the history
…ypes)
  • Loading branch information
pthom committed Nov 7, 2024
1 parent c75db40 commit 27f06bf
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 25 deletions.
15 changes: 0 additions & 15 deletions src/litgen/integration_tests/_pydef_nanobind/nanobind_mylib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,8 @@ void py_init_module_lg_mylib(nb::module_& m)
void * buffer_from_pyarray = buffer.data();
size_t buffer_count = buffer.shape(0);

#ifdef _WIN32
using np_uint_l = uint32_t;
using np_int_l = int32_t;
#else
using np_uint_l = uint64_t;
using np_int_l = int64_t;
#endif

// Define a lambda to compute the letter code for the buffer type
auto _nanobind_buffer_type_to_letter_code = [](uint8_t dtype_code, size_t sizeof_item) -> char
Expand Down Expand Up @@ -1463,13 +1458,8 @@ void py_init_module_lg_mylib(nb::module_& m)
void * buffer_from_pyarray = buffer.data();
size_t buffer_count = buffer.shape(0);

#ifdef _WIN32
using np_uint_l = uint32_t;
using np_int_l = int32_t;
#else
using np_uint_l = uint64_t;
using np_int_l = int64_t;
#endif

// Define a lambda to compute the letter code for the buffer type
auto _nanobind_buffer_type_to_letter_code = [](uint8_t dtype_code, size_t sizeof_item) -> char
Expand Down Expand Up @@ -1672,13 +1662,8 @@ void py_init_module_lg_mylib(nb::module_& m)
void * buffer_from_pyarray = buffer.data();
size_t buffer_count = buffer.shape(0);

#ifdef _WIN32
using np_uint_l = uint32_t;
using np_int_l = int32_t;
#else
using np_uint_l = uint64_t;
using np_int_l = int64_t;
#endif

// Define a lambda to compute the letter code for the buffer type
auto _nanobind_buffer_type_to_letter_code = [](uint8_t dtype_code, size_t sizeof_item) -> char
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,10 @@ def make_adapted_lambda_code_end_template_buffer(self) -> str:
char {template_buffer_name}_type = {template_buffer_name}.dtype().char_();
"""
elif self.options.bind_library == BindLibraryType.nanobind:
# Contrary to pybind, we get info about the exact size in bits, so that we can use precisely sized types below
_nanobind_buffer_type_to_letter_code = """
#ifdef _WIN32
using np_uint_l = uint32_t;
using np_int_l = int32_t;
#else
using np_uint_l = uint64_t;
using np_int_l = int64_t;
#endif
// Define a lambda to compute the letter code for the buffer type
auto _nanobind_buffer_type_to_letter_code = [](uint8_t dtype_code, size_t sizeof_item) -> char
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,8 @@ def test_template_buffer_nanobind():
const void * buf_from_pyarray = buf.data();
size_t buf_count = buf.shape(0);
#ifdef _WIN32
using np_uint_l = uint32_t;
using np_int_l = int32_t;
#else
using np_uint_l = uint64_t;
using np_int_l = int64_t;
#endif
// Define a lambda to compute the letter code for the buffer type
auto _nanobind_buffer_type_to_letter_code = [](uint8_t dtype_code, size_t sizeof_item) -> char
Expand Down

0 comments on commit 27f06bf

Please sign in to comment.