How to use the thewalrus.libwalrus.haf_real function in thewalrus

To help you get started, we’ve selected a few thewalrus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github XanaduAI / thewalrus / examples / timing_int_vs_real.py View on Github external
start = time.time()
    for i in range(reps):
        matrix = np.random.randint(low=-1, high=2, size=[size, size])
        A = np.complex128(np.clip(matrix+matrix.T, -1, 1))
        res = haf_complex(A, recursive=True)

    end = time.time()
    print('Mean time taken (complex, recursive): ', (end - start)/reps)
    # print('\t Haf result: ', res)
    times[ind, 1] = (end - start)/reps

    start = time.time()
    for i in range(reps):
        matrix = np.random.randint(low=-1, high=2, size=[size, size])
        A = np.float64(np.clip(matrix+matrix.T, -1, 1))
        res = haf_real(A)

    end = time.time()
    print('Mean time taken (real): ', (end - start)/reps)
    # print('\t Haf result: ', res)
    times[ind, 2] = (end - start)/reps

    start = time.time()
    for i in range(reps):
        matrix = np.random.randint(low=-1, high=2, size=[size, size])
        A = np.float64(np.clip(matrix+matrix.T, -1, 1))
        res = haf_real(A, recursive=True)

    end = time.time()
    print('Mean time taken (real, recursive): ', (end - start)/reps)
    # print('\t Haf result: ', res)
    times[ind, 3] = (end - start)/reps
github XanaduAI / thewalrus / thewalrus / _hafnian.py View on Github external
# all array values have zero imaginary parts
        return haf_real(np.float64(A.real), loop=loop, recursive=recursive, quad=quad)

    if np.issubdtype(A.dtype, np.integer) and not loop:
        # array data is an integer type, and the user is not
        # requesting the loop hafnian
        return haf_int(np.int64(A))

    if np.issubdtype(A.dtype, np.integer) and loop:
        # array data is an integer type, and the user is
        # requesting the loop hafnian. Currently no
        # integer function for loop hafnians, have to instead
        # convert to float and use haf_real
        A = np.float64(A)

    return haf_real(
        A, loop=loop, recursive=recursive, quad=quad, approx=approx, nsamples=num_samples
    )
github XanaduAI / thewalrus / examples / timing_int_vs_real.py View on Github external
start = time.time()
    for i in range(reps):
        matrix = np.random.randint(low=-1, high=2, size=[size, size])
        A = np.float64(np.clip(matrix+matrix.T, -1, 1))
        res = haf_real(A)

    end = time.time()
    print('Mean time taken (real): ', (end - start)/reps)
    # print('\t Haf result: ', res)
    times[ind, 2] = (end - start)/reps

    start = time.time()
    for i in range(reps):
        matrix = np.random.randint(low=-1, high=2, size=[size, size])
        A = np.float64(np.clip(matrix+matrix.T, -1, 1))
        res = haf_real(A, recursive=True)

    end = time.time()
    print('Mean time taken (real, recursive): ', (end - start)/reps)
    # print('\t Haf result: ', res)
    times[ind, 3] = (end - start)/reps

    start = time.time()
    for i in range(reps):
        matrix = np.random.randint(low=-1, high=2, size=[size, size])
        A = np.int64(np.clip(matrix+matrix.T, -1, 1))
        res = haf_int(A)

    end = time.time()
    print('Mean time taken (int): ', (end - start)/reps)
    # print('\t Haf result: ', res)
    times[ind, 4] = (end - start)/reps
github XanaduAI / thewalrus / thewalrus / _hafnian.py View on Github external
if approx:
        if np.any(np.iscomplex(A)):
            raise ValueError("Input matrix must be real")

        if np.any(A < 0):
            raise ValueError("Input matrix must not have negative entries")

    if A.dtype == np.complex:
        # array data is complex type
        if np.any(np.iscomplex(A)):
            # array values contain non-zero imaginary parts
            return haf_complex(A, loop=loop, recursive=recursive, quad=quad)

        # all array values have zero imaginary parts
        return haf_real(np.float64(A.real), loop=loop, recursive=recursive, quad=quad)

    if np.issubdtype(A.dtype, np.integer) and not loop:
        # array data is an integer type, and the user is not
        # requesting the loop hafnian
        return haf_int(np.int64(A))

    if np.issubdtype(A.dtype, np.integer) and loop:
        # array data is an integer type, and the user is
        # requesting the loop hafnian. Currently no
        # integer function for loop hafnians, have to instead
        # convert to float and use haf_real
        A = np.float64(A)

    return haf_real(
        A, loop=loop, recursive=recursive, quad=quad, approx=approx, nsamples=num_samples
    )