6
6
function quad (x:: Vector , param)
7
7
mat = param. mat
8
8
xt = x- param. vec
9
- return 0.5 * vecdot (xt, mat* xt)
9
+ return 0.5 * dot (xt, mat* xt)
10
10
end
11
11
12
12
function quad_gradient! (storage:: Vector , x:: Vector , param)
@@ -19,7 +19,7 @@ function quad_fun_gradient!(storage::Vector, x::Vector, param)
19
19
mat = param. mat
20
20
xt = x- param. vec
21
21
storage .= mat* xt
22
- return 0.5 * vecdot (xt, mat* xt)
22
+ return 0.5 * dot (xt, mat* xt)
23
23
end
24
24
25
25
function quad_hessian! (storage:: Matrix , x:: Vector , param)
@@ -32,7 +32,7 @@ struct MatVecHolder{Tv <: AbstractVector,
32
32
vec:: Tv
33
33
end
34
34
35
- function _quadraticproblem (N:: Int ; mat:: AbstractArray{T,2} = spdiagm ( float (1 : N)),
35
+ function _quadraticproblem (N:: Int ; mat:: AbstractArray{T,2} = sparse ( Diagonal ( float (1 : N) )),
36
36
x0:: AbstractVector{T} = ones (N),
37
37
initial_x:: AbstractVector{T} = zeros (N),
38
38
name:: AbstractString = " Quadratic Diagonal ($N )" ) where T <: Number
@@ -72,7 +72,7 @@ function paraboloid(x::AbstractArray, param::ParaboloidStruct)
72
72
@. xt = x - param. vec
73
73
xt[2 : end ] .- = param. alpha* xt[1 ]^ 2
74
74
75
- return 0.5 * vecdot (xt, mat* xt)
75
+ return 0.5 * dot (xt, mat* xt)
76
76
end
77
77
78
78
function paraboloid_gradient! (storage:: AbstractArray , x:: AbstractArray , param:: ParaboloidStruct )
@@ -97,14 +97,14 @@ function paraboloid_fun_gradient!(storage::AbstractArray, x::AbstractArray, para
97
97
storage .= mat* xt
98
98
storage[1 ] -= 2.0 * param. alpha* xt[1 ]* sum (storage[2 : end ])
99
99
100
- return 0.5 * vecdot (xt, mat* xt)
100
+ return 0.5 * dot (xt, mat* xt)
101
101
end
102
102
103
103
function paraboloid_hessian! (storage,x,param)
104
104
error (" Hessian not implemented for Paraboloid" )
105
105
end
106
106
107
- function _paraboloidproblem (N:: Int ; mat:: AbstractArray{T,2} = spdiagm ( float (1 : N)),
107
+ function _paraboloidproblem (N:: Int ; mat:: AbstractArray{T,2} = sparse ( Diagonal ( float (1 : N) )),
108
108
x0:: AbstractVector{T} = ones (N),
109
109
initial_x:: AbstractVector{T} = zeros (N),
110
110
alpha:: T = 10.0 ,
@@ -126,21 +126,17 @@ end
126
126
examples[" Paraboloid Diagonal" ] = _paraboloidproblem (100 )
127
127
128
128
function _randommatrix (N:: Int , scaling:: Bool = true )
129
- F = qrfact (randn (N,N))
129
+ F = qr (randn (N,N))
130
130
if scaling
131
- retval = F[ :Q ] ' * spdiagm ( float (1 : N))* F[ :Q ]
131
+ retval = F. Q ' * sparse ( Diagonal ( float (1 : N))) * F . Q
132
132
else
133
- retval = F[ :Q ] ' * F[ :Q ]
133
+ retval = F. Q ' * F. Q
134
134
end
135
135
retval
136
136
end
137
137
138
- # TODO : From Julia 0.7 onwards, we can use Base.Test.guardsrand() to restore the existing seed
139
- oldseed = copy (Base. GLOBAL_RNG) # Store current seed
140
-
141
- srand (0 )
138
+ guardsrand (0 ) do
142
139
examples[" Paraboloid Random Matrix" ] = _paraboloidproblem (100 ;
143
140
name = " Paraboloid Random Matrix (100)" ,
144
141
mat = _randommatrix (100 ))
145
-
146
- copy! (Base. GLOBAL_RNG, oldseed) # Restore current seed
142
+ end
0 commit comments