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

Method match

mlx/export.cpp:599–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

597};
598
599bool FunctionTable::match(
600 const Args& args,
601 const std::map<std::string, array>& kwargs,
602 const Function& fun) {
603 for (auto& k : fun.kwarg_keys) {
604 if (kwargs.find(k) == kwargs.end()) {
605 return false;
606 }
607 }
608
609 auto match_inputs = [shapeless = this->shapeless](
610 const array& x, const array& y) {
611 if (x.dtype() != y.dtype()) {
612 return false;
613 }
614 if (x.ndim() != y.ndim()) {
615 return false;
616 }
617 if (!shapeless && x.shape() != y.shape()) {
618 return false;
619 }
620 return true;
621 };
622
623 int i = 0;
624 for (; i < args.size(); ++i) {
625 if (!match_inputs(args[i], fun.inputs[i])) {
626 return false;
627 }
628 }
629 for (auto& [_, in] : kwargs) {
630 if (!match_inputs(in, fun.inputs[i++])) {
631 return false;
632 }
633 }
634
635 return true;
636}
637
638std::pair<FunctionTable::Function&, bool> FunctionTable::emplace(
639 const Args& args,

Callers

nothing calls this directly

Calls 3

findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected