Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriceSalvaire committed Jan 25, 2024
1 parent 4e14b33 commit 0e60528
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
33 changes: 0 additions & 33 deletions PySpice/Unit/Unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ class SiDerivedUnit:
##############################################

def __init__(self, string=None, powers=None):

if powers is not None:
self._powers = self.new_powers()
self._powers.update(powers)
Expand Down Expand Up @@ -393,7 +392,6 @@ def __new__(meta, class_name, base_classes, attributes):

@classmethod
def init_unit(meta, cls):

si_unit = cls.SI_UNIT
if not (isinstance(si_unit, SiDerivedUnit) and si_unit):
# si_unit is not defined
Expand All @@ -407,10 +405,8 @@ def init_unit(meta, cls):

@classmethod
def register_unit(meta, cls):

obj = cls()
meta._units[obj.unit_suffix] = obj

if obj.si_unit:
hash_ = obj.si_unit.hash
if hash_ in meta._hash_map:
Expand Down Expand Up @@ -440,13 +436,11 @@ def from_hash(meta, hash_):

@classmethod
def from_si_unit(meta, si_unit, unique=True):

# Fixme:
# - handle power of units
# unit -> numpy vector, divide and test for identical factor
# define unit, format as V^2
# - complex unit

units = meta._hash_map.get(si_unit.hash, None)
if unique and units is not None:
if len(units) > 1:
Expand Down Expand Up @@ -484,11 +478,9 @@ class Unit(metaclass=UnitMetaclass):
##############################################

def __init__(self, si_unit=None):

self._unit_name = self.UNIT_NAME
self._unit_suffix = self.UNIT_SUFFIX
self._quantity = self.QUANTITY

if si_unit is None:
self._si_unit = self.SI_UNIT
else:
Expand Down Expand Up @@ -559,7 +551,6 @@ def _equivalent_prefixed_unit(self, si_unit):
##############################################

def _equivalent_unit(self, si_unit):

equivalent_unit = UnitMetaclass.from_si_unit(si_unit)
if equivalent_unit is not None:
return equivalent_unit
Expand Down Expand Up @@ -705,7 +696,6 @@ def from_si_unit(cls, si_unit):

@classmethod
def from_prefixed_unit(cls, unit, power=0):

if unit.unit_suffix:
unit_key = str(unit)
else:
Expand All @@ -720,7 +710,6 @@ def from_prefixed_unit(cls, unit, power=0):
##############################################

def __init__(self, unit=None, power=None, value_ctor=None, values_ctor=None):

if unit is None:
self._unit = Unit()
else:
Expand Down Expand Up @@ -816,10 +805,8 @@ def str(self, spice=False, unit=True):
# Fixme: unit clash, e.g. mm ???

string = self._power.str(spice)

if unit:
string += str(self._unit)

if spice:
# F is interpreted as f = femto
if string == 'F':
Expand All @@ -832,7 +819,6 @@ def str(self, spice=False, unit=True):
# U+2109 ℉
string = string.replace('Ω', 'Ohm') # U+CEA0
string = string.replace('μ', 'u') # U+CEBC

return string

##############################################
Expand Down Expand Up @@ -875,9 +861,7 @@ def simple_value(cls, value):
##############################################

def __init__(self, prefixed_unit, value):

self._prefixed_unit = prefixed_unit

if isinstance(value, UnitValue):
# Fixme: anonymous ???
if not self.is_same_unit(value):
Expand Down Expand Up @@ -1129,9 +1113,7 @@ def __rmul__(self, other):
##############################################

def __floordiv__(self, other):

"""self // other """

if (isinstance(other, UnitValue)):
equivalent_unit = self.unit.divide(other.unit, True)
value = float(self) // float(other)
Expand Down Expand Up @@ -1167,9 +1149,7 @@ def __rfloordiv__(self, other):
##############################################

def __truediv__(self, other):

"""self / other"""

if (isinstance(other, UnitValue)):
equivalent_unit = self.unit.divide(other.unit, True)
value = float(self) / float(other)
Expand Down Expand Up @@ -1345,9 +1325,7 @@ def convert_to_power(self, power=0):
##############################################

def canonise(self):

# log10(10**n) = n log10(1) = 0 log10(10**-n) = -n log10(0) = -oo

try:
abs_value = abs(float(self))
log = math.log(abs_value)/math.log(1000)
Expand Down Expand Up @@ -1507,18 +1485,15 @@ class UnitValues(np.ndarray):

@classmethod
def from_ndarray(cls, array, prefixed_unit):

# cls._logger.debug('UnitValues.__new__ ' + str((cls, array, prefixed_unit)))

# obj = cls(prefixed_unit, array.shape, array.dtype) # Fixme: buffer ???
# obj[...] = array[...]

obj = array.view(UnitValues)
obj._prefixed_unit = prefixed_unit

if isinstance(array, UnitValues):
return array.convert(prefixed_unit)

return obj

##############################################
Expand All @@ -1534,9 +1509,7 @@ def __new__(cls,

obj = super(UnitValues, cls).__new__(cls, shape, dtype, buffer, offset, strides, order)
# obj = np.asarray(input_array).view(cls)

obj._prefixed_unit = prefixed_unit

return obj

##############################################
Expand Down Expand Up @@ -1724,9 +1697,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
##############################################

# def __array_wrap__(self, out_array, context=None):
#
# self._logger.debug('\n self={}\n out_array={}\n context={}'.format(self, out_array, context))
#
# return super(UnitValues, self).__array_wrap__(out_array, context)

##############################################
Expand All @@ -1741,9 +1712,7 @@ def as_ndarray(self, scale=False):
##############################################

def __getitem__(self, slice_):

value = super(UnitValues, self).__getitem__(slice_)

if isinstance(value, UnitValue): # slice
return value
else:
Expand All @@ -1752,14 +1721,12 @@ def __getitem__(self, slice_):
##############################################

def __setitem__(self, slice_, value):

if isinstance(value, UnitValue):
self._check_unit(value)
value = self._convert_value(value).value
elif isinstance(value, UnitValues):
self._check_unit(value)
value = self._convert_value(value)

super(UnitValues, self).__setitem__(slice_, value)

##############################################
Expand Down
6 changes: 0 additions & 6 deletions PySpice/Unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,23 @@ class UnitValueShorcut:
##############################################

def __init__(self, prefixed_unit):

self._prefixed_unit = prefixed_unit

##############################################

def _new_value(self, other):

return self._prefixed_unit.new_value(other)

##############################################

def __call__(self, other):

"""self(other)"""

return self._new_value(other)

##############################################

def __rmatmul__(self, other):

"""other @ self"""

return self._new_value(other)

####################################################################################################
Expand Down

0 comments on commit 0e60528

Please sign in to comment.