Skip to content

Commit

Permalink
Update variable.String
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed Sep 30, 2023
1 parent 4303c49 commit b8f159d
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 204 deletions.
104 changes: 52 additions & 52 deletions autograd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Example() {
fmt.Println(x.Grad)

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

func Example_numericalDiff() {
Expand All @@ -33,7 +33,7 @@ func Example_numericalDiff() {
fmt.Println(numerical.Diff(f, v))

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

func Example_creator() {
Expand All @@ -59,15 +59,15 @@ func Example_creator() {
fmt.Println(y.Creator.Input[0].Creator.Input[0].Creator.Input[0] == x)

// Output:
// variable[0.5]
// variable[1.648721270700128]
// variable[3.297442541400256]
// variable([0.5])
// variable([1.648721270700128])
// variable([3.297442541400256])
//
// *variable.SquareT[variable[1.2840254166877414]]
// *variable.SquareT[variable([1.2840254166877414])]
// true
// *variable.ExpT[variable[0.25]]
// *variable.ExpT[variable([0.25])]
// true
// *variable.SquareT[variable[0.5]]
// *variable.SquareT[variable([0.5])]
// true
}

Expand All @@ -82,7 +82,7 @@ func Example_func() {
fmt.Println(x.Grad)

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

func Example_add() {
Expand All @@ -96,8 +96,8 @@ func Example_add() {
fmt.Println(x.Grad, y.Grad)

// Output:
// variable[13]
// variable[4] variable[6]
// variable([13])
// variable([4]) variable([6])
}

func Example_reuse() {
Expand All @@ -110,8 +110,8 @@ func Example_reuse() {
fmt.Println(x.Grad)

// Output:
// variable[9]
// variable[3]
// variable([9])
// variable([3])
}

func Example_cleargrad() {
Expand All @@ -127,8 +127,8 @@ func Example_cleargrad() {
fmt.Println(x.Grad)

// Output:
// variable[2]
// variable[3]
// variable([2])
// variable([3])
}

func Example_generation() {
Expand All @@ -142,8 +142,8 @@ func Example_generation() {
fmt.Println(x.Grad)

// Output:
// variable[32]
// variable[64]
// variable([32])
// variable([64])
}

func Example_shpere() {
Expand All @@ -161,7 +161,7 @@ func Example_shpere() {
fmt.Println(x.Grad, y.Grad)

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

func Example_matyas() {
Expand All @@ -181,7 +181,7 @@ func Example_matyas() {
fmt.Println(x.Grad, y.Grad)

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

func Example_rosenbrock() {
Expand All @@ -201,7 +201,7 @@ func Example_rosenbrock() {
fmt.Println(x0.Grad, x1.Grad)

// Output:
// variable[-2] variable[400]
// variable([-2]) variable([400])
}

func Example_gradientDescent() {
Expand Down Expand Up @@ -241,17 +241,17 @@ func Example_gradientDescent() {
}

// Output:
// variable[0] variable[2]
// variable[0.6837118569138317] variable[0.4659526837427042]
// variable[0.8263177857050957] variable[0.6820311873361097]
// variable[0.8947837494333546] variable[0.8001896451930564]
// variable[0.9334871723401226] variable[0.8711213202579401]
// variable[0.9569899983530249] variable[0.9156532462021957]
// variable[0.9718168065095137] variable[0.9443132014542008]
// variable[0.9813809710644894] variable[0.9630332658658076]
// variable[0.9876355102559093] variable[0.9753740541653942]
// variable[0.9917613994572028] variable[0.9835575421346807]
// variable[0.9944984367782456] variable[0.9890050527419593]
// variable([0]) variable([2])
// variable([0.6837118569138317]) variable([0.4659526837427042])
// variable([0.8263177857050957]) variable([0.6820311873361097])
// variable([0.8947837494333546]) variable([0.8001896451930564])
// variable([0.9334871723401226]) variable([0.8711213202579401])
// variable([0.9569899983530249]) variable([0.9156532462021957])
// variable([0.9718168065095137]) variable([0.9443132014542008])
// variable([0.9813809710644894]) variable([0.9630332658658076])
// variable([0.9876355102559093]) variable([0.9753740541653942])
// variable([0.9917613994572028]) variable([0.9835575421346807])
// variable([0.9944984367782456]) variable([0.9890050527419593])
}

func Example_newton() {
Expand Down Expand Up @@ -283,16 +283,16 @@ func Example_newton() {
}

// Output:
// variable[2]
// variable[1.4545454545454546]
// variable[1.1510467893775467]
// variable[1.0253259289766978]
// variable[1.0009084519430513]
// variable[1.0000012353089454]
// variable[1.000000000002289]
// variable[1]
// variable[1]
// variable[1]
// variable([2])
// variable([1.4545454545454546])
// variable([1.1510467893775467])
// variable([1.0253259289766978])
// variable([1.0009084519430513])
// variable([1.0000012353089454])
// variable([1.000000000002289])
// variable([1])
// variable([1])
// variable([1])
}

func Example_newton_double() {
Expand Down Expand Up @@ -325,16 +325,16 @@ func Example_newton_double() {
}

// Output:
// variable[2]
// variable[1.4545454545454546]
// variable[1.1510467893775467]
// variable[1.0253259289766978]
// variable[1.0009084519430513]
// variable[1.0000012353089454]
// variable[1.000000000002289]
// variable[1]
// variable[1]
// variable[1]
// variable([2])
// variable([1.4545454545454546])
// variable([1.1510467893775467])
// variable([1.0253259289766978])
// variable([1.0009084519430513])
// variable([1.0000012353089454])
// variable([1.000000000002289])
// variable([1])
// variable([1])
// variable([1])
}

func Example_double() {
Expand All @@ -351,5 +351,5 @@ func Example_double() {
fmt.Println(x.Grad)

// Output:
// variable[100]
// variable([100])
}
2 changes: 1 addition & 1 deletion dot/dot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ExampleVar() {

// Output:
// "0x**********" [label="x", color=orange, style=filled]
// "0x**********" [label="x[1]", color=orange, style=filled]
// "0x**********" [label="x([1])", color=orange, style=filled]
// true
// false
}
Expand Down
2 changes: 1 addition & 1 deletion numerical/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func ExampleDiff() {
fmt.Println(numerical.Diff(f, v))

// Output:
// variable[4.000000000004]
// variable([4.000000000004])
}
30 changes: 15 additions & 15 deletions variable/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func ExampleAddT() {
fmt.Println(f.Backward(variable.OneLike(a), variable.OneLike(b)))

// Output:
// variable[2 3]
// variable[3 4]
// [variable[5 7]]
// [variable[1 1] variable[1 1]]
// variable([2 3])
// variable([3 4])
// [variable([5 7])]
// [variable([1 1]) variable([1 1])]
}

func ExampleAdd() {
Expand All @@ -32,7 +32,7 @@ func ExampleAdd() {
fmt.Println(a.Grad, b.Grad)

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

func ExampleAddC() {
Expand All @@ -44,8 +44,8 @@ func ExampleAddC() {
fmt.Println(x.Grad)

// Output:
// variable[13]
// variable[1]
// variable([13])
// variable([1])
}

func ExampleAdd_broadcast() {
Expand All @@ -59,8 +59,8 @@ func ExampleAdd_broadcast() {
fmt.Println(a.Grad)

// Output:
// variable[11 12 13]
// variable[3]
// variable([11 12 13])
// variable([3])
}

func ExampleAdd_double() {
Expand All @@ -82,9 +82,9 @@ func ExampleAdd_double() {
fmt.Println(y.Grad.Grad == ga.Grad, y.Grad.Grad == gb.Grad)

// Output:
// variable[1] variable[1] variable[1]
// variable([1]) variable([1]) variable([1])
// true true
// variable[1] variable[1] variable[1]
// variable([1]) variable([1]) variable([1])
// true true
}

Expand All @@ -102,8 +102,8 @@ func ExampleAdd_double_a() {
fmt.Println(y.Grad.Grad == a.Grad.Grad) // ggy = gga

// Output:
// variable[1] <nil>
// variable[1]
// variable([1]) <nil>
// variable([1])
// true
}

Expand All @@ -121,7 +121,7 @@ func ExampleAdd_double_b() {
fmt.Println(y.Grad.Grad == b.Grad.Grad) // ggy = ggb

// Output:
// <nil> variable[1]
// variable[1]
// <nil> variable([1])
// variable([1])
// true
}
4 changes: 2 additions & 2 deletions variable/broadcast_to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ func ExampleBroadcastTo() {
fmt.Println(x.Grad)

// Output:
// variable[2 2 2]
// variable[3]
// variable([2 2 2])
// variable([3])
}
34 changes: 17 additions & 17 deletions variable/cos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func ExampleCosT() {
fmt.Println(f.Backward(variable.OneLike(x)))

// Output:
// variable[0.7853981633974483]
// [variable[0.7071067811865476]]
// [variable[-0.7071067811865475]]
// variable([0.7853981633974483])
// [variable([0.7071067811865476])]
// [variable([-0.7071067811865475])]
}

func ExampleCos() {
Expand All @@ -32,8 +32,8 @@ func ExampleCos() {
fmt.Println([]float64{1.0 / math.Sqrt2})

// Output:
// variable[0.7071067811865476]
// variable[-0.7071067811865475]
// variable([0.7071067811865476])
// variable([-0.7071067811865475])
// [0.7071067811865476]
}

Expand All @@ -54,16 +54,16 @@ func ExampleCos_double() {
}

// Output:
// variable[0.5403023058681398]
// variable[-0.8414709848078965]
// variable[-0.5403023058681398]
// variable[0.8414709848078965]
// variable[0.5403023058681398]
// variable[-0.8414709848078965]
// variable[-0.5403023058681398]
// variable[0.8414709848078965]
// variable[0.5403023058681398]
// variable[-0.8414709848078965]
// variable[-0.5403023058681398]
// variable[0.8414709848078965]
// variable([0.5403023058681398])
// variable([-0.8414709848078965])
// variable([-0.5403023058681398])
// variable([0.8414709848078965])
// variable([0.5403023058681398])
// variable([-0.8414709848078965])
// variable([-0.5403023058681398])
// variable([0.8414709848078965])
// variable([0.5403023058681398])
// variable([-0.8414709848078965])
// variable([-0.5403023058681398])
// variable([0.8414709848078965])
}
12 changes: 6 additions & 6 deletions variable/div_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func ExampleDiv() {
fmt.Println(a.Grad, b.Grad)

// Output:
// variable[5]
// variable[0.5] variable[-2.5]
// variable([5])
// variable([0.5]) variable([-2.5])
}

func ExampleDiv_broadcast() {
Expand All @@ -31,8 +31,8 @@ func ExampleDiv_broadcast() {
fmt.Println(a.Grad, b.Grad)

// Output:
// variable[0.5 1 1.5 2 2.5]
// variable[2.5] variable[-3.75]
// variable([0.5 1 1.5 2 2.5])
// variable([2.5]) variable([-3.75])
}

func ExampleDiv_double() {
Expand All @@ -50,6 +50,6 @@ func ExampleDiv_double() {
fmt.Println(y.Grad.Grad)

// Output:
// variable[-0.25] variable[2.25]
// variable[-2]
// variable([-0.25]) variable([2.25])
// variable([-2])
}
Loading

0 comments on commit b8f159d

Please sign in to comment.