Utility Functions#

Helper functions for platform precision detection and threading control.

Platform Precision Detection#

numpy_quaddtype.is_longdouble_128()#

Check if the platform’s long double type is 128-bit.

This is useful for determining whether the longdouble backend provides true quad precision on the current platform.

Returns:

True if long double is 128-bit, False otherwise.

Return type:

bool

Platform behavior:

  • Linux x86_64: Returns False (80-bit extended precision)

  • Linux aarch64: Returns True (128-bit quad precision)

  • macOS (all): Returns False (64-bit double precision)

  • Windows (all): Returns False (64-bit double precision)

Note

When this returns True, the SLEEF and longdouble backends share the same IEEE 754 binary128 representation, making inter-backend casting lossless.

Example

>>> from numpy_quaddtype import is_longdouble_128
>>> if is_longdouble_128():
...     print("Native quad precision available via longdouble")
... else:
...     print("Use SLEEF backend for quad precision")

Threading Control#

These functions control the number of threads used by QuadBLAS for parallel operations.

numpy_quaddtype.set_num_threads(n)#

Set the number of threads used by QuadBLAS operations.

Parameters:

n (int) – Number of threads to use. Must be a positive integer.

Raises:

ValueError – If n is not a positive integer.

Example

>>> from numpy_quaddtype import set_num_threads, get_num_threads
>>> set_num_threads(4)
>>> get_num_threads()
4

Note

This function has no effect if QuadBLAS is disabled (e.g., on Windows).

numpy_quaddtype.get_num_threads()#

Get the current number of threads used by QuadBLAS.

Returns:

Current thread count for QuadBLAS operations.

Return type:

int

Example

>>> from numpy_quaddtype import get_num_threads
>>> get_num_threads()
4
numpy_quaddtype.get_quadblas_version()#

Get the QuadBLAS library version string.

Returns:

Version string if QuadBLAS is available, None otherwise.

Return type:

str or None

Example

>>> from numpy_quaddtype import get_quadblas_version
>>> version = get_quadblas_version()
>>> if version:
...     print(f"QuadBLAS version: {version}")
... else:
...     print("QuadBLAS not available")

Note

QuadBLAS is automatically disabled on Windows builds due to MSVC compatibility issues. In this case, the function returns None.

Example: Optimizing Thread Usage#

import numpy as np
from numpy_quaddtype import (
    QuadPrecDType, 
    set_num_threads, 
    get_num_threads,
    get_quadblas_version
)

# Check QuadBLAS availability
version = get_quadblas_version()
if version:
    print(f"QuadBLAS {version} available")

    # Get current threads
    print(f"Default threads: {get_num_threads()}")

    # Create test array
    arr = np.random.randn(100000).astype(QuadPrecDType())

    # Benchmark with different thread counts
    import time

    for threads in [1, 2, 4, 8]:
        set_num_threads(threads)

        start = time.time()
        for _ in range(10):
            result = np.matmul(arr, arr)
        elapsed = time.time() - start

        print(f"  {threads} threads: {elapsed:.3f}s")
else:
    print("QuadBLAS not available - single-threaded operations only")