From 83d4ddb03bd42d6d35e526e10374911d4d4dad33 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:01:52 +0200 Subject: [PATCH 1/8] Update arrays.wx --- modules/std/syntax/primitives/arrays.wx | 124 ++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 7 deletions(-) diff --git a/modules/std/syntax/primitives/arrays.wx b/modules/std/syntax/primitives/arrays.wx index a118cd30..1b7a9af2 100644 --- a/modules/std/syntax/primitives/arrays.wx +++ b/modules/std/syntax/primitives/arrays.wx @@ -16,6 +16,7 @@ List of functionality: - Aggregation: Sum, Min, Max with inverse step, Average - Clamp/Clip: Bound all elements to a range - Chunking/Splitting: Split into fixed-size blocks + - Sliding window: Windowed views for DSP, stats, ML TODO: A test To know which one is the faster: @@ -26,7 +27,6 @@ Missing or possible extensions: - Set operations: Union, Intersection, Difference, Unique/Distinct - Chunking/Splitting: group by predicate - Flatten/Concat: For arrays-of-arrays - - Sliding window: Windowed views for DSP, stats, ML - Reorganize the file, it's crappy actually Possible application fields: @@ -37,7 +37,114 @@ Completion: - For full "batteries-included" status, add functional, searching, set, and chunking utilities. #end -'TO TEST: +'Extract (copy) and virtual 2d array window +Function SlidingExtract( src:T[], 'The source + srcLength:ChunkFormat Ptr, + srcHeight:ChunkFormat Ptr, + + 'position of the window to extract: + srcOffsetX:UInt, + srcOffsetY:UInt, + srcOffsetLength:ChunkFormat, + srcOffsetHeight:ChunkFormat, + + 'destination array reference + dst:T[] ) + + #rem + + - Example: + scr: + ****** length: 6 + ***12* height: 3 + ***34* window: + offsetx: 4 + offsety: 2 + offsetLength: 2 + offsetHeight: 2 + result: + 1234 + #end +End + +'Insert (paste) a virtual 2d array window +Function SlidingInsert( src:T[], 'The source + srcLength:ChunkFormat Ptr, + srcHeight:ChunkFormat Ptr, + + 'destination array reference + dst:T[], + + 'position of the window to extract: + dstOffsetX:UInt, + dstOffsetY:UInt, + dstOffsetLength:ChunkFormat, + dstOffsetHeight:ChunkFormat ) + + #rem + + - Example: + scr: + 1234 -> 12 srcLength: 2 + 34 srcHeight: 2 + + result (dest): + ****** dstLength: 6 + ***12* dstHeight: 3 + ***34* window: + dstOffsetx: 4 + dstOffsety: 2 + dstOffsetLength: 2 + dstOffsetHeight: 2 + #end +End + +'Copy a virtual 2d array to another virtual 2d array +Function SlidingCopyTo( src:T[], 'The source + srcLength:ChunkFormat Ptr, + srcHeight:ChunkFormat Ptr, + + 'position of the scr window: + srcOffsetX:UInt, + srcOffsetY:UInt, + srcOffsetLength:ChunkFormat, + srcOffsetHeight:ChunkFormat, + + dest:T[], 'the destination array + dstLength:ChunkFormat Ptr, + dstHeight:ChunkFormat Ptr, + + 'position of the dest window: + dstOffsetX:UInt, + dstOffsetY:UInt ) + #rem + + - Example: + scr: + ****** length: 6 + ***00* height: 3 + ***00* window: + offsetx: 4 + offsety: 2 + offsetLength: 2 + offsetHeight: 2 + dest + + ****** length: 6 + **X*** height: 4 + ****** window: + ****** offsetx: 3 + offsety: 2 + + result: + ****** + **00** + **00** + ****** + #end +End + +'Read a window from a virtual 2d array to another virtual 2d array Function SlidingRead( this:T[], 'data to write into: @@ -58,7 +165,9 @@ Function SlidingRead( this:T[], ptrY:UInt ) 'Return the content - data[0]=this[ SlidingGetPtr( Varptr(length), + data[0]=this[ SlidingGetPtr( this, + + Varptr(length), Varptr(height), Varptr(offsetX), @@ -70,7 +179,7 @@ Function SlidingRead( this:T[], Varptr(ptrY)) ] End -'TO TEST: +'Write a window from a virtual 2d array to another virtual 2d array Function SlidingWrite( this:T[], 'data to write/set: @@ -91,7 +200,9 @@ Function SlidingWrite( this:T[], ptrY:UInt ) 'Return the content - data[0]=this[ SlidingGetPtr( Varptr(length), + data[0]=this[ SlidingGetPtr( this, + + Varptr(length), Varptr(height), Varptr(offsetX), @@ -103,7 +214,7 @@ Function SlidingWrite( this:T[], Varptr(ptrY)) ] End -Private 'Get a pointer for read/write in a virtual 2d array from a sliding window +'Get a pointer for read/write in a virtual 2d array from a sliding window Function SlidingGetPtr:ChunkFormat Ptr( this:T[], 'dimension x,y of the unidimensional array: @@ -139,7 +250,6 @@ Function SlidingGetPtr:ChunkFormat Ptr( this:T[], 'Return the content Return ptrX End -Public 'TO TEST: Function Splitting:T[][]( this:T[],chunksLength:Int ) From fa5aeab853334fece3331a6cd6d44cb8723d2b83 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:02:35 +0200 Subject: [PATCH 2/8] Rename modules/std/syntax/primitives/arrays.wx to modules/std/syntax/primitives/arrays/arrays.wx --- modules/std/syntax/primitives/{ => arrays}/arrays.wx | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename modules/std/syntax/primitives/{ => arrays}/arrays.wx (100%) diff --git a/modules/std/syntax/primitives/arrays.wx b/modules/std/syntax/primitives/arrays/arrays.wx similarity index 100% rename from modules/std/syntax/primitives/arrays.wx rename to modules/std/syntax/primitives/arrays/arrays.wx From 806153b8c4a97319f7ff52ead43c0dd13d887cb3 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:03:26 +0200 Subject: [PATCH 3/8] Update syntax.xw --- modules/std/syntax/syntax.xw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/std/syntax/syntax.xw b/modules/std/syntax/syntax.xw index 9ed1ad37..30a14cc1 100644 --- a/modules/std/syntax/syntax.xw +++ b/modules/std/syntax/syntax.xw @@ -5,7 +5,7 @@ Namespace std.syntax #Import "consts/logicals" #Import "consts/strings" -#Import "primitives/arrays" +#Import "primitives/arrays/arrays" #Import "primitives/variants/variantcasts" #Import "primitives/variants/meta" #Import "primitives/variants/makevars" From 62f1c15d956a0160eb1d14f9debdc4cc12f77419 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:06:16 +0200 Subject: [PATCH 4/8] Create sliding.wx --- .../std/syntax/primitives/arrays/sliding.wx | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 modules/std/syntax/primitives/arrays/sliding.wx diff --git a/modules/std/syntax/primitives/arrays/sliding.wx b/modules/std/syntax/primitives/arrays/sliding.wx new file mode 100644 index 00000000..0ca17b5f --- /dev/null +++ b/modules/std/syntax/primitives/arrays/sliding.wx @@ -0,0 +1,220 @@ + +Namespace stdlib.syntax + +#rem MiniLibrary: Arrays slicing window +Since 2025-07-20 (Aida 4) +Author: iDkP from GaragePixel + +'Extract (copy) and virtual 2d array window +Function SlidingExtract( src:T[], 'The source + srcLength:ChunkFormat Ptr, + srcHeight:ChunkFormat Ptr, + + 'position of the window to extract: + srcOffsetX:UInt, + srcOffsetY:UInt, + srcOffsetLength:ChunkFormat, + srcOffsetHeight:ChunkFormat, + + 'destination array reference + dst:T[] ) + + #rem + + - Example: + scr: + ****** length: 6 + ***12* height: 3 + ***34* window: + offsetx: 4 + offsety: 2 + offsetLength: 2 + offsetHeight: 2 + result: + 1234 + #end +End + +'Insert (paste) a virtual 2d array window +Function SlidingInsert( src:T[], 'The source + srcLength:ChunkFormat Ptr, + srcHeight:ChunkFormat Ptr, + + 'destination array reference + dst:T[], + + 'position of the window to extract: + dstOffsetX:UInt, + dstOffsetY:UInt, + dstOffsetLength:ChunkFormat, + dstOffsetHeight:ChunkFormat ) + + #rem + + - Example: + scr: + 1234 -> 12 srcLength: 2 + 34 srcHeight: 2 + + result (dest): + ****** dstLength: 6 + ***12* dstHeight: 3 + ***34* window: + dstOffsetx: 4 + dstOffsety: 2 + dstOffsetLength: 2 + dstOffsetHeight: 2 + #end +End + +'Copy a virtual 2d array to another virtual 2d array +Function SlidingCopyTo( src:T[], 'The source + srcLength:ChunkFormat Ptr, + srcHeight:ChunkFormat Ptr, + + 'position of the scr window: + srcOffsetX:UInt, + srcOffsetY:UInt, + srcOffsetLength:ChunkFormat, + srcOffsetHeight:ChunkFormat, + + dest:T[], 'the destination array + dstLength:ChunkFormat Ptr, + dstHeight:ChunkFormat Ptr, + + 'position of the dest window: + dstOffsetX:UInt, + dstOffsetY:UInt ) + #rem + + - Example: + scr: + ****** length: 6 + ***00* height: 3 + ***00* window: + offsetx: 4 + offsety: 2 + offsetLength: 2 + offsetHeight: 2 + dest + + ****** length: 6 + **X*** height: 4 + ****** window: + ****** offsetx: 3 + offsety: 2 + + result: + ****** + **00** + **00** + ****** + #end +End + +'Read a window from a virtual 2d array to another virtual 2d array +Function SlidingRead( this:T[], + + 'data to write into: + data:T Ptr, + + 'dimension x,y of the unidimensional array: + length:ChunkFormat Ptr, + height:ChunkFormat Ptr, + + 'position of the window: + offsetX:UInt, + offsetY:UInt, + offsetLength:ChunkFormat, + offsetHeight:ChunkFormat, + + 'Pointer in the window: + ptrX:UInt, + ptrY:UInt ) + + 'Return the content + data[0]=this[ SlidingGetPtr( this, + + Varptr(length), + Varptr(height), + + Varptr(offsetX), + Varptr(offsetY), + Varptr(offsetLength), + Varptr(offsetHeight), + + Varptr(ptrX), + Varptr(ptrY)) ] +End + +'Write a window from a virtual 2d array to another virtual 2d array +Function SlidingWrite( this:T[], + + 'data to write/set: + data:T Ptr, + + 'dimension x,y of the unidimensional array: + length:ChunkFormat Ptr, + height:ChunkFormat Ptr, + + 'position of the window: + offsetX:UInt, + offsetY:UInt, + offsetLength:ChunkFormat, + offsetHeight:ChunkFormat, + + 'Pointer in the window: + ptrX:UInt, + ptrY:UInt ) + + 'Return the content + data[0]=this[ SlidingGetPtr( this, + + Varptr(length), + Varptr(height), + + Varptr(offsetX), + Varptr(offsetY), + Varptr(offsetLength), + Varptr(offsetHeight), + + Varptr(ptrX), + Varptr(ptrY)) ] +End + +'Get a pointer for read/write in a virtual 2d array from a sliding window +Function SlidingGetPtr:ChunkFormat Ptr( this:T[], + + 'dimension x,y of the unidimensional array: + length:ChunkFormat Ptr, + height:ChunkFormat Ptr, + + 'position of the window: + offsetX:UInt Ptr, + offsetY:UInt Ptr, + offsetLength:ChunkFormat Ptr, + offsetHeight:ChunkFormat Ptr, + + 'Pointer in the window: + ptrX:UInt Ptr, + ptrY:UInt Ptr ) + + 'The pointer is inside the window + ptrX[0]=ptrX[0]>offsetLength[0] ? offsetLength[0] Else ptrX[0] 'guard + ptrY[0]=ptrY[0]>offsetHeight[0] ? offsetHeight[0] Else ptrY[0] 'guard + + 'The window is inside the 2d array + offsetX[0]=offsetX[0]<=length[0]-offsetLength[0] ? offsetX[0] Else length[0]-offsetLength[0] 'guard, here <= avoids sub (edge case) + offsetY[0]=offsetY[0]<=height[0]-offsetHeight[0] ? offsetY[0] Else height[0]-offsetHeight[0] 'guard, here <= avoids sub (edge case) + + 'Shift the pointer inside the 2d array + ptrX[0]+=offsetX[0] + ptrY[0]+=offsetY[0] + + 'Pointer from 2d array to 1d array + ptrY[0]*=length[0]-1 + ptrX[0]+=ptrY[0] + + 'Return the content + Return ptrX +End From 7dfcab70bbbee64e835881124eb229de497a502c Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:07:21 +0200 Subject: [PATCH 5/8] Update and rename sliding.wx to slidings.wx --- modules/std/syntax/primitives/arrays/{sliding.wx => slidings.wx} | 1 + 1 file changed, 1 insertion(+) rename modules/std/syntax/primitives/arrays/{sliding.wx => slidings.wx} (99%) diff --git a/modules/std/syntax/primitives/arrays/sliding.wx b/modules/std/syntax/primitives/arrays/slidings.wx similarity index 99% rename from modules/std/syntax/primitives/arrays/sliding.wx rename to modules/std/syntax/primitives/arrays/slidings.wx index 0ca17b5f..1a1c99bd 100644 --- a/modules/std/syntax/primitives/arrays/sliding.wx +++ b/modules/std/syntax/primitives/arrays/slidings.wx @@ -4,6 +4,7 @@ Namespace stdlib.syntax #rem MiniLibrary: Arrays slicing window Since 2025-07-20 (Aida 4) Author: iDkP from GaragePixel +#end 'Extract (copy) and virtual 2d array window Function SlidingExtract( src:T[], 'The source From a6262226a000db122b4d73f5eedf4a9a99825186 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:08:32 +0200 Subject: [PATCH 6/8] Update arrays.wx --- .../std/syntax/primitives/arrays/arrays.wx | 215 +----------------- 1 file changed, 1 insertion(+), 214 deletions(-) diff --git a/modules/std/syntax/primitives/arrays/arrays.wx b/modules/std/syntax/primitives/arrays/arrays.wx index 1b7a9af2..ab69728f 100644 --- a/modules/std/syntax/primitives/arrays/arrays.wx +++ b/modules/std/syntax/primitives/arrays/arrays.wx @@ -4,6 +4,7 @@ Namespace std.syntax #rem MiniLibrary: Arrays Since 2021? - 2025-02-02 - 2025-06-19 - 2025-06-21 (Aida 4) Author: iDkP from GaragePixel +#end List of functionality: - Copying (CopyTo for inlined usage) @@ -37,220 +38,6 @@ Completion: - For full "batteries-included" status, add functional, searching, set, and chunking utilities. #end -'Extract (copy) and virtual 2d array window -Function SlidingExtract( src:T[], 'The source - srcLength:ChunkFormat Ptr, - srcHeight:ChunkFormat Ptr, - - 'position of the window to extract: - srcOffsetX:UInt, - srcOffsetY:UInt, - srcOffsetLength:ChunkFormat, - srcOffsetHeight:ChunkFormat, - - 'destination array reference - dst:T[] ) - - #rem - - - Example: - scr: - ****** length: 6 - ***12* height: 3 - ***34* window: - offsetx: 4 - offsety: 2 - offsetLength: 2 - offsetHeight: 2 - result: - 1234 - #end -End - -'Insert (paste) a virtual 2d array window -Function SlidingInsert( src:T[], 'The source - srcLength:ChunkFormat Ptr, - srcHeight:ChunkFormat Ptr, - - 'destination array reference - dst:T[], - - 'position of the window to extract: - dstOffsetX:UInt, - dstOffsetY:UInt, - dstOffsetLength:ChunkFormat, - dstOffsetHeight:ChunkFormat ) - - #rem - - - Example: - scr: - 1234 -> 12 srcLength: 2 - 34 srcHeight: 2 - - result (dest): - ****** dstLength: 6 - ***12* dstHeight: 3 - ***34* window: - dstOffsetx: 4 - dstOffsety: 2 - dstOffsetLength: 2 - dstOffsetHeight: 2 - #end -End - -'Copy a virtual 2d array to another virtual 2d array -Function SlidingCopyTo( src:T[], 'The source - srcLength:ChunkFormat Ptr, - srcHeight:ChunkFormat Ptr, - - 'position of the scr window: - srcOffsetX:UInt, - srcOffsetY:UInt, - srcOffsetLength:ChunkFormat, - srcOffsetHeight:ChunkFormat, - - dest:T[], 'the destination array - dstLength:ChunkFormat Ptr, - dstHeight:ChunkFormat Ptr, - - 'position of the dest window: - dstOffsetX:UInt, - dstOffsetY:UInt ) - #rem - - - Example: - scr: - ****** length: 6 - ***00* height: 3 - ***00* window: - offsetx: 4 - offsety: 2 - offsetLength: 2 - offsetHeight: 2 - dest - - ****** length: 6 - **X*** height: 4 - ****** window: - ****** offsetx: 3 - offsety: 2 - - result: - ****** - **00** - **00** - ****** - #end -End - -'Read a window from a virtual 2d array to another virtual 2d array -Function SlidingRead( this:T[], - - 'data to write into: - data:T Ptr, - - 'dimension x,y of the unidimensional array: - length:ChunkFormat Ptr, - height:ChunkFormat Ptr, - - 'position of the window: - offsetX:UInt, - offsetY:UInt, - offsetLength:ChunkFormat, - offsetHeight:ChunkFormat, - - 'Pointer in the window: - ptrX:UInt, - ptrY:UInt ) - - 'Return the content - data[0]=this[ SlidingGetPtr( this, - - Varptr(length), - Varptr(height), - - Varptr(offsetX), - Varptr(offsetY), - Varptr(offsetLength), - Varptr(offsetHeight), - - Varptr(ptrX), - Varptr(ptrY)) ] -End - -'Write a window from a virtual 2d array to another virtual 2d array -Function SlidingWrite( this:T[], - - 'data to write/set: - data:T Ptr, - - 'dimension x,y of the unidimensional array: - length:ChunkFormat Ptr, - height:ChunkFormat Ptr, - - 'position of the window: - offsetX:UInt, - offsetY:UInt, - offsetLength:ChunkFormat, - offsetHeight:ChunkFormat, - - 'Pointer in the window: - ptrX:UInt, - ptrY:UInt ) - - 'Return the content - data[0]=this[ SlidingGetPtr( this, - - Varptr(length), - Varptr(height), - - Varptr(offsetX), - Varptr(offsetY), - Varptr(offsetLength), - Varptr(offsetHeight), - - Varptr(ptrX), - Varptr(ptrY)) ] -End - -'Get a pointer for read/write in a virtual 2d array from a sliding window -Function SlidingGetPtr:ChunkFormat Ptr( this:T[], - - 'dimension x,y of the unidimensional array: - length:ChunkFormat Ptr, - height:ChunkFormat Ptr, - - 'position of the window: - offsetX:UInt Ptr, - offsetY:UInt Ptr, - offsetLength:ChunkFormat Ptr, - offsetHeight:ChunkFormat Ptr, - - 'Pointer in the window: - ptrX:UInt Ptr, - ptrY:UInt Ptr ) - - 'The pointer is inside the window - ptrX[0]=ptrX[0]>offsetLength[0] ? offsetLength[0] Else ptrX[0] 'guard - ptrY[0]=ptrY[0]>offsetHeight[0] ? offsetHeight[0] Else ptrY[0] 'guard - - 'The window is inside the 2d array - offsetX[0]=offsetX[0]<=length[0]-offsetLength[0] ? offsetX[0] Else length[0]-offsetLength[0] 'guard, here <= avoids sub (edge case) - offsetY[0]=offsetY[0]<=height[0]-offsetHeight[0] ? offsetY[0] Else height[0]-offsetHeight[0] 'guard, here <= avoids sub (edge case) - - 'Shift the pointer inside the 2d array - ptrX[0]+=offsetX[0] - ptrY[0]+=offsetY[0] - - 'Pointer from 2d array to 1d array - ptrY[0]*=length[0]-1 - ptrX[0]+=ptrY[0] - - 'Return the content - Return ptrX -End - 'TO TEST: Function Splitting:T[][]( this:T[],chunksLength:Int ) 'ToTest From 4bc3269284daa35e2afc88b88cfdc70c0da3fdf2 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:09:36 +0200 Subject: [PATCH 7/8] Update syntax.xw --- modules/std/syntax/syntax.xw | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/std/syntax/syntax.xw b/modules/std/syntax/syntax.xw index 30a14cc1..f7e02a96 100644 --- a/modules/std/syntax/syntax.xw +++ b/modules/std/syntax/syntax.xw @@ -6,6 +6,7 @@ Namespace std.syntax #Import "consts/strings" #Import "primitives/arrays/arrays" +#Import "primitives/arrays/slicings" #Import "primitives/variants/variantcasts" #Import "primitives/variants/meta" #Import "primitives/variants/makevars" From 8fecb33092d328db741c156c2810436e6abfca96 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Sun, 20 Jul 2025 01:13:47 +0200 Subject: [PATCH 8/8] Update syntax.xw --- modules/std/syntax/syntax.xw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/std/syntax/syntax.xw b/modules/std/syntax/syntax.xw index f7e02a96..90eb6ca7 100644 --- a/modules/std/syntax/syntax.xw +++ b/modules/std/syntax/syntax.xw @@ -6,7 +6,7 @@ Namespace std.syntax #Import "consts/strings" #Import "primitives/arrays/arrays" -#Import "primitives/arrays/slicings" +#Import "primitives/arrays/slidings" #Import "primitives/variants/variantcasts" #Import "primitives/variants/meta" #Import "primitives/variants/makevars"