From 08afe51cd113935ce779cf8b4acf4db9736c9039 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Fri, 18 Jul 2025 21:53:50 +0200 Subject: [PATCH 1/3] Update minmax.wx --- modules/std/syntax/funcs/minmax.wx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/std/syntax/funcs/minmax.wx b/modules/std/syntax/funcs/minmax.wx index ee0bdc12..d1800f30 100644 --- a/modules/std/syntax/funcs/minmax.wx +++ b/modules/std/syntax/funcs/minmax.wx @@ -37,10 +37,6 @@ Function Min:T1(a:T1 Ptr,b:T2 Ptr) Where T1 Implements INumeric And End Function Min:T(a:T,b:T,c:T) Where T Implements INumeric - - '3 arguments breaks the overloading of the language min/max stuff - 'So the language library non-native stuff was undoned, - 'and in the the word we'll have peace! Return a Date: Fri, 18 Jul 2025 22:09:50 +0200 Subject: [PATCH 2/3] Update minmax.wx --- modules/std/syntax/funcs/minmax.wx | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/modules/std/syntax/funcs/minmax.wx b/modules/std/syntax/funcs/minmax.wx index d1800f30..c0fce01b 100644 --- a/modules/std/syntax/funcs/minmax.wx +++ b/modules/std/syntax/funcs/minmax.wx @@ -104,3 +104,36 @@ Function Max:T1(a:T1 Ptr,b:T2 Ptr,c:T3 Ptr) Where T1 Implements INu 'Note that byte with int,float,double are incompatible Return Cast(a[0]:T(a:T Ptr,b:T Ptr,c:T Ptr,d:T Ptr) + 'Pointer version + 'Order 4 + Return Min(a,Min(b,Min(c,d))) +End + +Function Max:T(a:T Ptr,b:T Ptr,c:T Ptr,d:T Ptr) + 'Pointer version + 'Order 4 + Return Max(a,Max(b,Max(c,d))) +End + +Function SetMin( a:T Ptr, b:T Ptr) + + 'iDkP from GaragePixel + '2025-02-18 + + 'Pointer accelerations + If Pointer( b ) < Pointer( a ) + Assign( a, b ) + End +End + +Function SetMax( a:T Ptr, b:T Ptr) + + 'iDkP from GaragePixel + '2025-02-18 + + If Pointer( b ) > Pointer( a ) + Assign( a, b ) + End +End From 50800479ef813b0b308682b2ed3abde703fd9b9a Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Fri, 18 Jul 2025 23:13:06 +0200 Subject: [PATCH 3/3] Update arrays.wx --- modules/std/syntax/primitives/arrays.wx | 327 +++++++++++++++++++++--- 1 file changed, 296 insertions(+), 31 deletions(-) diff --git a/modules/std/syntax/primitives/arrays.wx b/modules/std/syntax/primitives/arrays.wx index 4b352959..a1c87a09 100644 --- a/modules/std/syntax/primitives/arrays.wx +++ b/modules/std/syntax/primitives/arrays.wx @@ -5,9 +5,6 @@ Namespace std.syntax Since 2021? - 2025-02-02 - 2025-06-19 - 2025-06-21 (Aida 4) Author: iDkP from GaragePixel -Purpose: - Review and completeness assessment of the stdlib.syntax array minilibrary. - List of functionality: - Copying (CopyTo for inlined usage) - Reversal (full, subrange, pointer, inverse, pairwise, preserve) @@ -15,23 +12,32 @@ List of functionality: - Scaling and tiling (Stretch, Scale, Tile) - Interleaving (Interleave) - Patterned rearrangement (Twirl, Swap) + - Fill: Fill with single value or pattern + - Aggregation: Sum, Min, Max with inverse step + - Clamp/Clip: Bound all elements to a range TODO: +A test To know which one is the faster: + - AssignIff(Max(Varptr(this[n]),Varptr(result))[0]<>this[n],Varptr(result)) + - c=a[n];out = c < out ? c Else out + Missing or possible extensions: - - Aggregation: Sum, Min, Max, Average. - - Set operations: Union, Intersection, Difference, Unique/Distinct. - - Chunking/Splitting: Split into fixed-size blocks, group by predicate. - - Flatten/Concat: For arrays-of-arrays. - - Fill: Fill with single value or pattern. - - Clamp/Clip: Bound all elements to a range. - - Sliding window: Windowed views for DSP, stats, ML. - -Summary: - - For most projects—especially graphics, DSP, procedural, and systems—it is already a **top-tier array toolkit**. - - Documentation and naming make it both accessible and powerful. -#end - -Function CopyTo:T[]( this:T[], out:T[], srcOffset:Int=0, dstOffset:Int=0, count:Int=Null ) + - Aggregation: Average, complete min/max + - Set operations: Union, Intersection, Difference, Unique/Distinct + - Chunking/Splitting: Split into fixed-size blocks, 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: + - For core permutations, copying, and pattern generation + - Graphics, DSP, procedural, and systems + +Completion: + - For full "batteries-included" status, add functional, searching, set, and chunking utilities. +#end + +Function CopyTo:T[]( this:T[],out:T[],srcOffset:Int=0,dstOffset:Int=0,count:Int=Null ) ' 'A CopyTo who can be inlined 'Usage example: @@ -49,11 +55,270 @@ End #rem monkeydoc @pro Return a copy of the array is needed #end -Function Cpynd:T[](data:T[],needed:Bool) - 'Both useful and elegant^^ - Return needed ? CopyTo(data,New T[data.Length]) Else data +Function Cpynd:T[]( data:T[],needed:Bool ) + 'Both useful and elegant^^ + Return needed ? CopyTo(data,New T[data.Length]) Else data +End + +' --- Bound all elements to a range: + +Function ClipArray( this:T1[],min:T2,max:T3 ) Where T1 Implements INumeric And + T2 Implements INumeric And + T3 Implements INumeric + + 'Note: The template cannot has T1 distingued from an array or anything else, + 'leading a funcList.FindFunc() internal error, because the actual array class isn't a + 'real class but, like Mark said, a pseudo-class. So we cannot derivated it from an + 'interface for constraint inference. The name ClipArray was choosen to klunge it. + + Local thisSize:=this.Size + For Local n:=0 until thisSize + Clip(Varptr(this[n]),Varptr(min),Varptr(max)) + End +End + +Function ClipArrayOver( this:T1[],limit:T2 ) Where T1 Implements INumeric And + T2 Implements INumeric + Local thisSize:=this.Size + For Local n:=0 until thisSize + ClipOver(Varptr(this[n]),Varptr(limit)) + End +End + +Function ClipArrayUnder( this:T1[],limit:T2 ) Where T1 Implements INumeric And + T2 Implements INumeric + Local thisSize:=this.Size + For Local n:=0 until thisSize + ClipUnder(Varptr(this[n]),Varptr(limit)) + End +End + +' --- Aggregations: + +Function Min:T( this:T[],minlim:T=0 ) Where T Implements INumeric + Local thisSize:=this.Size + Local result:T=minlim 'implicit casting + For Local n:=0 Until thisSize + AssignIff(Min(Varptr(this[n]),Varptr(result))[0]<>this[n],Varptr(result)) + End +End + +Function Max:T( this:T[],maxlim:T=LongMax ) Where T Implements INumeric + Local thisSize:=this.Size + Local result:T=maxlim 'auto and implicit casting + For Local n:=0 Until thisSize + AssignIff(Max(Varptr(this[n]),Varptr(result))[0]<>this[n],Varptr(result)) + End +End + +Function Min:T(a:T[],inverse:Bool8) Where T Implements INumeric + + 'iDkP from GaragePixel + '2025-02-18 + + 'Order n + + Local out:T + Local len:=T.Length + Local c:=out + Local starts:Int, ends:Int, shift:Int + + If inverse=False8 + starts=len + ends=0 + shift=-1 + Else + starts=0 + ends=len + shift=1 + End + + For Local n:=starts Until ends Step shift + c=a[n];out = c < out ? c Else out + End + + Return out End +Function Max:T(a:T[],inverse:Bool8) Where T Implements INumeric + + 'iDkP from GaragePixel + '2025-02-18 + + 'Order n + + Local out:T + Local len:=T.Length + Local c:=out + Local starts:Int, ends:Int, shift:Int + + If last=False8 + starts=len + ends=0 + shift=-1 + Else + starts=0 + ends=len + shift=1 + End + + For Local n:=starts Until ends Step shift + c=a[n];out = c>=out ? c Else out + End + + Return out +End + +Function Min:T(a:T[],inverse:Bool) Where T Implements INumeric + + 'iDkP from GaragePixel + '2025-02-18 + + 'Order n + + Local out:T + Local len:=T.Length + Local c:=out + Local starts:Int, ends:Int, shift:Int + + If inverse=False + starts=len + ends=0 + shift=-1 + Else + starts=0 + ends=len + shift=1 + End + + For Local n:=starts Until ends Step shift + c=a[n];out = c < out ? c Else out + End + + Return out +End + +Function Max:T(a:T[],inverse:Bool) Where T Implements INumeric + + 'iDkP from GaragePixel + '2025-02-18 + + 'Order n + + Local out:T + Local len:=T.Length + Local c:=out + Local starts:Int, ends:Int, shift:Int + + If last=False + starts=len + ends=0 + shift=-1 + Else + starts=0 + ends=len + shift=1 + End + + For Local n:=starts Until ends Step shift + c=a[n];out = c>=out ? c Else out + End + + Return out +End + +Function Sum:T( this:T[] ) Where T Implements INumeric + 'Unsafe version, potentially faster + Local thisSize:=this.Size + Local result:T=0 + For Local n:=0 Until thisSize + result+=this[n] + End + Return result +End + +Function SumSafe:T( this:T[] ) Where T Implements INumeric + 'Safe version + If this + Local thisSize:=this.Size + If thisSize<>0 + Local result:T=0 + For Local n:=0 Until thisSize + result+=this[n] + End + Return result + Else + Return 0 + End + End + Return Null +End + +#rem monkeydoc @expert The length of the array. +In the case of multi-dimensional arrays, the length of the array is the product +of the sizes of all dimensions. +#end +Function Length:B( this:T[] ) + Return this.Length() +End + +Function GetSizeInt:Int( this:T[],dimension:Int ) + 'Gets the size of a single array dimension. + Return GetSize( this ) +End + +Function GetSize:B( this:T[],dimension:D ) + 'Gets the size of a single array dimension. + + 'Note: the actual compiler 2025-07-17 will always return int (B=int) + 'GetSizeInt and GetSize generic are so identical for now. + 'In the future, GetSizeInt will be used as sugar but not in stdlib, + 'maybe in a dedicated std wrote over, for beginners. + + 'D datatype of is the pointer for each dimensions. + 'Actually, the dimension is represented by an int and its max size + 'is the allowed by int adressage. If we want create many arrays + 'some dimensions in byte, it will save many megabyte to use + 'a certain type to reference the dimension of same type. + Return this.GetSize(dimension) +End + +Function Resize:B( this:T[],length:B ) + 'Resizes an array. + 'Returns a copy of the array resized to length `length`. + 'Note that this method does not modify this array in any way. + Return this.Resize(length) +End + +Function Slice:T[]( this:T[],from:B,copy:Bool=True ) + 'Extracts a subarray from the array. + 'Returns an array consisting of all elements from `from` until (but not including) `tail`, + 'or until the end of the string if `tail` is not specified. + 'If either `from` or `tail` is negative, it represents an offset from the end of the array. + Return Slice(from,Length(this)) +End + +Function Slice:T[]( this:T[],from:B,tail:B,copy:Bool=True ) + If copy Return this.Slice(from,tail) + this=this.Slice(from,tail) + Return this +End + +Function Fill( this:T[],value:T,from:B=0,toEnd:B=Null ) + If toEnd=Null toEnd=this.Length 'auto + For Local n:=from Until toEnd + this[n]=value + End +End +Function FillFast( this:T[],value:T ) + If toEnd=Null toEnd=this.Length + For Local n:=0 Until toEnd + this[n]=value + End +End + +'------------ + #rem monkeydoc hidden Merges two sorted arrays into a single sorted array. Merges the elements of arrays a and b, preserving order and stability. @@ -71,7 +336,7 @@ On elements: @param b Second array. @return A new array containing all elements from a and b. #end -Function Merge:T[]( a:T[], b:T[] ) +Function Merge:T[]( a:T[],b:T[] ) Local na:Int = a.Length Local nb:Int = b.Length Local res:T[] = New T[na + nb] @@ -110,7 +375,7 @@ On elements [1, 2, 3, 4] @param arr Array to be reversed. #end -Function Reverse:T[]( arr:T[], copy:Bool=True ) +Function Reverse:T[]( arr:T[],copy:Bool=True ) Local out:=Cpynd(arr, copy) @@ -141,7 +406,7 @@ On elements [1, 2, 3, 4] with start=1, atEnd=2 @param start Index of the first element in the range. @param atEnd Index of the last element in the range (inclusive). #end -Function Reverse( data:T[], start:Int, atEnd:Int, copy:Bool=True ) +Function Reverse( data:T[],start:Int,atEnd:Int,copy:Bool=True ) Local out:=Cpynd(data, copy) @@ -156,7 +421,7 @@ Function Reverse( data:T[], start:Int, atEnd:Int, copy:Bool=True ) Return out End -Function Reverse( data:T[], start:Int Ptr, atEnd:Int Ptr, copy:Bool=True ) +Function Reverse( data:T[],start:Int Ptr,atEnd:Int Ptr,copy:Bool=True ) Local out:=Cpynd(data, copy) @@ -191,7 +456,7 @@ Function Flip:T[]( this:T[], copy:Bool=True ) Return out End -Function Flipflap:T[]( this:T[], preserve:Bool=False, copy:Bool=True ) +Function Flipflap:T[]( this:T[],preserve:Bool=False,copy:Bool=True ) 'Input (odd set): '123456789 'Output with preserve=False (default): @@ -240,7 +505,7 @@ Function Flipflap:T[]( this:T[], preserve:Bool=False, copy:Bool=True ) Return result End -Function Rotate:T[]( this:T[], pivot:Int=Null, copy:Bool=True ) +Function Rotate:T[]( this:T[],pivot:Int=Null,copy:Bool=True ) ' Output (for pivot=4): ' 123456789 (input) ' 765432198 @@ -269,11 +534,11 @@ Function Rotate:T[]( this:T[], pivot:Int=Null, copy:Bool=True ) Return Rot( this,vec,False ) End -Function Stretch:T[]( this:T[], factor:Int=0, copy:Bool=True ) +Function Stretch:T[]( this:T[],factor:Int=0,copy:Bool=True ) Return Scale(this,factor,copy) End -Function Scale:T[]( this:T[], factor:Int=0, copy:Bool=True ) +Function Scale:T[]( this:T[],factor:Int=0,copy:Bool=True ) ' Element-wise stretch/shrink of an array. ' Expansion: repeats each element by 'factor'. ' Contraction: keeps every abs(factor)-th element, always preserves first and last. @@ -327,7 +592,7 @@ Function Scale:T[]( this:T[], factor:Int=0, copy:Bool=True ) End End -Function Tile:T[]( this:T[], factor:Int=0, copy:Bool=True ) +Function Tile:T[]( this:T[],factor:Int=0,copy:Bool=True ) ' Expands or contracts the array by a scale factor. ' Examples: ' with [1,2,3], Tile(3) → [1,2,3,1,2,3,1,2,3] @@ -369,7 +634,7 @@ End @author: iDkP for GaragePixel, @since 2021? #end -Function Rot:T[]( arr:T[], shift:Int, copy:Bool=True ) +Function Rot:T[]( arr:T[],shift:Int,copy:Bool=True ) ' ' this = "123456789" ' ' Print Rot( this, -3 ) ' ' Output: @@ -585,7 +850,7 @@ Function RotateByOffset:T[]( this:T[],offset:Int=Null,copy:Bool=True ) k+=1 End - If Not copy + If Not copy this=result result=this End