Skip to content

Commit

Permalink
Update some files
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed Oct 21, 2023
1 parent b949a9d commit 014b7e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions optimizer/sgd.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package optimizer

import (
"github.com/itsubaki/autograd/matrix"
)
import "github.com/itsubaki/autograd/matrix"

// SGD is an optimizer that the Stochastic Gradient Descent algorithm.
type SGD struct {
Expand Down
4 changes: 4 additions & 0 deletions variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func NewOf(v ...[]float64) *Variable {
return &Variable{Data: v}
}

func ZeroLike(v *Variable) *Variable {
return &Variable{Data: matrix.ZeroLike(v.Data)}
}

func OneLike(v *Variable) *Variable {
return &Variable{Data: matrix.OneLike(v.Data)}
}
Expand Down
8 changes: 8 additions & 0 deletions variable/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ func ExampleConst() {
// const([1])
}

func ExampleZeroLike() {
v := variable.New(1, 2, 3, 4)
fmt.Println(variable.ZeroLike(v))

// Output:
// variable([0 0 0 0])
}

func ExampleOneLike() {
v := variable.New(1, 2, 3, 4)
fmt.Println(variable.OneLike(v))
Expand Down

0 comments on commit 014b7e6

Please sign in to comment.