How to use d_number method in fMBT

Best Python code snippet using fMBT_python

currency.py

Source:currency.py Github

copy

Full Screen

1import decimal2from decimal import localcontext3from typing import Union4from .types import is_integer, is_string5from .units import units6class denoms:7 von = int(units["von"])8 kvon = int(units["kvon"])9 kvon = int(units["kvon"])10 kvon = int(units["kvon"])11 mvon = int(units["mvon"])12 mvon = int(units["mvon"])13 mvon = int(units["mvon"])14 gvon = int(units["gvon"])15 gvon = int(units["gvon"])16 gvon = int(units["gvon"])17 gvon = int(units["gvon"])18 microlat = int(units["microlat"])19 microlat = int(units["microlat"])20 microlat = int(units["microlat"])21 millilat = int(units["millilat"])22 millilat = int(units["millilat"])23 millilat = int(units["millilat"])24 lat = int(units["lat"])25 klat = int(units["klat"])26 klat = int(units["klat"])27 mlat = int(units["mlat"])28 glat = int(units["glat"])29 tlat = int(units["tlat"])30MIN_VON = 031MAX_VON = 2 ** 256 - 132def from_von(number: int, unit: str) -> Union[int, decimal.Decimal]:33 """34 Takes a number of von and converts it to any other lat unit.35 """36 if unit.lower() not in units:37 raise ValueError(38 "Unknown unit. Must be one of {0}".format("/".join(units.keys()))39 )40 if number == 0:41 return 042 if number < MIN_VON or number > MAX_VON:43 raise ValueError("value must be between 1 and 2**256 - 1")44 unit_value = units[unit.lower()]45 with localcontext() as ctx:46 ctx.prec = 99947 d_number = decimal.Decimal(value=number, context=ctx)48 result_value = d_number / unit_value49 return result_value50def to_von(number: Union[int, float, str, decimal.Decimal], unit: str) -> int:51 """52 Takes a number of a unit and converts it to von.53 """54 if unit.lower() not in units:55 raise ValueError(56 "Unknown unit. Must be one of {0}".format("/".join(units.keys()))57 )58 if is_integer(number) or is_string(number):59 d_number = decimal.Decimal(value=number)60 elif isinstance(number, float):61 d_number = decimal.Decimal(value=str(number))62 elif isinstance(number, decimal.Decimal):63 d_number = number64 else:65 raise TypeError("Unsupported type. Must be one of integer, float, or string")66 s_number = str(number)67 unit_value = units[unit.lower()]68 if d_number == decimal.Decimal(0):69 return 070 if d_number < 1 and "." in s_number:71 with localcontext() as ctx:72 multiplier = len(s_number) - s_number.index(".") - 173 ctx.prec = multiplier74 d_number = decimal.Decimal(value=number, context=ctx) * 10 ** multiplier75 unit_value /= 10 ** multiplier76 with localcontext() as ctx:77 ctx.prec = 99978 result_value = decimal.Decimal(value=d_number, context=ctx) * unit_value79 if result_value < MIN_VON or result_value > MAX_VON:80 raise ValueError("Resulting von value must be between 1 and 2**256 - 1")...

Full Screen

Full Screen

plotting_backend.py

Source:plotting_backend.py Github

copy

Full Screen

1"""An example of how to use IPython for plotting remote parallel data2The two files plotting_frontend.py and plotting_backend.py go together.3This file (plotting_backend.py) performs the actual computation. For this4example, the computation just generates a set of random numbers that5look like a distribution of particles with 2D position (x,y) and6momentum (px,py). In a real situation, this file would do some time7consuming and complicated calculation, and could possibly make calls8to MPI.9One important feature is that this script can also be run standalone without10IPython. This is nice as it allows it to be run in more traditional11settings where IPython isn't being used.12When used with IPython.parallel, this code is run on the engines. Because this13code doesn't make any plots, the engines don't have to have any plotting14packages installed.15"""16from __future__ import print_function17# Imports18import numpy as N19import time20import random21# Functions22def compute_particles(number):23 x = N.random.standard_normal(number)24 y = N.random.standard_normal(number)25 px = N.random.standard_normal(number)26 py = N.random.standard_normal(number)27 return x, y, px, py28def downsample(array, k):29 """Choose k random elements of array."""30 length = array.shape[0]31 indices = random.sample(xrange(length), k)32 return array[indices]33# Parameters of the run34number = 10000035d_number = 100036# The actual run37time.sleep(0) # Pretend it took a while38x, y, px, py = compute_particles(number)39# Now downsample the data40downx = downsample(x, d_number)41downy = downsample(x, d_number)42downpx = downsample(px, d_number)43downpy = downsample(py, d_number)44print("downx: ", downx[:10])45print("downy: ", downy[:10])46print("downpx: ", downpx[:10])...

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 fMBT 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