首页 \ 问答 \ 如何将文件内容读入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脚本存在一些问题: 您没有给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 ...
  • 几乎完全向量化的代码版本要快得多(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 ...
  • 将数据加载到数据库并在数据库中放置一些索引可能会更好。 然后,对数据进行简单查询将会非常快速。 您不需要很多工作来设置数据库。 您可以创建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代码的最佳方式,而且这似乎是可以进行矢量化的。 例如,要开始,位置数组看起来很简单: # 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 ...
  • 计时 这两个会话都是用。初始化的 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

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)