#NEWLINE# def c_code( self , node , name , inputs , outputs , sub ) : #NEWLINE# #INDENT# '\n        .. todo::\n\n            WRITEME\n        ' #NEWLINE# ( p , h , gp , gh , gp_iszero , gh_iszero ) = inputs #NEWLINE# ( targets_z , targets_t ) = outputs #NEWLINE# fail = sub [ 'fail' ] #NEWLINE# num_braces = 0 #NEWLINE# if node . copy_non_contiguous : #NEWLINE# #INDENT# raise UnimplementedError ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# basic_setup = '#define PROBMAXPOOLGRAD_COPY_NON_CONTIGUOUS 0\n' #NEWLINE# #UNINDENT# setup_nv_h = ( self . _argument_contiguity_check ( 'h' ) + '\n        if (%(h)s->nd != 4)\n        {\n            PyErr_Format(PyExc_ValueError,\n                "h must have nd=4, got nd=%%i", %(h)s->nd);\n            %(fail)s;\n        }\n\n        { //setup_nv_images brace 1\n\n        const int * images_dims = CudaNdarray_HOST_DIMS(%(h)s);\n        const int img_channels = images_dims[0];\n        const int imgSizeY = images_dims[1];\n        const int imgSizeX = images_dims[2];\n        const int batch_size = images_dims[3];\n\n        if(imgSizeY != imgSizeX){\n            PyErr_Format(PyExc_ValueError,\n                "images must be square(dims[1] == dims[2]). Shape (%%i,%%i,%%i,%%i)",\n                img_channels, imgSizeY, imgSizeX, batch_size);\n            %(fail)s;\n        }\n        if(%(ds)s > imgSizeY){\n            PyErr_Format(PyExc_ValueError,\n                "ds(%%d) must be <= imgSizeX(%%d) and imgSizeY(%%d).",\n                %(ds)s, imgSizeX, imgSizeY);\n            %(fail)s;\n        }\n        if (CudaNdarray_HOST_DIMS(%(h)s)[0] %% 16 != 0)\n        {\n            PyErr_Format(PyExc_ValueError,\n                "h must have a number of channels that is a multiple of 16. Got %%d",\n                CudaNdarray_HOST_DIMS(%(gh)s)[0]);\n            %(fail)s;\n        }\n\n\n        NVMatrix nv_h(%(h)s, img_channels * imgSizeY * imgSizeX,\n                          batch_size, "ProbMaxPool:nv_h");\n\n        ' ) #NEWLINE# num_braces += 1 #NEWLINE# setup_nv_p = ( self . _argument_contiguity_check ( 'p' ) + '\n        if (%(p)s->nd != 4)\n        {\n            PyErr_Format(PyExc_ValueError,\n                "P must have nd=4, got nd=%%i", %(p)s->nd);\n            %(fail)s;\n        }\n\n        { //setup_nv_images brace 1\n\n        int _outputsX = ((int)(ceil((imgSizeY - %(start)s - %(ds)s) / ((float)%(stride)s)))) + 1;\n\n\n        NVMatrix nv_p(%(p)s, img_channels * _outputsX * _outputsX, batch_size,\n        "ProbMaxPool:nv_p");\n        ' ) #NEWLINE# num_braces += 1 #NEWLINE# setup_nv_gh = ( self . _argument_contiguity_check ( 'gh' ) + '\n        if (%(gh)s->nd != 4)\n        {\n            PyErr_Format(PyExc_ValueError,\n                "gh must have nd=4, got nd=%%i", %(gh)s->nd);\n            %(fail)s;\n        }\n        if (CudaNdarray_HOST_DIMS(%(gh)s)[0] %% 16 != 0)\n        {\n            PyErr_Format(PyExc_ValueError,\n                "gh must have a number of channels that is a multiple of 16. Got %%d",\n                CudaNdarray_HOST_DIMS(%(gh)s)[0]);\n            %(fail)s;\n        }\n\n        { //setup_nv_gh brace 1\n\n        const int * gh_dims = CudaNdarray_HOST_DIMS(%(gh)s);\n        const int gh_channels = gh_dims[0];\n        const int ghSizeY = gh_dims[1];\n        const int ghSizeX = gh_dims[2];\n\n        NVMatrix nv_gh(%(gh)s, gh_channels * ghSizeY * ghSizeX,\n                       batch_size, "ProbMaxPool:nv_gh");\n        ' ) #NEWLINE# num_braces += 1 #NEWLINE# setup_nv_gp = ( self . _argument_contiguity_check ( 'gp' ) + '\n        if (%(gp)s->nd != 4)\n        {\n            PyErr_Format(PyExc_ValueError,\n                "gp must have nd=4, got nd=%%i", %(gp)s->nd);\n            %(fail)s;\n        }\n\n        { //setup_nv_images brace 1\n\n        int _outputsX = ((int)(ceil((imgSizeY - %(start)s - %(ds)s) / ((float)%(stride)s)))) + 1;\n\n\n        NVMatrix nv_gp(%(gp)s, img_channels * _outputsX * _outputsX, batch_size,\n        "ProbMaxPool:nv_gp");\n        ' ) #NEWLINE# num_braces += 1 #NEWLINE# setup_nv_targets_z = '\n        int target_z_dims [] = {\n            img_channels,\n            imgSizeX,\n            imgSizeY,\n            batch_size };\n\n        if (CudaNdarray_prep_output(& %(targets_z)s, 4, target_z_dims))\n        {\n            %(fail)s;\n        }\n\n        { // setup_nv_target brace # 1\n\n        NVMatrix nv_targets_z(%(targets_z)s,\n                            target_z_dims[0] * target_z_dims[1] * target_z_dims[2],\n                            target_z_dims[3], "ProbMaxPool:nv_targets_z");\n\n        ' #NEWLINE# num_braces += 1 #NEWLINE# setup_nv_targets_t = '\n        int target_t_dims [] = {\n            img_channels,\n            _outputsX,\n            _outputsX,\n            batch_size };\n\n        if (CudaNdarray_prep_output(& %(targets_t)s, 4, target_t_dims))\n        {\n            %(fail)s;\n        }\n\n        { // setup_nv_target brace # 1\n\n        NVMatrix nv_targets_t(%(targets_t)s, target_t_dims[0] * target_t_dims[1] * target_t_dims[2],\n                            target_t_dims[3], "ProbMaxPool:nv_targets_t");\n\n\n        float * gp_iszero = CudaNdarray_DEV_DATA(%(gp_iszero)s);\n        float * gh_iszero = CudaNdarray_DEV_DATA(%(gh_iszero)s);\n        ' #NEWLINE# num_braces += 1 #NEWLINE# undo_pool = '\n        localProbMaxUndo(nv_h, nv_p, nv_gh, nv_gp, nv_targets_z, nv_targets_t,\n                         %(ds)s, %(start)s, %(stride)s, _outputsX, imgSizeX, gp_iszero, gh_iszero);\n        ' #NEWLINE# braces = ( '}' * num_braces ) #NEWLINE# rval = ( ( ( ( ( ( ( ( basic_setup + setup_nv_h ) + setup_nv_p ) + setup_nv_gh ) + setup_nv_gp ) + setup_nv_targets_z ) + setup_nv_targets_t ) + undo_pool ) + braces ) #NEWLINE# start = self . start #NEWLINE# stride = self . stride #NEWLINE# ds = self . ds #NEWLINE# rval = ( rval % locals ( ) ) #NEWLINE# return rval