From 21169230a87ea12506decbf47f7d5a09d06580af Mon Sep 17 00:00:00 2001 From: Flora Canou Date: Mon, 22 Apr 2024 16:40:17 +0800 Subject: [PATCH] Skewed wedgie fix - Fixed wedgie computation when the norm involves nonzero skew. - Wedgie now displays integer if possible. - Clarified the "antinullspace" function. --- te_common.py | 9 ++++++++- te_temperament_measures.py | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/te_common.py b/te_common.py index 036196d..9e4a764 100644 --- a/te_common.py +++ b/te_common.py @@ -1,4 +1,4 @@ -# © 2020-2024 Flora Canou | Version 1.4.0 +# © 2020-2024 Flora Canou | Version 1.4.2 # This work is licensed under the GNU General Public License version 3. import re, functools, itertools, warnings @@ -361,10 +361,17 @@ def matrix2array (main): return np.array (main/functools.reduce (gcd, tuple (main)), dtype = int).squeeze () def nullspace (covectors): + """Row-style nullspace.""" frac_nullspace_matrix = Matrix (covectors).nullspace () return np.column_stack ([matrix2array (entry) for entry in frac_nullspace_matrix]) def antinullspace (vectors): + """ + Column-style nullspace. + *Antinullspace* is a term that's supposed to be eliminated. + It's antitranspose--nullspace--antitranspose + where *antitranspose* refers to flip and transpose. + """ frac_antinullspace_matrix = Matrix (np.flip (vectors.T)).nullspace () return np.flip (np.row_stack ([matrix2array (entry) for entry in frac_antinullspace_matrix])) diff --git a/te_temperament_measures.py b/te_temperament_measures.py index 858d7fe..dfe2638 100644 --- a/te_temperament_measures.py +++ b/te_temperament_measures.py @@ -1,4 +1,4 @@ -# © 2020-2024 Flora Canou | Version 1.3.0 +# © 2020-2024 Flora Canou | Version 1.4.2 # This work is licensed under the GNU General Public License version 3. import itertools, re, warnings @@ -109,14 +109,21 @@ def tune (self, optimizer = "main", norm = te.Norm (), inharmonic = False, analyse = tune def wedgie (self, norm = te.Norm (wtype = "equilateral"), show = True): - combinations = itertools.combinations (range (self.mapping.shape[1]), self.mapping.shape[0]) - wedgie = np.array ([ - linalg.det (norm.tuning_x (self.mapping, self.subgroup)[:, entry]) for entry in combinations - ]) + combinations = itertools.combinations ( + range (self.mapping.shape[1] + (1 if norm.skew else 0)), self.mapping.shape[0]) + wedgie = np.array ( + [linalg.det (norm.tuning_x (self.mapping, self.subgroup)[:, entry]) for entry in combinations]) wedgie *= np.copysign (1, wedgie[0]) + + # convert to integer type if possible + wedgie_int = wedgie.astype (int) + if all (wedgie == wedgie_int): + wedgie = wedgie_int + if show: self.__show_header () print (f"Wedgie: {wedgie}", sep = "\n") + return wedgie def complexity (self, ntype = "breed", norm = te.Norm (), inharmonic = False): @@ -157,7 +164,7 @@ def __complexity (self, ntype, norm, inharmonic): norm.tuning_x (mapping, subgroup) @ norm.tuning_x (mapping, subgroup).T )) / index - # complexity = linalg.norm (self.wedgie (norm = norm, show = False)) #same + # complexity = linalg.norm (self.wedgie (norm = norm)) #same if ntype == "breed": #Graham Breed's RMS (default) complexity *= 1/np.sqrt (mapping.shape[1]**mapping.shape[0]) elif ntype == "smith": #Gene Ward Smith's RMS