Skip to content

Commit

Permalink
Rename Scale to Mul
Browse files Browse the repository at this point in the history
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
  • Loading branch information
zenador committed May 11, 2023
1 parent 0fcf0a7 commit 012b2e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions model/histogram/float_histogram.go
Expand Up @@ -159,12 +159,12 @@ func (h *FloatHistogram) ZeroBucket() Bucket[float64] {
}
}

// Scale scales the FloatHistogram by the provided factor, i.e. it scales all
// Mul multiplies the FloatHistogram by the provided factor, i.e. it scales all
// bucket counts including the zero bucket and the count and the sum of
// observations. The bucket layout stays the same. This method changes the
// receiving histogram directly (rather than acting on a copy). It returns a
// pointer to the receiving histogram for convenience.
func (h *FloatHistogram) Scale(factor float64) *FloatHistogram {
func (h *FloatHistogram) Mul(factor float64) *FloatHistogram {
h.ZeroCount *= factor
h.Count *= factor
h.Sum *= factor
Expand Down
4 changes: 2 additions & 2 deletions model/histogram/float_histogram_test.go
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestFloatHistogramScale(t *testing.T) {
func TestFloatHistogramMul(t *testing.T) {
cases := []struct {
name string
in *FloatHistogram
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestFloatHistogramScale(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
require.Equal(t, c.expected, c.in.Scale(c.scale))
require.Equal(t, c.expected, c.in.Mul(c.scale))
// Has it also happened in-place?
require.Equal(t, c.expected, c.in)
})
Expand Down
8 changes: 4 additions & 4 deletions promql/engine.go
Expand Up @@ -2427,15 +2427,15 @@ func vectorElemBinop(op parser.ItemType, lhs, rhs float64, hlhs, hrhs *histogram
if hrhs.Schema >= hlhs.Schema {
return 0, hlhs.Copy().Sub(hrhs).Compact(0), true
}
return 0, hrhs.Copy().Scale(-1).Add(hlhs).Compact(0), true
return 0, hrhs.Copy().Mul(-1).Add(hlhs).Compact(0), true
}
return lhs - rhs, nil, true
case parser.MUL:
if hlhs != nil && hrhs == nil {
return 0, hlhs.Copy().Scale(rhs), true
return 0, hlhs.Copy().Mul(rhs), true
}
if hlhs == nil && hrhs != nil {
return 0, hrhs.Copy().Scale(lhs), true
return 0, hrhs.Copy().Mul(lhs), true
}
return lhs * rhs, nil, true
case parser.DIV:
Expand Down Expand Up @@ -2635,7 +2635,7 @@ func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without
// The histogram being added/subtracted must have
// an equal or larger schema.
if s.H.Schema >= group.histogramMean.Schema {
toAdd := right.Scale(-1).Add(left)
toAdd := right.Mul(-1).Add(left)
group.histogramMean.Add(toAdd)
} else {
toAdd := left.Sub(right)
Expand Down
4 changes: 2 additions & 2 deletions promql/functions.go
Expand Up @@ -162,7 +162,7 @@ func extrapolatedRate(vals []parser.Value, args parser.Expressions, enh *EvalNod
if resultHistogram == nil {
resultFloat *= factor
} else {
resultHistogram.Scale(factor)
resultHistogram.Mul(factor)
}

return append(enh.Out, Sample{F: resultFloat, H: resultHistogram})
Expand Down Expand Up @@ -467,7 +467,7 @@ func funcAvgOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNode
// The histogram being added/subtracted must have
// an equal or larger schema.
if h.H.Schema >= mean.Schema {
toAdd := right.Scale(-1).Add(left)
toAdd := right.Mul(-1).Add(left)
mean.Add(toAdd)
} else {
toAdd := left.Sub(right)
Expand Down

0 comments on commit 012b2e7

Please sign in to comment.