Skip to content
Snippets Groups Projects
  • Tim Gates's avatar
    a56281af
    docs: fix a few simple typos · a56281af
    Tim Gates authored and Andreas Klöckner's avatar Andreas Klöckner committed
    There are small typos in:
    - aksetup_helper.py
    - doc/types.rst
    - examples/black-hole-accretion.py
    - pyopencl/__init__.py
    - pyopencl/cl/pyopencl-random123/array.h
    
    Fixes:
    - Should read `unconditional` rather than `uncondtional`.
    - Should read `transferring` rather than `transfering`.
    - Should read `recipes` rather than `recipies`.
    - Should read `preferred` rather than `prefered`.
    - Should read `corresponding` rather than `correpsonding`.
    - Should read `arrays` rather than `arrrays`.
    
    Closes #500
    a56281af
    History
    docs: fix a few simple typos
    Tim Gates authored and Andreas Klöckner's avatar Andreas Klöckner committed
    There are small typos in:
    - aksetup_helper.py
    - doc/types.rst
    - examples/black-hole-accretion.py
    - pyopencl/__init__.py
    - pyopencl/cl/pyopencl-random123/array.h
    
    Fixes:
    - Should read `unconditional` rather than `uncondtional`.
    - Should read `transferring` rather than `transfering`.
    - Should read `recipes` rather than `recipies`.
    - Should read `preferred` rather than `prefered`.
    - Should read `corresponding` rather than `correpsonding`.
    - Should read `arrays` rather than `arrrays`.
    
    Closes #500
types.rst 1.18 KiB

OpenCL Type Mapping

Scalar Types

For ease of use, a the cltypes module provides convenient mapping from OpenCL type names to their equivalent numpy types. This saves you from referring back to the OpenCL spec to see that a cl_long is 64 bit unsigned integer. Use the module as follows:

>>> import numpy as np
>>> import pyopencl as cl
>>> import pyopencl.cltypes
>>> cl_uint = cl.cltypes.uint(42)   # maps to numpy.uint32
>>> cl_long = cl.cltypes.long(1235) # maps to numpy.int64
>>> floats = np.empty((128,), dtype=cl.cltypes.float) # array of numpy.float32

Note

The OpenCL type bool does not have a corresponding :mod:`numpy` type defined here, because OpenCL does not specify the in-memory representation (or even the storage size) for this type.

Vector Types

The corresponding vector types are also made available in the same package, allowing you to easily create numpy arrays with the appropriate memory layout.

>>> import numpy as np
>>> array_of_float16 = np.empty((128,), dtype=cl.cltypes.float16) # array of float16