Python builtins.max() Examples
The following are 25
code examples of builtins.max().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
builtins
, or try the search function
.
Example #1
Source File: core.py From mars with Apache License 2.0 | 6 votes |
def _tree_reduction(cls, tensor, axis): op = tensor.op kw = getattr(op, '_get_op_kw')() or {} keepdims = op.keepdims combine_size = op.combine_size or options.combine_size if isinstance(combine_size, dict): combine_size = dict((ax, combine_size.get(ax)) for ax in axis) else: assert isinstance(combine_size, int) n = builtins.max(int(combine_size ** (1.0 / (len(axis) or 1))), 2) combine_size = dict((ax, n) for ax in axis) times = 1 for i, n in enumerate(tensor.chunk_shape): if i in combine_size and combine_size[i] != 1: times = int(builtins.max(times, ceil(log(n, combine_size[i])))) for i in range(times - 1): [tensor] = cls._partial_reduction(tensor, axis, op.dtype, True, combine_size, OperandStage.combine) return cls._partial_reduction(tensor, axis, op.dtype, keepdims, combine_size, OperandStage.agg, kw)
Example #2
Source File: tensor.py From dgl with Apache License 2.0 | 6 votes |
def pad_packed_tensor(input, lengths, value, l_min=None): old_shape = input.shape if isinstance(lengths, th.Tensor): max_len = as_scalar(lengths.max()) else: max_len = builtins.max(lengths) if l_min is not None: max_len = builtins.max(max_len, l_min) batch_size = len(lengths) device = input.device x = input.new(batch_size * max_len, *old_shape[1:]) x.fill_(value) index = [] for i, l in enumerate(lengths): index.extend(range(i * max_len, i * max_len + l)) index = th.tensor(index).to(device) return scatter_row(x, index, input).view(batch_size, max_len, *old_shape[1:])
Example #3
Source File: tensor.py From dgl with Apache License 2.0 | 6 votes |
def pad_packed_tensor(input, lengths, value, l_min=None): old_shape = input.shape if isinstance(lengths, tf.Tensor): max_len = as_scalar(lengths.max()) else: max_len = builtins.max(lengths) if l_min is not None: max_len = builtins.max(max_len, l_min) batch_size = len(lengths) ndim = input.ndim tensor_list = [] cum_row = 0 pad_nparray = np.zeros((ndim, 2), dtype=np.int32) for l in lengths: t = input[cum_row:cum_row+l] pad_nparray[0, 1] = max_len - l t = tf.pad(t, tf.constant(pad_nparray), mode='CONSTANT', constant_values=value) tensor_list.append(t) cum_row += l return tf.stack(tensor_list, axis=0)
Example #4
Source File: cluster_monitor.py From KubeOperator with Apache License 2.0 | 5 votes |
def sync_node_time(cluster): hosts = C_Host.objects.filter( Q(project_id=cluster.id) & ~Q(name='localhost') & ~Q(name='127.0.0.1') & ~Q(name='::1')) data = [] times = [] result = { 'success': True, 'data': [] } for host in hosts: ssh_config = SshConfig(host=host.ip, port=host.port, username=host.username, password=host.password, private_key=None) ssh_client = SSHClient(ssh_config) res = ssh_client.run_cmd('date') gmt_date = res[0] GMT_FORMAT = '%a %b %d %H:%M:%S CST %Y' date = time.strptime(gmt_date, GMT_FORMAT) timeStamp = int(time.mktime(date)) times.append(timeStamp) show_time = time.strftime('%Y-%m-%d %H:%M:%S', date) time_data = { 'hostname': host.name, 'date': show_time, } data.append(time_data) result['data'] = data max = builtins.max(times) min = builtins.min(times) # 如果最大值减最小值超过5分钟 则判断有错 if (max - min) > 300000: result['success'] = False return result
Example #5
Source File: new_min_max.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def newmax(*args, **kwargs): return new_min_max(_builtin_max, *args, **kwargs)
Example #6
Source File: new_min_max.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def newmax(*args, **kwargs): return new_min_max(_builtin_max, *args, **kwargs)
Example #7
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def _get_smart_fold_pos(line, start, end): linelen = end - start ispace = line.rfind(' ', start, end) # The space we waste for smart folding should be max. 1/3rd of the line if ispace != -1 and ispace >= start + (2 * linelen) // 3: return ispace return end
Example #8
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def _postprocess_eval_line(self, evalline, fname, span): lines = evalline.split('\n') # If line ended on '\n', last element is ''. We remove it and # add the trailing newline later manually. trailing_newline = (lines[-1] == '') if trailing_newline: del lines[-1] lnum = linenumdir(span[0], fname) if self._linenums else '' clnum = lnum if self._contlinenums else '' linenumsep = '\n' + lnum clinenumsep = '\n' + clnum foldedlines = [self._foldline(line) for line in lines] outlines = [clinenumsep.join(lines) for lines in foldedlines] result = linenumsep.join(outlines) # Add missing trailing newline if trailing_newline: trailing = '\n' if self._linenums: # Last line was folded, but no linenums were generated for # the continuation lines -> current line position is not # in sync with the one calculated from the last line number unsync = ( len(foldedlines) and len(foldedlines[-1]) > 1 and not self._contlinenums) # Eval directive in source consists of more than one line multiline = span[1] - span[0] > 1 if unsync or multiline: # For inline eval directives span[0] == span[1] # -> next line is span[0] + 1 and not span[1] as for # line eval directives nextline = max(span[1], span[0] + 1) trailing += linenumdir(nextline, fname) else: trailing = '' return result + trailing
Example #9
Source File: stats.py From Turing with MIT License | 5 votes |
def max_index(args): return args.index(builtins.max(args))
Example #10
Source File: stats.py From Turing with MIT License | 5 votes |
def max(args): return builtins.max(args)
Example #11
Source File: sanity.py From reframe with BSD 3-Clause "New" or "Revised" License | 5 votes |
def max(*args): '''Replacement for the built-in :func:`max() <python:max>` function.''' return builtins.max(*args)
Example #12
Source File: max.py From pyramda with MIT License | 5 votes |
def max(xs): return builtins.max(xs)
Example #13
Source File: new_min_max.py From addon with GNU General Public License v3.0 | 5 votes |
def newmax(*args, **kwargs): return new_min_max(_builtin_max, *args, **kwargs)
Example #14
Source File: _multimethods.py From unumpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _ptp_default(a, axis=None, out=None, keepdims=False): result = max(a, axis=axis, out=out, keepdims=keepdims) result -= min(a, axis=axis, out=None, keepdims=keepdims) return result
Example #15
Source File: _multimethods.py From unumpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def max(a, axis=None, out=None, keepdims=False): return (a, mark_non_coercible(out))
Example #16
Source File: _intbv.py From myhdl with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self, val=0, min=None, max=None, _nrbits=0): if _nrbits: self._min = 0 self._max = 2**_nrbits else: self._min = min self._max = max if max is not None and min is not None: if min >= 0: _nrbits = len(bin(max - 1)) elif max <= 1: _nrbits = len(bin(min)) else: # make sure there is a leading zero bit in positive numbers _nrbits = builtins.max(len(bin(max - 1)) + 1, len(bin(min))) if isinstance(val, int): self._val = val elif isinstance(val, str): mval = val.replace('_', '') self._val = int(mval, 2) _nrbits = len(mval) elif isinstance(val, intbv): self._val = val._val self._min = val._min self._max = val._max _nrbits = val._nrbits else: raise TypeError("intbv constructor arg should be int or string") self._nrbits = _nrbits self._handleBounds() # support for the 'min' and 'max' attribute
Example #17
Source File: tensor.py From dgl with Apache License 2.0 | 5 votes |
def max(input, dim): return tf.reduce_max(input, axis=dim)
Example #18
Source File: tensor.py From dgl with Apache License 2.0 | 5 votes |
def reduce_max(input): return input.max()
Example #19
Source File: tensor.py From dgl with Apache License 2.0 | 5 votes |
def max(input, dim): return nd.max(input, axis=dim)
Example #20
Source File: tensor.py From dgl with Apache License 2.0 | 5 votes |
def reduce_max(input): return input.max()
Example #21
Source File: tensor.py From dgl with Apache License 2.0 | 5 votes |
def max(input, dim): # NOTE: the second argmax array is not returned return th.max(input, dim=dim)[0]
Example #22
Source File: _intbv.py From myhdl with GNU Lesser General Public License v2.1 | 5 votes |
def _hasFullRange(self): min, max = self._min, self._max if max <= 0: return False if min not in (0, -max): return False return max & max - 1 == 0 # hash
Example #23
Source File: _intbv.py From myhdl with GNU Lesser General Public License v2.1 | 5 votes |
def max(self): return self._max
Example #24
Source File: _multimethods.py From unumpy with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _block_default(arrays): import unumpy as np rec = _Recurser(recurse_if=lambda x: type(x) is list) list_ndim = None any_empty = False for index, value, entering in rec.walk(arrays): if type(value) is tuple: # not strictly necessary, but saves us from: # - more than one way to do things - no point treating tuples like # lists # - horribly confusing behaviour that results when tuples are # treated like ndarray raise TypeError( "{} is a tuple. " "Only lists can be used to arrange blocks, and np.block does " "not allow implicit conversion from tuple to ndarray.".format(index) ) if not entering: curr_depth = len(index) elif len(value) == 0: curr_depth = len(index) + 1 any_empty = True else: continue if list_ndim is not None and list_ndim != curr_depth: raise ValueError( "List depths are mismatched. First element was at depth {}, " "but there is an element at depth {} ({})".format( list_ndim, curr_depth, index ) ) list_ndim = curr_depth # convert all the arrays to ndarrays arrays = rec.map_reduce(arrays, f_map=asarray, f_reduce=list) elem_ndim = rec.map_reduce( arrays, f_map=lambda xi: np.ndim(xi), f_reduce=builtins.max ) ndim = builtins.max(list_ndim, elem_ndim) first_axis = ndim - list_ndim arrays = rec.map_reduce( arrays, f_map=lambda xi: _atleast_xd(xi, ndim), f_reduce=list ) return rec.map_reduce( arrays, f_reduce=lambda xs, axis: concatenate(list(xs), axis=axis - 1), f_kwargs=lambda axis: dict(axis=axis + 1), axis=first_axis, )
Example #25
Source File: _intbv.py From myhdl with GNU Lesser General Public License v2.1 | 4 votes |
def signed(self): ''' Return new intbv with the values interpreted as signed The intbv.signed() function will classify the value of the intbv instance either as signed or unsigned. If the value is classified as signed it will be returned unchanged as integer value. If the value is considered unsigned, the bits as specified by _nrbits will be considered as 2's complement number and returned. This feature will allow to create slices and have the sliced bits be considered a 2's complement number. The classification is based on the following possible combinations of the min and max value. ----+----+----+----+----+----+----+---- -3 -2 -1 0 1 2 3 1 min max 2 min max 3 min max 4 min max 5 min max 6 min max 7 min max 8 neither min nor max is set 9 only max is set 10 only min is set From the above cases, # 1 and 2 are considered unsigned and the signed() function will convert the value to a signed number. Decision about the sign will be done based on the msb. The msb is based on the _nrbits value. So the test will be if min >= 0 and _nrbits > 0. Then the instance is considered unsigned and the value is returned as 2's complement number. ''' # value is considered unsigned if self.min is not None and self.min >= 0 and self._nrbits: # get 2's complement value of bits msb = self._nrbits - 1 sign = ((self._val >> msb) & 0x1) > 0 # mask off the bits msb-1:lsb, they are always positive mask = (1 << msb) - 1 retVal = self._val & mask # if sign bit is set, subtract the value of the sign bit if sign: retVal -= 1 << msb else: # value is returned just as is retVal = self._val if self._nrbits: M = 2**(self._nrbits - 1) return intbv(retVal, min=-M, max=M) else: return intbv(retVal)