Skip to content

Commit

Permalink
identified fraction and too many timecat by mini as bottle neck!
Browse files Browse the repository at this point in the history
  • Loading branch information
neo451 committed Mar 26, 2024
1 parent 6255c22 commit 5eed201
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/core/pattern.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ local bjork
bjork = require("xi.euclid").bjork
local getScale
getScale = require("xi.scales").getScale
local Fraction, tofrac, tofloat
local Fraction, tofrac
do
local _obj_0 = require("xi.fraction")
Fraction, tofrac, tofloat = _obj_0.Fraction, _obj_0.tofrac, _obj_0.tofloat
Fraction, tofrac = _obj_0.Fraction, _obj_0.tofrac
end
local Event, Span, State
do
Expand Down
2 changes: 1 addition & 1 deletion src/core/pattern.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import map, filter, string_lambda, reduce, id, flatten, totable, dump, concat, rotate, union, timeToRand, curry, type from require "xi.utils"
import bjork from require "xi.euclid"
import getScale from require "xi.scales"
import Fraction, tofrac, tofloat from require "xi.fraction"
import Fraction, tofrac from require "xi.fraction"
import Event, Span, State from require "xi.types"
import visit from require "xi.mini.visitor"
fun = require "xi.fun"
Expand Down
8 changes: 3 additions & 5 deletions src/core/pattern_factory.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
local C, cpm
do
local _obj_0 = require("xi.pattern")
C, cpm = _obj_0.C, _obj_0.cpm
end
local cpm
cpm = require("xi.pattern").cpm
local Stream
Stream = require("xi.stream").Stream
local Clock
Clock = require("xi.clock").Clock
local C = require("xi.control")
local Streams = { }
local DefaultClock = Clock()
local p
Expand Down
3 changes: 2 additions & 1 deletion src/core/pattern_factory.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import C, cpm from require "xi.pattern"
import cpm from require "xi.pattern"
import Stream from require "xi.stream"
import Clock from require "xi.clock"
C = require"xi.control"

Streams = {}
DefaultClock = Clock!
Expand Down
33 changes: 25 additions & 8 deletions src/utils/fraction.moon
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,33 @@ local *
abs = math.abs
floor = math.floor

-- decimaltofraction1 = (x, N) ->
-- N = N or 1000000
-- a, b = 0, 1
-- c, d = 1, 1
-- while b <= N and d <= N
-- mediant = (a+c)/(b+d)
-- if x == mediant
-- if b + d <= N
-- return a + c, b + d
-- elseif d > b
-- return c, d
-- else
-- return a, b
-- elseif x > mediant
-- a, b = a + c, b + d
-- else
-- c, d = a + c, b + d
--
-- if b > N
-- return c, d
-- else
-- return a, b

decimaltofraction = (x0, err) ->
err = err or 0.0000000001
local num, den
g = abs x0 -- or x0:abs()
g = abs x0
sign = x0 / g
a, b, c, d = 0, 1, 1, 0
local s
Expand All @@ -25,7 +48,7 @@ decimaltofraction = (x0, err) ->
return sign * num, den

error "Fraction: failed to find a fraction for " .. x0
0, 1
return 0, 1

gcd = (a, b) -> (b == 0) and a or gcd(b, a % b)

Expand Down Expand Up @@ -205,10 +228,4 @@ tofrac = (x) ->
else
return x

tofloat = (x) ->
if type(x) == "fraction"
return x\asFloat!
else
return x

return { :Fraction, :gcd_reduce, :tofrac, :tofloat }

0 comments on commit 5eed201

Please sign in to comment.