cumbof/hdlib

IndexError in running the 'What is the Dollar of Mexico?' example

Closed this issue · 2 comments

Hi, I was trying to follow the examples and initially noticed a missing import statement.

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[2], line 3
      1 # Collapse USA information into a single vector
      2 # USTATES = [(NAM * USA) + (CAP * WDC) + (MON * DOL)]
----> 3 ustates_nam = bind(space.get(names=["NAM"])[0], space.get(names=["USA"])[0]) # Bind NAM with USA
      4 ustates_cap = bind(space.get(names=["CAP"])[0], space.get(names=["WDC"])[0]) # Bind CAP with WDC
      5 ustates_mon = bind(space.get(names=["MON"])[0], space.get(names=["DOL"])[0]) # Bind MON with DOL

NameError: name 'bind' is not defined

Importing bind from arithmetic as follows does not solve it, as it leads to the following error.

from hdlib.arithmetic import bind
In [4]: # Collapse USA information into a single vector
   ...: # USTATES = [(NAM * USA) + (CAP * WDC) + (MON * DOL)]
   ...: ustates_nam = bind(space.get(names=["NAM"])[0], space.get(names=["USA"])[0]) # Bind NAM with USA
   ...: ustates_cap = bind(space.get(names=["CAP"])[0], space.get(names=["WDC"])[0]) # Bind CAP with WDC
   ...: ustates_mon = bind(space.get(names=["MON"])[0], space.get(names=["DOL"])[0]) # Bind MON with DOL
   ...: ustates = bundle(bundle(ustates_nam, ustates_cap), ustates_mon) # Bundle ustates_nam, ustates_cap, and ustates_mon
   ...: 
   ...: # Repeat the last step to encode MEX information in a single vector
   ...: # MEXICO = [(NAM * MEX) + (CAP * MXC) + (MON * PES)]
   ...: mexico_nam = bind(space.get(names=["NAM"])[0], space.get(names=["MEX"])[0]) # Bind NAM with MEX
   ...: mexico_cap = bind(space.get(names=["CAP"])[0], space.get(names=["MXC"])[0]) # Bind CAP with MXC
   ...: mexico_mon = bind(space.get(names=["MON"])[0], space.get(names=["PES"])[0]) # Bind MON with PES
   ...: mexico = bundle(bundle(mexico_nam, mexico_cap), mexico_mon) # Bundle mexico_nam, mexico_cap, and mexico_mon
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[4], line 5
      3 ustates_nam = bind(space.get(names=["NAM"])[0], space.get(names=["USA"])[0]) # Bind NAM with USA
      4 ustates_cap = bind(space.get(names=["CAP"])[0], space.get(names=["WDC"])[0]) # Bind CAP with WDC
----> 5 ustates_mon = bind(space.get(names=["MON"])[0], space.get(names=["DOL"])[0]) # Bind MON with DOL
      6 ustates = bundle(bundle(ustates_nam, ustates_cap), ustates_mon) # Bundle ustates_nam, ustates_cap, and ustates_mon
      8 # Repeat the last step to encode MEX information in a single vector
      9 # MEXICO = [(NAM * MEX) + (CAP * MXC) + (MON * PES)]

IndexError: list index out of range

There is a bind method in the space module as well. I am not sure if I used the right method/function. Could you update the example please? Thanks.

This issue is part of the openjournals/joss-reviews#5704 review.

cumbof commented

Thanks for reporting this issue @anilbey

I've just updated the documentation by importing bind and bundle from hdlib.arithmetic.
Also, the IndexError comes out because there are no vectors called DOL in the space (it must refer to USD actually). Btw, everything's fixed now.
I decided to maintain the vector's name as DOL to make it synced with the unit test in test/test.py.

Feel free to close this issue if the problem is solved.
Thanks!

Thanks @cumbof for the quick reply. It works now.