Example #1
0
    def test_save_longcomplex(self):
        val = np.longcomplex(1.01 + 2.3j)
        data = {'val': val}
        save_data(data, 'bubu' + HEN_FILE_EXTENSION)
        data_out = load_data('bubu' + HEN_FILE_EXTENSION)

        assert np.allclose(data['val'], data_out['val'])
Example #2
0
def scalar_instances(times=True, extended_precision=True, user_dtype=True):
    # Hard-coded list of scalar instances.
    # Floats:
    yield param(np.sqrt(np.float16(5)), id="float16")
    yield param(np.sqrt(np.float32(5)), id="float32")
    yield param(np.sqrt(np.float64(5)), id="float64")
    if extended_precision:
        yield param(np.sqrt(np.longdouble(5)), id="longdouble")

    # Complex:
    yield param(np.sqrt(np.complex64(2 + 3j)), id="complex64")
    yield param(np.sqrt(np.complex128(2 + 3j)), id="complex128")
    if extended_precision:
        yield param(np.sqrt(np.longcomplex(2 + 3j)), id="clongdouble")

    # Bool:
    # XFAIL: Bool should be added, but has some bad properties when it
    # comes to strings, see also gh-9875
    # yield param(np.bool_(0), id="bool")

    # Integers:
    yield param(np.int8(2), id="int8")
    yield param(np.int16(2), id="int16")
    yield param(np.int32(2), id="int32")
    yield param(np.int64(2), id="int64")

    yield param(np.uint8(2), id="uint8")
    yield param(np.uint16(2), id="uint16")
    yield param(np.uint32(2), id="uint32")
    yield param(np.uint64(2), id="uint64")

    # Rational:
    if user_dtype:
        yield param(rational(1, 2), id="rational")

    # Cannot create a structured void scalar directly:
    structured = np.array([(1, 3)], "i,i")[0]
    assert isinstance(structured, np.void)
    assert structured.dtype == np.dtype("i,i")
    yield param(structured, id="structured")

    if times:
        # Datetimes and timedelta
        yield param(np.timedelta64(2), id="timedelta64[generic]")
        yield param(np.timedelta64(23, "s"), id="timedelta64[s]")
        yield param(np.timedelta64("NaT", "s"), id="timedelta64[s](NaT)")

        yield param(np.datetime64("NaT"), id="datetime64[generic](NaT)")
        yield param(np.datetime64("2020-06-07 12:43", "ms"),
                    id="datetime64[ms]")

    # Strings and unstructured void:
    yield param(np.bytes_(b"1234"), id="bytes")
    yield param(np.unicode_("2345"), id="unicode")
    yield param(np.void(b"4321"), id="unstructured_void")
Example #3
0
reveal_type(np.short())  # E: {short}
reveal_type(np.intc())  # E: {intc}
reveal_type(np.intp())  # E: {intp}
reveal_type(np.int0())  # E: {intp}
reveal_type(np.int_())  # E: {int_}
reveal_type(np.longlong())  # E: {longlong}

reveal_type(np.ubyte())  # E: {ubyte}
reveal_type(np.ushort())  # E: {ushort}
reveal_type(np.uintc())  # E: {uintc}
reveal_type(np.uintp())  # E: {uintp}
reveal_type(np.uint0())  # E: {uintp}
reveal_type(np.uint())  # E: {uint}
reveal_type(np.ulonglong())  # E: {ulonglong}

reveal_type(np.half())  # E: {half}
reveal_type(np.single())  # E: {single}
reveal_type(np.double())  # E: {double}
reveal_type(np.float_())  # E: {double}
reveal_type(np.longdouble())  # E: {longdouble}
reveal_type(np.longfloat())  # E: {longdouble}

reveal_type(np.csingle())  # E: {csingle}
reveal_type(np.singlecomplex())  # E: {csingle}
reveal_type(np.cdouble())  # E: {cdouble}
reveal_type(np.complex_())  # E: {cdouble}
reveal_type(np.cfloat())  # E: {cdouble}
reveal_type(np.clongdouble())  # E: {clongdouble}
reveal_type(np.clongfloat())  # E: {clongdouble}
reveal_type(np.longcomplex())  # E: {clongdouble}
Example #4
0
np.half()
np.single()
np.double()
np.float_()
np.longdouble()
np.longfloat()

np.csingle()
np.singlecomplex()
np.cdouble()
np.complex_()
np.cfloat()
np.clongdouble()
np.clongfloat()
np.longcomplex()

np.bool_().item()
np.int_().item()
np.uint64().item()
np.float32().item()
np.complex128().item()
np.str_().item()
np.bytes_().item()

np.bool_().tolist()
np.int_().tolist()
np.uint64().tolist()
np.float32().tolist()
np.complex128().tolist()
np.str_().tolist()
Example #5
0
    #function of L
    def L(m, X, hp):
        return np.exp(1j * X * hp / 2) * special.iv(m, -1j * X * hp / 2)

    #end
    #beta matrix
    for i in media:
        for n in order:
            beta[i, n + N] = np.sqrt(k[i]**2 - alpha[n + N]**2)
    #phi matrix
    for j in layer:
        for n in order:
            phi[j, n + N, n + N] = np.exp(1j * beta[j, n + N] * ep[j])
            phi[j, n + 3 * N + 1, n + 3 * N + 1] = np.exp(
                np.longcomplex(-1j * beta[j, n + N] * ep[j]))
    #w matrix
    for i in media:
        for j in layer:
            for n in order:
                for m in np.linspace(-N, N, 2 * N + 1):
                    #modules11
                    w[i, j, m + N, n + N] = L(m - n, beta[i, n + N], h[j])
                    #modules12
                    w[i, j, m + N, n + 3 * N + 1] = L(m - n, -beta[i, n + N],
                                                      h[j])
                    #modules21
                    if mode == 'tm':
                        w[i, j, m + 3 * N + 1,
                          n + N] = (k[i]**2 - alpha[m + N] * alpha[n + N]
                                    ) / epsilon[i] / beta[i, n + N] * L(
Example #6
0
reveal_type(np.short())  # E: numpy.signedinteger[numpy.typing._
reveal_type(np.intc())  # E: numpy.signedinteger[numpy.typing._
reveal_type(np.intp())  # E: numpy.signedinteger[numpy.typing._
reveal_type(np.int0())  # E: numpy.signedinteger[numpy.typing._
reveal_type(np.int_())  # E: numpy.signedinteger[numpy.typing._
reveal_type(np.longlong())  # E: numpy.signedinteger[numpy.typing._

reveal_type(np.ubyte())  # E: numpy.unsignedinteger[numpy.typing._
reveal_type(np.ushort())  # E: numpy.unsignedinteger[numpy.typing._
reveal_type(np.uintc())  # E: numpy.unsignedinteger[numpy.typing._
reveal_type(np.uintp())  # E: numpy.unsignedinteger[numpy.typing._
reveal_type(np.uint0())  # E: numpy.unsignedinteger[numpy.typing._
reveal_type(np.uint())  # E: numpy.unsignedinteger[numpy.typing._
reveal_type(np.ulonglong())  # E: numpy.unsignedinteger[numpy.typing._

reveal_type(np.half())  # E: numpy.floating[numpy.typing._
reveal_type(np.single())  # E: numpy.floating[numpy.typing._
reveal_type(np.double())  # E: numpy.floating[numpy.typing._
reveal_type(np.float_())  # E: numpy.floating[numpy.typing._
reveal_type(np.longdouble())  # E: numpy.floating[numpy.typing._
reveal_type(np.longfloat())  # E: numpy.floating[numpy.typing._

reveal_type(np.csingle())  # E: numpy.complexfloating[numpy.typing._
reveal_type(np.singlecomplex())  # E: numpy.complexfloating[numpy.typing._
reveal_type(np.cdouble())  # E: numpy.complexfloating[numpy.typing._
reveal_type(np.complex_())  # E: numpy.complexfloating[numpy.typing._
reveal_type(np.cfloat())  # E: numpy.complexfloating[numpy.typing._
reveal_type(np.clongdouble())  # E: numpy.complexfloating[numpy.typing._
reveal_type(np.clongfloat())  # E: numpy.complexfloating[numpy.typing._
reveal_type(np.longcomplex())  # E: numpy.complexfloating[numpy.typing._