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

Initial offset design ideas #12015

Draft
wants to merge 54 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
eb37ef5
Initial offset design ideas
AdRiley Jan 7, 2025
7989ce8
Offset Column design work
AdRiley Jan 9, 2025
b0bf1c8
Table design
AdRiley Jan 9, 2025
d8740d2
Start to add test framework
AdRiley Jan 9, 2025
1cd2aa6
Add set_mode
AdRiley Jan 9, 2025
5130f56
Green
AdRiley Jan 10, 2025
bd3768a
More tests
AdRiley Jan 10, 2025
cdffb5d
One more test
AdRiley Jan 10, 2025
b490f0a
Table.offset Red
AdRiley Jan 10, 2025
a74f5fa
Plumbing
AdRiley Jan 10, 2025
ee45c92
More plumbing
AdRiley Jan 10, 2025
da5ec3f
First table test green
AdRiley Jan 10, 2025
089cf05
Next green table test
AdRiley Jan 10, 2025
af95bdc
Next table tests
AdRiley Jan 10, 2025
0d2933f
Green
AdRiley Jan 13, 2025
b331d7d
Red
AdRiley Jan 13, 2025
937f851
Green using mask solution
AdRiley Jan 13, 2025
d01bd24
Refactor
AdRiley Jan 13, 2025
a811df6
refactor
AdRiley Jan 13, 2025
8a97331
Refactor
AdRiley Jan 13, 2025
5d44c4d
More green tests
AdRiley Jan 13, 2025
09664f0
Red
AdRiley Jan 13, 2025
7c41b53
Green
AdRiley Jan 13, 2025
ccfb97c
Refactor
AdRiley Jan 13, 2025
68181ad
Green
AdRiley Jan 13, 2025
1cda931
Red
AdRiley Jan 14, 2025
c1e663a
Green
AdRiley Jan 14, 2025
5b9f789
Green
AdRiley Jan 14, 2025
1119796
Green
AdRiley Jan 14, 2025
c999528
Red
AdRiley Jan 14, 2025
7a2fa9e
Green
AdRiley Jan 14, 2025
4afadeb
Ordering and closet fill
AdRiley Jan 14, 2025
7a60ce6
Green
AdRiley Jan 14, 2025
14ca426
Refactor
AdRiley Jan 14, 2025
b6acd89
Refactor
AdRiley Jan 14, 2025
74d80a8
Refactor
AdRiley Jan 14, 2025
64dde8a
Cleanup
AdRiley Jan 14, 2025
6de5c51
Refactor
AdRiley Jan 15, 2025
9309586
Documentaion
AdRiley Jan 15, 2025
c50fef4
Column Names
AdRiley Jan 15, 2025
f928e1e
Multiple columns
AdRiley Jan 16, 2025
1b37fa6
Refactor
AdRiley Jan 16, 2025
134b818
Refactor
AdRiley Jan 16, 2025
67f9137
Refactor
AdRiley Jan 16, 2025
b9c69e2
Refactor
AdRiley Jan 16, 2025
791740a
Refactor
AdRiley Jan 16, 2025
8df3f4c
set_mode=update
AdRiley Jan 16, 2025
1dd496d
More tests
AdRiley Jan 17, 2025
88a8063
Remove on_problems
AdRiley Jan 17, 2025
b572fde
Rename to Fill_With
AdRiley Jan 17, 2025
6a37f2d
Documentation
AdRiley Jan 17, 2025
1eeff6f
Revert "Remove on_problems"
AdRiley Jan 17, 2025
3d5c77d
fmt
AdRiley Jan 17, 2025
7819762
New alias
AdRiley Jan 17, 2025
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
Prev Previous commit
Next Next commit
Green
  • Loading branch information
AdRiley committed Jan 17, 2025
commit 5b9f789ce8021fc7029ffae0cc9f03bb98f9eb34
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ private static class OffsetRunningStatistic implements RunningStatistic<OffsetIt
Column sourceColumn;
int n;
OffFill offFill;
int closestPos;

OffsetRunningStatistic(Column sourceColumn, int n, OffFill offFill) {
result = new int[sourceColumn.getSize()];
this.sourceColumn = sourceColumn;
this.n = offFill==OffFill.WRAP_AROUND && sourceColumn.getSize() != 0 ? n % sourceColumn.getSize() : n;
this.offFill = offFill;
this.closestPos = -1;
}

@Override
Expand All @@ -52,13 +50,13 @@ public void calculateNextValue(int i, OffsetIterator it) {
}
if (n<0) {
if (it.current_n <= Math.abs(n)) {
closestPos = it.rolling_queue.peek();
it.closestPos = it.rolling_queue.peek();
}
if (it.current_n >= Math.abs(n)) {
result[i] = it.rolling_queue.poll();
}
} else {
closestPos = i;
it.closestPos = i;
if (it.current_n >= Math.abs(n)) {
result[it.rolling_queue.poll()] = i;
}
Expand All @@ -70,7 +68,7 @@ public void calculateNextValue(int i, OffsetIterator it) {
public void finalise(OffsetIterator it) {
int fillValue = switch (offFill) {
case NOTHING -> -1;
case CLOSEST_VALUE -> closestPos;
case CLOSEST_VALUE -> it.closestPos;
case WRAP_AROUND -> -1;
case CONSTANT -> -1;
};
Expand Down Expand Up @@ -114,12 +112,14 @@ private static class OffsetIterator {
Queue<Integer> rolling_queue;
Queue<Integer> fill_queue;
int current_n;
int closestPos;

public OffsetIterator(int n)
{
this.rolling_queue = new LinkedList<>();
this.fill_queue = new LinkedList<>();
this.current_n = 0;
this.closestPos = -1;
}
}
}
25 changes: 24 additions & 1 deletion test/Table_Tests/src/Common_Table_Operations/Offset_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ add_offset_specs suite_builder setup =
group_builder.specify "Works with positive n and column of nothings" <|
r = t.offset ["B"] 1 ..Wrap_Around
r . at "TEMP" . to_vector . should_equal [Nothing, Nothing, Nothing]
suite_builder.group prefix+"Table.Offset works with grouping" group_builder->
suite_builder.group prefix+"Table.Offset works with grouping - default fill strategy" group_builder->
t2 = build_sorted_table [["Group", ["A", "A", "A", "B", "B", "B", "B", "C", "C"]], ["Col", [1, 2, 3, 1, 2, 3, 4, 1, 2]]]
group_builder.specify "Negative n shifts the values down" <|
r = t2.offset ["Col"] -1 ..Nothing group_by=["Group"]
Expand All @@ -252,3 +252,26 @@ add_offset_specs suite_builder setup =
group_builder.specify "Large positive n values work" <|
r = t2.offset ["Col"] 1024 ..Nothing group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing]
suite_builder.group prefix+"Table.Offset works with grouping - closest fill strategy" group_builder->
t2 = build_sorted_table [["Group", ["A", "A", "A", "B", "B", "B", "B", "C", "C"]], ["Col", [1, 2, 3, 1, 2, 3, 4, 1, 2]]]
group_builder.specify "Negative n shifts the values down" <|
r = t2.offset ["Col"] -1 ..Closest_Value group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [1, 1, 2, 1, 1, 2, 3, 1, 1]
group_builder.specify "Positive n shifts the values up" <|
r = t2.offset ["Col"] 1 ..Closest_Value group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [2, 3, 3, 2, 3, 4, 4, 2, 2]
group_builder.specify "Negative n shifts the values down (n=2)" <|
r = t2.offset ["Col"] -2 ..Closest_Value group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [1, 1, 1, 1, 1, 1, 2, 1, 1]
group_builder.specify "Positive n shifts the values up (n=2)" <|
r = t2.offset ["Col"] 2 ..Closest_Value group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [3, 3, 3, 3, 4, 4, 4, 2, 2]
group_builder.specify "Zero n is a no-op" <|
r = t2.offset ["Col"] 0 ..Closest_Value group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [1, 2, 3, 1, 2, 3, 4, 1, 2]
group_builder.specify "Large negative n values work" <|
r = t2.offset ["Col"] -1024 ..Closest_Value group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [1, 1, 1, 1, 1, 1, 1, 1, 1]
group_builder.specify "Large positive n values work" <|
r = t2.offset ["Col"] 1024 ..Closest_Value group_by=["Group"]
r . at "TEMP" . to_vector . should_equal [3, 3, 3, 4, 4, 4, 4, 2, 2]