示例#1
0
文件: xnor.cs 项目: fel88/Xnor
        public static void THNN_Bin_SpatialConvolutionMM_updateOutput_frame(
            IntPtr output,                                                       //float
            IntPtr weight,                                                       //int
            IntPtr bias,                                                         //float
            IntPtr ones,                                                         //float
            IntPtr bin_col,                                                      //int
            IntPtr alphas,                                                       //float
            int kW, int kH,
            int dW, int dH,
            int padW, int padH,
            Int64 nInputPlane,
            Int64 inputWidth, Int64 inputHeight,
            Int64 nOutputPlane,
            Int64 outputWidth, Int64 outputHeight,
            bool quantOutput = false)
        {
            IntPtr output2d;

            //var   output2d = THFloatTensor_newWithStorage2d(output->storage, output->storageOffset, nOutputPlane, -1, outputHeight * outputWidth, -1);
            //var output2d = THFloatTensor_newWithStorage2d(output, (int)nOutputPlane, -1, (int)(outputHeight * outputWidth), -1);



            var strg   = THWrapper.THFloatTensor_storage(output);
            var offset = THWrapper.THFloatTensor_storageOffset(output);

            output2d = THWrapper.THFloatTensor_newWithStorage2d(strg, offset, nOutputPlane, (long)-1, outputWidth * outputHeight, (long)-1);
            //InternalArray output2d = new InternalArray(new int[] { });
            THWrapper.THFloatTensor_zero(output2d);

            binary_gemm_cpu(weight, bin_col, output2d, (int)nOutputPlane, (int)(kW * kH * nInputPlane), (int)(outputHeight * outputWidth), 0, 1, 1, alphas, quantOutput);

            if (bias != null && THWrapper.THFloatTensor_nDimension(bias) != 0)
            {
                THWrapper.THFloatTensor_addmm(output2d, 1, output2d, 1, bias, ones);
                //THFloatTensor_addmm(output2d, 1, output2d, 1, bias, ones);
            }
            THWrapper.THFloatTensor_free(output2d);

            //THWrapper.THFloatTensor_free(_ones);
            //THFloatTensor_free(output2d);
        }