Skip to content

Commit

Permalink
instance check for ABC real seems to be slow. See if removing that im…
Browse files Browse the repository at this point in the history
…proves performance.
  • Loading branch information
jagerber48 committed Dec 28, 2024
1 parent 7aeeed0 commit ddf2e1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions uncertainties/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from builtins import str, zip, range, object
from math import isnan, sqrt # Optimization: no attribute look-up
from numbers import Real
from typing import Optional, Union

from uncertainties.formatting import format_ufloat
Expand Down Expand Up @@ -286,7 +285,7 @@ class UFloat(object):
def __init__(
self,
nominal_value: float,
uncertainty: Union[UCombo, Real],
uncertainty: Union[UCombo, float],
tag: Optional[str] = None,
):
"""
Expand All @@ -302,7 +301,7 @@ def __init__(
float such that a new UCombo and UAtom is generated.
"""
self._nominal_value = float(nominal_value)
if isinstance(uncertainty, Real):
if isinstance(uncertainty, float):
if not isnan(uncertainty) and uncertainty < 0:
raise NegativeStdDev("The standard deviation cannot be negative")
if uncertainty == 0:
Expand Down
7 changes: 3 additions & 4 deletions uncertainties/ucombo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from collections import defaultdict
from math import sqrt
from numbers import Real
from typing import Optional, Tuple, Union
import uuid

Expand Down Expand Up @@ -92,14 +91,14 @@ def __add__(self: UCombo, other) -> UCombo:
def __radd__(self: UCombo, other: UCombo) -> UCombo:
return self.__add__(other)

def __mul__(self: UCombo, scalar: Real) -> UCombo:
if not isinstance(scalar, Real):
def __mul__(self: UCombo, scalar: float) -> UCombo:
if not isinstance(scalar, float):
return NotImplemented
if scalar == 0 or not self:
return UCombo(())
return UCombo(((self, float(scalar)),))

def __rmul__(self: UCombo, scalar: Real) -> UCombo:
def __rmul__(self: UCombo, scalar: float) -> UCombo:
return self.__mul__(scalar)

def __iter__(self: UCombo):
Expand Down

0 comments on commit ddf2e1d

Please sign in to comment.