Skip to content
Merged
Show file tree
Hide file tree
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
62 changes: 62 additions & 0 deletions src/xsref/reference_tolerances_other.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Generate error tolerance tables for unspecified
compiler/platform/os combinations by creating tables that are looser
than all platform specific tables for a given collection of test cases
for a particular function for a particular set of input types.."""


import argparse
import numpy as np
import polars as pl
import pyarrow as pa
import pyarrow.parquet as pq

from functools import reduce
from pathlib import Path

from xsref.tables import _get_git_info


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("table_path_root")
parser.add_argument("--factor", type=float, default=4.0)
args = parser.parse_args()
table_path_root = Path(args.table_path_root)

for inpath in table_path_root.glob("**/In_*.parquet"):
types = inpath.name.removesuffix(".parquet").replace("In_", "")
pattern = f"Err_{types}_*.parquet"
other_err_table_name = pattern.replace("*", "other")
err_tables = []
for errpath in inpath.parent.glob(pattern):
if errpath.name == other_err_table_name:
continue
err_tables.append(pl.read_parquet(errpath).to_numpy())
other_err_table = reduce(lambda x, y: np.maximum(x, y), err_tables)
factor = other_err_table.dtype.type(args.factor)
with np.errstate(over="ignore"):
other_err_table = np.maximum(
other_err_table, np.finfo(other_err_table.dtype).eps
) * factor
X = [
pa.array(other_err_table[:, i]) for i in range(other_err_table.shape[1])
]
other_err_table = pa.table(X, names=pq.read_schema(errpath).names)

metadata = pq.read_schema(inpath).metadata
metadata[b"input_checksum"] = b"NA"
metadata[b"output_checksum"] = b"NA"
metadata[b"scipy_version"] = b"NA"
metadata[b"cpp_compiler"] = b"NA"
metadata[b"cpp_compiler_version"] = b"NA"
metadata[b"architecture"] = b"NA"
metadata[b"operating_system"] = b"NA"
commit_hash, working_tree = _get_git_info()
metadata[b"xsref_commit_hash"] = commit_hash
metadata[b"working_tree_state"] = working_tree

other_err_table = other_err_table.replace_schema_metadata(metadata)
outpath = inpath.parent / other_err_table_name
pq.write_table(
other_err_table, outpath, compression="zstd", compression_level=22
)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 31 additions & 3 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
import warnings

from functools import reduce
from numpy.testing import assert_allclose
from pathlib import Path

Expand All @@ -30,7 +31,7 @@ def get_tables_paths():
"In_", "Err_"
).removesuffix(".parquet")
tol_pattern = rf"{tol_pattern}*.parquet"
tol_table_paths = list(input_table_path.glob(tol_pattern))
tol_table_paths = list(input_table_path.parent.glob(tol_pattern))
output.append((input_table_path, output_table_path, tol_table_paths))
return output

Expand Down Expand Up @@ -64,8 +65,6 @@ def test_checksums_match(
# Test that the Sha256 checksum for the input table stored in the
# output table's metadata matches the actual Sha256 checksum of the
# input table.
if output_table_path is None:
return
input_table_checksum_expected = _calculate_checksum(input_table_path)
output_metadata = pq.read_schema(output_table_path).metadata
input_table_checksum_observed = (
Expand All @@ -74,14 +73,43 @@ def test_checksums_match(
assert input_table_checksum_observed == input_table_checksum_expected

output_table_checksum_expected = _calculate_checksum(output_table_path)

for tol_table_path in tol_table_paths:
if "_other.parquet" in tol_table_path.name:
# Default tol tables not generated in the same way, so
# consistency tested separately.
continue
tol_metadata = pq.read_schema(tol_table_path).metadata
input_table_checksum_observed = (
tol_metadata[b"input_checksum"].decode("ascii")
)
output_table_checksum_observed = (
tol_metadata[b"output_checksum"].decode("ascii")
)
assert input_table_checksum_observed == input_table_checksum_expected
assert output_table_checksum_observed == output_table_checksum_expected

def test_default_tol_table(
self, input_table_path, output_table_path, tol_table_paths
):
tol_tables = []
other_tol_table = None
for tol_table_path in tol_table_paths:
if "_other.parquet" not in tol_table_path.name:
tol_tables.append(pl.read_parquet(tol_table_path).to_numpy())
else:
other_tol_table = pl.read_parquet(tol_table_path).to_numpy()
max_error = reduce(lambda x, y: np.maximum(x, y), tol_tables)
max_error = np.maximum(max_error, np.finfo(other_tol_table.dtype).eps)
# The default table should be looser than all specific tables, but not
# too loose. Need special handling for infinite tolerances.
with np.errstate(over="ignore"):
assert np.all(
((other_tol_table > max_error)
& (other_tol_table < 16 * max_error))
| (np.isinf(other_tol_table) & np.isinf(max_error))
| (np.isinf(other_tol_table) & np.isinf(16 * max_error))
)

def test_consistent_type_signatures_metadata(
self, input_table_path, output_table_path, tol_table_paths
Expand Down