

def c_code(self, node, name, inputs, outputs, sub):
    (_indices, _indptr, _d, _g) = _indptr
    (_zout,) = outputs
    if (node.inputs[2].type.dtype in ('complex64', 'complex128')):
        raise NotImplementedError('Complex types are not supported for b')
    if (node.inputs[3].type.dtype in ('complex64', 'complex128')):
        raise NotImplementedError('Complex types are not supported for g_ab')
    return ('\n        if (PyArray_NDIM(%(_d)s) != 2) {PyErr_SetString(PyExc_NotImplementedError, "rank(d) != 2"); %(fail)s;}\n        if (PyArray_NDIM(%(_g)s) != 2) {PyErr_SetString(PyExc_NotImplementedError, "rank(g) != 2"); %(fail)s;}\n        if (PyArray_NDIM(%(_indices)s) != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(indices) != 1"); %(fail)s;}\n        if (PyArray_NDIM(%(_indptr)s) != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(indptr) != 1"); %(fail)s;}\n\n        if( PyArray_TYPE(%(_indices)s) != NPY_INT32) {\n        PyErr_SetString(PyExc_NotImplementedError, "C"); %(fail)s;}\n\n        if( PyArray_TYPE(%(_indptr)s) != NPY_INT32)\n        {PyErr_SetString(PyExc_NotImplementedError, "D"); %(fail)s;}\n\n        if( PyArray_DIMS(%(_d)s)[1] != PyArray_DIMS(%(_g)s)[1])\n        {PyErr_SetString(PyExc_NotImplementedError, "d and g have different numbers of columns"); %(fail)s;}\n\n        if (!%(_zout)s\n            || (PyArray_DIMS(%(_zout)s)[0] != PyArray_DIMS(%(_indices)s)[0]))\n        {\n            Py_XDECREF(%(_zout)s);\n            %(_zout)s = (PyArrayObject*) PyArray_SimpleNew(1, PyArray_DIMS(%(_indices)s), PyArray_TYPE(%(_g)s));\n        }\n\n        {   //makes it compile even though labels jump over variable definitions.\n            npy_intp nnz = PyArray_DIMS(%(_indices)s)[0];\n            npy_intp N =  PyArray_DIMS(%(_indptr)s)[0]-1; //TODO: error checking with this\n\n            npy_intp Sindices = PyArray_STRIDES(%(_indices)s)[0]/PyArray_DESCR(%(_indices)s)->elsize;\n            npy_intp Sindptr = PyArray_STRIDES(%(_indptr)s)[0]/PyArray_DESCR(%(_indptr)s)->elsize;\n\n            const npy_intp Sd1 = PyArray_STRIDES(%(_d)s)[1]/PyArray_DESCR(%(_d)s)->elsize;\n            const npy_intp Sg1 = PyArray_STRIDES(%(_g)s)[1]/PyArray_DESCR(%(_g)s)->elsize;\n\n            const npy_intp K = PyArray_DIMS(%(_d)s)[1];\n\n            const npy_int32 * __restrict__ indptr = (npy_int32 *)PyArray_DATA(%(_indptr)s);\n            const npy_int32 * __restrict__ indices = (npy_int32 *)PyArray_DATA(%(_indices)s);\n\n            // loop over columns\n            for (npy_int32 j = 0; j < N; ++j)\n            {\n                // extract j-th row of dense matrix\n                const dtype_%(_d)s* __restrict__ d_row = (dtype_%(_d)s*)(PyArray_BYTES(%(_d)s) + PyArray_STRIDES(%(_d)s)[0] * j);\n                if(j >= PyArray_DIMS(%(_d)s)[0]) {PyErr_SetString(PyExc_NotImplementedError, "G"); %(fail)s;}\n\n                // for each non-null value in the sparse column\n                for (npy_int32 i_idx = indptr[j * Sindptr]; i_idx < indptr[(j+1) * Sindptr]; ++i_idx)\n                {\n                    // extract row index of non-null value\n                    npy_int32 i = indices[i_idx * Sindices];\n\n                    // extract corresponding row in gradient\n                    const dtype_%(_g)s* __restrict__ g_row = (dtype_%(_g)s*)(PyArray_BYTES(%(_g)s) + PyArray_STRIDES(%(_g)s)[0] * i);\n                    double ip = 0.0;\n\n                    // make sure that row index is not bigger than actual number of rows\n                    // Note: wouldn\'t the above operation fail if that were the case ?\n                    //       when would this ever be true anyway ?\n                    if (i >= PyArray_DIMS(%(_g)s)[0])\n                    {PyErr_SetString(PyExc_NotImplementedError, "H"); %(fail)s;}\n\n                    // perform dot product of dense and sparse rows\n                    for(int k = 0; k < K; ++k)\n                    {\n                        ip += d_row[k * Sd1] * g_row[k*Sg1];\n                    }\n\n                    // write resulting gradient to sparse output\n                    ((dtype_%(_zout)s* __restrict__)(PyArray_BYTES(%(_zout)s) + i_idx * PyArray_STRIDES(%(_zout)s)[0]))[0] = ip;\n                }\n            }\n        }\n\n        ' % dict(locals(), **sub))

dataset/ETHPy150Open rizar/attention-lvcsr/libs/Theano/theano/sparse/basic.py StructuredDotGradCSC.c_code/VarMisuse@30/37 `inputs`->`_indptr`