lava
lava copied to clipboard
Variable Int not preserved as type Int in get/set Var but automatically converted to float
Discussed in https://github.com/lava-nc/lava/discussions/261
Originally posted by waltergallegog June 28, 2022
I'm trying to access the value of a Var of type int, using the get() method. However, the type I'm getting is float.
Is this expected?
How can I get the value without it being converted to float?.
Here is the relevant snips of my code. The var I want to access is in_data
# Minimal process with an InPort
class P2(AbstractProcess):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.inp = InPort(shape=(1,))
self.in_data = Var(shape=(1,), init=0)
# A minimal PyProcModel implementing P2
@implements(proc=P2, protocol=LoihiProtocol)
@requires(CPU)
@tag('floating_pt')
class PyProcModelB(PyLoihiProcessModel):
inp : PyInPort = LavaPyType(PyInPort.VEC_DENSE, int)
in_data: int = LavaPyType(int, int)
def run_spk(self):
self.in_data = self.inp.recv()
dummy = self.in_data[0]
print(f"Received input data in P2: {dummy}")
print(f"Received input type in P2: {type(dummy)}")
# main
sender = P1()
recv = P2()
sender.run(RunSteps(num_steps=1), Loihi1SimCfg())
recv_data = recv.in_data.get()[0]
Here you can get the full script: https://github.com/waltergallegog/code-sharing/blob/master/lava/discussions/get_int.py
When running it I obtain int64 type inside the process, but float64 from the main:
Received input data in P2: 5
Received input type in P2: <class 'numpy.int64'>
Received input data in main: 5.0
Received input type in main: <class 'numpy.float64'>
I believe we cast the payload to float when using get/set.