mirror of
https://github.com/ml-explore/mlx.git
synced 2025-10-19 08:20:15 +08:00
Allow None input to compiled functions (#2621)
* Allow None input to compiled functions * Allow None input to compiled functions
This commit is contained in:
@@ -441,6 +441,7 @@ struct PyCompiledFun {
|
||||
constexpr uint64_t array_identifier = 18446744073709551557UL;
|
||||
constexpr uint64_t list_identifier = 18446744073709551533UL;
|
||||
constexpr uint64_t dict_identifier = 18446744073709551521UL;
|
||||
constexpr uint64_t none_identifier = 10239356951478402889UL;
|
||||
|
||||
// Flatten the tree with hashed constants and structure
|
||||
std::function<void(nb::handle)> recurse;
|
||||
@@ -476,10 +477,12 @@ struct PyCompiledFun {
|
||||
} else if (nb::isinstance<nb::float_>(obj)) {
|
||||
auto r = nb::cast<double>(obj);
|
||||
constants.push_back(*reinterpret_cast<uint64_t*>(&r));
|
||||
} else if (obj.is_none()) {
|
||||
constants.push_back(none_identifier);
|
||||
} else {
|
||||
std::ostringstream msg;
|
||||
msg << "[compile] Function arguments must be trees of arrays "
|
||||
<< "or constants (floats, ints, or strings), but received "
|
||||
<< "or constants (floats, ints, strings, or None), but received "
|
||||
<< "type " << type_name_str(obj) << ".";
|
||||
throw std::invalid_argument(msg.str());
|
||||
}
|
||||
|
Reference in New Issue
Block a user