我正在尝试编译一个使用的CMake项目
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wall -std=gnu++0x")
Run Code Online (Sandbox Code Playgroud)
在MacOS X Lion下的CMakeLists.txt文件中.我已经安装了XCode 4.2.1.但编译器失败了:
cd something/src/lib && /usr/bin/c++ -Dlib_ginacra_EXPORTS -Wall -std=gnu++0x -fPIC -o CMakeFiles/lib_ginacra.dir/utilities.cpp.o -c something/src/lib/utilities.cpp
cc1plus: error: unrecognized command line option "-std=gnu++0x"
Run Code Online (Sandbox Code Playgroud)
编译器的版本是:
c++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
Run Code Online (Sandbox Code Playgroud) 假设我们有一个功能f(x,y)和另一个功能
def g():
# ...
f(i,j) # i,j vary and f is called multiple times
# ...
Run Code Online (Sandbox Code Playgroud)
我们要编写一个单元测试,以检查是否f调用了次数并具有正确的参数。
def test_g():
with patch('mymodule.f') as function:
assert function.gacs.call_count == correct_no_calls
Run Code Online (Sandbox Code Playgroud)
有
function.assert_called_with(...)
Run Code Online (Sandbox Code Playgroud)
但这仅指最后一次通话。因此,假设g电话f(1,2),然后f(2,3),function.assert_called_with(1,2)是False。
此外,还有
function.call_args_list
Run Code Online (Sandbox Code Playgroud)
产生call具有正确参数的对象列表。将此列表与call我们在单元测试中创建的对象进行比较感觉很麻烦。call似乎是模拟库的内部类。
有一个更好的方法吗?我使用此设置来测试apply功能的并行执行。
我用来click定义一个 CLI,它采用datetimes 和逗号分隔的参数列表。
import click
def valid_date(s):
try:
return dt.strptime(s, "%Y-%m-%d")
except ValueError:
msg = "Not a valid date: '{0}'.".format(s)
raise Exception(msg)
except TypeError:
return None
split_parameter = lambda _, __, s: s.split(",")
check_date = lambda _, __, s: valid_date(s)
@click.command()
@click.argument('symbols', callback=split_parameter)
@click.option('--start_date', callback=check_date)
@click.option('--end_date', callback=check_date)
@click.option('--file_name')
def f(symbols, start_date, end_date, file_name):
return None
Run Code Online (Sandbox Code Playgroud)
它有效,但 s 周围的逻辑callback有点尴尬。拆分列表和转换都datetime中断了单击的简单结构。有没有一种Python式的方法可以做到这一点?
我们想使用R的dtw库,以便将某些时间序列数据缩小和扩展到标准长度。
考虑具有等效列的三个时间序列。moref是长度(行)的105,mobig是130和mosmall100。我们希望项目mobig和mosmall以105的长度。
moref <- good_list[[2]]
mobig <- good_list[[1]]
mosmall <- good_list[[3]]
Run Code Online (Sandbox Code Playgroud)
因此,我们计算两个对齐。
ali1 <- dtw(mobig, moref)
ali2 <- dtw(mosmall, moref)
Run Code Online (Sandbox Code Playgroud)
如果我们打印出对齐结果是:
DTW alignment object
Alignment size (query x reference): 130 x 105
Call: dtw(x = mobig, y = moref)
DTW alignment object
Alignment size (query x reference): 100 x 105
Call: dtw(x = mosmall, y = moref)
Run Code Online (Sandbox Code Playgroud)
那么我们到底想要什么?根据我的理解,我们需要使用扭曲函数ali1$index1或ali1$index2为了缩小或扩大时间序列。但是,如果我们调用以下命令
length(ali1$index1)
length(ali2$index1)
length(ali1$index2)
length(ali2$index2)
Run Code Online (Sandbox Code Playgroud)
结果是
[1] …Run Code Online (Sandbox Code Playgroud) 我将在周末学习Perl的面试.为了更深入地理解我正在尝试实现树类.
#use strict;
#use warnings;
package Tree;
sub new {
my $class = shift @_;
my $content = shift @_;
my @array = shift @_;
return bless { "content" => $content, "array" => @array }, $class;
}
sub num_children {
my $self = shift @_;
my @array = $self->{"array"};
return scalar @array;
}
return 1;
Run Code Online (Sandbox Code Playgroud)
为了测试(错误的)树类,我实现了以下测试脚本.
#!/usr/bin/perl
require Tree;
my $t = Tree->new("#", undef);
my $tt = Tree->new("*", undef);
my $tttt = Tree->new("-", undef);
my $ttttt = Tree->new(".", undef);
my …Run Code Online (Sandbox Code Playgroud) 我正在编写一个使用分数的小程序:
struct fraction
{
int num;
int den;
};
typedef struct fraction FRAC;
Run Code Online (Sandbox Code Playgroud)
我使用一个最不常见的多重函数来添加两个分数(之后不再简化它们):
FRAC *add (FRAC a, FRAC b)
{
int l = lcm(a.den, b.den);
FRAC *sum;
sum = malloc(sizeof(FRAC));
sum->den = l;
int la = l/a.den;
int lb = l/b.den;
sum->num = a.num*la + b.num*lb;
return sum;
}
Run Code Online (Sandbox Code Playgroud)
给定一个数组FRAC我想用以下函数计算总和:
FRAC* fraction_sum (FRAC *a, unsigned int size)
{
int i;
FRAC* sum = malloc(sizeof(FRAC));
sum->num = 0;
sum->den = 0;
for (i = 0; i < size; …Run Code Online (Sandbox Code Playgroud) python ×2
c ×1
c++ ×1
c++11 ×1
gcc ×1
mocking ×1
osx-lion ×1
perl ×1
python-click ×1
r ×1
testing ×1
time-series ×1
tree ×1
unit-testing ×1
xcode ×1