Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit ef9615d

Browse files
Merge pull request #271 from SciML/compats
fix compats and undefined memory
2 parents 06ddd90 + 7b027a8 commit ef9615d

7 files changed

Lines changed: 14 additions & 10 deletions

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ BandedMatrices = "0.15.11"
2222
BlockBandedMatrices = "0.8.6, 0.9"
2323
DiffEqBase = "6.4.1"
2424
ForwardDiff = "0.10"
25-
LazyArrays = "0.16.12"
26-
LazyBandedMatrices = "0.2.11"
25+
LazyArrays = "0.17"
26+
LazyBandedMatrices = "0.3"
2727
ModelingToolkit = "0.10.0, 1.0, 2.0, 3.0"
2828
NNlib = "0.6, 0.7"
2929
StaticArrays = "0.10, 0.11, 0.12"

src/composite_operators.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct DiffEqOperatorCombination{T,O<:Tuple{Vararg{AbstractDiffEqLinearOperator{
5353
T = eltype(ops[1])
5454
if cache == nothing
5555
cache = Vector{T}(undef, size(ops[1], 1))
56+
fill!(cache,0)
5657
end
5758
# TODO: safecheck dimensions
5859
new{T,typeof(ops),typeof(cache)}(ops, cache)
@@ -96,7 +97,9 @@ struct DiffEqOperatorComposition{T,O<:Tuple{Vararg{AbstractDiffEqLinearOperator{
9697
# Construct a list of caches to be used by mul! and ldiv!
9798
caches = []
9899
for op in ops[1:end-1]
99-
push!(caches, Vector{T}(undef, size(op, 1)))
100+
tmp = Vector{T}(undef, size(op, 1))
101+
fill!(tmp,0)
102+
push!(caches,tmp)
100103
end
101104
caches = tuple(caches...)
102105
end

src/derivative_operators/abstract_operator_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ end
166166
################################################################################
167167

168168
function *(coeff_func::Function, A::DerivativeOperator{T,N,Wind}) where {T,N,Wind}
169-
coefficients = A.coefficients === nothing ? Vector{T}(undef, A.len) : A.coefficients
169+
coefficients = A.coefficients === nothing ? zeros(T,A.len) : A.coefficients
170170

171171
DerivativeOperator{T,N,Wind,typeof(A.dx),typeof(A.stencil_coefs),
172172
typeof(A.low_boundary_coefs),typeof(coefficients),

src/derivative_operators/derivative_operator.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function CenteredDifference{N}(derivative_order::Int,
103103
calculate_weights(derivative_order, high_boundary_x[end-i], high_boundary_x)) for i in boundary_point_count:-1:1]
104104
high_boundary_coefs = convert(SVector{boundary_point_count},_high_boundary_coefs)
105105

106-
coefficients = coeff_func isa Nothing ? nothing : Vector{T}(undef,len)
106+
coefficients = coeff_func isa Nothing ? nothing : zeros(T,len)
107107

108108
DerivativeOperator{T,N,false,typeof(dx),typeof(stencil_coefs),
109109
typeof(low_boundary_coefs),typeof(coefficients),
@@ -169,7 +169,7 @@ function UpwindDifference{N}(derivative_order::Int,
169169
_high_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T}, ((-1/dx)^derivative_order) * calculate_weights(derivative_order, oneunit(T)*x0, high_boundary_x)) for x0 in R_boundary_deriv_spots]
170170
high_boundary_coefs = convert(SVector{boundary_point_count},_high_boundary_coefs)
171171

172-
coefficients = Vector{T}(undef,len)
172+
coefficients = zeros(T,len)
173173
if coeff_func != nothing
174174
compute_coeffs!(coeff_func, coefficients)
175175
end
@@ -215,7 +215,7 @@ function UpwindDifference{N}(derivative_order::Int,
215215
high_boundary_coefs = [_upwind_coefs ; _downwind_coefs]
216216

217217
# Compute coefficients
218-
coefficients = Vector{T}(undef,len)
218+
coefficients = zeros(T,len)
219219
if coeff_func != nothing
220220
compute_coeffs!(coeff_func, coefficients)
221221
end

src/derivative_operators/multi_dim_bc_operators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ slice_rmul lets you multiply each vector like strip of an array `u` with a linea
1616
"""
1717
function slice_rmul(A::AbstractDiffEqLinearOperator, u::AbstractArray{T,N}, dim::Int) where {T,N}
1818
@assert N != 1
19-
u_temp = similar(u)
19+
u_temp = zero(u)
2020

2121
_slice_rmul!(u_temp, A, u, dim, CartesianIndices(axes(u)[1:dim-1]), CartesianIndices(axes(u)[(dim+1):end]))
2222

src/matrixfree_operators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ end
2424
return n <= length(M.size) ? M.size[n] : 1
2525
end
2626
@inline ==(M1::MatrixFreeOperator, M2::MatrixFreeOperator) = M1.f == M2.f && M1.args == M2.args && M1.size == M2.size && M1.opnorm == M2.opnorm && M1.ishermitian == M2.ishermitian
27-
@inline Base.:*(A::MatrixFreeOperator, X::AbstractVecOrMat) = mul!(similar(X), A, X)
27+
@inline Base.:*(A::MatrixFreeOperator, X::AbstractVecOrMat) = mul!(zero(X), A, X)
2828

2929
# Overloading LinearAlgebra functions
3030
LinearAlgebra.ishermitian(M::MatrixFreeOperator) = M.ishermitian
@@ -60,7 +60,7 @@ end
6060

6161
function (M::MatrixFreeOperator{F,N})(u, p, t) where {F,N}
6262
update_coefficients!(M,u,p,t)
63-
du = similar(u)
63+
du = zero(u)
6464
if isconstant(M)
6565
M.f(du, u, p)
6666
else

test/upwind_operators_interface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ end
586586
L = UpwindDifference(1,2, 0.1, N, 1.0)
587587
analyticL = 10.0*analyticOneTwoPos()
588588
x = rand(7)
589+
@show x
589590

590591
# Test that multiplication agrees with analytic multiplication
591592
@test L*x analyticL*x

0 commit comments

Comments
 (0)