MCPcopy Create free account
hub / github.com/ml-explore/mlx / validate_argnums_argnames

Function validate_argnums_argnames

python/src/transforms.cpp:40–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40auto validate_argnums_argnames(
41 const std::optional<IntOrVec>& argnums,
42 const StrOrSet& argnames) {
43 std::unordered_set<std::string> setnames;
44 if (auto pv = std::get_if<std::string>(&argnames); pv) {
45 setnames = {*pv};
46 } else {
47 setnames = std::get<std::unordered_set<std::string>>(argnames);
48 }
49
50 if (!argnums.has_value()) {
51 // argnums was not provided and argnames was empty
52 if (setnames.empty()) {
53 return std::make_pair(std::vector<int>{0}, setnames);
54 } else {
55 return std::make_pair(std::vector<int>{}, setnames);
56 }
57 }
58
59 std::vector<int> vecnums;
60 if (auto pv = std::get_if<int>(&(*argnums)); pv) {
61 vecnums = {*pv};
62 } else {
63 vecnums = std::get<std::vector<int>>(*argnums);
64 }
65
66 return std::make_pair(vecnums, setnames);
67}
68
69auto py_value_and_grad(
70 const nb::callable& fun,

Callers 1

init_transformsFunction · 0.85

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected