本文整理汇总了Python中warnings._warn函数的典型用法代码示例。如果您正苦于以下问题:Python _warn函数的具体用法?Python _warn怎么用?Python _warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _randbelow
def _randbelow(self, n, _log=_log, _int=int, _maxwidth=1<<BPF,
_Method=_MethodType, _BuiltinMethod=_BuiltinMethodType):
"""Return a random int in the range [0,n)
Handles the case where n has more bits than returned
by a single call to the underlying generator.
"""
try:
getrandbits = self.getrandbits
except AttributeError:
pass
else:
# Only call self.getrandbits if the original random() builtin method
# has not been overridden or if a new getrandbits() was supplied.
# This assures that the two methods correspond.
if type(self.random) is _BuiltinMethod or type(getrandbits) is _Method:
k = _int(1.00001 + _log(n-1, 2.0)) # 2**k > n-1 > 2**(k-2)
r = getrandbits(k)
while r >= n:
r = getrandbits(k)
return r
if n >= _maxwidth:
_warn("Underlying random() generator does not supply \n"
"enough bits to choose from a population range this large")
return _int(self.random() * n)
示例2: __eq__
def __eq__(self, other):
try:
r = isinstance(self, other)
_warn("Do not use == to check for event type. That is hacky. Use isinstance instead.")
return r
except TypeError:
return False
示例3: _randbelow
def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type,
Method=_MethodType, BuiltinMethod=_BuiltinMethodType):
"Return a random int in the range [0,n). Raises ValueError if n==0."
getrandbits = self.getrandbits
# Only call self.getrandbits if the original random() builtin method
# has not been overridden or if a new getrandbits() was supplied.
if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
k = n.bit_length() # don't use (n-1) here because n can be 1
r = getrandbits(k) # 0 <= r < 2**k
while r >= n:
r = getrandbits(k)
return r
# There's an overriden random() method but no new getrandbits() method,
# so we can only use random() from here.
random = self.random
if n >= maxsize:
_warn("Underlying random() generator does not supply \n"
"enough bits to choose from a population range this large.\n"
"To remove the range limitation, add a getrandbits() method.")
return int(random() * n)
rem = maxsize % n
limit = (maxsize - rem) / maxsize # int(limit * maxsize) % n == 0
r = random()
while r >= limit:
r = random()
return int(r*maxsize) % n
示例4: update
def update(self, *arg, **kw):
if arg:
if len(arg) > 1:
raise TypeError("at most one non-keyword argument permitted")
arg = arg[0]
if hasattr(arg, "keys"):
if not self.is_ordered(arg):
_warn(_WRNnoOrderArg, RuntimeWarning, stacklevel=2)
super(StableDict, self).update(arg)
ksl = self.__ksl
for k in arg.keys():
if k not in ksl:
ksl.append(k)
self.__ksl = ksl
else: # Must be a sequence of 2-tuples.
for pair in arg:
if len(pair) != 2:
raise ValueError("not a 2-tuple", pair)
self.__setitem__(pair[0], pair[1])
if kw:
# There have been additionial keyword arguments.
# Since Python passes them in an (unordered) dict
# we cannot possibly preserve their order (without
# inspecting the source or byte code of the call).
if len(kw) > 1:
_warn(_WRNnoOrderKW, RuntimeWarning, stacklevel=2)
super(StableDict, self).update(kw)
ksl = self.__ksl
for k in kw.iterkeys():
if k not in ksl:
ksl.append(k)
self.__ksl = ksl
示例5: _check_dtype_mistake
def _check_dtype_mistake(dtype):
"""
It's a very common mistake (at least for me) to pass-in a float64 when I
really want to pass in a `floatX`, and it would go unnoticed and slow-down
the computations a lot if I wouldn't check it here.
"""
if _np.issubdtype(dtype, _np.floating) and dtype != df.floatX:
_warn("Input array of floating-point dtype {} != df.floatX detected. Is this really what you want?".format(dtype))
示例6: evaluate
def evaluate(self):
df.Module.evaluate(self)
self.Winf.set_value(self.W.get_value() / _np.sqrt(self.buf_var.get_value() + self.eps))
self.binf.set_value(self.b.get_value() - self.Winf.get_value() * self.buf_mean.get_value())
# This check saved me from WTF'ing countless times!
if self.buf_count.get_value() == 0:
_warn("You're switching a BN-net to eval mode without having collected any statistics, that can't go well!")
示例7: __init__
def __init__(self, depth=0, stencil=0, antialiasing=0, major=2, minor=0, **kwargs):
self._sfContextSettings = _ffi.new('sfContextSettings*')
if antialiasing and not depth:
_warn("Antialiasing may not work if depth is not set")
self.depth_bits = depth
self.stencil_bits = stencil
self.antialiasing_level = antialiasing
self.major_version = major
self.minor_version = minor
if kwargs: self._set(**kwargs)
示例8: discontinued
def discontinued(_type, name, version, stack_level=2):
"""convenience func to warn about discontinued attributes
Arguments:
- _type should be one of class, method, function, argument
- name: the attributes name
- version: the version by which support for the old name will be
discontinued
- stack_level: as per warnings.warn"""
msg = "%s %s is discontinued, support will be stopped in version %s" % (_type, name, version)
_warn(msg, DeprecationWarning, stack_level)
示例9: deprecated
def deprecated(_type, old, new, version, stack_level=2):
"""a convenience function for deprecating classes, functions, arguments.
Arguments:
- _type should be one of class, method, function, argument
- old, new: the old and new names
- version: the version by which support for the old name will be
discontinued
- stack_level: as per warnings.warn"""
msg = "use %s %s instead of %s, support discontinued in version %s" % (_type, new, old, version)
_warn(msg, DeprecationWarning, stack_level)
示例10: pendingDeprecation
def pendingDeprecation(new_func):
"""
Raise `PendingDeprecationWarning` and display a message.
Uses inspect.stack() to determine the name of the item that this
is called from.
:param new_func: The name of the function that should be used instead.
:type new_func: string.
"""
warn_txt = "`{}` is pending deprecation. Please use `{}` instead."
_warn(warn_txt.format(inspect.stack()[1][3], new_func),
PlotPendingDeprecation)
示例11: deprecated
def deprecated(_type, old, new, version, stack_level=2):
"""a convenience function for deprecating classes, functions, arguments.
Arguments:
- _type should be one of class, method, function, argument
- old, new: the old and new names
- version: the version by which support for the old name will be
discontinued
- stack_level: as per warnings.warn"""
msg = "use %s %s instead of %s, support discontinued in version %s" % \
(_type, new, old, version)
# DeprecationWarnings are ignored by default in python 2.7, so temporarily
# force them to be handled.
with catch_warnings():
simplefilter("always")
_warn(msg, DeprecationWarning, stack_level)
示例12: _randbelow
def _randbelow(self, n, int=int, maxsize=1 << BPF, type=type, Method=_MethodType, BuiltinMethod=_BuiltinMethodType):
getrandbits = self.getrandbits
if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
k = n.bit_length()
r = getrandbits(k)
while r >= n:
r = getrandbits(k)
return r
random = self.random
if n >= maxsize:
_warn('Underlying random() generator does not supply \nenough bits to choose from a population range this large.\nTo remove the range limitation, add a getrandbits() method.')
return int(random()*n)
rem = maxsize % n
limit = (maxsize - rem)/maxsize
r = random()
while r >= limit:
r = random()
return int(r*maxsize) % n
示例13: _randbelow_without_getrandbits
def _randbelow_without_getrandbits(self, n, int=int, maxsize=1<<BPF):
"""Return a random int in the range [0,n). Raises ValueError if n==0.
The implementation does not use getrandbits, but only random.
"""
random = self.random
if n >= maxsize:
_warn("Underlying random() generator does not supply \n"
"enough bits to choose from a population range this large.\n"
"To remove the range limitation, add a getrandbits() method.")
return int(random() * n)
if n == 0:
raise ValueError("Boundary cannot be zero")
rem = maxsize % n
limit = (maxsize - rem) / maxsize # int(limit * maxsize) % n == 0
r = random()
while r >= limit:
r = random()
return int(r*maxsize) % n
示例14: __init__
def __init__(self, f=None, g=None, A=None, B=None, gamma=1.0, alpha=None, epsilon=None, *args, **kwargs):
super(ForwardBackward, self).__init__(*args, **kwargs)
if (A is None) == (f is None):
raise TypeError("must specify either A or f, but not both")
if A is None:
A = f.gradient
if (B is None) == (g is None):
raise TypeError("must specify either B or g, but not both")
if B is None:
B = g.gradient
if A.shape[0] is None:
assert B.shape[0] is not None
self.x = _np.zeros(B.shape[0])
elif B.shape[0] is None:
assert A.shape[0] is not None
self.x = _np.zeros(A.shape[0])
else:
assert A.shape[0] == B.shape[0]
self.x = _np.zeros(A.shape[0])
if not 0 < gamma < 2:
_warn("convergence is only guaranteed for 0 < gamma < 2")
if alpha is None:
if epsilon is not None:
if not 0 < epsilon < (9.0 - 4 * gamma) / (2.0 * gamma):
_warn("convergence is only guaranteed for 0 < epsilon < (9.0 - 4 * gamma) / (2.0 * gamma)")
alpha = 1 + (_np.sqrt(9.0 - 4 * gamma - 2 * epsilon * gamma) - 3) / gamma
else:
alpha = 0
else:
if not 0 <= alpha < 1:
_warn("convergence is only guaranteed for 0 <= alpha < 1")
if epsilon is not None:
_warn("ignoring epsilon since alpha is given")
self._A = A
self._B = B
self._tau = gamma / B.lipschitz
self._alpha = alpha
if self._alpha:
self._last_x = self.x
示例15: __new__
def __new__(cls, name, bases, dct):
newcls = super(cls, CallbackMeta).__new__(cls, name, bases, dct)
try:
argspec = _getargspec(dct["__init__"])
except (KeyError, TypeError):
pass
else:
args = argspec.args[1:]
if argspec.varargs:
_warn("varargs in %r" % cls)
if argspec.keywords:
_warn("keywords in %r" % cls)
for arg in args:
if arg in cls.registry:
_warn("ambiguous constructor argument %r in %r"
% (arg, cls))
else:
cls.registry[arg] = newcls
return newcls