Skip to content

Commit

Permalink
Merge 00db8ec into b44c85d
Browse files Browse the repository at this point in the history
  • Loading branch information
chewxy committed Oct 26, 2020
2 parents b44c85d + 00db8ec commit 0ac82c9
Show file tree
Hide file tree
Showing 9 changed files with 654 additions and 229 deletions.
22 changes: 22 additions & 0 deletions concurrency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gorgonia

import "runtime"

const (
// defaultBlockSize indicates the default size to chunk an array.
defaultBlockSize = 64

// minParallelBlocks indicates how many blocks an array must be split up into
// before we decide to parallelize
minParallelBlocks = 4
)

// workersChan creates a channel that is limited by the number of processor cores.
// To signal that a processor core is being used:
// ch <- struct{}{}
// When done:
// <- ch
func workersChan() chan struct{} { return make(chan struct{}, runtime.GOMAXPROCS(0)) }

// calcBlocks calculuates the best number of blocks given a blocksize
func calcBlocks(dim, blocksize int) int { return (dim + blocksize - 1) / blocksize }
2 changes: 2 additions & 0 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
gradOnDeviceFail = "Cannot get gradient of %v on %v"
makeValueFail = "Unable to make value of %v with shape %v"
allocFail = "Unable to allocate %v bytes on %v"

shapeMismatchErr = "Shape Mismatch. Expected %v. Got %v instead."
)

var empty struct{}
Expand Down
4 changes: 2 additions & 2 deletions example_err_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func Example_errorHandling() {
_ = nn2PlusWrong

// Output:
// nn: Softmax{-1}()(%9) :: Matrix float32
// nn: Softmax{-1, false}()(%9) :: Matrix float32
// An error occurs: Type inference error. Op: + false. Children: [Matrix float32, Matrix float64], OpType:Matrix a → Matrix a → Matrix a: Unable to unify while inferring type of + false: Unification Fail: float64 ~ float32 cannot be unified
// nn2: Softmax{-1}()(%9) :: Matrix float32
// nn2: Softmax{-1, false}()(%9) :: Matrix float32
// An error occurs (caught by recover()): Type inference error. Op: + false. Children: [Matrix float32, Matrix float64], OpType:Matrix a → Matrix a → Matrix a: Unable to unify while inferring type of + false: Unification Fail: float64 ~ float32 cannot be unified

}
6 changes: 6 additions & 0 deletions examples/convnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ func main() {
if err = m.fwd(x); err != nil {
log.Fatalf("%+v", err)
}

// Note: the correct losses should look like that
//
// The losses that are not commented out is used to test the stabilization function of Gorgonia.
//losses := G.Must(G.HadamardProd(G.Must(G.Neg(G.Must(G.Log(m.out)))), y))

losses := G.Must(G.Log(G.Must(G.HadamardProd(m.out, y))))
cost := G.Must(G.Mean(losses))
cost = G.Must(G.Neg(cost))
Expand Down

0 comments on commit 0ac82c9

Please sign in to comment.