Skip to content

Commit

Permalink
Make new stack size arithmetic match the old one exactly.
Browse files Browse the repository at this point in the history
  • Loading branch information
duvenaud committed Jul 2, 2023
1 parent 17d4bcc commit 41be2ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 0 additions & 5 deletions lib/fft.dx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ def odd_sized_palindrome(mid:a, seq:n=>a) -> ((n `Either` () `Either` n)=>a) giv
Right () -> mid
Right i -> seq[i]

def nextpow2(x:Nat) -> Nat =
case is_power_of_2 x of
True -> natlog2 x
False -> 1 + natlog2 x

'## Inner FFT functions

data FTDirection =
Expand Down
7 changes: 6 additions & 1 deletion lib/prelude.dx
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,11 @@ def natlog2(x:Nat) -> Nat =
False
unsafe_nat_diff(tmp, 1) -- TODO: something less horrible

def nextpow2(x:Nat) -> Nat =
case is_power_of_2 x of
True -> natlog2 x
False -> 1 + natlog2 x

def general_integer_power(
times:(a,a)->a,
one:a, base:a,
Expand Down Expand Up @@ -2477,7 +2482,7 @@ struct Stack(h:Heap, a|Data) =

def ensure_size_at_least(req_size:Nat) -> {State h} () =
if req_size > self.buf_size() then
new_buf_size = intpow2 (1 + natlog2 req_size)
new_buf_size = intpow2 $ nextpow2 req_size
buf = self.unsafe_get_buffer()
logical_size = self.size()
cur_data = get $ unsafe_coerce(to=Ref(h, Fin logical_size => a), buf)
Expand Down

0 comments on commit 41be2ec

Please sign in to comment.