diff --git a/src/SIMDArray/PerformanceArray.fs b/src/SIMDArray/PerformanceArray.fs index 82c1346..d8107bf 100644 --- a/src/SIMDArray/PerformanceArray.fs +++ b/src/SIMDArray/PerformanceArray.fs @@ -15,7 +15,7 @@ open SIMDArrayUtils /// /// /// -let inline partitionUnordered f (array: _[]) = +let inline partitionUnordered ([] f: 'a -> bool) (array: _[]) = checkNonNull array let res = Array.zeroCreate array.Length let mutable upCount = 0 @@ -70,7 +70,7 @@ let inline distinctByUnordered keyf (array:'T[]) = /// /// /// -let inline mapInPlace f (array :'T[]) = +let inline mapInPlace ([] f: 'T -> 'T) (array :'T[]) = checkNonNull array @@ -85,7 +85,7 @@ let inline mapInPlace f (array :'T[]) = /// /// Predicate to fitler with /// -let inline filterSimplePredicate (f: ^T -> bool) (array: ^T[]) = +let inline filterSimplePredicate ([] f: ^T -> bool) (array: ^T[]) = checkNonNull array if array.Length = 0 then invalidArg "array" "Array can not be empty." @@ -110,7 +110,7 @@ let inline filterSimplePredicate (f: ^T -> bool) (array: ^T[]) = /// /// Predicate to fitler with /// -let inline whereSimplePredicate (f: ^T -> bool) (array: ^T[]) = +let inline whereSimplePredicate ([] f: ^T -> bool) (array: ^T[]) = filterSimplePredicate f array diff --git a/src/SIMDArray/SIMDArray.fs b/src/SIMDArray/SIMDArray.fs index 23a81a2..b96f00c 100644 --- a/src/SIMDArray/SIMDArray.fs +++ b/src/SIMDArray/SIMDArray.fs @@ -17,7 +17,7 @@ open SIMDArrayUtils /// /// /// -let inline skipWhile (vf : Vector< ^T> -> bool) (sf : ^T -> bool) (array : ^T[]) : ^T[] = +let inline skipWhile ([] vf : Vector< ^T> -> bool) ([] sf : ^T -> bool) (array : ^T[]) : ^T[] = checkNonNull array if array.Length <> 0 then let mutable i = 0 @@ -43,7 +43,7 @@ let inline skipWhile (vf : Vector< ^T> -> bool) (sf : ^T -> bool) (array : ^T[]) /// /// /// -let inline takeWhile (vf : Vector< ^T> -> bool) (sf : ^T -> bool) (array : ^T[]) : ^T[] = +let inline takeWhile ([] vf : Vector< ^T> -> bool) ([] sf : ^T -> bool) (array : ^T[]) : ^T[] = checkNonNull array if array.Length <> 0 then @@ -72,9 +72,9 @@ let inline takeWhile (vf : Vector< ^T> -> bool) (sf : ^T -> bool) (array : ^T[]) /// /// let inline mapFold - (vf: ^State Vector -> ^T Vector -> ^U Vector * ^State Vector) - (sf : ^State -> ^T -> ^U * ^State) - (combiner : ^State -> ^State -> ^State) + ([] vf: ^State Vector -> ^T Vector -> ^U Vector * ^State Vector) + ([] sf : ^State -> ^T -> ^U * ^State) + ([] combiner : ^State -> ^State -> ^State) (acc : ^State) (array: ^T[]) : ^U[] * ^State = @@ -114,9 +114,9 @@ let inline mapFold /// /// let inline mapFoldBack - (vf: ^T Vector -> ^State Vector -> ^U Vector * ^State Vector) - (sf : ^T -> ^State -> ^U * ^State) - (combiner : ^State -> ^State -> ^State) + ([] vf: ^T Vector -> ^State Vector -> ^U Vector * ^State Vector) + ([] sf : ^T -> ^State -> ^U * ^State) + ([] combiner : ^State -> ^State -> ^State) (array: ^T[]) (acc : ^State) : ^U[] * ^State = @@ -160,9 +160,9 @@ let inline mapFoldBack /// Initial value to accumulate from /// Source array let inline fold - (vf: ^State Vector -> ^T Vector -> ^State Vector) - (sf : ^State -> ^T -> ^State) - (combiner : ^State -> ^State -> ^State) + ([] vf: ^State Vector -> ^T Vector -> ^State Vector) + ([] sf : ^State -> ^T -> ^State) + ([] combiner : ^State -> ^State -> ^State) (acc : ^State) (array: ^T[]) : ^State = @@ -198,9 +198,9 @@ let inline fold /// Initial value to accumulate from /// Source array let inline foldBack - (vf: ^State Vector -> ^T Vector -> ^State Vector) - (sf : ^State -> ^T -> ^State) - (combiner : ^State -> ^State -> ^State) + ([] vf: ^State Vector -> ^T Vector -> ^State Vector) + ([] sf : ^State -> ^T -> ^State) + ([] combiner : ^State -> ^State -> ^State) (array: ^T[]) (acc : ^State) : ^State = @@ -236,9 +236,9 @@ let inline foldBack /// Initial value to accumulate from /// Source array let inline fold2 - (vf : ^State Vector -> ^T Vector -> ^U Vector -> ^State Vector) - (sf : ^State -> ^T -> ^U -> ^State) - (combiner : ^State -> ^State -> ^State) + ([] vf : ^State Vector -> ^T Vector -> ^U Vector -> ^State Vector) + ([] sf : ^State -> ^T -> ^U -> ^State) + ([] combiner : ^State -> ^State -> ^State) (acc : ^State) (array1: ^T[]) (array2: ^U[]) : ^State = @@ -282,9 +282,9 @@ let inline fold2 /// Initial value to accumulate from /// Source array let inline foldBack2 - (vf : ^State Vector -> ^T Vector -> ^U Vector -> ^State Vector) - (sf : ^State -> ^T -> ^U -> ^State) - (combiner : ^State -> ^State -> ^State) + ([] vf : ^State Vector -> ^T Vector -> ^U Vector -> ^State Vector) + ([] sf : ^State -> ^T -> ^U -> ^State) + ([] combiner : ^State -> ^State -> ^State) (array1: ^T[]) (array2: ^U[]) (acc : ^State) : ^State = @@ -324,9 +324,9 @@ let inline foldBack2 /// Function to combine the Vector elements at the end /// Source array let inline reduce - (vf: ^State Vector -> ^T Vector -> ^State Vector) - (sf: ^State -> ^T -> ^State ) - (combiner : ^State -> ^State -> ^State) + ([] vf: ^State Vector -> ^T Vector -> ^State Vector) + ([] sf: ^State -> ^T -> ^State ) + ([] combiner : ^State -> ^State -> ^State) (array: ^T[]) : ^State = fold vf sf combiner Unchecked.defaultof< ^State> array @@ -338,9 +338,9 @@ let inline reduce /// Function to combine the Vector elements at the end /// Source array let inline reduceBack - (vf: ^State Vector -> ^T Vector -> ^State Vector) - (sf: ^State -> ^T -> ^State ) - (combiner : ^State -> ^State -> ^State) + ([] vf: ^State Vector -> ^T Vector -> ^State Vector) + ([] sf: ^State -> ^T -> ^State ) + ([] combiner : ^State -> ^State -> ^State) (array: ^T[]) : ^State = foldBack vf sf combiner array Unchecked.defaultof< ^State> @@ -452,7 +452,7 @@ let inline clear (array : ^T[]) (index : int) (length : int) : unit = /// /// How large to make the array /// A function that accepts every Nth index and returns a Vector to be copied into the array -let inline init (count :int) (vf : int -> Vector< ^T>) (sf : int -> ^T) = +let inline init (count :int) ([] vf : int -> Vector< ^T>) ([] sf : int -> ^T) = if count < 0 then invalidArg "count" "The input must be non-negative." @@ -505,8 +505,8 @@ let inline sum (array:^T[]) : ^T = /// /// let inline sumBy - (vf: Vector< ^T> -> Vector< ^U>) - (sf : ^T -> ^U) + ([] vf: Vector< ^T> -> Vector< ^U>) + ([] sf : ^T -> ^U) (array:^T[]) : ^U = checkNonNull array @@ -546,7 +546,7 @@ let inline average (array:^T[]) : ^T = /// /// let inline averageBy - (vf: Vector< ^T> -> Vector< ^U>) (sf: ^T -> ^U) (array:^T[]) : ^U = + ([] vf: Vector< ^T> -> Vector< ^U>) ([] sf: ^T -> ^U) (array:^T[]) : ^U = let sum = sumBy vf sf array LanguagePrimitives.DivideByInt< ^U> sum array.Length @@ -560,7 +560,7 @@ let inline averageBy /// A function to handle the leftover scalar elements if array is not divisible by Vector.count /// The source array let inline map - (vf : ^T Vector -> ^U Vector) (sf : ^T -> ^U) (array : ^T[]) : ^U[] = + ([] vf : ^T Vector -> ^U Vector) ([] sf : ^T -> ^U) (array : ^T[]) : ^U[] = checkNonNull array let count = Vector< ^T>.Count @@ -588,8 +588,8 @@ let inline map /// returned vector do not have to be the same type but must be the same width /// The source array let inline map2 - (vf : ^T Vector -> ^U Vector -> ^V Vector) - (sf : ^T -> ^U -> ^V) + ([] vf : ^T Vector -> ^U Vector -> ^V Vector) + ([] sf : ^T -> ^U -> ^V) (array1 : ^T[]) (array2 :^U[]) : ^V[] = @@ -627,8 +627,8 @@ let inline map2 let inline map3 - (vf : ^T Vector -> ^U Vector -> ^V Vector -> ^W Vector) - (sf : ^T -> ^U -> ^V -> ^W) + ([] vf : ^T Vector -> ^U Vector -> ^V Vector -> ^W Vector) + ([] sf : ^T -> ^U -> ^V -> ^W) (array1 : ^T[]) (array2 :^U[]) (array3 :^V[]): ^W[] = checkNonNull array1 @@ -664,8 +664,8 @@ let inline map3 /// The source array let inline mapi2 - (vf : int -> ^T Vector -> ^U Vector -> ^V Vector) - (sf : int -> ^T -> ^U -> ^V) + ([] vf : int -> ^T Vector -> ^U Vector -> ^V Vector) + ([] sf : int -> ^T -> ^U -> ^V) (array1 : ^T[]) (array2 :^U[]) : ^V[] = checkNonNull array1 @@ -699,8 +699,8 @@ let inline mapi2 /// does not have to be the same type but must be the same width /// The source array let inline mapi - (vf : int -> ^T Vector -> ^U Vector) - (sf: int -> ^T -> ^U) + ([] vf : int -> ^T Vector -> ^U Vector) + ([] sf: int -> ^T -> ^U) (array : ^T[]) : ^U[] = checkNonNull array @@ -728,8 +728,8 @@ let inline mapi /// Accepts a Vector /// let inline iter - (vf : Vector< ^T> -> unit) - (sf : ^T -> unit) + ([] vf : Vector< ^T> -> unit) + ([] sf : ^T -> unit) (array : ^T[]) : unit = checkNonNull array @@ -754,8 +754,8 @@ let inline iter /// Accepts two Vectors /// let inline iter2 - (vf : Vector< ^T> -> Vector< ^U> -> unit) - (sf : ^T -> ^U -> unit) + ([] vf : Vector< ^T> -> Vector< ^U> -> unit) + ([] sf : ^T -> ^U -> unit) (array1: ^T[]) (array2: ^U[]) : unit = checkNonNull array1 @@ -785,8 +785,8 @@ let inline iter2 /// Accepts the current index and associated Vector /// let inline iteri - (vf : int -> Vector< ^T> -> unit) - (sf : int -> ^T -> unit) + ([] vf : int -> Vector< ^T> -> unit) + ([] sf : int -> ^T -> unit) (array : ^T[]) : unit = checkNonNull array @@ -812,8 +812,8 @@ let inline iteri /// Accepts two Vectors /// let inline iteri2 - (vf : int -> Vector< ^T> -> Vector< ^U> -> unit) - (sf : int -> ^T -> ^U -> unit) + ([] vf : int -> Vector< ^T> -> Vector< ^U> -> unit) + ([] sf : int -> ^T -> ^U -> unit) (array1: ^T[]) (array2: ^U[]) : unit = checkNonNull array1 @@ -844,8 +844,8 @@ let inline iteri2 /// let inline mapInPlace - ( vf : ^T Vector -> ^T Vector) - ( sf : ^T -> ^T ) + ([] vf : ^T Vector -> ^T Vector) + ([] sf : ^T -> ^T ) (array: ^T[]) : unit = checkNonNull array @@ -870,7 +870,7 @@ let inline mapInPlace /// Takes a 'T and returns an option /// let inline pick - (vf : ^T Vector -> ^U Option) (sf: ^T -> ^U Option) (array: ^T[]) : ^U = + ([] vf : ^T Vector -> ^U Option) ([] sf: ^T -> ^U Option) (array: ^T[]) : ^U = checkNonNull array let count = Vector< ^T>.Count @@ -906,7 +906,7 @@ let inline pick /// Takes a 'T and returns an option /// let inline tryPick - (vf : ^T Vector -> ^U Option) (sf: ^T -> ^U Option) (array: ^T[]) : ^U Option = + ([] vf : ^T Vector -> ^U Option) ([] sf: ^T -> ^U Option) (array: ^T[]) : ^U Option = checkNonNull array @@ -937,7 +937,7 @@ let inline tryPick /// Takes a 'T and returns true or false /// let inline findIndex - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : int = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : int = checkNonNull array @@ -973,7 +973,7 @@ let inline findIndex /// Takes a 'T and returns true or false /// let inline find - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : ^T = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : ^T = array.[findIndex vf sf array] @@ -987,7 +987,7 @@ let inline find /// Takes a 'T and returns true or false /// let inline findIndexBack - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : int = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : int = checkNonNull array @@ -1024,7 +1024,7 @@ let inline findIndexBack /// Takes a 'T and returns true or false /// let inline findBack - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : ^T = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : ^T = array.[findIndexBack vf sf array] @@ -1039,7 +1039,7 @@ let inline findBack /// Takes a 'T and returns true or false /// let inline tryFindIndex - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : int Option = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : int Option = checkNonNull array @@ -1077,7 +1077,7 @@ let inline tryFindIndex /// Takes a 'T and returns true or false /// let inline tryFind - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : ^T Option = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : ^T Option = match tryFindIndex vf sf array with | Some i -> Some array.[i] @@ -1093,7 +1093,7 @@ let inline tryFind /// Takes a 'T and returns true or false /// let inline tryFindIndexBack - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : int Option = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : int Option = checkNonNull array @@ -1131,7 +1131,7 @@ let inline tryFindIndexBack /// Takes a 'T and returns true or false /// let inline tryFindBack - (vf : ^T Vector -> bool) (sf: ^T -> bool) (array: ^T[]) : ^T Option = + ([] vf : ^T Vector -> bool) ([] sf: ^T -> bool) (array: ^T[]) : ^T Option = match tryFindIndexBack vf sf array with | Some i -> Some array.[i] @@ -1143,8 +1143,8 @@ let inline tryFindBack /// Takes a Vector and returns true or false to indicate existence /// let inline exists - (vf : ^T Vector -> bool) - (sf : ^T -> bool) + ([] vf : ^T Vector -> bool) + ([] sf : ^T -> bool) (array: ^T[]) : bool = checkNonNull array @@ -1173,8 +1173,8 @@ let inline exists /// Takes a Vector and returns true or false /// let inline forall - (vf : ^T Vector -> bool) - (sf : ^T -> bool) + ([] vf : ^T Vector -> bool) + ([] sf : ^T -> bool) (array: ^T[]) : bool = checkNonNull array @@ -1203,8 +1203,8 @@ let inline forall /// Takes two Vectors and returns true or false to indicate existence /// let inline exists2 - (vf : ^T Vector -> ^U Vector -> bool) - (sf : ^T -> ^U -> bool) + ([] vf : ^T Vector -> ^U Vector -> bool) + ([] sf : ^T -> ^U -> bool) (array1: ^T[]) (array2: ^U[]) : bool = checkNonNull array1 @@ -1236,8 +1236,8 @@ let inline exists2 /// Takes two Vectors and returns true or false to indicate existence /// let inline forall2 - (vf : ^T Vector -> ^U Vector -> bool) - (sf : ^T -> ^U -> bool) + ([] vf : ^T Vector -> ^U Vector -> bool) + ([] sf : ^T -> ^U -> bool) (array1: ^T[]) (array2: ^U[]) : bool = @@ -1329,8 +1329,8 @@ let inline max (array :^T[]) : ^T = /// /// let inline maxBy - (vf: Vector< ^T> -> Vector< ^T>) - (sf: ^T -> ^T) + ([] vf: Vector< ^T> -> Vector< ^T>) + ([] sf: ^T -> ^T) (array :^T[]) : ^T = checkNonNull array @@ -1379,8 +1379,8 @@ let inline maxBy /// /// let inline minBy - (vf: Vector< ^T> -> Vector< ^T>) - (sf: ^T -> ^T) + ([] vf: Vector< ^T> -> Vector< ^T>) + ([] sf: ^T -> ^T) (array :^T[]) : ^T = checkNonNull array @@ -1461,8 +1461,8 @@ let inline min (array :^T[]) : ^T = /// compares Vector chunks of each array /// /// -let inline compareWith (vf : Vector< ^T> -> Vector< ^U> -> int) - (sf : ^T -> ^U -> int) +let inline compareWith ([] vf : Vector< ^T> -> Vector< ^U> -> int) + ([] sf : ^T -> ^U -> int) (array1: ^T[]) (array2: ^U[]) = diff --git a/src/SIMDArray/SIMDArray.fsproj b/src/SIMDArray/SIMDArray.fsproj index e61df9a..3fb6641 100644 --- a/src/SIMDArray/SIMDArray.fsproj +++ b/src/SIMDArray/SIMDArray.fsproj @@ -10,6 +10,9 @@ aed427e4-ce8c-47fc-8918-2bac5d4d3d35 5 + + + diff --git a/src/SIMDArray/SIMDArrayParrallel.fs b/src/SIMDArray/SIMDArrayParrallel.fs index 8e3f212..b697eab 100644 --- a/src/SIMDArray/SIMDArrayParrallel.fs +++ b/src/SIMDArray/SIMDArrayParrallel.fs @@ -11,7 +11,7 @@ open System.Numerics /// /// Accepts a Vector /// -let inline iter vf sf (array : ^T[]) = +let inline iter ([] vf: Vector< ^T> -> unit) ([] sf: ^T -> unit) (array : ^T[]) = checkNonNull array let count = Vector< ^T>.Count let len = array.Length @@ -28,7 +28,7 @@ let inline iter vf sf (array : ^T[]) = /// /// Accepts the current index and associated Vector /// -let inline iteri vf sf (array : ^T[]) = +let inline iteri ([] vf: int -> Vector< ^T> -> unit) ([] sf: int -> ^T -> unit) (array : ^T[]) = checkNonNull array let count = Vector< ^T>.Count let len = array.Length @@ -48,7 +48,7 @@ let inline iteri vf sf (array : ^T[]) = /// A function to handle the leftover scalar elements if array is not divisible by Vector.count /// The source array let inline map - (vf : ^T Vector -> ^U Vector) (sf : ^T -> ^U) (array : ^T[]) : ^U[] = + ([] vf : ^T Vector -> ^U Vector) ([] sf : ^T -> ^U) (array : ^T[]) : ^U[] = checkNonNull array let count = Vector< ^T>.Count @@ -75,7 +75,7 @@ let inline map /// does not have to be the same type but must be the same width /// The source array let inline mapi - (vf :int -> ^T Vector -> ^U Vector) (sf : int -> ^T -> ^U) (array : ^T[]) : ^U[] = + ([] vf :int -> ^T Vector -> ^U Vector) ([] sf : int -> ^T -> ^U) (array : ^T[]) : ^U[] = checkNonNull array let count = Vector< ^T>.Count @@ -106,10 +106,10 @@ let inline mapi /// Initial value to accumulate from /// Source array let inline fold - (vf: ^State Vector -> ^T Vector -> ^State Vector) - (sf : ^State -> ^T -> ^State) - (vcombiner : ^State Vector-> ^State Vector-> ^State Vector) - (scombiner : ^State -> ^State -> ^State) + ([] vf: ^State Vector -> ^T Vector -> ^State Vector) + ([] sf : ^State -> ^T -> ^State) + ([] vcombiner : ^State Vector-> ^State Vector-> ^State Vector) + ([] scombiner : ^State -> ^State -> ^State) (acc : ^State) (array: ^T[]) : ^State = @@ -170,8 +170,8 @@ let inline sum (array:^T[]) : ^T = /// /// let inline sumBy - (vf: Vector< ^T> -> Vector< ^U>) - (sf : ^T -> ^U) + ([] vf: Vector< ^T> -> Vector< ^U>) + ([] sf : ^T -> ^U) (array:^T[]) : ^U = checkNonNull array @@ -211,7 +211,7 @@ let inline average (array:^T[]) : ^T = /// /// let inline averageBy - (vf: Vector< ^T> -> Vector< ^U>) (sf: ^T -> ^U) (array:^T[]) : ^U = + ([] vf: Vector< ^T> -> Vector< ^U>) ([] sf: ^T -> ^U) (array:^T[]) : ^U = let sum = sumBy vf sf array LanguagePrimitives.DivideByInt< ^U> sum array.Length diff --git a/src/SIMDArray/SIMDArrayUtils.fs b/src/SIMDArray/SIMDArrayUtils.fs index 20967ad..86e64bf 100644 --- a/src/SIMDArray/SIMDArrayUtils.fs +++ b/src/SIMDArray/SIMDArrayUtils.fs @@ -19,13 +19,13 @@ let inline checkNonNull arg = open System.Threading.Tasks open System -let inline private applyTask fromInc toExc stride f = +let inline private applyTask fromInc toExc stride ([] f: ^a -> unit) = let mutable i = fromInc while i < toExc do f i i <- i + stride -let inline private applyTaskAggregate fromInc toExc stride acc f : ^T = +let inline private applyTaskAggregate fromInc toExc stride acc ([] f: ^a -> ^T -> ^T) : ^T = let mutable i = fromInc let mutable acc = acc while i < toExc do @@ -34,7 +34,7 @@ let inline private applyTaskAggregate fromInc toExc stride acc f : ^T = acc -let inline ForStride (fromInclusive : int) (toExclusive :int) (stride : int) (f : int -> unit) = +let inline ForStride (fromInclusive : int) (toExclusive :int) (stride : int) ([] f : int -> unit) = let numStrides = (toExclusive-fromInclusive)/stride if numStrides > 0 then @@ -60,7 +60,8 @@ let inline ForStride (fromInclusive : int) (toExclusive :int) (stride : int) (f Task.WaitAll(taskArray) -let inline ForStrideAggregate (fromInclusive : int) (toExclusive :int) (stride : int) (acc: ^T) (f : int -> ^T -> ^T) combiner = +let inline ForStrideAggregate (fromInclusive : int) (toExclusive :int) (stride : int) (acc: ^T) + ([] f : int -> ^T -> ^T) ([] combiner: ^T -> ^T -> ^T) = let numStrides = (toExclusive-fromInclusive)/stride if numStrides > 0 then let numTasks = Math.Min(Environment.ProcessorCount,numStrides)