bmi

028 程序的控制结构小结

放肆的年华 提交于 2020-03-13 11:56:51
目录 一、数字类型及操作 二、字符串类型及操作 三、程序的分支结构 四、程序的循环结构 一、数字类型及操作 整数类型的无限范围及4种进制表示 浮点数类型的近似无限范围、小尾数及科学计数法 +、-、*、/、//、%、**、二元增强赋值操作符 abs()、divmod()、pow()、round()、max()、min() int()、float()、complex() # DayDayUpQ3.py dayup = 1.0 dayfactor = 0.01 for i in range(365): if i % 7 in [6, 0]: dayup = dayup * (1 - dayfactor) else: dayup = dayup * (1 + dayfactor) print("工作日的力量:{:.2f} ".format(dayup)) # 工作日的力量:4.63 工作日的力量:4.63 def dayUP(df): dayup = 1 for i in range(365): if i % 7 in [6, 0]: dayup = dayup * (1 - 0.01) else: dayup = dayup * (1 + df) return dayup dayfactor = 0.01 while dayUP(dayfactor) < 37.78: dayfactor

BMI for generating masks with AVX512

一世执手 提交于 2020-02-15 07:41:03
问题 I was inspired by this link https://www.sigarch.org/simd-instructions-considered-harmful/ to look into how AVX512 performs. My idea was that the clean up loop after the loop could be removed using the AVX512 mask operations. Here is the code I am using void daxpy2(int n, double a, const double x[], double y[]) { __m512d av = _mm512_set1_pd(a); int r = n&7, n2 = n - r; for(int i=-n2; i<0; i+=8) { __m512d yv = _mm512_loadu_pd(&y[i+n2]); __m512d xv = _mm512_loadu_pd(&x[i+n2]); yv = _mm512_fmadd

BMI for generating masks with AVX512

非 Y 不嫁゛ 提交于 2020-02-15 07:39:20
问题 I was inspired by this link https://www.sigarch.org/simd-instructions-considered-harmful/ to look into how AVX512 performs. My idea was that the clean up loop after the loop could be removed using the AVX512 mask operations. Here is the code I am using void daxpy2(int n, double a, const double x[], double y[]) { __m512d av = _mm512_set1_pd(a); int r = n&7, n2 = n - r; for(int i=-n2; i<0; i+=8) { __m512d yv = _mm512_loadu_pd(&y[i+n2]); __m512d xv = _mm512_loadu_pd(&x[i+n2]); yv = _mm512_fmadd

python的函数

旧巷老猫 提交于 2020-01-21 03:11:06
#函数 def fun_bmi(name,height,weight): '''根据身高体重计算BMI指数 name: 姓名 ''' print(name + "的身高:"+ str(height) + "米 \t 体重为:"+ str(weight) + "千克") bmi = weight / (height * height) print(name + "的BMI的指数为:" +str(bmi)) if bmi < 18.5: print("您的体重过轻") if bmi >= 18.5 and bmi < 24.9: print("您的体重属于正常范围") if bmi >= 24.9: print("您要减肥了") return name,height,weight,bmi #return不管在函数的什么位置,只要执行就会结束函数 a = fun_bmi("thea",1.65,55) #调用函数 print(type(a),a) #函数的返回值保存是一个元组 def func(): #空语句,占位作用 ... #形参设置默认值,默认参数必须指向不可变对象 def demo(obj = []): print("obj的值为:",obj) obj.append(3) demo() demo() #形参的默认参数是可变对象,第一次调用列表添加元素

How to efficiently find the n-th set bit?

ぐ巨炮叔叔 提交于 2020-01-12 14:09:15
问题 For code related to this question, I need to compute the following as fast as possible: Given a 32 bit integer i , compute the position of the n -th least significant set bit. Both n and the result should be 0-indexed. For example, given the number i = 11010110101 2 and n = 4, the desired number is 7 as the fourth set bit is at position 7: 110 1 0110101. Using the pdep instruction from the BMI2 instruction set extension for x86 and the commonly available __builtin_ctz() intrinsic function,

Header for _blsr_u64 with Sun supplied GCC on Solaris 11?

柔情痞子 提交于 2020-01-04 05:21:14
问题 We've got some code that runs on multiple platforms. The code uses BMI/BMI2 intrinsics when available, like a Core i7 5th gen. GCC supplied by Sun on Solaris 11.3 is defining __BMI__ and __BMI2__ , but its having trouble locating BMI/BMI2 intrinsics: $ cat test.cxx #include <x86intrin.h> int main(int argc, char* argv[]) { unsigned long long t = argc; #if defined(__BMI__) || defined(__BMI2__) t = _blsr_u64(t); #endif return int(t); } $ /bin/g++ -march=native test.cxx -o test.exe test.cxx: In

Header for _blsr_u64 with Sun supplied GCC on Solaris 11?

梦想与她 提交于 2020-01-04 05:21:08
问题 We've got some code that runs on multiple platforms. The code uses BMI/BMI2 intrinsics when available, like a Core i7 5th gen. GCC supplied by Sun on Solaris 11.3 is defining __BMI__ and __BMI2__ , but its having trouble locating BMI/BMI2 intrinsics: $ cat test.cxx #include <x86intrin.h> int main(int argc, char* argv[]) { unsigned long long t = argc; #if defined(__BMI__) || defined(__BMI2__) t = _blsr_u64(t); #endif return int(t); } $ /bin/g++ -march=native test.cxx -o test.exe test.cxx: In

Confusion about bsr and lzcnt

这一生的挚爱 提交于 2020-01-03 08:29:06
问题 I'm a bit confused about both instructions. First let's discard the special case when the scanned value is 0 and the undefined/bsr or bitsize/lzcnt result - this difference is clear and not part of my question. Let's take the binary value 0001 1111 1111 1111 1111 1111 1111 1111 According to Intel's spec the result for lzcnt is 3 According to Intel's spec the result for bsr is 28 lzcnt counts, bsr returns the index or distance from bit 0 (which is the lsb). How can both instructions be the

Compiler macro to detect BMI2 instruction set

牧云@^-^@ 提交于 2019-12-23 13:13:12
问题 I was searching on the web to find a proper solution, without much success. So I hope one of you know something about it: Is there any way to detect the "Intel Bit Manipulation Instruction Sets 2" (BMI2) compile time? I want to make some conditional thing based on the availability of it. 回答1: With GCC you can check for the __BMI2__ macro. This macro will be defined if the target supports BMI2 (e.g. -mbmi2 , -march=haswell ). This is the macro that the instrinsic's headers ( x86intrin.h ,

Python入门篇

断了今生、忘了曾经 提交于 2019-12-20 17:12:46
Python关键字 需要注意的是,由于 Python 是严格区分大小写的,保留字也不例外。所以,我们可以说 if 是保留字,但 IF 就不是保留字。 Python2.x raw_input()函数与input()函数:获取用户输入的字符串 Python 2.x 提供了一个 raw_input() 函数总会将用户输入的内容放入字符串中,因此用户可以输入任何内容,raw_input() 函数总是返回一个字符串。 input() 函数则比较怪异:要求用户输入的必须是符合 Python 语法的表达式。通常来说,用户只能输入整数、浮点数、复数、字符串等。重点是格式必须正确,比如输入字符串时必须使用双引号,否则 Python 就会报错。 1.代码块:获取用户输入的字符串 #!/usr/bin/python #encoding=utf-8 ''' @ 功能:获取用户输入的字符串 ''' msg = raw_input ( "请输入字符串:" ) print ( type ( msg ) ) print ( msg ) """ @功能:获取用户输入的数值 """ value = input ( "请输入数值:" ) print ( type ( value ) ) print ( value ) 1.运行结果 2.代码块:字符串赋值 #!/usr/bin/python #encoding=utf