-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#11 wip reading multiple matrices from same file
- Loading branch information
Showing
2 changed files
with
34 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,45 @@ | ||
from itertools import pairwise | ||
import os | ||
from pathlib import Path | ||
import numpy as np | ||
import pytest | ||
|
||
@pytest.mark.parametrize("filename", ["A", "Ciap", "pVp"]) | ||
def test_output(filename): | ||
# convert from script location to where the output files should be located | ||
# Convert from the script location to where the output files should be located. | ||
script_dir = Path(os.path.abspath(__file__)).parent | ||
example_output_dir = script_dir.parent / "build" / "examples" / "geom_1" | ||
|
||
assert example_output_dir.exists() | ||
|
||
with open(example_output_dir / filename) as output, open( | ||
example_output_dir / f"{filename}_ref" | ||
) as reference_output: | ||
output = list(output) | ||
for i, line in enumerate(reference_output): | ||
if line.endswith(":"): | ||
continue | ||
assert np.fromstring(output[i], sep=" ") == pytest.approx( | ||
np.fromstring(line, sep=" "), rel=1e-6, abs=1e-6 | ||
) | ||
# matrix_boundaries = [line for line in file if line.endswith(':')] + [-1] | ||
# for idx in range(len(matrix_boundaries)-1): | ||
|
||
# output = np.loadtxt(example_output_dir / filename, skiprows=matrix_boundaries[idx]) | ||
# reference_output = np.loadtxt(example_output_dir / f"{filename}_ref", skiprows=matrix_boundaries[idx]+1, max_rows=matrix_boundaries[idx+1]-matrix_boundaries[idx]) | ||
# assert output.shape == reference_output.shape | ||
# assert output == pytest.approx(reference_output, rel=1e-6, abs=1e-6) | ||
with open(example_output_dir / f"{filename}_ref") as reference_output: | ||
# output = list(output) | ||
# for i, line in enumerate(reference_output): | ||
# if line.endswith(":"): | ||
# continue | ||
# assert np.fromstring(output[i], sep=" ") == pytest.approx( | ||
# np.fromstring(line, sep=" "), rel=1e-6, abs=1e-6 | ||
# ) | ||
matrix_boundaries = [ | ||
line_num | ||
for line_num, line in enumerate(reference_output) | ||
# Get header lines for matrices and blank last line. | ||
if line.strip().endswith(":") | ||
] + [len(reference_output)] # JOSH - RESUME HERE | ||
print(f"{matrix_boundaries = }") | ||
for header_row, end_row in pairwise(matrix_boundaries): | ||
start_row = header_row + 1 | ||
num_rows = end_row - start_row | ||
output = np.loadtxt( | ||
example_output_dir / filename, | ||
skiprows=start_row, | ||
max_rows=num_rows, | ||
) | ||
reference_output = np.loadtxt( | ||
example_output_dir / f"{filename}_ref", | ||
skiprows=start_row, | ||
max_rows=num_rows, | ||
) | ||
assert output.shape == reference_output.shape | ||
assert output + 1 == pytest.approx(reference_output, rel=1e-6, abs=1e-6) | ||
assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters