def main(): bm = Benchmark( datasets=[ Dataset( factories=[ lambda n: make_quat_dataset(n, dtype=np.float16), ], title='16bits', extra_args=dict( dtype=np.uint16 ) ), Dataset( factories=[ lambda n: make_quat_dataset(n, dtype=np.float32), ], title='32bits', extra_args=dict( dtype=np.uint32 ) ), Dataset( factories=[ lambda n: make_quat_dataset(n, dtype=np.float64), ], title='64bits', extra_args=dict( dtype=np.uint64 ) ) ], dataset_sizes=[2 ** n for n in range(25)], kernels=[ Kernel( stmt="quaternion.encode_quat_to_uint(DATASET, dtype=EXTRA_ARGS['dtype'], encoder=fp.encode_fp_to_std_snorm)", setup='from fpq import quaternion\nfrom fpq import fp', label='encode_quat_to_uint(std)' ), Kernel( stmt="quaternion.encode_quat_to_uint(DATASET, dtype=EXTRA_ARGS['dtype'], encoder=fp.encode_fp_to_ogl_snorm)", setup='from fpq import quaternion\nfrom fpq import fp', label='encode_quat_to_uint(ogl)' ), ], xlabel='dataset sizes', title='encode_quat_to_uint' ) bm.run() script_name, _ = os.path.splitext(os.path.basename(__file__)) bm.save_as_html(filepath=script_name + '.html')
def make_dataset(n, *, dtype): dataset = make_quat_dataset(n, dtype=dtype) max_abs_inds = fpq.utils.get_max_component_indices(np.absolute(dataset)) sign = np.sign(dataset[max_abs_inds]) rest_components = fpq.utils.remove_component(dataset, indices=max_abs_inds) rest_components *= sign[..., None] return rest_components.transpose()
def main(): dataset_size = 100000 src_dtype = np.float64 dst_dtype = np.uint64 dataset = make_quat_dataset(dataset_size, dtype=src_dtype) mt.trace( quaternion.encode_quat_to_uint, target_args=dict( q=dataset, dtype=dst_dtype, ), related_traces_output_mode=mt.RelatedTracesOutputMode.FOR_EACH_FILE, include_patterns={'*/fpq/*'}, exclude_patterns=None )
def make_dataset(n, *, src_dtype, dst_dtype, encoder): dataset = make_quat_dataset(n, dtype=src_dtype) return quaternion.encode_quat_to_uint(dataset, dtype=dst_dtype, encoder=encoder)