#NEWLINE# @ staticmethod #NEWLINE# def c_code_template( dtype ) : #NEWLINE# #INDENT# ( init_decl , begin_row_loop , inside_row_loop , end_row_loop ) = SoftmaxWithBias . c_code_template ( dtype ) #NEWLINE# return ( init_decl , '\n        if (PyArray_NDIM(%(y_idx)s) != 1)\n        {\n            PyErr_SetString(PyExc_ValueError, "y_idx not 1d tensor");\n            %(fail)s;\n        }\n        if (PyArray_DIMS(%(x)s)[0] != PyArray_DIMS(%(y_idx)s)[0])\n        {\n            PyErr_Format(PyExc_ValueError,\n                "number of rows in x (%%ld) does not match length of y (%%ld)",\n                (long int)PyArray_DIMS(%(x)s)[0],\n                (long int)PyArray_DIMS(%(y_idx)s)[0]);\n            %(fail)s;\n        }\n\n        if ((NULL == %(nll)s) //initial condition\n            || (PyArray_DIMS(%(nll)s)[0] != PyArray_DIMS(%(y_idx)s)[0]))\n        {\n            if (NULL != %(nll)s) Py_XDECREF(%(nll)s);\n            %(nll)s = (PyArrayObject*)PyArray_SimpleNew(1,\n                PyArray_DIMS(%(y_idx)s), PyArray_TYPE(%(x)s));\n            if(!%(nll)s)\n            {\n                PyErr_SetString(PyExc_MemoryError,\n                     "failed to alloc nll output");\n                %(fail)s;\n            }\n        }\n        if ((NULL == %(am)s)\n            || (PyArray_DIMS(%(am)s)[0] != PyArray_DIMS(%(y_idx)s)[0]))\n        {\n            Py_XDECREF(%(am)s);\n            %(am)s = (PyArrayObject*) PyArray_SimpleNew(1,\n                PyArray_DIMS(%(y_idx)s), PyArray_TYPE(%(y_idx)s));\n            if(!%(am)s)\n            {\n                PyErr_SetString(PyExc_MemoryError,\n                     "failed to alloc am output");\n                %(fail)s;\n            }\n        }\n                ' , begin_row_loop , '\n            const %(y_idx_type) s y_i = ((%(y_idx_type)s*)(PyArray_BYTES(%(y_idx)s) + PyArray_STRIDES(%(y_idx)s)[0] * i))[0];\n            dtype_%(nll) s* __restrict__ nll_i = (dtype_%(nll)s*)(PyArray_BYTES(%(nll)s) + PyArray_STRIDES(%(nll)s)[0] * i);\n            %(am_type)s* __restrict__ am_i = (%(am_type)s*) (PyArray_BYTES(%(am)s) + PyArray_STRIDES(%(am)s)[0] * i);\n                ' , inside_row_loop , '\n            if ((y_i >= PyArray_DIMS(%(x)s)[1]) || (y_i < 0))\n            {\n                PyErr_SetString(PyExc_ValueError, "y_i value out of bounds");\n                %(fail)s;\n            }\n            nll_i[0] = - x_i[y_i*Sx]\n                       - b_i[y_i*Sb]\n                       + row_max\n                       + log(sum);\n            am_i[0] = row_max_j;\n                ' , end_row_loop )