gpt4 book ai didi

由 C++ STL 卷积

转载 作者:可可西里 更新时间:2023-11-01 15:24:57 25 4
gpt4 key购买 nike

是否有一个很好的算法实现来计算 C++ STL(或什至提升)中两个范围的卷积?即带有原型(prototype)的东西(两个范围 a..bc..d 的卷积):

template< class Iterator >
void convolution(Iterator a, Iterator b, Iterator c, Iterator d);

修改 a..b 范围

最佳答案

是 std::transform

std::transform(a, b, c, a, Op);

// a b is the the first input range
// c is the start of the second range (which must be at least as large as (b-a)
//
// We then use a as the output iterator as well.

// Op is a BinaryFunction

回复评论中关于如何进行状态累加的评论:

struct Operator
{
State& state;
Operator(Sate& state) : state(state) {}
Type operator()(TypeR1 const& r1Value, TypeR2 const& r2Value) const
{
Plop(state, r1Value, r2Value);
return Convolute(state, r2Value, r2Value);
}
};
State theState = 0;
Operator Op(theState);

关于由 C++ STL 卷积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com