File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -44,10 +44,23 @@ def layout_type(self):
4444 return LayoutType ()
4545
4646
47- @numba .extending .typeof_impl .register (MultiVector )
48- def _typeof_MultiVector (val : MultiVector , c ) -> MultiVectorType :
49- val ._numba_type_ = MultiVectorType (dtype = val .value .dtype )
50- return val ._numba_type_
47+ # The docs say we should use register a function to determine the numba type
48+ # with `@numba.extending.typeof_impl.register(MultiVector)`, but this is way
49+ # too slow (https://github.com/numba/numba/issues/5839). Instead, we use the
50+ # undocumented `_numba_type_` attribute, and use our own cache. In future
51+ # this may need to be a weak cache, but for now the objects are tiny anyway.
52+ _cache = {}
53+
54+ @property
55+ def _numba_type_ (self ):
56+ dt = self .value .dtype
57+ try :
58+ return _cache [dt ]
59+ except KeyError :
60+ ret = _cache [dt ] = MultiVectorType (dtype = dt )
61+ return ret
62+
63+ MultiVector ._numba_type_ = _numba_type_
5164
5265
5366@numba .extending .register_model (MultiVectorType )
You can’t perform that action at this time.
0 commit comments