Skip to content

Commit

Permalink
fix(415): atOp's writeHash doesn't panic anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
owulveryck committed Jun 29, 2020
1 parent 9f5ade0 commit 16dc78b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 1 addition & 5 deletions op_tensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ func (op atOp) Do(inputs ...Value) (retVal Value, err error) {
}

func (op atOp) WriteHash(h hash.Hash) {
fmt.Fprintf(h, "atOp")
if err := binary.Write(h, binary.LittleEndian, op.d); err != nil {
panic(err)
}
fmt.Fprintf(h, "at%v", op.coordinates)
fmt.Fprintf(h, "atOp%v%v", op.d, op.coordinates)
}

func (op atOp) Hashcode() uint32 { return simpleHash(op) }
Expand Down
13 changes: 13 additions & 0 deletions op_tensor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gorgonia

import (
"crypto/sha256"
"runtime"
"testing"

Expand Down Expand Up @@ -345,3 +346,15 @@ func TestConcatOp(t *testing.T) {
assert.True(ValueEq(xG, aG))
assert.True(ValueEq(xx.Value(), aa.Value()))
}

func Test_atOp_WriteHash(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Fail()
}
}()
h := sha256.New()

at := &atOp{}
at.WriteHash(h)
}

0 comments on commit 16dc78b

Please sign in to comment.