For fun: Expressive C++ 17 Coding Challenge in D

kerdemdemir kerdemdemir at hotmail.com
Fri Oct 6 18:21:39 UTC 2017


I am a total beginner but I want to post that a lot.

auto autoCorrelation(R)(R range)
         if (isRandomAccessRange!R)
{

	import std.numeric : fft, inverseFft;
	import std.range : chain, repeat, zip, dropBack;
	import std.algorithm : map;
	import std.complex;
	
	auto residual = residualPowerOf2(range.length);
	auto fftResult = range.chain(repeat(0, residual)).fft();
	auto autoCorrResult = fftResult.zip(fftResult.map!(a => 
a.conj())).
							map!( a=> a[0] * a[1] ).
							inverseFft().
							dropBack(residual).
							map!( a => a.re );
				
	return autoCorrResult;
}	

I implemented auto correlation in C++ before which is I believe 
2~3 time bigger(also I needed to compile fftw, lapack etc.. ) :
https://forum.kde.org/viewtopic.php?f=74&t=118619 .

That was the moment I feel in love with D.



More information about the Digitalmars-d-learn mailing list