Skip to content

Commit 38e27aa

Browse files
authored
Standardize cost model type names to snake_case (#7464)
The JavaScript visualization code used camelCase (addedSizes, multipliedSizes, minSize, maxSize) while the JSON data files consistently use snake_case (added_sizes, multiplied_sizes, min_size, max_size). This fixes the ValueContains visualization when using added_sizes model type. Changes: - Rename evaluators to match JSON format - Update formula display cases - Add consistent intercept/slope coefficient support
1 parent 1e7322a commit 38e27aa

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

doc/cost-models/shared/utils.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,33 +131,34 @@ const CostModelEvaluators = {
131131
return (coeffs.c0 || 0) + (coeffs.c1 || 0) * args[1] + (coeffs.c2 || 0) * args[2];
132132
},
133133

134-
addedSizes: (coeffs, args) => {
135-
// addedSizes models cost as linear in sum of sizes
134+
added_sizes: (coeffs, args) => {
135+
// added_sizes models cost as linear in sum of sizes
136136
const sum = args.reduce((a, b) => a + b, 0);
137-
return (coeffs.c0 || 0) + (coeffs.c1 || 0) * sum;
137+
const c0 = coeffs.c0 || coeffs.intercept || 0;
138+
const c1 = coeffs.c1 || coeffs.slope || 0;
139+
return c0 + c1 * sum;
138140
},
139141

140-
multipliedSizes: (coeffs, args) => {
141-
// multipliedSizes models cost as linear in product of sizes
142+
multiplied_sizes: (coeffs, args) => {
143+
// multiplied_sizes models cost as linear in product of sizes
142144
const product = args.reduce((a, b) => a * b, 1);
143145
const c0 = coeffs.c0 || coeffs.intercept || 0;
144146
const c1 = coeffs.c1 || coeffs.slope || 0;
145147
return c0 + c1 * product;
146148
},
147149

148-
multiplied_sizes: (coeffs, args) => {
149-
// Alias for multipliedSizes (snake_case version)
150-
return CostModelEvaluators.multipliedSizes(coeffs, args);
151-
},
152-
153-
minSize: (coeffs, args) => {
150+
min_size: (coeffs, args) => {
154151
const min = Math.min(...args);
155-
return (coeffs.c0 || 0) + (coeffs.c1 || 0) * min;
152+
const c0 = coeffs.c0 || coeffs.intercept || 0;
153+
const c1 = coeffs.c1 || coeffs.slope || 0;
154+
return c0 + c1 * min;
156155
},
157156

158-
maxSize: (coeffs, args) => {
157+
max_size: (coeffs, args) => {
159158
const max = Math.max(...args);
160-
return (coeffs.c0 || 0) + (coeffs.c1 || 0) * max;
159+
const c0 = coeffs.c0 || coeffs.intercept || 0;
160+
const c1 = coeffs.c1 || coeffs.slope || 0;
161+
return c0 + c1 * max;
161162
},
162163

163164
linear_in_max_yz: (coeffs, args) => {
@@ -301,17 +302,16 @@ function formatModelFormula(modelType, coefficients) {
301302
case 'linear_in_yz':
302303
return `${formatCoeff(c0)} + ${formatCoeff(c1)} × (arg2) + ${formatCoeff(c2)} × (arg3) picoseconds`;
303304

304-
case 'addedSizes':
305+
case 'added_sizes':
305306
return `${formatCoeff(c0)} + ${formatCoeff(c1)} × (sum of args) picoseconds`;
306307

307-
case 'multipliedSizes':
308308
case 'multiplied_sizes':
309309
return `${formatCoeff(c0)} + ${formatCoeff(c1)} × (product of args) picoseconds`;
310310

311-
case 'minSize':
311+
case 'min_size':
312312
return `${formatCoeff(c0)} + ${formatCoeff(c1)} × (min of args) picoseconds`;
313313

314-
case 'maxSize':
314+
case 'max_size':
315315
return `${formatCoeff(c0)} + ${formatCoeff(c1)} × (max of args) picoseconds`;
316316

317317
case 'linear_in_max_yz':

0 commit comments

Comments
 (0)