### OpenCL Device Information Example Source: https://pynufft.readthedocs.io/en/latest/installation/OpenCL.html This snippet displays the output of the 'clinfo' command, showing detailed information about the detected OpenCL platform and device. It is useful for verifying OpenCL installation and understanding device capabilities. ```text Platform Name Intel(R) OpenCL Number of devices 1 Device Name Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz Device Vendor Intel(R) Corporation Device Vendor ID 0x8086 Device Version OpenCL 1.2 (Build 117) Driver Version 1.2.0.117 Device OpenCL C Version OpenCL C 1.2 Device Type CPU Device Profile FULL_PROFILE Device Available Yes Compiler Available Yes Linker Available Yes Max compute units 8 Max clock frequency 2600MHz Device Partition (core) Max number of sub-devices 8 Supported partition types by counts, equally, by names (Intel) Supported affinity domains (n/a) Max work item dimensions 3 Max work item sizes 8192x8192x8192 Max work group size 8192 Preferred work group size multiple 128 Preferred / native vector sizes char 1 / 32 short 1 / 16 int 1 / 8 long 1 / 4 half 0 / 0 (n/a) float 1 / 8 double 1 / 4 (cl_khr_fp64) Half-precision Floating-point support (n/a) Single-precision Floating-point support (core) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero No Round to infinity No IEEE754-2008 fused multiply-add No Support is emulated in software No Correctly-rounded divide and sqrt operations No Double-precision Floating-point support (cl_khr_fp64) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No Address bits 64, Little-Endian Global memory size 33613447168 (31.3GiB) Error Correction support No Max memory allocation 8403361792 (7.826GiB) Unified memory for Host and Device Yes Minimum alignment for any data type 128 bytes Alignment of base address 1024 bits (128 bytes) Global Memory cache type Read/Write Global Memory cache size 262144 (256KiB) Global Memory cache line size 64 bytes Image support Yes Max number of samplers per kernel 480 Max size for 1D images from buffer 525210112 pixels ``` -------------------------------- ### Example nvcc Output Source: https://pynufft.readthedocs.io/en/latest/installation/Windows.html This is an example of the output you would expect to see when running the 'nvcc -V' command, indicating a successful installation of the CUDA toolkit. ```text nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Tue_Jun_12_23:09_12_Central_Daylight_time_2018 Cuda compilation tool, release 9.2, V9.2.148 ``` -------------------------------- ### Install clinfo using Homebrew Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/Macbook.rst.txt After installing Homebrew, use this command to install clinfo, a utility to display information about installed OpenCL drivers. ```bash brew install clinfo ``` -------------------------------- ### Install PyNUFFT from Git Repository Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/init.rst.txt Clone the latest code from the GitHub repository and install it locally. This method is useful for development or when needing the most recent changes. ```bash git clone https://github.com/jyhmiinlin/pynufft $ cd pynufft $ python setup.py install --user ``` -------------------------------- ### Install PyNUFFT using pip Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/init.rst.txt Use this command to install the PyNUFFT package directly from the Python Package Index. ```bash $ pip install pynufft ``` -------------------------------- ### Full 2D NUFFT script example Source: https://pynufft.readthedocs.io/en/latest/_sources/tutor/more2D.rst.txt A complete Python script demonstrating a 2D NUFFT transform, including planning, forward transform, and image restoration. ```python import numpy import scipy.misc import matplotlib.pyplot from pynufft import NUFFT import pkg_resources # Load the 2D trajectory DATA_PATH = pkg_resources.resource_filename('pynufft', './src/data/') om = numpy.load(DATA_PATH+'om2D.npz')['arr_0'] # Define NUFFT parameters Nd = (256, 256) # image size Kd = (512, 512) # k-space size Jd = (6, 6) # interpolation size # Create and plan the NUFFT object NufftObj = NUFFT() NufftObj.plan(om, Nd, Kd, Jd) # Load and prepare the image image = scipy.misc.ascent()[::2, ::2] image = image / numpy.max(image[...]) # Perform forward transform y = NufftObj.forward(image) # Restore image using different solvers image0 = NufftObj.solve(y, solver='cg', maxiter=50) image2 = NufftObj.adjoint(y) image3 = NufftObj.solve(y, solver='L1TVOLS', maxiter=50, rho=0.1) # Display results matplotlib.pyplot.figure(figsize=(12, 4)) matplotlib.pyplot.subplot(1, 3, 1) matplotlib.pyplot.title('Restored image (cg)') matplotlib.pyplot.imshow(image0.real, cmap=matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=0.0, vmax=1)) matplotlib.pyplot.subplot(1, 3, 2) matplotlib.pyplot.title('Adjoint transform') matplotlib.pyplot.imshow(image2.real, cmap=matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=0.0, vmax=5)) matplotlib.pyplot.subplot(1, 3, 3) matplotlib.pyplot.title('L1TV OLS') matplotlib.pyplot.imshow(image3.real, cmap=matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=0.0, vmax=1)) matplotlib.pyplot.tight_layout() matplotlib.pyplot.show() # Display the spectrum of the restored image (cg) matplotlib.pyplot.figure() spectrum = numpy.fft.fftshift(numpy.fft.fft2(image0)) matplotlib.pyplot.imshow(numpy.log(numpy.abs(spectrum)), cmap=matplotlib.cm.gray) matplotlib.pyplot.title('Spectrum of restored image (cg)') matplotlib.pyplot.show() ``` -------------------------------- ### Install PyCUDA, Reikna, and PyNUFFT Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/Windows.rst.txt Install the necessary Python packages for PyNUFFT using pip within an Anaconda prompt. Ensure you have Anaconda3 installed and the prompt is open. ```bash pip install pycuda pip install reikna pip install pynufft ``` -------------------------------- ### Run pynufft tests Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/Macbook.rst.txt Execute the pynufft tests to verify installation and performance. This snippet shows the output of the test execution, including device information and error metrics. ```python Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from pynufft import tests as t >>> t.test_init() No cuda device found. Check your pycuda installation. device name = 0.024686098098754883 0.0167756986618042 error gx2= 2.1132891e-07 error gy= 1.1100628500806993e-07 acceleration= 1.4715391946662406 7.563086748123169 4.348098039627075 acceleration in solver= 1.7394011540668561 ``` -------------------------------- ### Experimental Multiprocessing Example for NUFFT Source: https://pynufft.readthedocs.io/en/latest/_sources/manu/multiple_NUFFT.rst.txt An experimental example demonstrating the use of Python's multiprocessing module with NUFFT, specifically designed to handle mixed CUDA and OpenCL backends. This requires careful setup to avoid issues with unpicklable contexts. ```python .. literalinclude:: ../../../tests/parallel_NUFFT.py ``` -------------------------------- ### Test PyNUFFT Initialization Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/Windows.rst.txt Run a Python script to test the initialization of the PyNUFFT library. This involves starting the Python interpreter and calling a specific test function. ```python python from pynufft import tests tests.test_init() ``` -------------------------------- ### Install Homebrew on Macbook Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/Macbook.rst.txt Use this command in the terminal to install Homebrew, a package manager for macOS. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Troubleshooting cl.exe Not Found Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/Windows.rst.txt This example shows the error message when the 'cl' command (Microsoft C/C++ compiler) is not recognized, indicating it's not in the system's PATH. The subsequent command demonstrates the expected output after the PATH is correctly configured. ```bash C:\Users\User>cl `cl` is not recognized as an internal or external command, operable program or batch file. ``` ```bash C:\Users\User>cl Microsoft (R) C/C++ Optimizing Compiler Version 19.0024215.1 for x86 Copyright (C) Microsoft Corpooration. All rights reserved. usage: cl [ option... ] filename... [ /link linkoption... ] ``` -------------------------------- ### Run pynufft Tests on Macbook Source: https://pynufft.readthedocs.io/en/latest/installation/Macbook.html Execute the pynufft tests to verify the installation and check performance metrics on your Macbook. This snippet shows the expected output, including device information and error rates. ```python from pynufft import tests as t t.test_init() ``` -------------------------------- ### Experimental Multiprocessing with NUFFT (PyCUDA Backend) Source: https://pynufft.readthedocs.io/en/latest/manu/multiple_NUFFT.html An example demonstrating the experimental use of Python's multiprocessing module with PyNUFFT, utilizing a PyCUDA backend. Each process creates and executes a NUFFT instance on the GPU, with CPU affinity controlled via taskset. ```python """ An example of multiprocessing with NUFFT using PyCUDA backend, wrapped inside the atomic_NUFFT wrapper class. The two processes are running on two CPU cores. Each process creates one NUFFT and offloads the computations to GPU. nvidia-smi confirms that two python programs are using the GPU. """ import numpy from pynufft import NUFFT, helper import scipy.misc import matplotlib.pyplot import multiprocessing import os class atomic_NUFFT: def __init__(self, om, Nd, Kd, Jd, device_indx): """ This caches the parameters only. Any other GPU related stuffs are carried out in run() """ self.om = om self.Nd = Nd self.Kd = Kd self.Jd = Jd # self.API = API self.device_indx = device_indx def run(self, x, cpu_cores): """ In this method, the NUFFT are created and executed on a fixed CPU core. """ pid= os.getpid() print('pid=', pid) os.system("taskset -p -c %d-%d %d" % (cpu_cores[0], cpu_cores[1], pid)) """ Control the CPU affinity. Otherwise the process on one core can be switched to another core. """ # create NUFFT # NUFFT = NUFFT(self.API, ) # plan the NUFFT device_list = helper.device_list() self.NUFFT = NUFFT(device_list[self.device_indx]) self.NUFFT.plan(self.om, self.Nd, self.Kd, self.Jd) # send the image to device gx = self.NUFFT.to_device(x) # carry out 10000 forward transform for pp in range(0, 10000): gy = self.NUFFT._forward_device(gx) # return the object return gy.get() Nd = (256,256) Kd = (512,512) Jd = (6,6) om = numpy.random.randn(35636, 2) x = scipy.misc.ascent()[::2,::2] om1 = om[om[:,0]>0, :] om2 = om[om[:,0]<=0, :] # create pool pool = multiprocessing.Pool(2) # create the list to receive the return values results = [] # Now enter the first process # This is the standard multiprocessing Pool D = atomic_NUFFT(om1, Nd, Kd, Jd, 0) ``` -------------------------------- ### diagnose() Source: https://pynufft.readthedocs.io/en/latest/index.html Performs diagnostic checks on the system or PyNUFFT installation. ```APIDOC ## diagnose() ### Description Runs diagnostic tests to check the status and configuration of PyNUFFT. ### Function `diagnose()` ``` -------------------------------- ### Check CUDA Compiler Version Source: https://pynufft.readthedocs.io/en/latest/_sources/installation/Windows.rst.txt Verify that the NVIDIA CUDA compiler (nvcc) is installed and accessible by checking its version. This command should be run in a Windows command prompt. ```bash nvcc -V ``` -------------------------------- ### Plan Each NUFFT Instance Immediately After Creation Source: https://pynufft.readthedocs.io/en/latest/_sources/manu/multiple_NUFFT.rst.txt Create and plan each NUFFT instance individually as soon as it is initialized. This method allows for immediate execution of forward or backward transforms for each instance. ```python # Create the first NUFFT NufftObj1 = NUFFT() NufftObj1.plan(om1, Nd, Kd, Jd) # Create the second NUFFT NufftObj2 = NUFFT() NufftObj2.plan(om2, Nd, Kd, Jd) y1 = NufftObj1.forward(x) y2 = NufftObj2.forward(x) ``` -------------------------------- ### Plan NUFFT Object (Basic) Source: https://pynufft.readthedocs.io/en/latest/API/init.html Initializes the NUFFT object and plans it with the provided geometry. Use this for standard planning without specifying Fourier transform axes. ```python >>> from pynufft import NUFFT >>> NufftObj = NUFFT() >>> NufftObj.plan(om, Nd, Kd, Jd) ``` -------------------------------- ### Initialize NUFFT Device Constructor Source: https://pynufft.readthedocs.io/en/latest/API/init.html Constructor for initializing NUFFT on a specific heterogeneous device. Requires API type, platform, and device numbers. ```python >>> from pynufft import NUFFT >>> NufftObj = NUFFT_device(API='cuda', platform_number=0, device_number=0, verbosity=0) ``` -------------------------------- ### Initiate PyNUFFT Object Source: https://pynufft.readthedocs.io/en/latest/_sources/tutor/basic_use.rst.txt Import the NUFFT class and create an instance of the NufftObj object. This object is initially empty and requires planning before use. ```python # import NUFFT class from pynufft import NUFFT # Initiate the NufftObj object NufftObj = NUFFT() ``` -------------------------------- ### Multiple NUFFT_hsa Instances with Specific Devices Source: https://pynufft.readthedocs.io/en/latest/_sources/manu/multiple_NUFFT.rst.txt Demonstrates creating and planning multiple NUFFT instances using specific devices, likely for HSA-compatible hardware. Each instance is planned immediately after creation, followed by forward transformations. ```python from pynufft import NUFFT, helper # Create the first NUFFT(device) NufftObj1 = NUFFT(helper.device_list()[0]) NufftObj1.plan(om1, Nd, Kd, Jd) # Create the second NUFFT(device) NufftObj2 = NUFFT(helper.device_list()[0]) NufftObj2.plan(om2, Nd, Kd, Jd) y1 = NufftObj1.forward(x) y2 = NufftObj2.forward(x) ``` -------------------------------- ### Initialize NUFFT Object with Device Source: https://pynufft.readthedocs.io/en/latest/API/init.html Instantiate the NUFFT class specifying a device index for acceleration. This requires the helper module to list available devices. ```python >>> from pynufft import NUFFT, helper >>> device = helper.device_list()[0] >>> NufftObj = NUFFT(device) # for first acceleration device in the system ``` -------------------------------- ### Successful cl.exe Execution Source: https://pynufft.readthedocs.io/en/latest/installation/Windows.html After correctly setting the system path for Visual Studio, running 'cl.exe' should now execute without the 'not recognized' error, displaying its usage information. ```text C:\Users\User>cl Microsoft (R) C/C++ Optimizing Compiler Version 19.0024215.1 for x86 Copyright (C) Microsoft Corpooration. All rights reserved. usage: cl [ option... ] filename... [ /link linkoption... ] ``` -------------------------------- ### Generate 2D Random Coordinates Source: https://pynufft.readthedocs.io/en/latest/_sources/tutor/basic_use.rst.txt Generate random non-Cartesian coordinates for planning the NUFFT object. This example creates 100 random samples across a 2D plane. ```python # generating 2D random coordinates import numpy om = numpy.random.randn(100, 2) ``` -------------------------------- ### Generate Cartesian k-space Trajectories Source: https://pynufft.readthedocs.io/en/latest/manu/realistic_om.html This snippet generates Cartesian k-space trajectories for NUFFT. It's primarily for testing purposes as FFT is generally preferred for Cartesian data. Ensure PyNUFFT and SciPy are installed. ```python # Generating trajectories for Cartesian k-space import numpy import matplotlib.pyplot matplotlib.pyplot.gray() def fake_Cartesian(Nd): dim = len(Nd) # dimension M = numpy.prod(Nd) om = numpy.zeros((M, dim), dtype = numpy.float) grid = numpy.indices(Nd) for dimid in range(0, dim): om[:, dimid] = (grid[dimid].ravel() *2/ Nd[dimid] - 1.0)*numpy.pi return om import scipy.misc from pynufft import NUFFT Nd = (256,256) Kd = (512,512) Jd = (6,6) image = scipy.misc.ascent()[::2,::2] om = fake_Cartesian(Nd) print('Number of samples (M) = ', om.shape[0]) print('Dimension = ', om.shape[1]) print('Nd = ', Nd) print('Kd = ', Kd) print('Jd = ', Jd) NufftObj = NUFFT() NufftObj.plan(om, Nd, Kd, Jd) y = NufftObj.forward(image) y2 = y.reshape(Nd, order='C') x2 = numpy.fft.ifftshift(numpy.fft.ifftn(numpy.fft.ifftshift(y2))) matplotlib.pyplot.subplot(1,3,1) matplotlib.pyplot.imshow(image.real, vmin = 0, vmax = 255) matplotlib.pyplot.title('Original image') matplotlib.pyplot.subplot(1,3,2) matplotlib.pyplot.imshow(x2.real, vmin = 0, vmax = 255) matplotlib.pyplot.title('Restored image') matplotlib.pyplot.subplot(1,3,3) matplotlib.pyplot.imshow(abs(image - x2), vmin = 0, vmax = 255) matplotlib.pyplot.title('Difference map') matplotlib.pyplot.show() ``` -------------------------------- ### Initialize and Plan NUFFT Object Source: https://pynufft.readthedocs.io/en/latest/tutor/more2D.html Creates a NUFFT object and plans it with specified image dimensions (Nd), k-space dimensions (Kd), and interpolation grid size (Jd). ```python NufftObj = NUFFT() Nd = (256, 256) # image size print('setting image dimension Nd...', Nd) Kd = (512, 512) # k-space size print('setting spectrum dimension Kd...', Kd) Jd = (6, 6) # interpolation size print('setting interpolation size Jd...', Jd) NufftObj.plan(om, Nd, Kd, Jd) ``` -------------------------------- ### Nvidia OpenCL Device Information Source: https://pynufft.readthedocs.io/en/latest/installation/OpenCL.html This snippet displays the output of 'clinfo' for an Nvidia GPU, showing device name, vendor, OpenCL version, driver version, and compute capabilities. It is useful for verifying OpenCL installation on Nvidia hardware. ```text Platform Name NVIDIA CUDA Number of devices 1 Device Name GeForce GTX 1060 Device Vendor NVIDIA Corporation Device Vendor ID 0x10de Device Version OpenCL 1.2 CUDA Driver Version 415.18 Device OpenCL C Version OpenCL C 1.2 Device Type GPU Device Topology (NV) PCI-E, 01:00.0 Device Profile FULL_PROFILE Device Available Yes Compiler Available Yes Linker Available Yes Max compute units 10 Max clock frequency 1670MHz Compute Capability (NV) 6.1 Device Partition (core) Max number of sub-devices 1 Supported partition types None Supported affinity domains (n/a) Max work item dimensions 3 Max work item sizes 1024x1024x64 Max work group size 1024 Preferred work group size multiple 32 Warp size (NV) 32 Preferred / native vector sizes char 1 / 1 short 1 / 1 int 1 / 1 long 1 / 1 half 0 / 0 (n/a) float 1 / 1 double 1 / 1 (cl_khr_fp64) Half-precision Floating-point support (n/a) Single-precision Floating-point support (core) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No Correctly-rounded divide and sqrt operations Yes Double-precision Floating-point support (cl_khr_fp64) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No ``` -------------------------------- ### _create_kspace_sampling_density() (CPU Solvers) Source: https://pynufft.readthedocs.io/en/latest/index.html Helper function to create k-space sampling density for CPU solvers. ```APIDOC ## _create_kspace_sampling_density() (CPU Solvers) ### Description Generates the sampling density in k-space for CPU-based computations. ### Function `_create_kspace_sampling_density()` ``` -------------------------------- ### Initialize NUFFT Object (Default) Source: https://pynufft.readthedocs.io/en/latest/API/init.html Instantiate the NUFFT class with default settings. This is suitable for basic CPU operations. ```python >>> from pynufft import NUFFT >>> NufftObj = NUFFT() ``` -------------------------------- ### NUFFT Class Initialization Source: https://pynufft.readthedocs.io/en/latest/API/init.html Initializes the NUFFT class with optional device index and legacy settings. ```APIDOC ## NUFFT Class Initialization ### Description Initializes the NUFFT class with optional device index and legacy settings. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **_device_indx** (int) - Optional - The index of the device to use. - **_legacy** (bool) - Optional - Flag for legacy behavior. ### Request Example ```python from pynufft import NUFFT nufft_instance = NUFFT(_device_indx=0, _legacy=False) ``` ### Response #### Success Response (200) Initializes the NUFFT object. #### Response Example ```python # No explicit response object, initialization is successful if no exception is raised. ``` ``` -------------------------------- ### device_list() Source: https://pynufft.readthedocs.io/en/latest/index.html Returns a list of available devices. ```APIDOC ## device_list() ### Description Retrieves a list of available computational devices (e.g., CPU, GPU). ### Function `device_list()` ``` -------------------------------- ### device_list Function Source: https://pynufft.readthedocs.io/en/latest/API/init.html Returns a tuple of available devices for acceleration. Returns an empty tuple if no devices are available. ```APIDOC ## device_list Function ### Description Returns a tuple of available devices for acceleration. Returns an empty tuple if no devices are available. ### Returns - `devices` (tuple): A tuple containing information about available acceleration devices. ### Usage ```python # Example usage available_devices = pynufft.src._helper.helper.device_list() ``` ``` -------------------------------- ### NUFFT Class - _precompute_sp_cpu Source: https://pynufft.readthedocs.io/en/latest/API/init.html Private method to precompute the adjoint (gridding) and Toepitz interpolation matrix on the CPU. ```APIDOC ## NUFFT Class - _precompute_sp_cpu ### Description Private: Precompute adjoint (gridding) and Toepitz interpolation matrix. ### Method `_precompute_sp_cpu()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters **None** (_Python Nonetype_) ### Returns self: instance ### Return type instance ``` -------------------------------- ### Plan Multiple NUFFT Instances After Creation Source: https://pynufft.readthedocs.io/en/latest/_sources/manu/multiple_NUFFT.rst.txt Create multiple NUFFT objects and plan them after all instances have been initialized. This approach is suitable when you need to set up several NUFFT operations before executing any. ```python # Create the first NUFFT NufftObj1 = NUFFT() # Create the second NUFFT NufftObj2 = NUFFT() # Plan the first instance NufftObj1.plan(om1, Nd, Kd, Jd) NufftObj2.plan(om2, Nd, Kd, Jd) ``` -------------------------------- ### plan() Source: https://pynufft.readthedocs.io/en/latest/index.html Plans or sets up a computation, likely for NUFFT/NUDFT. ```APIDOC ## plan() ### Description Sets up and plans a computation, typically for NUFFT or NUDFT. ### Function `plan()` ``` -------------------------------- ### Plan NUFFT Object (with ft_axes) Source: https://pynufft.readthedocs.io/en/latest/API/init.html Initializes the NUFFT object and plans it with geometry and optional Fourier transform axes. This allows for specifying which axes to use for the Fourier transform. ```python >>> NufftObj.plan(om, Nd, Kd, Jd, ft_axes) ``` -------------------------------- ### Plan NUFFT using Legacy Method Source: https://pynufft.readthedocs.io/en/latest/API/init.html Plans the NUFFT object using a legacy method, typically for CPU-based operations. This is an alternative to the standard CPU planning. ```python >>> import pynufft >>> NufftObj = pynufft.NUFFT_cpu() >>> NufftObj.plan(om, Nd, Kd, Jd) ``` -------------------------------- ### Import PyNUFFT and Dependencies Source: https://pynufft.readthedocs.io/en/latest/tutor/more2D.html Import necessary libraries including numpy, scipy.misc, matplotlib.pyplot, and the NUFFT class from pynufft. ```python import numpy import scipy.misc import matplotlib.pyplot from pynufft import NUFFT ``` -------------------------------- ### CPU NUFFT Forward Transform and Comparison Source: https://pynufft.readthedocs.io/en/latest/manu/multiple_NUFFT.html Plans and executes a NUFFT forward transform on the CPU using the `NUFFT` class. It then compares the result with a previously computed one (e.g., from GPU or multiprocessing). ```python NUFFT_cpu1 = NUFFT() NUFFT_cpu1.plan(om1, Nd, Kd, Jd) y1 = NUFFT_cpu1.forward(x) print('norm = ', numpy.linalg.norm(y1 - result1) / numpy.linalg.norm(y1)) ``` ```python NUFFT_cpu2 = NUFFT() NUFFT_cpu2.plan(om2, Nd, Kd, Jd) y2 = NUFFT_cpu2.forward(x) print('norm = ', numpy.linalg.norm(y2 - result2) / numpy.linalg.norm(y2)) ``` -------------------------------- ### cCopy() (Metaprogramming) Source: https://pynufft.readthedocs.io/en/latest/index.html Copies complex data. ```APIDOC ## cCopy() (Metaprogramming) ### Description Copies complex data from one location to another. ### Function `cCopy()` ``` -------------------------------- ### cSqrt() (Metaprogramming) Source: https://pynufft.readthedocs.io/en/latest/index.html Computes the square root of complex numbers. ```APIDOC ## cSqrt() (Metaprogramming) ### Description Calculates the square root of complex numbers. ### Function `cSqrt()` ``` -------------------------------- ### pynufft.src._helper.helper.plan Source: https://pynufft.readthedocs.io/en/latest/API/init.html Plans the NUFFT object, preparing necessary structures for computation based on input parameters. ```APIDOC ## pynufft.src._helper.helper.plan ### Description Plans the NUFFT object, preparing necessary structures for computation based on input parameters. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **om** (numpy.float) - Coordinate * **Nd** (tuple of int) - Image shape * **Kd** (tuple of int) - Oversampled grid shape * **Jd** (tuple of int) - Interpolator size * **ft_axes** (tuple of int, optional) - Axes where FFT takes place * **format** (string, optional, default='CSR') - Output format of the interpolator. ‘CSR’: the precomputed Compressed Sparse Row (CSR) matrix. ‘pELL’: partial ELLPACK which precomputes the concatenated 1D interpolators. * **radix** (int, optional) - Radix for computation ### Request Example None ### Response #### Success Response * **dictionary** - Dictionary containing NUFFT plan information #### Response Example None ``` -------------------------------- ### create_kernel_sets() (Metaprogramming) Source: https://pynufft.readthedocs.io/en/latest/index.html Creates sets of kernels for metaprogramming tasks. ```APIDOC ## create_kernel_sets() (Metaprogramming) ### Description Generates sets of kernels used in metaprogramming operations. ### Function `create_kernel_sets()` ``` -------------------------------- ### NUFFT Constructor Source: https://pynufft.readthedocs.io/en/latest/API/init.html Initializes a NUFFT object. It can be initialized without arguments for default settings, or with a device index to specify a particular acceleration device. ```APIDOC ## NUFFT Constructor ### Description Initializes a NUFFT object. It can be initialized without arguments for default settings, or with a device index to specify a particular acceleration device. ### Method __init__ ### Parameters - **_device_indx** (NoneType) - Optional - The index of the device to use. - **_legacy** (NoneType) - Optional - Legacy mode flag. ### Returns - **NUFFT**: The pynufft.NUFFT instance. ### Return Type - **NUFFT**: The pynufft.NUFFT class ### Example ```python >>> from pynufft import NUFFT >>> NufftObj = NUFFT() ``` ```python >>> from pynufft import NUFFT, helper >>> device = helper.device_list()[0] >>> NufftObj = NUFFT(device) # for first acceleration device in the system ``` ``` -------------------------------- ### NUFFT Class - plan_legacy Source: https://pynufft.readthedocs.io/en/latest/API/init.html Designs the min-max interpolator for legacy execution. It requires the off-grid locations, image size, oversampled frequency grid size, and interpolator size as input. ```APIDOC ## NUFFT Class - plan_legacy ### Description Designs the min-max interpolator for legacy execution. ### Method `plan_legacy(_om_, _Nd_, _Kd_, _Jd_, _ft_axes=None_) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **om** (_numpy.float array_, matrix size = M * ndims_) – The M off-grid locations in the frequency domain. Normalized between [-pi, pi] * **Nd** (_tuple_, ndims integer elements.) – The matrix size of equispaced image. Example: Nd=(256,256) for a 2D image; Nd = (128,128,128) for a 3D image * **Kd** (_tuple_, ndims integer elements.) – The matrix size of the oversampled frequency grid. Example: Kd=(512,512) for 2D image; Kd = (256,256,256) for a 3D image * **Jd** (_tuple_, ndims integer elements.) – The interpolator size. Example: Jd=(6,6) for 2D image; Jd = (6,6,6) for a 3D image * **ft_axes** (_None_ or _tuple with optional integer elements._) – (Optional) The axes for Fourier transform. The default is all axes if ‘None’ is given. ### Returns 0 ### Return type int, float ### Request Example ```python >>> import pynufft >>> NufftObj = pynufft.NUFFT_cpu() >>> NufftObj.plan(om, Nd, Kd, Jd) ``` ``` -------------------------------- ### NUFFT_cupy Source: https://pynufft.readthedocs.io/en/latest/index.html Documentation for the NUFFT_cupy class, designed for NUFFT operations using CuPy for GPU acceleration. ```APIDOC ## NUFFT_cupy ### Description NUFFT implementation utilizing CuPy for GPU computations. ### Class `NUFFT_cupy` ``` -------------------------------- ### _create_kspace_sampling_density() (HSA Solvers) Source: https://pynufft.readthedocs.io/en/latest/index.html Helper function to create k-space sampling density for HSA solvers. ```APIDOC ## _create_kspace_sampling_density() (HSA Solvers) ### Description Generates the sampling density in k-space for HSA-based computations. ### Function `_create_kspace_sampling_density()` ``` -------------------------------- ### cSpmv() (Metaprogramming) Source: https://pynufft.readthedocs.io/en/latest/index.html Performs sparse matrix-vector multiplication for complex numbers. ```APIDOC ## cSpmv() (Metaprogramming) ### Description Computes the product of a sparse matrix and a complex vector. ### Function `cSpmv()` ``` -------------------------------- ### Check OpenCL Driver Information Source: https://pynufft.readthedocs.io/en/latest/installation/Macbook.html Execute clinfo to display details about your system's OpenCL platform and devices. This is used to verify OpenCL compatibility for GPU acceleration. ```text Number of platforms 1 Platform Name Apple Platform Vendor Apple Platform Version OpenCL 1.2 (Jun 23 2023 20:24:12) Platform Profile FULL_PROFILE Platform Extensions cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event Platform Name Apple Number of devices 1 Device Name Apple M1 Device Vendor Apple Device Vendor ID 0x1027f00 Device Version OpenCL 1.2 Driver Version 1.2 1.0 Device OpenCL C Version OpenCL C 1.2 Device Type GPU Device Profile FULL_PROFILE Device Available Yes Compiler Available Yes Linker Available Yes Max compute units 8 Max clock frequency 1000MHz Device Partition (core) Max number of sub-devices 0 Supported partition types None Supported affinity domains (n/a) Max work item dimensions 3 Max work item sizes 256x256x256 Max work group size 256 Preferred work group size multiple (kernel) 32 Preferred / native vector sizes char 1 / 1 short 1 / 1 int 1 / 1 long 1 / 1 half 0 / 0 (n/a) float 1 / 1 double 1 / 1 (n/a) Half-precision Floating-point support (n/a) Single-precision Floating-point support (core) Denormals No Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No Correctly-rounded divide and sqrt operations Yes Double-precision Floating-point support (n/a) Address bits 64, Little-Endian Global memory size 11453251584 (10.67GiB) Error Correction support No Max memory allocation 2147483648 (2GiB) Unified memory for Host and Device Yes Minimum alignment for any data type 1 bytes Alignment of base address 32768 bits (4096 bytes) Global Memory cache type None Image support Yes Max number of samplers per kernel 32 Max size for 1D images from buffer 268435456 pixels Max 1D or 2D image array size 2048 images Base address alignment for 2D image buffers 256 bytes Pitch alignment for 2D image buffers 256 pixels Max 2D image size 16384x16384 pixels Max 3D image size 2048x2048x2048 pixels Max number of read image args 128 Max number of write image args 8 Local memory type Local Local memory size 32768 (32KiB) Max number of constant args 31 Max constant buffer size 1073741824 (1024MiB) Max size of kernel argument 4096 (4KiB) Queue properties Out-of-order execution No Profiling Yes Prefer user sync for interop Yes ``` -------------------------------- ### pynufft.src.re_subroutine.cMultiplyRealInplace Source: https://pynufft.readthedocs.io/en/latest/API/init.html Returns the kernel source of cMultiplyRealInplace. ```APIDOC ## pynufft.src.re_subroutine.cMultiplyRealInplace ### Description Returns the kernel source of cMultiplyRealInplace. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### pynufft.linalg.solve_cpu.solve Source: https://pynufft.readthedocs.io/en/latest/API/init.html Solves the NUFFT problem using specified solvers on CPU. ```APIDOC ## pynufft.linalg.solve_cpu.solve ### Description Solves the NUFFT problem on CPU. Supports solvers like 'cg', 'L1TVOLS', or 'L1TVLAD'. ### Parameters * **nufft**: NUFFT_cpu object * **y**: (M,) array, non-uniform data * **solver**: Optional. Solver to use ('cg', 'L1TVOLS', 'L1TVLAD'). Defaults to None. * **args**: Additional arguments for the solver. * **kwargs**: Additional keyword arguments for the solver. ### Returns * **x**: The reconstructed image. ``` -------------------------------- ### QR_process() Source: https://pynufft.readthedocs.io/en/latest/index.html Processes QR decomposition or related operations. ```APIDOC ## QR_process() ### Description Handles the processing of QR decomposition or related matrix operations. ### Function `QR_process()` ``` -------------------------------- ### Multiprocessing NUFFT Execution Source: https://pynufft.readthedocs.io/en/latest/manu/multiple_NUFFT.html Demonstrates using `multiprocessing.Pool` to run NUFFT computations asynchronously across multiple processes. Results are collected and compared. ```python result = pool.apply_async(D.run, args = (x, (0,3))) # the result is appended results.append(result) # Now enter the second process # This is the standard multiprocessing Pool D = atomic_NUFFT(om2, Nd, Kd, Jd, 0) # Non-obstructive result = pool.apply_async(D.run, args = (x, (4,7))) results.append(result) # closing the pool pool.close() pool.join() # results are appended # Now print the outputs result1 = results[0].get() result2 = results[1].get() ``` -------------------------------- ### pynufft.src.re_subroutine.cMultiplyVecInplace Source: https://pynufft.readthedocs.io/en/latest/API/init.html Returns the kernel source of cMultiplyVecInplace. ```APIDOC ## pynufft.src.re_subroutine.cMultiplyVecInplace ### Description Returns the kernel source of cMultiplyVecInplace. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### cRealShrink() (Metaprogramming) Source: https://pynufft.readthedocs.io/en/latest/index.html Performs real shrinkage on complex numbers. ```APIDOC ## cRealShrink() (Metaprogramming) ### Description Applies real shrinkage to complex numbers. ### Function `cRealShrink()` ``` -------------------------------- ### Plan NUFFT on Device Source: https://pynufft.readthedocs.io/en/latest/API/init.html Plans the NUFFT object for device execution (e.g., GPU). This method is suitable for accelerated computations. ```python >>> import pynufft >>> device=pynufft.helper.device_list()[0] >>> NufftObj = pynufft.NUFFT(device) >>> NufftObj.plan(om, Nd, Kd, Jd) ``` -------------------------------- ### NUFFT.plan Source: https://pynufft.readthedocs.io/en/latest/API/init.html Plans the NUFFT object by setting up the necessary parameters for the transformation based on the provided geometry. ```APIDOC ## NUFFT.plan ### Description Plans the NUFFT object by setting up the necessary parameters for the transformation based on the provided geometry. ### Method plan ### Parameters #### Parameters - **om** (numpy.float array) - The M off-grid locations in the frequency domain, normalized between [-pi, pi]. Matrix size is M * ndims. - **Nd** (tuple of int) - The matrix size of the equispaced image. Example: Nd=(256,256) for a 2D image. - **Kd** (tuple of int) - The matrix size of the oversampled frequency grid. Example: Kd=(512,512) for a 2D image. - **Jd** (tuple of int) - The interpolator size. Example: Jd=(6,6) for a 2D image. - **ft_axes** (tuple of int, optional) - The axes for Fourier transform. Defaults to all axes if None. ### Returns - **int, float** - Returns 0 upon successful planning. ### Variables - **Nd** - Initial value: Nd - **Kd** - Initial value: Kd - **Jd** - Initial value: Jd - **ft_axes** - Initial value: None ### Example ```python >>> from pynufft import NUFFT >>> NufftObj = NUFFT() >>> NufftObj.plan(om, Nd, Kd, Jd) ``` or ```python >>> NufftObj.plan(om, Nd, Kd, Jd, ft_axes) ``` ``` -------------------------------- ### L1TVOLS() (CPU Solvers) Source: https://pynufft.readthedocs.io/en/latest/index.html CPU solver for L1 Total Variation optimization problems. ```APIDOC ## L1TVOLS() (CPU Solvers) ### Description Performs L1 Total Variation optimization using CPU. ### Function `L1TVOLS()` ``` -------------------------------- ### pynufft.src.re_subroutine.cMultiplyConjVecInplace Source: https://pynufft.readthedocs.io/en/latest/API/init.html Returns the kernel source of cMultiplyConjVecInplace. ```APIDOC ## pynufft.src.re_subroutine.cMultiplyConjVecInplace ### Description Returns the kernel source of cMultiplyConjVecInplace. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Plan NUFFT on CPU Source: https://pynufft.readthedocs.io/en/latest/API/init.html Plans the NUFFT object for CPU execution using specified geometry. Use this when targeting CPU computations. ```python >>> from pynufft import NUFFT >>> NufftObj = NUFFT() >>> NufftObj.plan(om, Nd, Kd, Jd) ``` ```python >>> NufftObj.plan(om, Nd, Kd, Jd, ft_axes) ``` -------------------------------- ### NUFFT_torch Source: https://pynufft.readthedocs.io/en/latest/index.html Documentation for the NUFFT_torch class, enabling NUFFT operations with PyTorch. ```APIDOC ## NUFFT_torch ### Description NUFFT implementation compatible with PyTorch. ### Class `NUFFT_torch` ``` -------------------------------- ### _pipe_density() (CPU Solvers) Source: https://pynufft.readthedocs.io/en/latest/index.html Internal function for processing density in CPU solvers. ```APIDOC ## _pipe_density() (CPU Solvers) ### Description Processes density information within the CPU solver pipeline. ### Function `_pipe_density()` ``` -------------------------------- ### Import NUFFT Module Source: https://pynufft.readthedocs.io/en/latest/_sources/tutor/example.rst.txt Import the NUFFT class from the pynufft library. ```python from pynufft import NUFFT ``` -------------------------------- ### cHypot() (Metaprogramming) Source: https://pynufft.readthedocs.io/en/latest/index.html Calculates the hypotenuse for complex numbers. ```APIDOC ## cHypot() (Metaprogramming) ### Description Calculates the hypotenuse (magnitude) for complex numbers. ### Function `cHypot()` ``` -------------------------------- ### solve() (CPU Solvers) Source: https://pynufft.readthedocs.io/en/latest/index.html The main solve function for CPU-based optimization problems. ```APIDOC ## solve() (CPU Solvers) ### Description Executes the solving process for optimization problems on the CPU. ### Function `solve()` ``` -------------------------------- ### Forward NUFFT (Legacy) Source: https://pynufft.readthedocs.io/en/latest/API/init.html Performs the forward Non-Uniform Fast Fourier Transform using legacy device support. ```APIDOC ## Forward NUFFT (Legacy) ### Description Performs the forward Non-Uniform Fast Fourier Transform using legacy device support. ### Method _forward_legacy ### Parameters - **gx** (reikna gpu array) - The input gpu array, with size = Nd. - Type: reikna gpu array with dtype = numpy.complex64 ### Returns - **gy**: The output gpu array, with size = (M,) ### Return Type - **reikna gpu array**: reikna gpu array with dtype = numpy.complex64 ```