Skip to content

Commit

Permalink
Fix other platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Jan 4, 2025
1 parent f6ee38c commit fb960dd
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions ext/RandomExt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module RandomExt

@static if Sys.isapple()

using BFloat16s
using AppleAccelerate: BNNS
using .BNNS: BNNSFilterParameters,
Expand Down Expand Up @@ -43,11 +46,20 @@ end
BNNS.bnns_rng() = RNG()
BNNS.bnns_rng(seed::Integer) = RNG(seed)

Check warning on line 47 in ext/RandomExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/RandomExt.jl#L46-L47

Added lines #L46 - L47 were not covered by tests

function _get_rng_state(rng::RNG)
stateSize = BNNSRandomGeneratorStateSize(rng.ptr)
state = Memory{UInt8}(undef, Int64(stateSize))
BNNSRandomGeneratorGetState(rng.ptr, stateSize, state)
return state
@static if isdefined(Base, :Memory) #VERSION >= v"1.11"
function _get_rng_state(rng::RNG)
stateSize = BNNSRandomGeneratorStateSize(rng.ptr)
state = Memory{UInt8}(undef, Int64(stateSize))
BNNSRandomGeneratorGetState(rng.ptr, stateSize, state)
return state

Check warning on line 54 in ext/RandomExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/RandomExt.jl#L50-L54

Added lines #L50 - L54 were not covered by tests
end
else
function _get_rng_state(rng::RNG)
stateSize = BNNSRandomGeneratorStateSize(rng.ptr)
state = Vector{UInt8}(undef, Int64(stateSize))
BNNSRandomGeneratorGetState(rng.ptr, stateSize, state)
return state

Check warning on line 61 in ext/RandomExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/RandomExt.jl#L57-L61

Added lines #L57 - L61 were not covered by tests
end
end

function Base.copy!(dest::RNG, src::RNG)
Expand Down Expand Up @@ -170,5 +182,5 @@ function BNNS.seed!(seed=Base.rand(UInt64))
Random.seed!(BNNS.default_rng(), seed)

Check warning on line 182 in ext/RandomExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/RandomExt.jl#L181-L182

Added lines #L181 - L182 were not covered by tests
end


end
end # module

0 comments on commit fb960dd

Please sign in to comment.