Cody

# Problem 42795. Fast 1-D Convolution (valid shape)

Solution 864846

Submitted on 4 Apr 2016 by Jan Orwat
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%{ ╔═════════════════════════════════════════════════════════════╗ ║ Please note that problems in this series are designed for ║ ║ optimizing the code performance, rather than the usual Cody ║ ║ "size". We are achieving this goal by courtesy of LY Cao's ║ ║ new scoring function, which automatically grants a better ║ ║ score to a faster solution. Kindly note that simply using ║ ║ the conv function may result in a poor score or even failure║ ║ in one of the tests. Suggestions and comments are welcome. ║ ║ ║ ║ Thanks & have fun! ║ ║ Peng ║ ╚═════════════════════════════════════════════════════════════╝ %}

2   Pass
fid = fopen('EvaluateSolution.p','wb'); fwrite(fid,uint8(sscanf('7630312E30307630302E3030000CF01CCC561FB1000000C30000012D000001D160E44E2EC6DB5CE66B30F9B560AF40D6A7226365293F6413AE84ABD44D4C7EE5C617DCDAC2521B24B2951C23F50BA9DAA4179B35DCED27A697FC9CA9A308698729973CACEC16670C077236F96E9D16612152B0C32FC57E4755E80E40AC876804B7835D9703BC5A1D6FC519FDEDE22237DC59455FF0014FEBCEF1CB2A840158E11CDD5D6C78D594F50B575A4DF9FB54705F2C6D40341F12CE207B892CBEDEC018A1F94CFA1D5FBB9E1912BA424CD5C6C422D6F3451A8BDD2543834B3FFAD3107D8F16C78D75DD9F3AD197D5591B1686E190D8DF4B5EF3AC28C641296E92FB02BC395D442C03480E156E48F8B61AA3C6F1526AA95C1C466C77A3803AF8523098B0A3ED10A07E2F93274DC8207B05A572988754AAC211A330C2FEC7928CFD51D3A6FBDD9FFA6036C948E0C4239A16','%2x'))); fclose(fid);

3   Pass
u = 1; v = 1; y_correct = 1; assert(isequal(fconv1v(u,v),y_correct))

4   Pass
u = 1:10; v = 1:5; y_correct = conv(u,v,'valid'); assert(all(abs(fconv1v(u,v)-y_correct)<1e-10))

5   Pass
u = 1:5; v = 1:10; y_correct = zeros(1,0); assert(isequal(fconv1v(u,v),y_correct))

6   Pass
u = rand(20,1); v = rand(10,1); y_correct = conv(u,v,'valid'); assert(all(abs(fconv1v(u,v)-y_correct)<1e-10))

7   Pass
u = rand(10,1); v = rand(20,1); y_correct = zeros(0,1); assert(isequal(fconv1v(u,v),y_correct))

8   Pass
% Large data size global sol_score AbsTol = 1e-6; % Maximum absolute error tolerance uu = rand(5e6,15); vv = rand(2e5,15); for iter = 15:-1:1 u = uu(:,iter); v = vv(:,iter); t = builtin('tic'); y = fconv1v(u,v); timeSpan(iter) = builtin('toc',t); pass(iter) = EvaluateSolution(u,v,y,AbsTol); end sol_score = sum(timeSpan); assert(all(pass));

9   Pass
% New scoring function by LY Cao global sol_score fid = fopen('score.p','wb'); fwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x')); fclose(fid); score(sol_score);