Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
- cleanup
  • Loading branch information
FloraCanou committed Nov 21, 2023
1 parent 74f6fd4 commit d59ddef
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions te_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2023 Flora Canou | Version 0.26.3
# © 2020-2023 Flora Canou | Version 0.26.4
# This work is licensed under the GNU General Public License version 3.

import functools, warnings
Expand Down Expand Up @@ -155,7 +155,7 @@ def ratio2monzo (ratio, subgroup = None):
while ratio[1] % si == 0:
monzo[i] -= 1
ratio[1] /= si
if all (entry == 1 for entry in ratio):
if ratio[0] == 1 and ratio[1] == 1:
break
else:
raise ValueError ("improper subgroup. ")
Expand Down
2 changes: 1 addition & 1 deletion te_equal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2023 Flora Canou | Version 0.26.3
# © 2020-2023 Flora Canou | Version 0.26.4
# This work is licensed under the GNU General Public License version 3.

import re, warnings
Expand Down
2 changes: 1 addition & 1 deletion te_lattice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2023 Flora Canou | Version 0.26.3
# © 2020-2023 Flora Canou | Version 0.26.4
# This work is licensed under the GNU General Public License version 3.

import math, warnings
Expand Down
2 changes: 1 addition & 1 deletion te_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2023 Flora Canou | Version 0.26.3
# © 2020-2023 Flora Canou | Version 0.26.4
# This work is licensed under the GNU General Public License version 3.

import warnings
Expand Down
2 changes: 1 addition & 1 deletion te_optimizer_legacy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2023 Flora Canou | Version 0.26.3
# © 2020-2023 Flora Canou | Version 0.26.4
# This work is licensed under the GNU General Public License version 3.

import warnings
Expand Down
29 changes: 15 additions & 14 deletions te_symbolic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2023 Flora Canou | Version 0.26.2
# © 2020-2023 Flora Canou | Version 0.26.4
# This work is licensed under the GNU General Public License version 3.

import warnings
Expand All @@ -15,19 +15,20 @@ def __init__ (self, norm):

def get_weight_sym (self, subgroup):
wamount = Rational (self.wamount).limit_denominator (1e3)
if self.wtype == "tenney":
warnings.warn ("transcendental weight can be slow. Main optimizer recommended. ")
weight_vec = Matrix (subgroup).applyfunc (lambda si: log (2, si))
elif self.wtype == "wilson" or self.wtype == "benedetti":
weight_vec = Matrix (subgroup).applyfunc (lambda si: 1/si)
elif self.wtype == "equilateral":
weight_vec = Matrix.ones (len (subgroup), 1)
# elif self.wtype == "hahn24": #pending better implementation
# weight_vec = Matrix (subgroup).applyfunc (lambda si: floor (log (24, si)))
else:
warnings.warn ("weighter type not supported, using default (\"tenney\")")
self.wtype = "tenney"
return self.get_weight_sym (subgroup)
match self.wtype:
case "tenney":
warnings.warn ("transcendental weight can be slow. Main optimizer recommended. ")
weight_vec = Matrix (subgroup).applyfunc (lambda si: log (2, si))
case "wilson" | "benedetti":
weight_vec = Matrix (subgroup).applyfunc (lambda si: 1/si)
case "equilateral":
weight_vec = Matrix.ones (len (subgroup), 1)
# case "hahn24": #pending better implementation
# weight_vec = Matrix (subgroup).applyfunc (lambda si: floor (log (24, si)))
case _:
warnings.warn ("weighter type not supported, using default (\"tenney\")")
self.wtype = "tenney"
return self.get_weight_sym (subgroup)
return Matrix.diag (*weight_vec.applyfunc (lambda wi: Pow (wi, wamount)))

def get_skew_sym (self, subgroup):
Expand Down
2 changes: 1 addition & 1 deletion te_temperament_measures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2023 Flora Canou | Version 0.26.3
# © 2020-2023 Flora Canou | Version 0.26.4
# This work is licensed under the GNU General Public License version 3.

import itertools, re, warnings
Expand Down

0 comments on commit d59ddef

Please sign in to comment.