我有一种情况,我需要每0.5秒从一个设备处理5000个样本.
假设窗口大小为100,那么移动平均线将产生50个点.我正在尝试使用传统方法,即使用循环.但这是一种非常低效的方法.有什么建议 ?
好吧,所以我登上了盘子,想知道math.h平方根与其中有神奇数字的那个相比有多快(由Quake着名但由SGI制作).
但这最终导致了对我的伤害.
我首先在Mac上尝试过这种方法,其中math.h每次都会在Windows上获胜,而魔术数字总是赢得,但我认为这完全取决于我自己的高通.
在程序运行时使用"g ++ -o sq_root sq_root_test.cpp"在Mac上进行编译,大约需要15秒才能完成.但是在发布时在VS2005中进行编译只需要一瞬间.(实际上我必须在debug中编译才能让它显示一些数字)
我的穷人的基准?这真的很蠢吗?因为math.h得0.01,魔术数得0.(它不能那么快吗?)
我不知道这是否重要,但Mac是Intel,PC是AMD.Mac是否使用math.h sqroot的硬件?
我从http://en.wikipedia.org/wiki/Fast_inverse_square_root获得了快速平方根算法
//sq_root_test.cpp
#include <iostream>
#include <math.h>
#include <ctime>
float invSqrt(float x)
{
union {
float f;
int i;
} tmp;
tmp.f = x;
tmp.i = 0x5f3759df - (tmp.i >> 1);
float y = tmp.f;
return y * (1.5f - 0.5f * x * y * y);
}
int main() {
std::clock_t start;// = std::clock();
std::clock_t end;
float rootMe;
int iterations = 999999999;
// ---
rootMe = 2.0f; …Run Code Online (Sandbox Code Playgroud) 我的问题是,如果可以在scala中重载构造函数?
所以我可以编写如下代码:
var = new Foo(1)
var = new Foo("bar")
Run Code Online (Sandbox Code Playgroud)
如果不可能,有没有相同的技巧?
我需要像这样创建数组:
Array('firstkey' => Array('secondkey' => Array('nkey' => ...)))
Run Code Online (Sandbox Code Playgroud)
由此:
firstkey.secondkey.nkey.(...)
Run Code Online (Sandbox Code Playgroud) 我已经安装了带有Rails 2.3.5的Snow Leopard以及其他版本(2.2.2和1.2.6).我想使用2.2.2作为我想部署的网络服务器使用2.2.x版本的Rails.我试图卸载Rails 2.3.5但得到此错误:
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rails`
Run Code Online (Sandbox Code Playgroud)
有没有其他方法将Rails版本设置为其他已安装的Rails版本之一?
我<tr>在视图中有一个元素,我想在这个元素上动态添加类,具体取决于两个模型之间的关联(公司和包装之间的多对多).
结果应该是这样的
<tr class="pck1 pck3 pck5">
Run Code Online (Sandbox Code Playgroud)
在那里pck1,pck3并pck5与公司相关的包装.
我有一个由机器人标记的Java评估.每当我上传我的作业时,它都会显示一个这样的屏幕.
A good object-oriented design places each method into the most appropriate class. The most appropriate class for a method should be the same class as the data fields that that method needs to access. If you don't place a method into the right class, then this will most likely increase the amount of communication that is required between your classes. The score below measures the amount of communication between your classes. A lower score is better. 19 method invocations …
我有一些不等式{x,y},满足以下等式:
x>=0
y>=0
f(x,y)=x^2+y^2>=100
g(x,y)=x^2+y^2<=200
Run Code Online (Sandbox Code Playgroud)
需要注意的是x和y必须是整数.
在图形上它可以表示如下,蓝色区域是满足上述不等式的区域:

现在的问题是,Matlab中是否有任何函数可以找到每个可接受的对{x,y}?如果有算法来做这种事情,我也很高兴听到它.
当然,我们总能使用的一种方法是强力方法,我们测试每种可能的组合,{x,y}以查看是否满足不等式.但这是最后的手段,因为它耗费时间.我正在寻找一个聪明的算法来做到这一点,或者在最好的情况下,我可以直接使用现有的库.
这x^2+y^2>=100 and x^2+y^2<=200只是例子; 在现实中f,g可以是任何程度的任何多项式函数.
编辑:C#代码也受到欢迎.
c# matlab mathematical-optimization linear-programming nonlinear-optimization
如果我正在构建一个使用大量照片来说明服务的Web服务,那么实际检测照片是否聚焦将是有用的.
有没有办法以编程方式执行此操作?(更好的是,是否有这样的例程的开源实现?)