How to use _get_precision method in pytest-benchmark

Best Python code snippet using pytest-benchmark

box.py

Source:box.py Github

copy

Full Screen

...26 assert np.isscalar(low) and np.isscalar(high), 'box requires scalar bounds. '27 self.shape = tuple(shape)28 self.low = np.full(self.shape, low, dtype=dtype)29 self.high = np.full(self.shape, high, dtype=dtype)30 def _get_precision(dtype):31 if np.issubdtype(dtype, np.floating):32 return np.finfo(dtype).precision33 else:34 return np.inf35 low_precision = _get_precision(self.low.dtype)36 high_precision = _get_precision(self.high.dtype)37 dtype_precision = _get_precision(self.dtype)38 if min(low_precision, high_precision) > dtype_precision:39 logger.warn("Box bound precision lowered by casting to {}".format(self.dtype))40 self.low = self.low.astype(self.dtype)41 self.high = self.high.astype(self.dtype)42 # Boolean arrays which indicate the interval type for each coordinate43 self.bounded_below = -np.inf < self.low44 self.bounded_above = np.inf > self.high45 super(Box, self).__init__(self.shape, self.dtype)46 def is_bounded(self, manner="both"):47 below = np.all(self.bounded_below)48 above = np.all(self.bounded_above)49 if manner == "both":50 return below and above51 elif manner == "below":...

Full Screen

Full Screen

writer.py

Source:writer.py Github

copy

Full Screen

...6 def _get_normalized_fraction(fraction, precision):7 max_number = 2 ** (8 * precision)8 return int(fraction * max_number)9 @staticmethod10 def _get_precision(number):11 return math.ceil(math.log2(number + 1) / 8)12 def _write_int(self, number_int, precision):13 number_bytes = number_int.to_bytes(precision, byteorder='big')14 self.file.write(number_bytes)15 def _write_symbols(self, symbols_ranges):16 symbol_count = len(symbols_ranges)17 self._write_int(symbol_count - 1, 1)18 for symbol in symbols_ranges.keys():19 self._write_int(symbol, 1)20 def _write_ranges_start(self, symbols_dict):21 ranges_start = [x[0] for x in symbols_dict.values()]22 symbol_range_precision = self._get_precision((1 - ranges_start[-1]).denominator)23 self._write_int(symbol_range_precision, 1)24 for range_start in ranges_start:25 range_start_normalized = self._get_normalized_fraction(range_start, symbol_range_precision)26 self._write_int(range_start_normalized, symbol_range_precision)27 def _write_content_length(self, content_length):28 content_length_precision = self._get_precision(content_length)29 self._write_int(content_length_precision, 1)30 self._write_int(content_length, content_length_precision)31 def _write_content_fraction(self, content_fraction):32 numerator = content_fraction.numerator33 numerator_precision = self._get_precision(numerator) + 134 numerator_precision_precision = self._get_precision(numerator_precision)35 numerator_normalized = self._get_normalized_fraction(content_fraction, numerator_precision)36 self._write_int(numerator_precision_precision, 1)37 self._write_int(numerator_precision, numerator_precision_precision)38 self._write_int(numerator_normalized, numerator_precision)39 def write(self, content_fraction, content_length, symbols_dict):40 self._write_symbols(symbols_dict)41 self._write_ranges_start(symbols_dict)42 self._write_content_length(content_length)43 self._write_content_fraction(content_fraction)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful