Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Propositions of test_umath_accuracy improvements #16115

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from
Draft
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
58 changes: 58 additions & 0 deletions 58 numpy/core/tests/data/generate_umath_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np
import argparse
import mpmath

parser = argparse.ArgumentParser(
description='Generate umath data. '
'Input file can only contain hex numbers in separate rows, '
'empty lines and lines starting with "#" (comments).')
parser.add_argument('-i', '--input_file', type=str, required=True,
help="Name of file with inputs used to generate test data.")
parser.add_argument('-f', '--funcname', required=True,
help="Name of mpmath function used to generate data.")
parser.add_argument('-o', '--output_file', type=str, required=True,
help="Name of output file. Should be of the form "
"umath-validation-set-<funcname>.")
parser.add_argument('--dtype', type=str, required=True,
help="dtype of data")
parser.add_argument('--ulperror', type=int, default=2)

args = parser.parse_args()


def from_hex(s, dtype):
barr = bytearray.fromhex(s[2:])
barr.reverse()
return np.frombuffer(barr, dtype=dtype)[0]


def to_hex(x):
barr = bytearray(x)
barr.reverse()
return "0x" + barr.hex()


def lines_to_process(input_file, output_file):
for line in input_file:
if not line.strip() or line[0] == '#':
output_file.write(line)
continue
if '#' in line:
line = line[:line.index('#')]

yield line.strip()


mpfunc = getattr(mpmath, args.funcname)
tested_func = getattr(np, args.funcname)
dtype = getattr(np, args.dtype[3:])
with open(args.input_file, 'r') as input_file:
with open(args.output_file, 'w') as output_file:
for i, line in enumerate(lines_to_process(input_file, output_file)):
arg = from_hex(line, dtype)
exp = dtype(mpfunc(arg))
name = args.funcname+str(i+1).zfill(3)
output_file.write(
"{} {} {} {} {} # {} -> {}\n".format(
name, args.dtype, args.ulperror, to_hex(arg),
to_hex(exp), arg, exp))
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.