From ec4968ab3a8431498138cfafb62d7cc5bf03d3c1 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Thu, 27 Feb 2025 10:58:32 -0300 Subject: [PATCH] fix after merge and remove function overload Signed-off-by: martinvuyk --- .../src/collections/string/string_slice.mojo | 4 +- stdlib/src/memory/span.mojo | 42 +------------------ 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/stdlib/src/collections/string/string_slice.mojo b/stdlib/src/collections/string/string_slice.mojo index 2923f60180..cf2592fe7e 100644 --- a/stdlib/src/collections/string/string_slice.mojo +++ b/stdlib/src/collections/string/string_slice.mojo @@ -2197,6 +2197,8 @@ fn _memmem[ @always_inline +# FIXME(#2535): remove capturing once function effects can be parametrized +@parameter fn _is_utf8_continuation_byte[ w: Int ](vec: SIMD[DType.uint8, w]) -> SIMD[DType.bool, w]: @@ -2205,7 +2207,7 @@ fn _is_utf8_continuation_byte[ @always_inline fn _count_utf8_continuation_bytes(span: Span[Byte]) -> Int: - return span.count[func=_is_continuation_byte]() + return span.count[func=_is_utf8_continuation_byte]() @always_inline diff --git a/stdlib/src/memory/span.mojo b/stdlib/src/memory/span.mojo index 8cacaa47cc..a162270faf 100644 --- a/stdlib/src/memory/span.mojo +++ b/stdlib/src/memory/span.mojo @@ -510,47 +510,7 @@ struct Span[ ) ) - fn count[ - D: DType, //, func: fn[w: Int] (SIMD[D, w]) -> SIMD[DType.bool, w] - ](self: Span[Scalar[D]]) -> UInt: - """Count the amount of times the function returns `True`. - - Parameters: - D: The DType. - func: The function to evaluate. - - Returns: - The amount of times the function returns `True`. - """ - - alias widths = (256, 128, 64, 32, 16, 8) - var ptr = self.unsafe_ptr() - var length = len(self) - var amnt = UInt(0) - var processed = 0 - - @parameter - for i in range(len(widths)): - alias w = widths[i] - - @parameter - if simdwidthof[D]() >= w: - for _ in range((length - processed) // w): - var vec = (ptr + processed).load[width=w]() - - @parameter - if w >= 256: - amnt += Int(func(vec).cast[DType.uint16]().reduce_add()) - else: - amnt += Int(func(vec).cast[DType.uint8]().reduce_add()) - processed += w - - for i in range(length - processed): - amnt += Int(func(ptr[processed + i])) - - return amnt - - # FIXME(#2535): delete once function effects can be parametrized + # FIXME(#2535): parametrize capturing once function effects can be parametrized fn count[ D: DType, //, func: fn[w: Int] (SIMD[D, w]) capturing -> SIMD[DType.bool, w],