Minor optimization: use convert
rather than constructor to convert array type before output
#1182
Labels
convert
rather than constructor to convert array type before output
#1182
Currently, we use the constructor
output_writer.array_type
to convert array data prior to outputting:Oceananigans.jl/src/OutputWriters/fetch_output.jl
Line 17 in 03a6f85
But we should use
convert
instead, because this avoids allocating memory when no type conversion is needed:so
b
is just a reference toa
, butc
is not a reference toa
.This matters very little since we basically always need to allocate memory to convert from Float64 to Float32.
A related minor optimization would be to avoid converting views to the same type as the parent array, since we could just output those directly. I think we have to use dispatch on one of the type parameters of
SubArray
for that. But maybe simpler code is worth not implementing a minor optimization for an edge case.The text was updated successfully, but these errors were encountered: