nextsimhub / nextsimdg

neXtSIM_DG : next generation sea-ice model with DG
https://nextsim-dg.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
10 stars 13 forks source link

Slice ModelArrays #735

Open timspainNERSC opened 1 week ago

timspainNERSC commented 1 week ago

Both advection (#99) and the halo regions needed for MPI (#132) require moving around subsets of ModelArray data. A unified slicing class/library to provide a common interface would be a useful addition to the model.

timspainNERSC commented 1 week ago

Currently in progress on the branch slicer.

TomMelt commented 1 week ago

maybe 106445222 assertions is a bit overkill.

image

Could we reduce the size/dimensionality of this test case? https://github.com/nextsimhub/nextsimdg/blob/5216f7b8343a37de1e4924709820f63e0cff4d18/core/test/Slice_test.cpp#L137-L149

TomMelt commented 1 week ago

Thanks for sharing this branch @timspainNERSC. This will be super helpful.

I had a quick look and maybe I missed it. Is it possible to get the elements from a 1D slice back as a array/vector? possibly a std::array would be most sensible for my use case.

timspainNERSC commented 1 week ago

maybe 106445222 assertions is a bit overkill.

image

Could we reduce the size/dimensionality of this test case?

https://github.com/nextsimhub/nextsimdg/blob/5216f7b8343a37de1e4924709820f63e0cff4d18/core/test/Slice_test.cpp#L137-L149

😒 I do want a test that examines a high dimensionality array, but I can arrange the test so that there are fewer assertions. I GUESS.

timspainNERSC commented 1 week ago

Thanks for sharing this branch @timspainNERSC. This will be super helpful.

I had a quick look and maybe I missed it. Is it possible to get the elements from a 1D slice back as a array/vector? possibly a std::array would be most sensible for my use case.

Next on the TODO list. I should write that i the issue 🤔

timspainNERSC commented 1 week ago

maybe 106445222 assertions is a bit overkill. image Could we reduce the size/dimensionality of this test case? https://github.com/nextsimhub/nextsimdg/blob/5216f7b8343a37de1e4924709820f63e0cff4d18/core/test/Slice_test.cpp#L137-L149

😒 I do want a test that examines a high dimensionality array, but I can arrange the test so that there are fewer assertions. I GUESS.

${\textsf{\color{lightblue}[doctest]}}$ doctest version is "2.4.11" $${\textsf{\color{lightblue}[doctest]}}$$ run with "--help" for options $${\textsf{\color{dandelion}===============================================================================}}$$ $${\textsf{\color{lightblue}[doctest]}}$$ test cases: 4 | $${\textsf{\color{green} 4 passed}}$$ | $${\textsf{\color{black}0 failed}}$$ | $${\textsf{\color{black}0 skipped}}$$ $${\textsf{\color{lightblue}[doctest] }}$$ assertions: 423 | $${\textsf{\color{green}423 passed}}$$ | $${\textsf{\color{black}0 failed}}$$ | $${\textsf{\color{lightblue}[doctest]}}$$ Status: $${\textsf{\color{green}SUCCESS!}}$$

but also

             if (!message.empty()) goto end8d;

😎

timspainNERSC commented 1 week ago

How numpy behaves with a range of positive, 0, negative and absent indices. The test array a has 12 elements, where the value at each index is equal to the index.

Step = 1 (or absent)

stop value start < 0 start = 0 start > 0 (absent)
Large -ve a[-6:-16]=[] a[0:-16]=[] a[6:-16]=[] a[:-16]=[]
-length a[-6:-12]=[] a[0:-12]=[] a[6:-12]=[] a[:-12]=[]
-ve > start a[-6:-8]=[] a[0:-8]=[0,..,3] a[6:-8]=[] a[:-8]=[0,..,3]
-ve < start a[-6:-4]=[6,7] N/A a[6:-4]=[6,7] N/A
0 a[-6:0]=[] a[0:0]=[] a[6:0]=[] a[:0]=[]
+ve < start a[-6:4]=[] N/A a[6:4]=[] N/A
+ve > start a[-6:8]=[6,7] a[0:8]=[0,..,7] a[6:8]=[6,7] a[:8]=[0,..7]
length a[-6:12]=[6,..,11] a[0:12]=[0,..,11] a[6:12]=[6,..,11] a[:12]=[0,..,11]
large +ve a[-6:16]=[6,..,11] a[0:16]=[0,..,11] a[6:16]=[6,..,11] a[:16]=[0,..,11]
absent a[-6:]=[6,..,11] a[0:]=[0,..,11] a[6:]=[6,..,11] a[:]=[0,..,11]

step = 0

Causes an exception to be thrown.

Step = -1

stop value start < 0 start = 0 start > 0 (absent)
Large -ve a[-6:-16:-1]=[6,..,0] a[0:-16:-1]=[0] a[6:-16:-1]=[6,..,0] a[:-16:-1]=[11,..,0]
-length a[-6:-12:-1]=[6,..,1] a[0:-12:-1]=[] a[6:-12:-1]=[6,..,1] a[:-12:-1]=[11,..,1]
-ve > start a[-6:-8:-1]=[6,5] a[0:-8:-1]=[] a[6:-8:-1]=[6,5] a[:-8:-1]=[11,..,5]
-ve < start a[-6:-4:-1]=[] N/A a[6:-4:-1]=[] N/A
0 a[-6:0:-1]=[6,..,1] a[0:0:-1]=[] a[6:0:-1]=[6,..,1] a[:0:-1]=[11,..,1]
+ve < start a[-6:4:-1]=[6,5] N/A a[6:4:-1]=[6,5] N/A
+ve > start a[-6:8-1]=[] a[0:8:-1]=[] a[6:8:-1]=[6,7] a[:8:-1]=[11,..,9]
length a[-6:12:-1]=[] a[0:12:-1]=[] a[6:12:-1]=[] a[:12:-1]=[]
large +ve a[-6:16:-1]=[] a[0:16:-1]=[] a[6:16:-1]=[] a[:16:-1]=[]
absent a[-6::-1]=[6,..,0] a[0::-1]=[0] a[6::-1]=[6,..,0] a[::-1]=[11,..,0]

|step| > 1

Larger step sizes behave as expected, stepping the defined number of values from the same start index.