From d59ddef195e9b22867e77e7903436767f81d7b3e Mon Sep 17 00:00:00 2001 From: Flora Canou Date: Tue, 21 Nov 2023 12:08:28 +0800 Subject: [PATCH] Refactoring - cleanup --- te_common.py | 4 ++-- te_equal.py | 2 +- te_lattice.py | 2 +- te_optimizer.py | 2 +- te_optimizer_legacy.py | 2 +- te_symbolic.py | 29 +++++++++++++++-------------- te_temperament_measures.py | 2 +- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/te_common.py b/te_common.py index d62b3b3..ea5cae2 100644 --- a/te_common.py +++ b/te_common.py @@ -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 @@ -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. ") diff --git a/te_equal.py b/te_equal.py index 1af8903..e2fdd3b 100644 --- a/te_equal.py +++ b/te_equal.py @@ -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 diff --git a/te_lattice.py b/te_lattice.py index a681dc0..38d3016 100644 --- a/te_lattice.py +++ b/te_lattice.py @@ -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 diff --git a/te_optimizer.py b/te_optimizer.py index e40ca4b..35c48cf 100644 --- a/te_optimizer.py +++ b/te_optimizer.py @@ -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 diff --git a/te_optimizer_legacy.py b/te_optimizer_legacy.py index d3a54a2..c0a4ae9 100644 --- a/te_optimizer_legacy.py +++ b/te_optimizer_legacy.py @@ -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 diff --git a/te_symbolic.py b/te_symbolic.py index dcf4848..00b19c7 100644 --- a/te_symbolic.py +++ b/te_symbolic.py @@ -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 @@ -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): diff --git a/te_temperament_measures.py b/te_temperament_measures.py index 349b13a..61bd0b2 100644 --- a/te_temperament_measures.py +++ b/te_temperament_measures.py @@ -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