-
Hi everyone ! I have been playing around with TypeError: _invert_black_body_radiation(): incompatible function arguments. The following argument types are supported:
1. _invert_black_body_radiation(q_rad: numpy.ndarray[dtype=float64, shape=(*)], emissivity: numpy.ndarray[dtype=float64, shape=(*)], T_default: numpy.ndarray[dtype=float64, shape=(*)]) -> numpy.ndarray[dtype=float64, shape=(*)]
Invoked with types: ndarray, ndarray, ndarray The method in question is defined like this: /**
* @brief Compute the radiative equilibrium temperature of a body.
*
* @param q_rad Radiative heat flux [W/m^2].
* @param emissivity Emissivity [-].
* @param T_default Default temperature in case of irrelevant heat flux. [K]
* @return nb::tensor<nb::numpy, double, nb::shape<nb::any>> The equilibrium temperature [K].
*/
nb::tensor<nb::numpy, double, nb::shape<nb::any>> _invert_black_body_radiation(
nb::tensor<nb::numpy, double, nb::shape<nb::any>> q_rad,
nb::tensor<nb::numpy, double, nb::shape<nb::any>> emissivity,
nb::tensor<nb::numpy, double, nb::shape<nb::any>> T_default) {
size_t const n_facets = q_rad.shape(0);
assert(((emissivity.shape(0) == n_facets) && (T_default.shape(0) == n_facets)) &&
"The number of facets must be the same for all the inputs.");
std::vector<double> T_rad(T_default.data(), T_default.data() + n_facets);
for (size_t ifacet = 0; ifacet < n_facets; ifacet++) {
if (q_rad(ifacet) > 0.0) {
T_rad[ifacet] = std::pow(q_rad(ifacet) / (emissivity(ifacet) * SIGMA_BOLTZMANN), 0.25);
}
}
size_t const shape[1] = {n_facets};
return nb::tensor<nb::numpy, double, nb::shape<nb::any>>{T_rad.data(), /* ndim = */ 1, shape};
}
NB_MODULE(_computer, m) {
m.def("_invert_black_body_radiation", _invert_black_body_radiation, "q_rad"_a, "emissivity"_a,
"T_default"_a);
} and I tried invoking it like this: Tw = _comp_lib._invert_black_body_radiation(
q,
wall_emissivity,
prev_Tw,
) or even like this: Tw = _comp_lib._invert_black_body_radiation(
np.array(q, copy=False, dtype=np.float64),
np.array(vehicle.mesh.wall_emissivity, copy=False, dtype=np.float64),
np.array(prev_Tw, copy=False, dtype=np.float64),
) but I always have the same error. Does it ring a bell to someone by any chance ? :/ Thank you very much in advance for your help !! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 18 replies
-
Are you using nanobind |
Beta Was this translation helpful? Give feedback.
-
Hi @wjakob, Did you by any chance have some time to think about this issue ? In the same context, I noticed that the content of the vector printed from the C++ is correct but when I print the Python variable that receives the result from the C++ function, it does not contain the same data. Namely, in C++ I have this: ...
size_t const shape[1] = {n_facets};
std::cout << "T_rad.data()[0] = " << T_rad.data()[0] << std::endl;
return nb::tensor<nb::numpy, double, nb::shape<nb::any>>{T_rad.data(),
/* ndim = */ 1, shape};
} which (expectedly) shows T_rad.data()[0] = 273.15 But in Python, when I check this: ...
Tw = _comp_lib._invert_black_body_radiation(
q,
vehicle.mesh.wall_emissivity,
prev_Tw,
)
print(Tw[:10])
... I get: [ 0. 273.15 0. 273.15 273.15
273.15 1321.53307218 1322.34243458 273.15 1268.4787978 ] and, independently of the other values, you can see that the first value does not match the value it had in C++ right before returning. Does this point to an issue with the type of the items in the tensor ? It feels to me like it is miscounting bytes in one way or another. |
Beta Was this translation helpful? Give feedback.
Are you using nanobind
master
or0.1.0
? (In the latter case, please try themaster
branch). If that's not the issue, then could it be that you are not calling the function with 1D tensors? (You specifiednb::shape<nb::any>
-- if you want to accept any shape+dimension, remove thenb::shape
annotation completly.).