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

14 laplacian tests #22

Merged
merged 26 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cc3f2a3
Update .gitignore and remove .DS_Store
lorenzovarese Jul 10, 2024
75ac013
Add partial implementation of laplacian tests
lorenzovarese Jul 15, 2024
3b7d86e
Merge remote-tracking branch 'origin' into 14-laplacian-tests
lorenzovarese Jul 15, 2024
a2504c6
Fix offset_provider in the laplacian tests
lorenzovarese Jul 17, 2024
cef1063
Merge remote-tracking branch 'origin' into 14-laplacian-tests
lorenzovarese Jul 17, 2024
22baf59
Add partial implementation of the laplacian test. Incorrect outputs d…
lorenzovarese Jul 17, 2024
4837209
Change the input data of laplacian tests to an easier cartesian domain
lorenzovarese Jul 17, 2024
492fea6
Clean the inputs of laplacian tests
lorenzovarese Jul 17, 2024
ae3ec8f
Clean comments
lorenzovarese Jul 17, 2024
5b84314
Introduce canonicalization of arithmetic operations (fixes wrong resu…
tehrengruber Jul 17, 2024
9e33a2a
Fix typo
tehrengruber Jul 17, 2024
6d34e15
Add laplacian tests
lorenzovarese Jul 17, 2024
056df92
Remove previous laplacian tests in separate file
lorenzovarese Jul 17, 2024
66f323b
Clean the output generation in the max and min cases to homogenize it…
lorenzovarese Jul 17, 2024
1cfdb9c
Add a todo for the test of the border values when the out_offset will…
lorenzovarese Jul 17, 2024
b9018ac
Remove the Printf dependency and improve the print debug of the lapla…
lorenzovarese Jul 18, 2024
ffb8b2c
Fix naming cartesian offset provider
lorenzovarese Jul 18, 2024
814e14e
Ignore Manifest.toml (autogenerated)
lorenzovarese Jul 22, 2024
20f95e0
Add simple suggestions to laplacian tests (field operator)
lorenzovarese Jul 22, 2024
2a892e3
Fix tests and change the copy of border values in the laplacian
lorenzovarese Jul 22, 2024
74f0ffe
Improve copy of the border values in the reference computation of lap…
lorenzovarese Jul 22, 2024
761e434
Add `similar` to Fields
lorenzovarese Jul 22, 2024
d1af0f5
Add notes on future naming for mesh definitions
lorenzovarese Jul 23, 2024
ea9b2b1
Update similar override, use similar_field. Improve naming
lorenzovarese Jul 23, 2024
6f6563e
Use similar or similar_field wherever is possible
lorenzovarese Jul 23, 2024
d8724a1
Update test/gt2py_fo_exec.jl
lorenzovarese Jul 24, 2024
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
Binary file removed .github/.DS_Store
Binary file not shown.
15 changes: 1 addition & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ deps/src/

# Build artifacts for creating documentation generated by the Documenter package
docs/build/
docs/site/
.DS_Store

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml

# Python Env
.venv
env_setup.sh
.python-version

# Misc
.DS_Store
.vscode
Binary file removed docs/.DS_Store
Binary file not shown.
Binary file removed docs/src/.DS_Store
Binary file not shown.
Binary file removed notes/.DS_Store
Binary file not shown.
Binary file removed src/.DS_Store
Binary file not shown.
42 changes: 42 additions & 0 deletions src/GridTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export Dimension,
VERTICAL,
LOCAL,
Field,
similar_field,
Connectivity,
FieldOffset,
neighbor_sum,
Expand Down Expand Up @@ -207,6 +208,47 @@ function Field(
return Field(Tuple(dim), data, Tuple(broadcast_dims), origin = origin)
end

"""
similar_field(f::Field, ::Type{T}=eltype(f.data), dims::Dims=size(f.data)) where {T}

Create a new `Field` object similar to `f` but with a different element type `T` or different dimensions `dims`.

# Arguments
- `f::Field`: The original `Field` object to be replicated.
- `T`: The element type of the new `Field` object (default: element type of `f.data`).
- `dims::Dims`: The dimensions of the new `Field` object (default: size of `f.data`).

# Returns
- `Field`: A new `Field` object with the specified element type and dimensions.

# Examples
```julia-repl
julia> A1Dim_ = Dimension(:A1_, LOCAL);

julia> A1Dim = A1Dim_();

julia> in_field = Field((A1Dim, A1Dim), 3*ones(Float64, 4, 4))
4×4 Float64 Field with dimensions ("A1", "A1") with indices 1:4×1:4:
3.0 3.0 3.0 3.0
3.0 3.0 3.0 3.0
3.0 3.0 3.0 3.0
3.0 3.0 3.0 3.0

julia> out_field = similar(in_field, Int);

julia> size(out_field)
(4, 4)

julia> eltype(out_field)
Int64

```
"""
function similar_field(f::Field, ::Type{T}=eltype(f.data), dims::Dims=size(f.data)) where {T}
new_data = similar(f.data, T, dims)
return Field(f.dims, new_data, f.broadcast_dims, f.origin)
end

# TODO(tehrengruber): There is no need to have FieldOffset and FieldOffsetTS, remove FieldOffset
struct FieldOffsetTS{
Name,
Expand Down
Binary file removed src/examples/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion src/gt2py/gt2py.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ end
function preprocess_definiton(expr::Expr, closure_vars::Dict)
sat = single_assign_target_pass(expr)
ucc = unchain_compairs_pass(sat)
ssa = single_static_assign_pass(ucc)
nop = canonicalize_arithmetic_ops(ucc)
ssa = single_static_assign_pass(nop)
py_closure_vars = translate_closure_vars(closure_vars)
annotations = get_annotation(ssa, py_closure_vars)
return (ssa, py_closure_vars, annotations)
Expand Down
1 change: 1 addition & 0 deletions src/gt2py/jast_to_foast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ end

function visit_(sym::Val{:call}, args::Array, outer_loc)
if args[1] in bin_op
@assert length(args)==3 "Expected a binary operation. AST must be canonicalized using `canonicalize_arithmetic_ops` first."
return foast.BinOp(
op = visit(args[1]),
left = visit(args[2], outer_loc),
Expand Down
15 changes: 15 additions & 0 deletions src/gt2py/preprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ function unchain_compairs_pass(expr::Expr)::Expr
end
end

"""
Transform all arithmetic operations with more than two arguments into binary operations.
"""
function canonicalize_arithmetic_ops(expr)
if expr isa Expr
expr = Expr(expr.head, map(canonicalize_arithmetic_ops, expr.args)...) # visit all children

if expr.head == :call && expr.args[1] in bin_op && length(expr.args) > 3
op, a, b, tail... = expr.args
return canonicalize_arithmetic_ops(Expr(:call, op, Expr(:call, op, a, b), tail...))
end
end
return expr
end

function recursive_unchain(args::Array)::Expr
if length(args) == 3
return Expr(:call, args[2], args[1], args[3])
Expand Down
Binary file removed test/.DS_Store
Binary file not shown.
Loading
Loading