Skip to content

Commit 986b697

Browse files
Merge pull request #106 from SciML/ap_linalg_arrays
Handle and test ArrayPartition linear algebra over Arrays
2 parents f85bebc + ab09334 commit 986b697

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RecursiveArrayTools"
22
uuid = "731186ca-8d62-57ce-b412-fbd966d074cd"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "2.4.2"
4+
version = "2.4.3"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/array_partition.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ function LinearAlgebra.ldiv!(A::T, bb::ArrayPartition) where T<:Union{UnitUpperT
331331
lens = map(length, b)
332332
@inbounds for j in n:-1:1
333333
Ajj = T(getblock(A, lens, j, j))
334-
xj = ldiv!(Ajj, b[j])
334+
xj = ldiv!(Ajj, vec(b[j]))
335335
for i in j-1:-1:1
336336
Aij = getblock(A, lens, i, j)
337337
# bi = -Aij * xj + bi
338-
mul!(b[i], Aij, xj, -1, true)
338+
mul!(vec(b[i]), Aij, xj, -1, true)
339339
end
340340
end
341341
return bb
@@ -348,11 +348,11 @@ function LinearAlgebra.ldiv!(A::T, bb::ArrayPartition) where T<:Union{UnitLowerT
348348
lens = map(length, b)
349349
@inbounds for j in 1:n
350350
Ajj = T(getblock(A, lens, j, j))
351-
xj = ldiv!(Ajj, b[j])
351+
xj = ldiv!(Ajj, vec(b[j]))
352352
for i in j+1:n
353353
Aij = getblock(A, lens, i, j)
354354
# bi = -Aij * xj + b[i]
355-
mul!(b[i], Aij, xj, -1, true)
355+
mul!(vec(b[i]), Aij, xj, -1, true)
356356
end
357357
end
358358
return bb

test/upstream.jl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@ sol = solve(prob,AutoTsit5(Rosenbrock23()))
1414

1515
@test all(Array(sol) .== sol)
1616

17-
function f!(F, vars)
18-
x = vars.x[1]
19-
F.x[1][1] = (x[1]+3)*(x[2]^3-7)+18
20-
F.x[1][2] = sin(x[2]*exp(x[1])-1)
21-
y=vars.x[2]
22-
F.x[2][1] = (y[1]+3)*(y[2]^3-7)+18
23-
F.x[2][2] = sin(y[2]*exp(y[1])-1)
17+
function mymodel(F, vars)
18+
for i in 1:2
19+
x = vars.x[i]
20+
F.x[i][1,1] = (x[1,1]+3)*(x[1,2]^3-7)+18.0
21+
F.x[i][1,2] = sin(x[1,2]*exp(x[1,1])-1)
22+
F.x[i][2,1] = (x[2,1]+3)*(x[2,2]^3-7)+19.0
23+
F.x[i][2,2] = sin(x[2,2]*exp(x[2,1])-3)
24+
end
2425
end
25-
2626
# To show that the function works
27-
F = ArrayPartition([0.0 0.0],[0.0, 0.0])
28-
u0= ArrayPartition([0.1; 1.2], [0.1; 1.2])
29-
result = f!(F, u0)
30-
31-
# To show the NLsolve error that results with ArrayPartitions:
32-
nlsolve(f!, ArrayPartition([0.1; 1.2], [0.1; 1.2]))
27+
F = ArrayPartition([0.0 0.0; 0.0 0.0],[0.0 0.0; 0.0 0.0])
28+
u0= ArrayPartition([0.1 1.2; 0.1 1.2], [0.1 1.2; 0.1 1.2])
29+
result = mymodel(F, u0)
30+
nlsolve(mymodel, u0)

0 commit comments

Comments
 (0)