Skip to content

Instantly share code, notes, and snippets.

@gmarkall
Created January 6, 2023 19:40
Show Gist options
  • Save gmarkall/719a6146d883957ea1ab18858c5d32cb to your computer and use it in GitHub Desktop.
Save gmarkall/719a6146d883957ea1ab18858c5d32cb to your computer and use it in GitHub Desktop.
Demonstration of using a Numba target context to get the LLVM type for a Numba type
from numba import float64
from numba.core import typing, cpu
# Create a Numba type - a 1D C-ordered array of float64
numba_arr_type = float64[::1]
print("Numba type:", numba_arr_type)
# Construct a Numba target context for the CPU and use it to get the LLVM type
# for the given Numba type in that context
typingctx = typing.Context()
targetctx = cpu.CPUContext(typingctx, target='cpu')
llvm_arr_type = targetctx.get_value_type(numba_arr_type)
print("LLVM type: ", llvm_arr_type)
# Output:
# Numba type: array(float64, 1d, C)
# LLVM type: {i8*, i8*, i64, i64, double*, [1 x i64], [1 x i64]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment