1 private static Double[] uniform_filter1d_double_fast(Double[] input, int size) { 2 Double[] output = new Double[input.length]; 3 //https://github.com/scipy/scipy 4 //‘nearest’ (a a a a | a b c d | d d d d) 5 boolean more; 6 int size1 = size/2; 7 int size2 = size - size1 - 1; 8 int maxLines = input.length - 1; 9 int len = input.length; 10 int currentLine = 0; 11 double preWindowSum = 0.; 12 double preFirstValue = 0.; 13 boolean preInitialized = false; 14 do { 15 Double tmp = 0.; 16 if (!preInitialized) { 17 int start = 0; 18 preFirstValue = input[start]; 19 for (int i = 0; i < size1; i++) { 20 tmp = p_double_add(tmp, input[start]); 21 } 22 tmp = p_double_add(tmp, input[currentLine]); 23 for (int i = 0; i < size2; i++) { 24 tmp = p_double_add(tmp, input[currentLine+i+1]); 25 } 26 } else { 27 preWindowSum = p_double_subtract(preWindowSum, preFirstValue); 28 if (currentLine > size1) { 29 preFirstValue = input[currentLine-size1]; 30 } 31 if (currentLine+size2 <= maxLines) { 32 tmp = p_double_add(preWindowSum, input[currentLine+size2]); 33 } else { 34 tmp = p_double_add(tmp, input[maxLines]); 35 } 36 } 37 preWindowSum = tmp; 38 if (!preInitialized) { 39 preInitialized = true; 40 } 41 output[currentLine] = p_double_divide(tmp , size); 42 currentLine++; 43 more = currentLine < len; 44 } while (more); 45 return output; 46 }
以上为分析scipy库中的c++代码后所写。
标签:tmp,nearest,JAVA,size1,currentLine,int,double,uniform,input From: https://www.cnblogs.com/justbeginning/p/18298516