Skip to content

Commit 760e4c7

Browse files
committed
Add check for empty inputs in getEnergyStats
1 parent f670f33 commit 760e4c7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

internal/cmd/perfcomp/energystatistics_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ func TestEnergyStatistics(t *testing.T) {
8282
assert.NotEqual(t, nil, err)
8383
assert.ErrorContains(t, err, "both inputs must have the same number of columns")
8484

85+
x.Reset()
86+
y = &mat.Dense{}
87+
88+
_, _, _, err = getEnergyStatistics(x, y)
89+
assert.NotEqual(t, nil, err)
90+
assert.ErrorContains(t, err, "inputs cannot be empty")
91+
8592
x = mat.NewDense(2, 2, make([]float64, 4))
8693
y = mat.NewDense(3, 2, make([]float64, 6))
8794

internal/cmd/perfcomp/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ func getEnergyStatistics(x, y *mat.Dense) (float64, float64, float64, error) {
334334
if xcols != ycols {
335335
return 0, 0, 0, fmt.Errorf("both inputs must have the same number of columns")
336336
}
337+
if xrows == 0 || yrows == 0 {
338+
return 0, 0, 0, fmt.Errorf("inputs cannot be empty")
339+
}
337340

338341
xrowsf := float64(xrows)
339342
yrowsf := float64(yrows)

0 commit comments

Comments
 (0)