IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo function

maybe_null_pointer

def maybe_null_pointer[dtype: DType, //, present: Bool](ptr: Pointer[Scalar[dtype]]) -> NonNullPointer[dtype] if present else NullPointer[dtype]

Wraps ptr as a NonNullPointer when present, else drops it.

Lets a caller that knows at compile time whether an optional operand is supplied turn it into an OptionalPointer, so the kernels it reaches are specialized on the operand's presence rather than branching on null.

Parameters:

  • โ€‹dtype (DType): Element type of the pointed-to values (inferred).
  • โ€‹present (Bool): Whether ptr is a live operand.

Args:

Returns:

NonNullPointer[dtype] if present else NullPointer[dtype]: The OptionalPointer for ptr.

Was this page helpful?