首页
\
问答
\
如何将文件内容读入qmake变量并将其传递给编译器?(How to read file content into a qmake variable and pass it to the compiler?)
如何将文件内容读入qmake变量并将其传递给编译器?(How to read file content into a qmake variable and pass it to the compiler?)
如何将文件内容读入qmake项目文件中的变量? 例如,我希望从文件中读取
KEY
的内容并将其传递给编译器:DEFINES += KEY=**some magic and filename here**
How to read file content into a variable in qmake project file? For example, I'd like to have the contents of
KEY
read from a file and pass it to the compiler:DEFINES += KEY=**some magic and filename here**
原文:https://stackoverflow.com/questions/22403605
更新时间:2023-02-09 18:02
最满意答案
几乎完全向量化的代码版本要快得多(16.9%),假设你的代码被命名为
f()
:def g(): n=6 iters = 1000 S=np.repeat(list(itertools.product([-1,1], repeat = n+1)),iters, axis=0).reshape((-1,n+1)) F=np.random.choice(np.array([-1,0,0,1], dtype=np.int8), size = (iters*(2**(n+2)),n)) #oversampling F=F[~(F==0).all(1)][:iters*(2**(n+1))] FS=np.asanyarray(map(lambda x, y: np.convolve(x, y, 'valid'), F, S)) firstzero=(FS[:,0]==0).sum() bothzero=(FS==0).all(1).sum() print "firstzero", firstzero print "bothzero", bothzero
时间结果:
In [164]: %timeit f() firstzero 27171 bothzero 12151 firstzero 27206 bothzero 12024 firstzero 27272 bothzero 12135 firstzero 27173 bothzero 12079 1 loops, best of 3: 14.6 s per loop In [165]: %timeit g() firstzero 27182 bothzero 11952 firstzero 27365 bothzero 12174 firstzero 27318 bothzero 12173 firstzero 27377 bothzero 12072 1 loops, best of 3: 2.47 s per loop
An almost fully vectorized version of your code is much faster (16.9%), suppose yours is named
f()
:def g(): n=6 iters = 1000 S=np.repeat(list(itertools.product([-1,1], repeat = n+1)),iters, axis=0).reshape((-1,n+1)) F=np.random.choice(np.array([-1,0,0,1], dtype=np.int8), size = (iters*(2**(n+2)),n)) #oversampling F=F[~(F==0).all(1)][:iters*(2**(n+1))] FS=np.asanyarray(map(lambda x, y: np.convolve(x, y, 'valid'), F, S)) firstzero=(FS[:,0]==0).sum() bothzero=(FS==0).all(1).sum() print "firstzero", firstzero print "bothzero", bothzero
Timing result:
In [164]: %timeit f() firstzero 27171 bothzero 12151 firstzero 27206 bothzero 12024 firstzero 27272 bothzero 12135 firstzero 27173 bothzero 12079 1 loops, best of 3: 14.6 s per loop In [165]: %timeit g() firstzero 27182 bothzero 11952 firstzero 27365 bothzero 12174 firstzero 27318 bothzero 12173 firstzero 27377 bothzero 12072 1 loops, best of 3: 2.47 s per loop
相关问答
更多-
Cython,numpy加速(Cython, numpy speed-up)[2022-06-26]
您的Cython脚本存在一些问题: 您没有给Cython一些关键信息,例如范围中使用的x, y, M和N的类型。 我已经cython_sum了两个函数cython_sum和clamp因为你在Python级别不需要它们。 filter函数中出现的是什么? 我假设你的意思是arr 。 修复那些我将重写/修改你的Cython脚本,如下所示: from __future__ import division import numpy as np cimport numpy as np from cython cimp ... -
您可能要查找的是scipy.spatial.distance的代码,特别是cdist函数。 这可以有效地计算各种指标点之间的成对距离。 import numpy as np from scipy.spatial.distance import cdist A = np.random.random((1000, 2)) B = np.random.random((100, 2)) D = cdist(A, B, metric='euclidean') print(D.shape) # (1000, 100 ...
-
如何加快numpy代码(How to speed up numpy code)[2023-11-16]
几乎完全向量化的代码版本要快得多(16.9%),假设你的代码被命名为f() : def g(): n=6 iters = 1000 S=np.repeat(list(itertools.product([-1,1], repeat = n+1)),iters, axis=0).reshape((-1,n+1)) F=np.random.choice(np.array([-1,0,0,1], dtype=np.int8), size = (ite ... -
如何加快代码?(how to speed up the code?)[2022-05-06]
将数据加载到数据库并在数据库中放置一些索引可能会更好。 然后,对数据进行简单查询将会非常快速。 您不需要很多工作来设置数据库。 您可以创建SQLite数据库而无需单独的进程,并且它没有复杂的安装过程。 It might be better to load your data into a database and put some indexes on the database. Then it will be very fast to make simple queries against your da ... -
要充分利用numpy的速度,只要有可能就要创建ufuncs 。 如mgibsonbr所示,将vectorize应用于函数是一种方法,但如果可能的话,更好的方法就是构建一个利用numpy的内置ufuncs的函数。 所以像这样: >>> import numpy >>> a = numpy.random.random(10) >>> a + 1 array([ 1.29738145, 1.33004628, 1.45825441, 1.46171177, 1.56863326, 1.58 ...
-
用于Numpy的循环速度(For loop speed with Numpy)[2022-06-17]
向量化几乎总是加速numpy代码的最佳方式,而且这似乎是可以进行矢量化的。 例如,要开始,位置数组看起来很简单: # these are all of your j values inds = np.arange(0,SRpixels) # these are the j values you don't want to skip sel = np.invert((abs(SR_pointCloud[inds,0]) > SR_xMax) | (SR_pointCloud[inds,2] > SR_zMa ... -
用numpy加速循环(Speed up for loop with numpy)[2022-03-23]
计时 这两个会话都是用。初始化的 In [1]: C = np.random.rand(20,1600,500) In [2]: d = np.random.randint(0, 20, size=900) In [3]: e = np.random.randint(1600, size=900) In [4]: f = np.random.randint(400, size=900) In [5]: b = np.random.randint(100, size=50) In [6]: g = ... -
在我的环境中, mutmul ( @ )比einsum和dot具有适度的时间优势: In [27]: np.allclose(np.einsum('ijk,k',asset_returns,weights),asset_returns@weig ...: hts) Out[27]: True In [28]: %timeit asset_returns@weights 100 loops, best of 3: 3.91 ms per loop In [29]: %timeit np.einsum( ...
-
我np.where一下如何使用np.where来实现它只是一个X / Y问题 。 所以我将尝试解释如何优化此功能。 我的第一直觉是摆脱for循环,这无论如何都是痛点: import numpy as np from scipy.stats import logistic def func1(y, X, thresholds): ll = 0.0 for row in zip(y, X): if row[0] == 0: ll += logistic. ...
-
所有非0的元素都应更改为255: a[a != 0] = 255 All elements that are not 0 should change to 255: a[a != 0] = 255