Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, dtype=None, length=None, size=None, card=None, isSet=None, base=None, data=None):
super(SpiceCell, self).__init__()
self.dtype = dtype
self.length = length
self.size = size
self.card = card
self.isSet = isSet
self.adjust = 0 # Always False, because not implemented
self.init = 0 # Always False, because this is the constructor
self.base = base # void pointer
self.data = data
data = (c_int * size).from_buffer(base, 6 * BITSIZE['bool'])
super(Cell_Bool, self).__init__(4, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))
class Cell_Int(SpiceCell):
def __init__(self, size):
"""
Init a Int Spice Cell with a given size and length
:param size: number of elements
:type size: int
"""
base = (c_int * (6 + size))()
data = (c_int * size).from_buffer(base, 6 * BITSIZE['int'])
super(Cell_Int, self).__init__(2, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))
class Cell_Double(SpiceCell):
def __init__(self, size):
"""
Init a Double Spice Cell with a given size and length
:param size: number of elements
:type size: int
"""
base = (c_double * (6 + size))()
data = (c_double * size).from_buffer(base, 6 * BITSIZE['double'])
super(Cell_Double, self).__init__(1, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))
class Cell_Char(SpiceCell):
def __init__(self, size, length):
"""
Init a Char Spice Cell with a given size and length
return False
if not hasattr(other, '__iter__'):
return False
if isinstance(other, SpiceCell):
if other.dtype != self.dtype:
return False
if other.isSet != self.isSet:
return False
for x, y in zip(self, other):
if x != y:
return False
return True
# Spice Cell classes
class Cell_Time(SpiceCell):
def __init__(self, size):
"""
Init a Time Spice Cell with a given size and length
:param size: number of elements
:type size: int
"""
base = (c_int * (6 + size))()
data = (c_int * size).from_buffer(base, 6 * BITSIZE['time'])
super(Cell_Time, self).__init__(3, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))
class Cell_Bool(SpiceCell):
def __init__(self, size):
"""
Init a Bool Spice Cell with a given size and length
data = (c_int * size).from_buffer(base, 6 * BITSIZE['int'])
super(Cell_Int, self).__init__(2, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))
class Cell_Double(SpiceCell):
def __init__(self, size):
"""
Init a Double Spice Cell with a given size and length
:param size: number of elements
:type size: int
"""
base = (c_double * (6 + size))()
data = (c_double * size).from_buffer(base, 6 * BITSIZE['double'])
super(Cell_Double, self).__init__(1, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))
class Cell_Char(SpiceCell):
def __init__(self, size, length):
"""
Init a Char Spice Cell with a given size and length
:param size: number of elements
:type size: int
:param length: width of elements
:type length: int
"""
base = (c_char * ((6 + size) * length))()
data = (c_char * (size * length)).from_buffer(base, 6 * BITSIZE['char'] * length)
super(Cell_Char, self).__init__(0, length, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))
class Cell_Int(SpiceCell):
def __init__(self, size: int) -> None:
"""
Init a Int Spice Cell with a given size and length
:param size: number of elements
"""
base = (c_int * (6 + size))()
data = (c_int * size).from_buffer(base, 6 * BITSIZE["int"])
super(Cell_Int, self).__init__(
2, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)
)
class Cell_Double(SpiceCell):
def __init__(self, size: int) -> None:
"""
Init a Double Spice Cell with a given size and length
:param size: number of elements
"""
base = (c_double * (6 + size))()
data = (c_double * size).from_buffer(base, 6 * BITSIZE["double"])
super(Cell_Double, self).__init__(
1, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)
)
class Cell_Char(SpiceCell):
def __init__(self, size: int, length: int) -> None:
"""
Init a Char Spice Cell with a given size and length
def __eq__(self, other):
"""
element wise equality, other can be a list or cell
I think sets should not equal a non set even if
elements are equal... might be a bad idea
:param other:
:return:
"""
if not hasattr(other, "__iter__"):
return False
if len(self) != len(other):
return False
if isinstance(other, SpiceCell):
if other.dtype != self.dtype:
return False
if other.isSet != self.isSet:
return False
for x, y in zip(self, other):
if x != y:
return False
return True