Skip to content
Permalink
Browse files

Go report (#318)

* chore(fmt): gofmt -s -w

* chore(doc): fix typos

* chore: fix ineffective assigments

* chore: linter

* fix(im2col): code clarity and better variable assignment
  • Loading branch information...
owulveryck authored and chewxy committed Sep 6, 2019
1 parent bbd9d45 commit 1b4cc0a64e584711c1a09a8fed04b67bc35a47b3
@@ -159,4 +159,4 @@ func (ctx *context) DoWork() {
func (ctx *context) WorkAvailable() <-chan struct{} { return ctx.workAvailable }

// String implements runtime.Stringer and fmt.Stringer. It returns the name of the BLAS implementation.
func (ctxt *context) String() string { return "Blase" }
func (*context) String() string { return "Blase" }
@@ -73,7 +73,7 @@ func Broadcast(a, b *Node, pattern BroadcastPattern) (*Node, *Node, error) {
if len(broadcastOn[0]) > 0 {
children := Nodes{x}
for _, a := range broadcastOn[0] {
if a >= yshape.Dims(){
if a >= yshape.Dims() {
return nil, nil, errors.Errorf("Attempting to broadcast a on axis %d of b. But b has shape %v", a, yshape)
}

@@ -92,7 +92,7 @@ func Broadcast(a, b *Node, pattern BroadcastPattern) (*Node, *Node, error) {
if len(broadcastOn[1]) > 0 {
children := Nodes{y}
for _, a := range broadcastOn[1] {
if a >= xshape.Dims(){
if a >= xshape.Dims() {
return nil, nil, errors.Errorf("Attempting to broadcast b on axis %d of a. But a has shape %v", a, xshape)
}

@@ -62,6 +62,9 @@ func TestBroadcast(t *testing.T) {
t.Fatal(err)
}
z, err = Add(a, b)
if err != nil {
t.Fatal(err)
}
if a, b, err = Broadcast(x, y, NewBroadcastPattern(nil, []byte{1})); err != nil {
ioutil.WriteFile("Broadcast.dot", []byte(g.ToDot()), 0644)
t.Fatal(err)
@@ -133,6 +133,9 @@ func main() {

cudamodules := path.Join(gorgoniaLoc, "cudamodules.go")
f, err := os.OpenFile(cudamodules, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()

f.Write([]byte("// +build cuda\n\npackage gorgonia\n"))
@@ -13,7 +13,7 @@ import (
const DEBUG = true

var TABCOUNT uint32
var _logger_ = log.New(os.Stderr, "", 0)
var logger = log.New(os.Stderr, "", 0)
var replacement = "\n"

var (
@@ -27,7 +27,7 @@ func tabcount() int {
func enterLogScope() {
atomic.AddUint32(&TABCOUNT, 1)
tabcount := tabcount()
_logger_.SetPrefix(strings.Repeat("\t", tabcount))
logger.SetPrefix(strings.Repeat("\t", tabcount))
replacement = "\n" + strings.Repeat("\t", tabcount)
}

@@ -41,7 +41,7 @@ func leaveLogScope() {
} else {
atomic.StoreUint32(&TABCOUNT, uint32(tabcount))
}
_logger_.SetPrefix(strings.Repeat("\t", tabcount))
logger.SetPrefix(strings.Repeat("\t", tabcount))
replacement = "\n" + strings.Repeat("\t", tabcount)
}

@@ -50,8 +50,8 @@ func logf(format string, others ...interface{}) {
// format = strings.Replace(format, "\n", replacement, -1)
s := fmt.Sprintf(format, others...)
s = strings.Replace(s, "\n", replacement, -1)
_logger_.Println(s)
// _logger_.Printf(format, others...)
logger.Println(s)
// logger.Printf(format, others...)
}
}

@@ -7,7 +7,7 @@ import (
"os"
)

var _logger_ = log.New(os.Stderr, "", 0)
var logger = log.New(os.Stderr, "", 0)
var replacement = "\n"

func tabcount() int { return 0 }
@@ -35,15 +35,15 @@ func (n *node) Attributes() []encoding.Attribute {
`const`, "const|", // "&#34;" is shorter than "&quot;".
)
attrs := []encoding.Attribute{
encoding.Attribute{
{
Key: "id",
Value: fmt.Sprintf(`"%p"`, n.n),
},
encoding.Attribute{
{
Key: "shape",
Value: "Mrecord",
},
encoding.Attribute{
{
Key: "label",
Value: fmt.Sprintf(`"{{%s|%#x}|{Op|%s}|{Shape|%v}}"`,
htmlEscaper.Replace(n.n.Name()),
@@ -98,7 +98,7 @@ func tensorClose(a, b tensor.Tensor) bool {
if len(aFs) != len(bFs) {
return false
}
aFs = aFs[:len(aFs)]
aFs = aFs[:]
bFs = bFs[:len(aFs)]
for i, v := range aFs {
if !dawson.CloseF64(v, bFs[i]) {
@@ -112,7 +112,7 @@ func tensorClose(a, b tensor.Tensor) bool {
if len(aFs) != len(bFs) {
return false
}
aFs = aFs[:len(aFs)]
aFs = aFs[:]
bFs = bFs[:len(aFs)]
for i, v := range aFs {
if !dawson.CloseF32(v, bFs[i]) {
@@ -29,7 +29,7 @@ var wT tensor.Tensor
var yT tensor.Tensor
var xT tensor.Tensor

// in this example, we will generate random float64 values
// Float is an alias; in this example, we will generate random float64 values
var Float = tensor.Float64

// init generates random values for x, w, and y for demo purposes
@@ -217,12 +217,10 @@ func accuracy(target, predicted G.Value) float64 {
count := 0.0
targetArray := target.Data().([]float64)
predictedArray := predicted.Data().([]bool)
targetBool := false
for i := 0; i < target.Size(); i++ {
targetBool := false
if targetArray[i] == 1.0 {
targetBool = true
} else {
targetBool = false
}
if targetBool == predictedArray[i] {
count++
@@ -12,8 +12,10 @@ const pixelRange = 255
const (
imageMagic = 0x00000803
labelMagic = 0x00000801
Width = 28
Height = 28
// Width of the input tensor / picture
Width = 28
// Height of the input tensor / picture
Height = 28
)

func readLabelFile(r io.Reader, e error) (labels []Label, err error) {
@@ -37,7 +37,7 @@ func (g *Groups) Upsert(grp Group) {
*g = append(*g, grp)
}

// Have retuns true if GroupID is in groups
// Have returns true if GroupID is in groups
func (g *Groups) Have(grp Group) bool {
for i := 0; i < len(*g); i++ {
if (*g)[i].ID == grp.ID {
@@ -320,22 +320,20 @@ func (op im2colOp) do(prealloc, input Value) (retVal Value, err error) {
chanStride := h * w
inRowStride := inputStrides[2]

var imStart, imEnd, colStart, colEnd int
imEnd = imStart + batchStrideIm
colEnd = colStart + batchStrideCol

switch input.Dtype() {
case tensor.Float64:
imData := input.Data().([]float64)
colData := prealloc.Data().([]float64)
for i := 0; i < b; i++ {
imStart := i * batchStrideIm
colStart := i * batchStrideCol
imEnd := imStart + batchStrideIm
colEnd := colStart + batchStrideCol

if imEnd = imStart + batchStrideIm; imEnd >= len(imData) {
if imEnd >= len(imData) {
imEnd = len(imData)
}
if colEnd = colStart + batchStrideCol; colEnd >= len(colData) {
if colEnd >= len(colData) {
colEnd = len(colData)
}

@@ -347,11 +345,13 @@ func (op im2colOp) do(prealloc, input Value) (retVal Value, err error) {
for i := 0; i < b; i++ {
imStart := i * batchStrideIm
colStart := i * batchStrideCol
imEnd := imStart + batchStrideIm
colEnd := colStart + batchStrideCol

if imEnd = imStart + batchStrideIm; imEnd >= len(imData) {
if imEnd >= len(imData) {
imEnd = len(imData)
}
if colEnd = colStart + batchStrideCol; colEnd >= len(colData) {
if colEnd >= len(colData) {
colEnd = len(colData)
}

@@ -126,7 +126,6 @@ func TestBroadcastAdd(t *testing.T) {
}
}


var broadcastMulTests = []broadcastOpTest{
{name: "vec-mat",
a: tensor.New(tensor.WithShape(2), tensor.WithBacking([]float64{10, 20})),
@@ -970,6 +970,6 @@ func TestReshapeRuntime(t *testing.T) {
}

if !x.Value().Shape().Eq(tensor.Shape{28, 28}) {
t.Errorf("A mutation of shape has occured!")
t.Errorf("A mutation of shape has occurred")
}
}
@@ -584,7 +584,7 @@ func inverseSqrtDiff(x, y *Node) (err error) {
}

sub := newElemBinOp(subOpType, x, y)
if d, err = sub.Do(xdv.d, d); err != nil {
if _, err = sub.Do(xdv.d, d); err != nil {
return errors.Wrapf(err, doFail, sub)
}
return nil
@@ -178,7 +178,6 @@ func checkErr(t *testing.T, expected bool, err error, name string, id interface{
return false
}


func deepNodeEq(a, b *Node) bool {
if a == b {
return true
@@ -141,7 +141,7 @@ func (m *lispMachine) execDevTrans(op devTrans, n *Node, children Nodes) (err er
if mem, err = m.Get(op.to, calcMemSize(cv.Dtype(), child.shape)); err != nil {
return
}
if cd, err = makeValueFromMem(child.t, child.shape, mem); err != nil {
if _, err = makeValueFromMem(child.t, child.shape, mem); err != nil {
return
}
}

0 comments on commit 1b4cc0a

Please sign in to comment.
You can’t perform that action at this time.