You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was curious if there exists (or is even possible to implement) a variant of load! that accumulates the array instead of (over)writing?
e.g. if x=ones(3,3) and ds["var"][:, :] == ones(3,3), and you do load_acc!(variable(ds, "var"), x, :, :), you'd get x .== 2. I'm able to get around this by first writing data to a buffer, then accumulating x, but was just curious if there's a direct way of doing this... Could we quite useful for quickly accumulating statistics.
My current code looks something like this:
functionload_accumulate!(file, data, var, buf =similar(data))
NCDataset(file) do ds
NCDatasets.load!(variable(ds, var), buf, :, :)
data .+= buf
endend# and is useful for operations like this:functiondata_mean(files, data, var)
buf =similar(data)
for file in files
load_accumulate!(file, data, var, buf)
end
data ./=length(files)
end
... Thinking about this a bit more, I suppose in principle that what I'm suggesting above can be generalized to handle any type of metric, like
functionload_accumulate!(file, data, var, func::Function, buf =similar(data))
NCDataset(file) do ds
NCDatasets.load!(variable(ds, var), buf, :, :)
data .+=func(buf)
endend# e.g.:load!("data.nc", data, "T", x -> x .^2)
but I don't actually know if any of that is possible to do without (secretly?) allocating a buffer. So maybe my local implementation is the way to go?
The text was updated successfully, but these errors were encountered:
Thank you! I am doing the looping because I aggregate data from many different files, and I've found the multifile-reading to be quite slow in some instances (but perhaps I'll try to file a separate issue on that if I can).
I'll try experimenting more with groupby+agg, which seems fast so far!
I was curious if there exists (or is even possible to implement) a variant of
load!
that accumulates the array instead of (over)writing?e.g. if
x=ones(3,3)
andds["var"][:, :] == ones(3,3)
, and you doload_acc!(variable(ds, "var"), x, :, :)
, you'd getx .== 2
. I'm able to get around this by first writing data to a buffer, then accumulatingx
, but was just curious if there's a direct way of doing this... Could we quite useful for quickly accumulating statistics.My current code looks something like this:
... Thinking about this a bit more, I suppose in principle that what I'm suggesting above can be generalized to handle any type of metric, like
but I don't actually know if any of that is possible to do without (secretly?) allocating a buffer. So maybe my local implementation is the way to go?
The text was updated successfully, but these errors were encountered: