Skip to content

Commit 20bc3ae

Browse files
committed
Copy the last element in odd-sized arrays
1 parent 9d019d6 commit 20bc3ae

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/states.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ function nla(::NLADefault, x)
9393
return x
9494
end
9595

96-
function nla(nla_type, x_old)
96+
struct NLAT1 <: NonLinearAlgorithm end
97+
98+
struct NLAT2 <: NonLinearAlgorithm end
99+
100+
struct NLAT3 <: NonLinearAlgorithm end
101+
102+
function nla(nla_type::Union{NLAT1, NLAT2, NLAT3}, x_old)
97103
x_new = similar(x_old)
98104
nla!(nla_type, x_old, x_new)
99105
return x_new
@@ -111,7 +117,6 @@ ANN, and RNN-LSTM._" (2019).
111117
systems from data: A reservoir computing approach._"
112118
Physical review letters 120.2 (2018): 024102.
113119
"""
114-
struct NLAT1 <: NonLinearAlgorithm end
115120

116121
function nla!(::NLAT1, x_old, x_new)
117122
x_new[2:2:end, :] = x_old[2:2:end, :]
@@ -126,10 +131,12 @@ Apply the \$ \\text{T}_2 \$ transformation algorithm, as defined in [1].
126131
chaotic system using a hierarchy of deep learning methods: Reservoir computing, ANN,
127132
and RNN-LSTM._" (2019).
128133
"""
129-
struct NLAT2 <: NonLinearAlgorithm end
130134

131135
function nla!(::NLAT2, x_old, x_new)
132136
x_new[1, :] = x_old[1, :]
137+
if mod(size(x_new, 1), 2) != 0
138+
x_new[end, :] = x_old[end, :]
139+
end
133140
x_new[2:2:end, :] = x_old[2:2:end, :]
134141
x_new[3:2:end-1, :] = x_old[2:2:end-2, :].*x_old[1:2:end-3, :]
135142
end
@@ -142,10 +149,12 @@ Apply the \$ \\text{T}_3 \$ transformation algorithm, as defined in [1].
142149
chaotic system using a hierarchy of deep learning methods: Reservoir computing, ANN,
143150
and RNN-LSTM._" (2019).
144151
"""
145-
struct NLAT3 <: NonLinearAlgorithm end
146152

147153
function nla!(::NLAT3, x_old, x_new)
148-
x_new[1,:]= x_old[1, :]
154+
x_new[1, :] = x_old[1, :]
155+
if mod(size(x_new, 1), 2) != 0
156+
x_new[end, :] = x_old[end, :]
157+
end
149158
x_new[2:2:end, :]= x_old[2:2:end, :]
150159
x_new[3:2:end-1, :]= x_old[2:2:end-2, :].*x_old[4:2:end, :]
151160
end

0 commit comments

Comments
 (0)