# Specifying signature for jitclass method

**URL:** <https://numba.discourse.group/t/specifying-signature-for-jitclass-method/2244>\
**Category:** Support: How do I do ...?\
**Created:** [October 25, 2023, 11:00pm UTC](https://numba.discourse.group/t/specifying-signature-for-jitclass-method/2244 "2023-10-25T23:00:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Azmisov](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/azmisov/32/925_2.png) [@Azmisov](https://numba.discourse.group/u/Azmisov)\
**Post date:** [October 25, 2023, 11:00pm UTC](https://numba.discourse.group/t/specifying-signature-for-jitclass-method/2244/1 "2023-10-25T23:00:28Z")

</div>

Anyway to specify jitclass method signatures? For example:

```auto
@jitclass
class Test:
	number: float32

	def __init__ (self):
		self.number = np.float32(1293.341)

	def calc(self, n: uint64) -> float32:
		return n*self.number

TestType = as_numba_type(Test)

@njit(float32(TestType, uint64))
def Test_calc(self: TestType, n: uint64) -> float32:
	return n*self.number

t = Test()
# will succeed
print(Test_calc(t, 10))
print(Test_calc(t, 18446744073709551615))
# will fail
print(t.calc(10))
print(t.calc(18446744073709551615))

```

I’ve been thinking of just doing C-style “methods” instead, e.g. the Test\_calc function. Works, but not as clean obviously.

---

<div class="post-metadata">

**Author:** ![sschaer](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sschaer](https://numba.discourse.group/u/sschaer)\
**Post date:** [October 26, 2023, 11:27am UTC](https://numba.discourse.group/t/specifying-signature-for-jitclass-method/2244/2 "2023-10-26T11:27:44Z")

</div>

Numba’s default integer is `int64`. Your argument `18446744073709551615` is larger than the maximum value that can be represented. This is also what the error message tells you (kind of):

```auto
OverflowError Traceback (most recent call last)
g:\My Drive\Private\profile-tools\tests\_cy.ipynb Cell 1 line 2
     26 # will fail
     27 print(t.calc(10))
---> 28 print(t.calc(18446744073709551615))

OverflowError: int too big to convert

```

Simply pass the argument as an unsigned integer and it should work: `t.calc(np.uint64(18446744073709551615))`

`Test_calc` works because you define the signature and therefore Numba does the conversion for you. If you do not pass the signature you will observe the same issue.

---

<div class="post-metadata">

**Author:** ![Azmisov](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/azmisov/32/925_2.png) [@Azmisov](https://numba.discourse.group/u/Azmisov)\
**Post date:** [October 26, 2023, 11:30pm UTC](https://numba.discourse.group/t/specifying-signature-for-jitclass-method/2244/3 "2023-10-26T23:30:00Z")

</div>

Yeah I was aware of the numpy workaround. Though I was observing 10-50% overhead in converting all the arguments to numpy types in the interpreter. So was hoping to be able to specify signature for the jitclass method itself, like with Test\_calc

---

<div class="post-metadata">

**Author:** ![sschaer](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sschaer](https://numba.discourse.group/u/sschaer)\
**Post date:** [October 27, 2023, 6:31am UTC](https://numba.discourse.group/t/specifying-signature-for-jitclass-method/2244/4 "2023-10-27T06:31:25Z")

</div>

This conversion only needs to be done at the Python-Numba interface. If this has a significant impact on the runtime of your program, it suggests to me that there may be bigger design problems. Also keep in mind that you only need to do the explicit conversion to uint64 once. After the first call, the function is compiled and the conversion will be done for you. For example, the following works:

```auto
t = Test()
t.calc(nb.uint64(0))
t.calc(18446744073709551615)

```
