@@ -34,7 +34,6 @@ function optim.lswolfe(opfunc,x,t,d,f,g,gtd,options)
34
34
local abs = torch .abs
35
35
local min = math.min
36
36
local max = math.max
37
- local Tensor = torch .Tensor
38
37
39
38
-- verbose function
40
39
local function verbose (...)
@@ -56,25 +55,25 @@ function optim.lswolfe(opfunc,x,t,d,f,g,gtd,options)
56
55
while LSiter < maxIter do
57
56
-- check conditions:
58
57
if (f_new > (f + c1 * t * gtd )) or (LSiter > 1 and f_new >= f_prev ) then
59
- bracket = Tensor {t_prev ,t }
60
- bracketFval = Tensor {f_prev ,f_new }
61
- bracketGval = Tensor (2 ,g_new :size (1 ))
58
+ bracket = x . new {t_prev ,t }
59
+ bracketFval = x . new {f_prev ,f_new }
60
+ bracketGval = x . new (2 ,g_new :size (1 ))
62
61
bracketGval [1 ] = g_prev
63
62
bracketGval [2 ] = g_new
64
63
break
65
64
66
65
elseif abs (gtd_new ) <= - c2 * gtd then
67
- bracket = Tensor {t }
68
- bracketFval = Tensor {f_new }
69
- bracketGval = Tensor (1 ,g_new :size (1 ))
66
+ bracket = x . new {t }
67
+ bracketFval = x . new {f_new }
68
+ bracketGval = x . new (1 ,g_new :size (1 ))
70
69
bracketGval [1 ] = g_new
71
70
done = true
72
71
break
73
72
74
73
elseif gtd_new >= 0 then
75
- bracket = Tensor {t_prev ,t }
76
- bracketFval = Tensor {f_prev ,f_new }
77
- bracketGval = Tensor (2 ,g_new :size (1 ))
74
+ bracket = x . new {t_prev ,t }
75
+ bracketFval = x . new {f_prev ,f_new }
76
+ bracketGval = x . new (2 ,g_new :size (1 ))
78
77
bracketGval [1 ] = g_prev
79
78
bracketGval [2 ] = g_new
80
79
break
@@ -86,7 +85,7 @@ function optim.lswolfe(opfunc,x,t,d,f,g,gtd,options)
86
85
t_prev = t
87
86
local minStep = t + 0.01 * (t - tmp )
88
87
local maxStep = t * 10
89
- t = optim .polyinterp (Tensor {{tmp ,f_prev ,gtd_prev },
88
+ t = optim .polyinterp (x . new {{tmp ,f_prev ,gtd_prev },
90
89
{t ,f_new ,gtd_new }},
91
90
minStep , maxStep )
92
91
@@ -104,9 +103,9 @@ function optim.lswolfe(opfunc,x,t,d,f,g,gtd,options)
104
103
105
104
-- reached max nb of iterations?
106
105
if LSiter == maxIter then
107
- bracket = Tensor {0 ,t }
108
- bracketFval = Tensor {f ,f_new }
109
- bracketGval = Tensor (2 ,g_new :size (1 ))
106
+ bracket = x . new {0 ,t }
107
+ bracketFval = x . new {f ,f_new }
108
+ bracketGval = x . new (2 ,g_new :size (1 ))
110
109
bracketGval [1 ] = g
111
110
bracketGval [2 ] = g_new
112
111
end
@@ -123,7 +122,7 @@ function optim.lswolfe(opfunc,x,t,d,f,g,gtd,options)
123
122
local HIpos = - LOpos + 3
124
123
125
124
-- compute new trial value
126
- t = optim .polyinterp (Tensor {{bracket [1 ],bracketFval [1 ],bracketGval [1 ]* d },
125
+ t = optim .polyinterp (x . new {{bracket [1 ],bracketFval [1 ],bracketGval [1 ]* d },
127
126
{bracket [2 ],bracketFval [2 ],bracketGval [2 ]* d }})
128
127
129
128
-- test what we are making sufficient progress
0 commit comments