Skip to content

Commit

Permalink
perf: add a flag to turn off isinstance in TypeTracerArray._new (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski authored Mar 21, 2024
1 parent 7a4ec81 commit 1bf2c9f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/awkward/_nplikes/typetracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class TypeTracerArray(NDArrayOperatorsMixin, ArrayLike):
_dtype: numpy.dtype
_shape: tuple[ShapeItem, ...]

runtime_typechecks = True

def __new__(cls, *args, **kwargs):
raise TypeError(
"internal_error: the `TypeTracer` nplike's `TypeTracerArray` object should never be directly instantiated"
Expand All @@ -185,12 +187,13 @@ def _new(
self.form_key = form_key
self.report = report

if not isinstance(shape, tuple):
raise TypeError("typetracer shape must be a tuple")
if not all(isinstance(x, int) or x is unknown_length for x in shape):
raise TypeError("typetracer shape must be integers or unknown-length")
if not isinstance(dtype, np.dtype):
raise TypeError("typetracer dtype must be an instance of np.dtype")
if cls.runtime_typechecks:
if not isinstance(shape, tuple):
raise TypeError("typetracer shape must be a tuple")
if not all(isinstance(x, int) or x is unknown_length for x in shape):
raise TypeError("typetracer shape must be integers or unknown-length")
if not isinstance(dtype, np.dtype):
raise TypeError("typetracer dtype must be an instance of np.dtype")
self._shape = shape
self._dtype = dtype

Expand Down

0 comments on commit 1bf2c9f

Please sign in to comment.