diff --git a/package-lock.json b/package-lock.json index a172d35..33793ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,11 +4,12 @@ "requires": true, "packages": { "": { + "name": "ternary", "devDependencies": { "@wasm-tool/wasm-pack-plugin": "1.7.0", "html-webpack-plugin": "^5.6.0", "prettier": "3.3.3", - "webpack": "^5.93.0", + "webpack": "^5.94.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^5.0.4" } @@ -251,34 +252,11 @@ "@types/node": "*" } }, - "node_modules/@types/eslint": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.0.tgz", - "integrity": "sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, - "node_modules/@types/eslint-scope": { - "version": "3.7.7", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz", - "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/eslint": "*", - "@types/estree": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", - "dev": true, - "license": "MIT" + "dev": true }, "node_modules/@types/express": { "version": "4.17.21", @@ -2845,9 +2823,9 @@ } }, "node_modules/micromatch": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", - "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "license": "MIT", "dependencies": { @@ -4428,13 +4406,11 @@ } }, "node_modules/webpack": { - "version": "5.93.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.93.0.tgz", - "integrity": "sha512-Y0m5oEY1LRuwly578VqluorkXbvXKh7U3rLoQCEO04M97ScRr44afGVkI0FQFsXzysk5OgFAxjZAb9rsGQVihA==", + "version": "5.94.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.94.0.tgz", + "integrity": "sha512-KcsGn50VT+06JH/iunZJedYGUJS5FGjow8wb9c0v5n1Om8O1g4L6LjtfxwlXIATopoQu+vOXXa7gYisWxCoPyg==", "dev": true, - "license": "MIT", "dependencies": { - "@types/eslint-scope": "^3.7.3", "@types/estree": "^1.0.5", "@webassemblyjs/ast": "^1.12.1", "@webassemblyjs/wasm-edit": "^1.12.1", @@ -4443,7 +4419,7 @@ "acorn-import-attributes": "^1.9.5", "browserslist": "^4.21.10", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.17.0", + "enhanced-resolve": "^5.17.1", "es-module-lexer": "^1.2.1", "eslint-scope": "5.1.1", "events": "^3.2.0", diff --git a/package.json b/package.json index 5dd1109..16639f2 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@wasm-tool/wasm-pack-plugin": "1.7.0", "html-webpack-plugin": "^5.6.0", "prettier": "3.3.3", - "webpack": "^5.93.0", + "webpack": "^5.94.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^5.0.4" } diff --git a/src/lib.rs b/src/lib.rs index d029836..d655e86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,8 @@ pub mod words; use itertools::Itertools; use wasm_bindgen::prelude::*; +use words::countvector_to_slice; +use words::dyad_on_degree; use words::Letter; #[wasm_bindgen] @@ -229,28 +231,70 @@ fn guide_frame_to_result(structure: &GuideFrame) -> GuideResult { fn get_unimodular_basis( structures: &[GuideFrame], + scale: &[usize], step_sig: &[u8], ) -> Option<(Vec>, GuideResult)> { + /* + if (structure["multiplicity"] === 1) { + if (structure["polyoffset"].length === 1) { + // Check for two unequal step vectors. + outer: for (let i = 0; i < gs.length; ++i) { + for (let j = i; j < gs.length; ++j) { + if (!isEqual(gs[i], gs[j])) { + g = [...Object.values(gs[i])]; + h = [...Object.values(gs[j])]; + break outer; + } + } + } + } else { + g = [...Object.values(structure["aggregate"])]; + h = [...Object.values(structure["polyoffset"][1])]; + } + } else { + g = [...Object.values(structure["aggregate"])]; + h = [...Object.values(dyadOnDegree( + scaleWord, + scaleWord.length / structure["multiplicity"], + scaleWord.length / structure["multiplicity"], + ))]; + } + */ for structure in structures { - let structure = guide_frame_to_result(structure); - let gs = structure.clone().gs.clone(); - for i in 0..gs.clone().len() { - for j in i..gs.clone().len() { - if det3(step_sig, &gs.clone()[i], &gs.clone()[j]).abs() == 1 { - return Some(( - vec![gs.clone()[i].clone(), gs.clone()[j].clone()], - structure, - )); + if structure.multiplicity == 1 { + let structure = guide_frame_to_result(structure); + let gs = structure.gs.clone(); + for i in 0..gs.clone().len() { + for j in i..gs.clone().len() { + if det3(step_sig, &gs[i], &gs[j]).abs() == 1 { + return Some((vec![gs[i].clone(), gs[j].clone()], structure)); + } } } - } - let polyoffset = structure.clone().polyoffset; - for v in polyoffset { - for w in structure.clone().gs { - if det3(step_sig, &v, &w).abs() == 1 { - return Some((vec![v, w], structure)); + let polyoffset = structure.clone().polyoffset; + for v in polyoffset { + for w in structure.clone().gs { + if det3(step_sig, &v, &w).abs() == 1 { + return Some((vec![v, w], structure)); + } } } + } else { + // this branch handles diregular scales + let structure = guide_frame_to_result(structure); + let vec_for_gs_element = structure.gs[0].clone(); + let vec_for_detempered_period = countvector_to_slice(dyad_on_degree( + scale, + 0, + scale.len() / structure.clone().multiplicity as usize, + )) + .iter() + .map(|x| *x as u8) + .collect(); + return Some(( + vec![vec_for_gs_element, vec_for_detempered_period], + structure, + )); } } None @@ -266,9 +310,11 @@ pub fn word_to_profile(query: &[usize]) -> ScaleProfile { .iter() .map(|x| *x as u8) .collect::>(); - let structures = guide_frames(query); - let some_guide_frame = structures.first(); - if let Some(pair) = get_unimodular_basis(&guide_frames(query), &step_sig) { + if let Some(pair) = get_unimodular_basis( + &guide_frames(query), + &string_to_numbers(&brightest), + &step_sig, + ) { let (lattice_basis, structure) = pair; ScaleProfile { word: brightest, @@ -283,7 +329,7 @@ pub fn word_to_profile(query: &[usize]) -> ScaleProfile { ScaleProfile { word: brightest, lattice_basis: None, - structure: some_guide_frame.map(guide_frame_to_result), + structure: None, lm, ms, s0, diff --git a/src/words.rs b/src/words.rs index b3c5bff..15e960e 100644 --- a/src/words.rs +++ b/src/words.rs @@ -181,6 +181,19 @@ impl CountVector { } } +pub fn countvector_to_slice(v: CountVector) -> Vec { + if v.is_empty() { + vec![] + } else { + let max = *v.into_inner().last_key_value().unwrap().0; + let mut result = vec![0; max + 1]; + for key in v.into_inner().keys() { + result[*key] = *v.get(key).unwrap(); + } + result + } +} + /// Treating `scale` as a circular string (that is, "scale[i] == scale[i % scale.len()]"), /// take a slice of length `subword_length` from `degree`; assumes `subword_length` <= `scale`.len(). /// Reduce `degree` first.