Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cat with preallocated array to fix stackoverflow issue #1027

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/simulation/optimization_output_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,22 @@
empty!(cache.dirty_timestamps)
# Uncomment for performance testing of CacheFlush
#TimerOutputs.@timeit RUN_SIMULATION_TIMER "Concatenate arrays for flush" begin
arrays = (cache.data[x] for x in timestamps)
arrays = cat(arrays...; dims = ndims(first(arrays)) + 1)
#end
temp = cache.data[first(timestamps)]
sd = collect(size(temp))
push!(sd, length(timestamps))
arrays = Array{Float64}(undef, sd...)
for (ix, x) in enumerate(timestamps)
temp_data = cache.data[x]
if ndims(temp_data) == 1
arrays[:, ix] = temp_data

Check warning on line 117 in src/simulation/optimization_output_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/simulation/optimization_output_cache.jl#L117

Added line #L117 was not covered by tests
elseif ndims(temp_data) == 2
arrays[:, :, ix] = temp_data
elseif ndims(temp_data) == 3
arrays[:, :, :, ix] = temp_data

Check warning on line 121 in src/simulation/optimization_output_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/simulation/optimization_output_cache.jl#L120-L121

Added lines #L120 - L121 were not covered by tests
else
error("Arrays of dimensions $(ndims(temp_data)) are not supported")

Check warning on line 123 in src/simulation/optimization_output_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/simulation/optimization_output_cache.jl#L123

Added line #L123 was not covered by tests
end
end

return timestamps, arrays
end
Expand Down
Loading