Skip to content

Commit

Permalink
Fix type casting from/to array types
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrieleMessina authored Aug 19, 2024
1 parent abce8a1 commit 1b7044b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/symbols/types/type_casting_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def promote_value_to_type(self, var_value : any, from_type:'QutesDataType', to_t
return int(''.join([str(int(value)) for value in var_value]), 2)
return float(var_value)
case QutesDataType.string:
if isinstance(var_value, list):
return str(''.join([str(int(value)) for value in var_value]))
return str(var_value)
case QutesDataType.qubit:
return Qubit.fromValue(var_value)
Expand Down Expand Up @@ -112,10 +114,16 @@ def down_cast_value_to_type(self, var_value : any, from_type:'QutesDataType', to
case QutesDataType.bool:
return bool(int(from_type_value))
case QutesDataType.int:
return int(from_type_value)
if isinstance(from_type_value, list):
return int(''.join([str(int(value)) for value in from_type_value]), 2)
return int(from_type_value)
case QutesDataType.float:
if isinstance(from_type_value, list):
return int(''.join([str(int(value)) for value in from_type_value]), 2)
return float(from_type_value)
case QutesDataType.string:
if isinstance(from_type_value, list):
return str(''.join([str(int(value)) for value in from_type_value]))
return str(from_type_value)
case QutesDataType.qubit:
return Qubit.fromValue(var_value)
Expand Down

0 comments on commit 1b7044b

Please sign in to comment.