$66 GRAYBYTE WORDPRESS FILE MANAGER $51

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python37/lib64/python3.7/site-packages/numpy/core/tests/

HOME
Current File : /opt/alt/python37/lib64/python3.7/site-packages/numpy/core/tests//test_longdouble.py
from __future__ import division, absolute_import, print_function

import locale

import numpy as np
from numpy.testing import (
    run_module_suite, assert_, assert_equal, dec, assert_raises,
    assert_array_equal, TestCase, temppath,
)
from test_print import in_foreign_locale

LD_INFO = np.finfo(np.longdouble)
longdouble_longer_than_double = (LD_INFO.eps < np.finfo(np.double).eps)


_o = 1 + LD_INFO.eps
string_to_longdouble_inaccurate = (_o != np.longdouble(repr(_o)))
del _o


def test_scalar_extraction():
    """Confirm that extracting a value doesn't convert to python float"""
    o = 1 + LD_INFO.eps
    a = np.array([o, o, o])
    assert_equal(a[1], o)


# Conversions string -> long double

# 0.1 not exactly representable in base 2 floating point.
repr_precision = len(repr(np.longdouble(0.1)))
# +2 from macro block starting around line 842 in scalartypes.c.src.
@dec.skipif(LD_INFO.precision + 2 >= repr_precision,
            "repr precision not enough to show eps")
def test_repr_roundtrip():
    # We will only see eps in repr if within printing precision.
    o = 1 + LD_INFO.eps
    assert_equal(np.longdouble(repr(o)), o, "repr was %s" % repr(o))


def test_unicode():
    np.longdouble(u"1.2")


def test_string():
    np.longdouble("1.2")


def test_bytes():
    np.longdouble(b"1.2")


@in_foreign_locale
def test_fromstring_foreign_repr():
    f = 1.234
    a = np.fromstring(repr(f), dtype=float, sep=" ")
    assert_equal(a[0], f)


@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
def test_repr_roundtrip_bytes():
    o = 1 + LD_INFO.eps
    assert_equal(np.longdouble(repr(o).encode("ascii")), o)


@in_foreign_locale
def test_repr_roundtrip_foreign():
    o = 1.5
    assert_equal(o, np.longdouble(repr(o)))


def test_bogus_string():
    assert_raises(ValueError, np.longdouble, "spam")
    assert_raises(ValueError, np.longdouble, "1.0 flub")


@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
def test_fromstring():
    o = 1 + LD_INFO.eps
    s = (" " + repr(o))*5
    a = np.array([o]*5)
    assert_equal(np.fromstring(s, sep=" ", dtype=np.longdouble), a,
                 err_msg="reading '%s'" % s)


@in_foreign_locale
def test_fromstring_best_effort_float():
    assert_equal(np.fromstring("1,234", dtype=float, sep=" "),
                 np.array([1.]))


@in_foreign_locale
def test_fromstring_best_effort():
    assert_equal(np.fromstring("1,234", dtype=np.longdouble, sep=" "),
                 np.array([1.]))


def test_fromstring_bogus():
    assert_equal(np.fromstring("1. 2. 3. flop 4.", dtype=float, sep=" "),
                 np.array([1., 2., 3.]))


def test_fromstring_empty():
    assert_equal(np.fromstring("xxxxx", sep="x"),
                 np.array([]))


def test_fromstring_missing():
    assert_equal(np.fromstring("1xx3x4x5x6", sep="x"),
                 np.array([1]))


class FileBased(TestCase):

    ldbl = 1 + LD_INFO.eps
    tgt = np.array([ldbl]*5)
    out = ''.join([repr(t) + '\n' for t in tgt])

    def test_fromfile_bogus(self):
        with temppath() as path:
            with open(path, 'wt') as f:
                f.write("1. 2. 3. flop 4.\n")
            res = np.fromfile(path, dtype=float, sep=" ")
        assert_equal(res, np.array([1., 2., 3.]))

    @dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
    def test_fromfile(self):
        with temppath() as path:
            with open(path, 'wt') as f:
                f.write(self.out)
            res = np.fromfile(path, dtype=np.longdouble, sep="\n")
        assert_equal(res, self.tgt)

    @dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
    def test_genfromtxt(self):
        with temppath() as path:
            with open(path, 'wt') as f:
                f.write(self.out)
            res = np.genfromtxt(path, dtype=np.longdouble)
        assert_equal(res, self.tgt)

    @dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
    def test_loadtxt(self):
        with temppath() as path:
            with open(path, 'wt') as f:
                f.write(self.out)
            res = np.loadtxt(path, dtype=np.longdouble)
        assert_equal(res, self.tgt)

    @dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
    def test_tofile_roundtrip(self):
        with temppath() as path:
            self.tgt.tofile(path, sep=" ")
            res = np.fromfile(path, dtype=np.longdouble, sep=" ")
        assert_equal(res, self.tgt)


@in_foreign_locale
def test_fromstring_foreign():
    s = "1.234"
    a = np.fromstring(s, dtype=np.longdouble, sep=" ")
    assert_equal(a[0], np.longdouble(s))


@in_foreign_locale
def test_fromstring_foreign_sep():
    a = np.array([1, 2, 3, 4])
    b = np.fromstring("1,2,3,4,", dtype=np.longdouble, sep=",")
    assert_array_equal(a, b)


@in_foreign_locale
def test_fromstring_foreign_value():
    b = np.fromstring("1,234", dtype=np.longdouble, sep=" ")
    assert_array_equal(b[0], 1)


# Conversions long double -> string


def test_repr_exact():
    o = 1 + LD_INFO.eps
    assert_(repr(o) != '1')


@dec.knownfailureif(longdouble_longer_than_double, "BUG #2376")
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
def test_format():
    o = 1 + LD_INFO.eps
    assert_("{0:.40g}".format(o) != '1')


@dec.knownfailureif(longdouble_longer_than_double, "BUG #2376")
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
def test_percent():
    o = 1 + LD_INFO.eps
    assert_("%.40g" % o != '1')


@dec.knownfailureif(longdouble_longer_than_double, "array repr problem")
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
def test_array_repr():
    o = 1 + LD_INFO.eps
    a = np.array([o])
    b = np.array([1], dtype=np.longdouble)
    if not np.all(a != b):
        raise ValueError("precision loss creating arrays")
    assert_(repr(a) != repr(b))


if __name__ == "__main__":
    run_module_suite()

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
31 Aug 2024 3.40 AM
root / root
0755
__pycache__
--
31 Aug 2024 3.40 AM
root / root
0755
data
--
31 Aug 2024 3.40 AM
root / root
0755
test_abc.py
1.967 KB
25 Apr 2023 2.30 AM
root / root
0644
test_api.py
18.463 KB
25 Apr 2023 2.30 AM
root / root
0644
test_arrayprint.py
9.976 KB
25 Apr 2023 2.30 AM
root / root
0644
test_datetime.py
90.358 KB
25 Apr 2023 2.30 AM
root / root
0644
test_defchararray.py
25.16 KB
25 Apr 2023 2.30 AM
root / root
0644
test_deprecations.py
18.361 KB
25 Apr 2023 2.30 AM
root / root
0644
test_dtype.py
25.588 KB
25 Apr 2023 2.30 AM
root / root
0644
test_einsum.py
38.67 KB
25 Apr 2023 2.30 AM
root / root
0644
test_errstate.py
1.551 KB
25 Apr 2023 2.30 AM
root / root
0644
test_extint128.py
5.639 KB
25 Apr 2023 2.30 AM
root / root
0644
test_function_base.py
11.161 KB
25 Apr 2023 2.30 AM
root / root
0644
test_getlimits.py
4.505 KB
25 Apr 2023 2.30 AM
root / root
0644
test_half.py
18.211 KB
25 Apr 2023 2.30 AM
root / root
0644
test_indexerrors.py
4.822 KB
25 Apr 2023 2.30 AM
root / root
0644
test_indexing.py
46.842 KB
25 Apr 2023 2.30 AM
root / root
0644
test_item_selection.py
3.579 KB
25 Apr 2023 2.30 AM
root / root
0644
test_longdouble.py
5.827 KB
25 Apr 2023 2.30 AM
root / root
0644
test_machar.py
0.99 KB
25 Apr 2023 2.30 AM
root / root
0644
test_mem_overlap.py
28.871 KB
25 Apr 2023 2.30 AM
root / root
0644
test_memmap.py
6.909 KB
25 Apr 2023 2.30 AM
root / root
0644
test_multiarray.py
254.692 KB
25 Apr 2023 2.30 AM
root / root
0644
test_nditer.py
105.745 KB
25 Apr 2023 2.30 AM
root / root
0644
test_numeric.py
98.49 KB
25 Apr 2023 2.30 AM
root / root
0644
test_numerictypes.py
14.268 KB
25 Apr 2023 2.30 AM
root / root
0644
test_print.py
7.899 KB
25 Apr 2023 2.30 AM
root / root
0644
test_records.py
15.269 KB
25 Apr 2023 2.30 AM
root / root
0644
test_regression.py
79.308 KB
25 Apr 2023 2.30 AM
root / root
0644
test_scalarinherit.py
0.753 KB
25 Apr 2023 2.30 AM
root / root
0644
test_scalarmath.py
24.446 KB
25 Apr 2023 2.30 AM
root / root
0644
test_scalarprint.py
0.896 KB
25 Apr 2023 2.30 AM
root / root
0644
test_shape_base.py
18.109 KB
25 Apr 2023 2.30 AM
root / root
0644
test_ufunc.py
53.696 KB
25 Apr 2023 2.30 AM
root / root
0644
test_umath.py
96.47 KB
25 Apr 2023 2.30 AM
root / root
0644
test_umath_complex.py
19.336 KB
25 Apr 2023 2.30 AM
root / root
0644
test_unicode.py
13.904 KB
25 Apr 2023 2.30 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF