ModularM
Modular2y ago
8 replies
tkeitt

Traits with compile-time SIMD size

I can't seem to fulfill a trait that can return different length SIMDs
trait PRNGEngine(Movable):
    @staticmethod
    fn ndim() -> Int:
        """SIMD size."""
        pass

    fn next_scalar(inout self) -> UInt64:
        """Get only a single value from the generator."""
        pass

    fn next(inout self) -> SIMD[DType.uint64, Self.ndim()]:
        """Get Self.ndim() values from the generator."""
        pass


struct DummyEngine[n: Int](PRNGEngine):
    @staticmethod
    fn ndim() -> Int:
        """SIMD size."""
        return 2

    fn next_scalar(inout self) -> UInt64:
        """Get only a single value from the generator."""
        return 42

    fn next(inout self) -> SIMD[DType.uint64, Self.ndim()]:
        """Get Self.ndim() values from the generator."""
        var res: SIMD[DType.uint64, Self.ndim()] = 42
        return res

I can fall back to next_scalar. I'd like to be able to use
next
e.g. to generate a set of normal deviates, etc.
Was this page helpful?