Skip to content

Commit 0308362

Browse files
apronchenkovcopybara-github
authored andcommitted
Changed the method ExprOperator::GetSignature to return a shared-ptr
Motivation: The primary goal of this change is to provide efficient access to the operator’s aux_policy without incurring the cost of copying the full signature. This enables the use of `op.signature.aux_policy` for `ExprView` customisation. It also allows moving the `Validate*Count()` utilities to the `ExprOperator` base class, which was previously avoided because of the performance penalty of signature copying. --- Benchmark results for future reference: ```python from arolla import arolla _1 = arolla.int32(1) _2 = arolla.int32(2) op = arolla.M.math.add %timeit arolla.abc.get_operator_signature(op) # 356ns -> 313ns %timeit arolla.abc.aux_bind_op(op, _1, _2) # 1.05us -> 1.02us %timeit arolla.abc.aux_eval_op(op, _1, _2) # 442ns -> 405ns ``` PiperOrigin-RevId: 858086299 Change-Id: I764a2d50e6db68367cd0d4c94c0a4c8396eb1398
1 parent 2044cdb commit 0308362

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

py/koladata/expr/py_expr_eval.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,23 @@ PyObject* absl_nullable PyEvalOp(PyObject* /*self*/, PyObject** py_args,
179179
ASSIGN_OR_RETURN(auto signature, op->GetSignature(), SetPyErrFromStatus(_));
180180
std::vector<QValueOrExpr> bound_args;
181181
AuxBindingPolicyPtr policy_implementation;
182-
if (!AuxBindArguments(signature, py_args + 1,
182+
if (!AuxBindArguments(*signature, py_args + 1,
183183
(nargs - 1) | PY_VECTORCALL_ARGUMENTS_OFFSET,
184184
py_kwnames, &bound_args, &policy_implementation)) {
185185
return nullptr;
186186
}
187187

188188
// Generate `input_qvalues`.
189189
const auto param_name = [&signature](size_t i) -> std::string {
190-
if (!HasVariadicParameter(signature)) {
191-
DCHECK_LT(i, signature.parameters.size());
192-
return signature.parameters[i].name;
190+
if (!HasVariadicParameter(*signature)) {
191+
DCHECK_LT(i, signature->parameters.size());
192+
return signature->parameters[i].name;
193193
}
194-
if (i + 1 < signature.parameters.size()) {
195-
return signature.parameters[i].name;
194+
if (i + 1 < signature->parameters.size()) {
195+
return signature->parameters[i].name;
196196
}
197-
return absl::StrCat(signature.parameters.back().name, "[",
198-
i - signature.parameters.size() + 1, "]");
197+
return absl::StrCat(signature->parameters.back().name, "[",
198+
i - signature->parameters.size() + 1, "]");
199199
};
200200

201201
std::vector<TypedRef> input_qvalues;

py/koladata/operators/py_unified_binding_policy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ class UnifiedBindingPolicy : public AuxBindingPolicy {
734734
// (See the base class.)
735735
ExprNodePtr absl_nullable MakeLiteral(TypedValue&& value) const final {
736736
ASSIGN_OR_RETURN(auto result, koladata::expr::MakeLiteral(std::move(value)),
737-
(SetPyErrFromStatus(_), nullptr));
737+
SetPyErrFromStatus(_));
738738
return result;
739739
}
740740
};

0 commit comments

Comments
 (0)