You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
... the Stack class can only be instantiated to a single element type (in the example, an int).
It would be nice to be able to re-use the stack class for multiple element types:
Something like this:
IntStackClass = Stack(elemtype=int) # A template class is function (type params ...)->class
IntStackClass = Stack.instantiate(elemtype=int)
IntStackClass = numba.instantiate_types(StackTemplate, elemtype=int )
...
IntStackClass().push(1)
We can already do this by wrapping the creation of the stack class in a function who's parameter is elemtype. However, this isn't particularly nice since:
it makes the Stack class undocumented when its defined within a function
is rather inefficient since we're creating a Stack class object over and over for each call and additional memoization is required to prevent this,
Perhaps:
@jitclass_template(
template_type=("elemtype"),
spec=( ("head": deferred_type()),
("size": numba.intp),
)
class Stack(object)
def __init__():
self.head = None
self.size=0
def push():
if self.head is None:
self.head = LinkedNode(Stack.elemtype)() # Template instantiation reduce to LinkedNode#<elemtype>()
...
The text was updated successfully, but these errors were encountered:
Feature request
Currently, I don't think its possible to have a template jitclass. For example, in the
https://github.com/numba/numba/blob/master/examples/stack.py
... the Stack class can only be instantiated to a single element type (in the example, an int).
It would be nice to be able to re-use the stack class for multiple element types:
Something like this:
We can already do this by wrapping the creation of the stack class in a function who's parameter is elemtype. However, this isn't particularly nice since:
Perhaps:
The text was updated successfully, but these errors were encountered: