Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster Matchifile Parsing and Checks. #307

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions partitura/io/importmatch.py
manoskary marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
from typing import Union, Tuple, Optional, Callable, List
import warnings

from functools import partial
import numpy as np

from partitura import score
Expand Down Expand Up @@ -197,21 +197,21 @@ def load_matchfile(

parsed_lines = list()
# Functionality to remove duplicate lines
for i, line in enumerate(raw_lines):
if line in raw_lines[i + 1 :] and line != "":
warnings.warn(f"Duplicate line found in matchfile: {line}")
continue
parsed_line = parse_matchline(line, from_matchline_methods, version)
if parsed_line is None:
warnings.warn(f"Could not empty parse line: {line} ")
continue
parsed_lines.append(parsed_line)

len_raw_lines = len(raw_lines)
np_lines = np.array(raw_lines, dtype=str)
# Remove empty lines
np_lines = np_lines[np_lines != ""]
# Remove duplicate lines
_, idx = np.unique(np_lines, return_index=True)
manoskary marked this conversation as resolved.
Show resolved Hide resolved
np_lines = np_lines[np.sort(idx)]
# Parse lines
f = partial(parse_matchline, version=version, from_matchline_methods=from_matchline_methods)
f_vec = np.vectorize(f)
parsed_lines = f_vec(np_lines).tolist()
# Create MatchFile instance
mf = MatchFile(lines=parsed_lines)

# Validate match for duplicate snote_ids or pnote_ids
validate_match_ids(mf)

return mf


Expand Down