Skip to content

Commit

Permalink
Fix issue #33 (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
inthar-raven committed Aug 26, 2024
1 parent 704d412 commit 1c0e20c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 22 deletions.
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 65 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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<Vec<u8>>, 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
Expand All @@ -266,9 +310,11 @@ pub fn word_to_profile(query: &[usize]) -> ScaleProfile {
.iter()
.map(|x| *x as u8)
.collect::<Vec<u8>>();
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,
Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ impl<T> CountVector<T> {
}
}

pub fn countvector_to_slice(v: CountVector<usize>) -> Vec<i32> {
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.
Expand Down

0 comments on commit 1c0e20c

Please sign in to comment.