Skip to content

Commit d8c47e2

Browse files
authored
Merge pull request #92 from GaragePixel/develop
[Add] Sliding window - dummy code
2 parents 9658839 + 8fecb33 commit d8c47e2

3 files changed

Lines changed: 225 additions & 106 deletions

File tree

modules/std/syntax/primitives/arrays.wx renamed to modules/std/syntax/primitives/arrays/arrays.wx

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Namespace std.syntax
44
#rem MiniLibrary: Arrays
55
Since 2021? - 2025-02-02 - 2025-06-19 - 2025-06-21 (Aida 4)
66
Author: iDkP from GaragePixel
7+
#end
78

89
List of functionality:
910
- Copying (CopyTo for inlined usage)
@@ -16,6 +17,7 @@ List of functionality:
1617
- Aggregation: Sum, Min, Max with inverse step, Average
1718
- Clamp/Clip: Bound all elements to a range
1819
- Chunking/Splitting: Split into fixed-size blocks
20+
- Sliding window: Windowed views for DSP, stats, ML
1921

2022
TODO:
2123
A test To know which one is the faster:
@@ -26,7 +28,6 @@ Missing or possible extensions:
2628
- Set operations: Union, Intersection, Difference, Unique/Distinct
2729
- Chunking/Splitting: group by predicate
2830
- Flatten/Concat: For arrays-of-arrays
29-
- Sliding window: Windowed views for DSP, stats, ML
3031
- Reorganize the file, it's crappy actually
3132

3233
Possible application fields:
@@ -37,110 +38,6 @@ Completion:
3738
- For full "batteries-included" status, add functional, searching, set, and chunking utilities.
3839
#end
3940

40-
'TO TEST:
41-
Function SlidingRead<T,ChunkFormat>( this:T[],
42-
43-
'data to write into:
44-
data:T Ptr,
45-
46-
'dimension x,y of the unidimensional array:
47-
length:ChunkFormat Ptr,
48-
height:ChunkFormat Ptr,
49-
50-
'position of the window:
51-
offsetX:UInt,
52-
offsetY:UInt,
53-
offsetLength:ChunkFormat,
54-
offsetHeight:ChunkFormat,
55-
56-
'Pointer in the window:
57-
ptrX:UInt,
58-
ptrY:UInt )
59-
60-
'Return the content
61-
data[0]=this[ SlidingGetPtr( Varptr(length),
62-
Varptr(height),
63-
64-
Varptr(offsetX),
65-
Varptr(offsetY),
66-
Varptr(offsetLength),
67-
Varptr(offsetHeight),
68-
69-
Varptr(ptrX),
70-
Varptr(ptrY)) ]
71-
End
72-
73-
'TO TEST:
74-
Function SlidingWrite<T,ChunkFormat>( this:T[],
75-
76-
'data to write/set:
77-
data:T Ptr,
78-
79-
'dimension x,y of the unidimensional array:
80-
length:ChunkFormat Ptr,
81-
height:ChunkFormat Ptr,
82-
83-
'position of the window:
84-
offsetX:UInt,
85-
offsetY:UInt,
86-
offsetLength:ChunkFormat,
87-
offsetHeight:ChunkFormat,
88-
89-
'Pointer in the window:
90-
ptrX:UInt,
91-
ptrY:UInt )
92-
93-
'Return the content
94-
data[0]=this[ SlidingGetPtr( Varptr(length),
95-
Varptr(height),
96-
97-
Varptr(offsetX),
98-
Varptr(offsetY),
99-
Varptr(offsetLength),
100-
Varptr(offsetHeight),
101-
102-
Varptr(ptrX),
103-
Varptr(ptrY)) ]
104-
End
105-
106-
Private 'Get a pointer for read/write in a virtual 2d array from a sliding window
107-
Function SlidingGetPtr<T,ChunkFormat>:ChunkFormat Ptr( this:T[],
108-
109-
'dimension x,y of the unidimensional array:
110-
length:ChunkFormat Ptr,
111-
height:ChunkFormat Ptr,
112-
113-
'position of the window:
114-
offsetX:UInt Ptr,
115-
offsetY:UInt Ptr,
116-
offsetLength:ChunkFormat Ptr,
117-
offsetHeight:ChunkFormat Ptr,
118-
119-
'Pointer in the window:
120-
ptrX:UInt Ptr,
121-
ptrY:UInt Ptr )
122-
123-
'The pointer is inside the window
124-
ptrX[0]=ptrX[0]>offsetLength[0] ? offsetLength[0] Else ptrX[0] 'guard
125-
ptrY[0]=ptrY[0]>offsetHeight[0] ? offsetHeight[0] Else ptrY[0] 'guard
126-
127-
'The window is inside the 2d array
128-
offsetX[0]=offsetX[0]<=length[0]-offsetLength[0] ? offsetX[0] Else length[0]-offsetLength[0] 'guard, here <= avoids sub (edge case)
129-
offsetY[0]=offsetY[0]<=height[0]-offsetHeight[0] ? offsetY[0] Else height[0]-offsetHeight[0] 'guard, here <= avoids sub (edge case)
130-
131-
'Shift the pointer inside the 2d array
132-
ptrX[0]+=offsetX[0]
133-
ptrY[0]+=offsetY[0]
134-
135-
'Pointer from 2d array to 1d array
136-
ptrY[0]*=length[0]-1
137-
ptrX[0]+=ptrY[0]
138-
139-
'Return the content
140-
Return ptrX
141-
End
142-
Public
143-
14441
'TO TEST:
14542
Function Splitting<T>:T[][]( this:T[],chunksLength:Int )
14643
'ToTest
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
2+
Namespace stdlib.syntax
3+
4+
#rem MiniLibrary: Arrays slicing window
5+
Since 2025-07-20 (Aida 4)
6+
Author: iDkP from GaragePixel
7+
#end
8+
9+
'Extract (copy) and virtual 2d array window
10+
Function SlidingExtract<T,ChunkFormat>( src:T[], 'The source
11+
srcLength:ChunkFormat Ptr,
12+
srcHeight:ChunkFormat Ptr,
13+
14+
'position of the window to extract:
15+
srcOffsetX:UInt,
16+
srcOffsetY:UInt,
17+
srcOffsetLength:ChunkFormat,
18+
srcOffsetHeight:ChunkFormat,
19+
20+
'destination array reference
21+
dst:T[] )
22+
23+
#rem
24+
25+
- Example:
26+
scr:
27+
****** length: 6
28+
***12* height: 3
29+
***34* window:
30+
offsetx: 4
31+
offsety: 2
32+
offsetLength: 2
33+
offsetHeight: 2
34+
result:
35+
1234
36+
#end
37+
End
38+
39+
'Insert (paste) a virtual 2d array window
40+
Function SlidingInsert<T,ChunkFormat>( src:T[], 'The source
41+
srcLength:ChunkFormat Ptr,
42+
srcHeight:ChunkFormat Ptr,
43+
44+
'destination array reference
45+
dst:T[],
46+
47+
'position of the window to extract:
48+
dstOffsetX:UInt,
49+
dstOffsetY:UInt,
50+
dstOffsetLength:ChunkFormat,
51+
dstOffsetHeight:ChunkFormat )
52+
53+
#rem
54+
55+
- Example:
56+
scr:
57+
1234 -> 12 srcLength: 2
58+
34 srcHeight: 2
59+
60+
result (dest):
61+
****** dstLength: 6
62+
***12* dstHeight: 3
63+
***34* window:
64+
dstOffsetx: 4
65+
dstOffsety: 2
66+
dstOffsetLength: 2
67+
dstOffsetHeight: 2
68+
#end
69+
End
70+
71+
'Copy a virtual 2d array to another virtual 2d array
72+
Function SlidingCopyTo<T,ChunkFormat>( src:T[], 'The source
73+
srcLength:ChunkFormat Ptr,
74+
srcHeight:ChunkFormat Ptr,
75+
76+
'position of the scr window:
77+
srcOffsetX:UInt,
78+
srcOffsetY:UInt,
79+
srcOffsetLength:ChunkFormat,
80+
srcOffsetHeight:ChunkFormat,
81+
82+
dest:T[], 'the destination array
83+
dstLength:ChunkFormat Ptr,
84+
dstHeight:ChunkFormat Ptr,
85+
86+
'position of the dest window:
87+
dstOffsetX:UInt,
88+
dstOffsetY:UInt )
89+
#rem
90+
91+
- Example:
92+
scr:
93+
****** length: 6
94+
***00* height: 3
95+
***00* window:
96+
offsetx: 4
97+
offsety: 2
98+
offsetLength: 2
99+
offsetHeight: 2
100+
dest
101+
102+
****** length: 6
103+
**X*** height: 4
104+
****** window:
105+
****** offsetx: 3
106+
offsety: 2
107+
108+
result:
109+
******
110+
**00**
111+
**00**
112+
******
113+
#end
114+
End
115+
116+
'Read a window from a virtual 2d array to another virtual 2d array
117+
Function SlidingRead<T,ChunkFormat>( this:T[],
118+
119+
'data to write into:
120+
data:T Ptr,
121+
122+
'dimension x,y of the unidimensional array:
123+
length:ChunkFormat Ptr,
124+
height:ChunkFormat Ptr,
125+
126+
'position of the window:
127+
offsetX:UInt,
128+
offsetY:UInt,
129+
offsetLength:ChunkFormat,
130+
offsetHeight:ChunkFormat,
131+
132+
'Pointer in the window:
133+
ptrX:UInt,
134+
ptrY:UInt )
135+
136+
'Return the content
137+
data[0]=this[ SlidingGetPtr( this,
138+
139+
Varptr(length),
140+
Varptr(height),
141+
142+
Varptr(offsetX),
143+
Varptr(offsetY),
144+
Varptr(offsetLength),
145+
Varptr(offsetHeight),
146+
147+
Varptr(ptrX),
148+
Varptr(ptrY)) ]
149+
End
150+
151+
'Write a window from a virtual 2d array to another virtual 2d array
152+
Function SlidingWrite<T,ChunkFormat>( this:T[],
153+
154+
'data to write/set:
155+
data:T Ptr,
156+
157+
'dimension x,y of the unidimensional array:
158+
length:ChunkFormat Ptr,
159+
height:ChunkFormat Ptr,
160+
161+
'position of the window:
162+
offsetX:UInt,
163+
offsetY:UInt,
164+
offsetLength:ChunkFormat,
165+
offsetHeight:ChunkFormat,
166+
167+
'Pointer in the window:
168+
ptrX:UInt,
169+
ptrY:UInt )
170+
171+
'Return the content
172+
data[0]=this[ SlidingGetPtr( this,
173+
174+
Varptr(length),
175+
Varptr(height),
176+
177+
Varptr(offsetX),
178+
Varptr(offsetY),
179+
Varptr(offsetLength),
180+
Varptr(offsetHeight),
181+
182+
Varptr(ptrX),
183+
Varptr(ptrY)) ]
184+
End
185+
186+
'Get a pointer for read/write in a virtual 2d array from a sliding window
187+
Function SlidingGetPtr<T,ChunkFormat>:ChunkFormat Ptr( this:T[],
188+
189+
'dimension x,y of the unidimensional array:
190+
length:ChunkFormat Ptr,
191+
height:ChunkFormat Ptr,
192+
193+
'position of the window:
194+
offsetX:UInt Ptr,
195+
offsetY:UInt Ptr,
196+
offsetLength:ChunkFormat Ptr,
197+
offsetHeight:ChunkFormat Ptr,
198+
199+
'Pointer in the window:
200+
ptrX:UInt Ptr,
201+
ptrY:UInt Ptr )
202+
203+
'The pointer is inside the window
204+
ptrX[0]=ptrX[0]>offsetLength[0] ? offsetLength[0] Else ptrX[0] 'guard
205+
ptrY[0]=ptrY[0]>offsetHeight[0] ? offsetHeight[0] Else ptrY[0] 'guard
206+
207+
'The window is inside the 2d array
208+
offsetX[0]=offsetX[0]<=length[0]-offsetLength[0] ? offsetX[0] Else length[0]-offsetLength[0] 'guard, here <= avoids sub (edge case)
209+
offsetY[0]=offsetY[0]<=height[0]-offsetHeight[0] ? offsetY[0] Else height[0]-offsetHeight[0] 'guard, here <= avoids sub (edge case)
210+
211+
'Shift the pointer inside the 2d array
212+
ptrX[0]+=offsetX[0]
213+
ptrY[0]+=offsetY[0]
214+
215+
'Pointer from 2d array to 1d array
216+
ptrY[0]*=length[0]-1
217+
ptrX[0]+=ptrY[0]
218+
219+
'Return the content
220+
Return ptrX
221+
End

modules/std/syntax/syntax.xw

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Namespace std.syntax
55
#Import "consts/logicals"
66
#Import "consts/strings"
77

8-
#Import "primitives/arrays"
8+
#Import "primitives/arrays/arrays"
9+
#Import "primitives/arrays/slidings"
910
#Import "primitives/variants/variantcasts"
1011
#Import "primitives/variants/meta"
1112
#Import "primitives/variants/makevars"

0 commit comments

Comments
 (0)