{"record":{"id":"25f54a571b9aa03e","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-speci-25f54a","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Specified kernel size (%ux%ux%ux%u = %u) does not match size of kernel variable (%u), in expression '%s'.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Specified kernel size \\(%ux%ux%ux%u = %u\\) does not match size of kernel variable \\(%u\\), in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":20975,"sourceCode":"                xstride = (int)mem[opcode[18]],\n                ystride = (int)mem[opcode[19]],\n                zstride = (int)mem[opcode[20]],\n                xsize = opcode[27]==~0U?wI/xstride:(unsigned int)mem[opcode[27]],\n                ysize = opcode[28]==~0U?hI/ystride:(unsigned int)mem[opcode[28]],\n                zsize = opcode[29]==~0U?dI/zstride:(unsigned int)mem[opcode[29]];\n\n              if (wI*hI*dI*sI!=size(opcode[2])) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Specified input size (%ux%ux%ux%u = %u) does \"\n                                            \"not match size of input variable (%u), in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            wI,hI,dI,sI,wI*hI*dI*sI,size(opcode[2]),\n                                            s0);\n              }\n              if (wK*hK*dK*sK!=size(opcode[7])) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Specified kernel size (%ux%ux%ux%u = %u) does \"\n                                            \"not match size of kernel variable (%u), in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            wK,hK,dK,sK,wK*hK*dK*sK,size(opcode[7]),\n                                            s0);\n              }\n\n              arg2 = !channel_mode?sI*sK:channel_mode==1?std::max(sI,sK):\n                channel_mode==2?std::max(sI,sK)/std::min(sI,sK):1U;\n\n              opcode[1] = pos = vector(xsize*ysize*zsize*arg2);\n              opcode[3] = (ulongT)wI;\n              opcode[4] = (ulongT)hI;\n              opcode[5] = (ulongT)dI;\n              opcode[6] = (ulongT)sI;\n              opcode[8] = (ulongT)wK;\n              opcode[9] = (ulongT)hK;\n              opcode[10] = (ulongT)dK;","sourceCodeStart":20957,"sourceCodeEnd":20993,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L20957-L20993","documentation":"The kernel-side counterpart of the input size check in the same convolution opcode: the kernel variable (opcode[7]) element count must equal wK*hK*dK*sK. Immediately after validating the input size, the parser validates the kernel geometry; a mismatch aborts the expression before any convolution runs.","triggerScenarios":"Passing a kernel vector whose length does not match its declared 4D kernel geometry in the expression-level convolution call (e.g. a 3x3 kernel declared as 3x3x1x1=9 values but supplied with 8), or reusing a kernel variable resized elsewhere in the expression.","commonSituations":"Changing kernel size (3x3 to 5x5) without updating the declared geometry; building the kernel dynamically with fill() and getting a different length; mixing separable vs full kernels with wrong parameter counts.","solutions":["Ensure the kernel vector has exactly wK*hK*dK*sK elements (3x3 -> 9 values, 5x5 -> 25).","Update the declared kernel geometry after any kernel-size change.","Build the kernel with a geometry-matched constructor/fill in the same expression.","Print/verify kernel length before the convolution call."],"exampleFix":"// before\nk = [1,2,3,4,5,6,7,8]; convolve(in, k, ..., 3,3,1,1, ...) // 8 != 9\n// after\nk = [1,2,3,4,5,6,7,8,9]; convolve(in, k, ..., 3,3,1,1, ...)","handlingStrategy":"validation","validationCode":"size_t kLen = kernel.size();\nunsigned long expect = (unsigned long)wK*hK*dK*sK;\nif (kLen != expect) throw std::runtime_error(\"kernel geometry \" + std::to_string(expect) + \" != kernel size \" + std::to_string(kLen));","typeGuard":"bool kernel_fits(const CImg<float>& k, unsigned wK, unsigned hK, unsigned dK, unsigned sK) {\n  return (unsigned long)k.size() == (unsigned long)wK*hK*dK*sK;\n}","tryCatchPattern":"try {\n  img.fill(expr.c_str());\n} catch (const CImgArgumentException& e) {\n  // rebuild kernel with matching geometry\n}","preventionTips":["Update declared kernel geometry whenever kernel size changes","Build kernels via geometry-aware constructors (e.g. CImg(w,h,d,s))","Check kernel length before each convolution call"],"tags":["cimg","math-parser","convolution","kernel","size-mismatch"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}