Skip to content

Commit

Permalink
Merge #709
Browse files Browse the repository at this point in the history
709: Add copy method for DataF. r=simonbyrne a=jb-mackay

Adds a `Base.copy` method for `DataF`. Necessary for copying `PointFields` around.

- [x] Code follows the [style guidelines](https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/) OR N/A.
- [x] Unit tests are included OR N/A.
- [x] Code is exercised in an integration test OR N/A.
- [x] Documentation has been added/updated OR N/A.


Co-authored-by: Ben Mackay <[email protected]>
  • Loading branch information
bors[bot] and jb-mackay authored May 6, 2022
2 parents e4c5262 + e4b1ca0 commit 9e35919
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/DataLayouts/DataLayouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ end
col[] = val
end

Base.copy(data::DataF{S}) where {S} = DataF{S}(copy(parent(data)))

# ======================
# DataSlab2D DataLayout
# ======================
Expand Down
4 changes: 4 additions & 0 deletions test/DataLayouts/data0d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ TestFloatTypes = (Float32, Float64)
10eps()

@test sum(x -> x[2], data) sum(array[:, 3]) atol = 10eps()

data_copy = copy(data)
@test data_copy isa DataF
@test data_copy[] == data[]
end
end

Expand Down

0 comments on commit 9e35919

Please sign in to comment.