Skip to content

Commit cd31ac9

Browse files
format test
1 parent 4a6c243 commit cd31ac9

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

test/sparse_vector.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,41 @@ using LinearSolve
33
using LinearAlgebra
44

55
# Constructing sparse array
6-
function hess_sparse(x::Vector{T}) where T
7-
return [-sin(x[1] + x[2]) + 1, -sin(x[1] + x[2]), -sin(x[1] + x[2]), -sin(x[1] + x[2]) + 1.0, 1.0, 1.0, 12.0*x[5]^2 + 1.0, 1.0]
6+
function hess_sparse(x::Vector{T}) where {T}
7+
return [
8+
-sin(x[1] + x[2]) + 1,
9+
-sin(x[1] + x[2]),
10+
-sin(x[1] + x[2]),
11+
-sin(x[1] + x[2]) + 1.0,
12+
1.0,
13+
1.0,
14+
12.0 * x[5]^2 + 1.0,
15+
1.0,
16+
]
817
end
918
rowval = [1, 1, 2, 2, 3, 4, 5, 6]
1019
colval = [1, 2, 1, 2, 3, 4, 5, 6]
1120

1221
# Constructing sparse vec
13-
function grad_sparse(x::Vector{T}) where T<: Number
14-
return [cos(x[1] + x[2]), cos(x[1] + x[2]), 2*x[3], 1/2, 4*x[5]^3, 1/2]
22+
function grad_sparse(x::Vector{T}) where {T <: Number}
23+
return [cos(x[1] + x[2]), cos(x[1] + x[2]), 2 * x[3], 1 / 2, 4 * x[5]^3, 1 / 2]
1524
end
1625
gradinds = [1, 2, 3, 4, 5, 6]
1726

1827
# Forming the matrix and vector
19-
x0 = [0.7853981648713337, 0.7853981693418342, 1.023999999999997e-7, -1.0, 0.33141395338218227, -1.0]
28+
x0 = [
29+
0.7853981648713337,
30+
0.7853981693418342,
31+
1.023999999999997e-7,
32+
-1.0,
33+
0.33141395338218227,
34+
-1.0,
35+
]
2036
n = length(x0)
21-
hess_mat = sparse(rowval, colval, hess_sparse(x0), n, n)
37+
hess_mat = sparse(rowval, colval, hess_sparse(x0), n, n)
2238
grad_vec = sparsevec(gradinds, grad_sparse(x0), n)
2339

2440
# # Converting grad_vec to dense succeds in solving
25-
prob = LinearProblem(hess_mat, grad_vec)
41+
prob = LinearProblem(hess_mat, grad_vec)
2642
linsolve = init(prob)
2743
@test solve(linsolve).u hess_mat \ Array(grad_vec)

0 commit comments

Comments
 (0)