{"record":{"id":"f971f0795348763b","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-s-f971f0","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s%s %s%s (of type '%s') cannot be considered as a square matrix, in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?)(.+?) (.+?)(.+?) \\(of type '(.+?)'\\) cannot be considered as a square matrix, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":25216,"sourceCode":"                                      \"CImg<%s>::%s: %s%s Specified index '%s' is NaN.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",s_arg);\n        }\n      }\n\n      // Check a matrix is square.\n      void check_matrix_square(const unsigned int arg, const unsigned int n_arg,\n                               char *const ss, char *const se, const char saved_char) {\n        _cimg_mp_check_type(arg,n_arg,2,0);\n        const unsigned int\n          siz = size(arg),\n          n = (unsigned int)cimg::round(std::sqrt((float)siz));\n        if (n*n!=siz) {\n          const char *s_arg;\n          if (*s_op!='F') s_arg = !n_arg?\"\":n_arg==1?\"Left-hand\":\"Right-hand\";\n          else s_arg = !n_arg?\"\":n_arg==1?\"First\":n_arg==2?\"Second\":n_arg==3?\"Third\":\"One\";\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s %s%s (of type '%s') \"\n                                      \"cannot be considered as a square matrix, in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",\n                                      s_arg,*s_op=='F'?(*s_arg?\" argument\":\" Argument\"):(*s_arg?\" operand\":\" Operand\"),\n                                      s_type(arg)._data,s0);\n        }\n      }\n\n      // Check type compatibility for one argument.\n      // Bits of 'mode' tells what types are allowed:\n      // { 1 = scalar | 2 = vectorN }.\n      // If 'N' is not zero, it also restricts the vectors to be of size N only.\n      void check_type(const unsigned int arg, const unsigned int n_arg,\n                      const unsigned int mode, const unsigned int N,\n                      char *const ss, char *const se, const char saved_char) {\n        const bool\n          _is_scalar = is_scalar(arg),\n          _is_vector = is_vector(arg) && (!N || size(arg)==N);","sourceCodeStart":25198,"sourceCodeEnd":25234,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L25198-L25234","documentation":"CImg's math parser requires operands/arguments used as matrices to be square (n*n == siz). When a scalar or vector operand's size is not a perfect square where a square matrix is required, this CImgArgumentException is thrown during parsing. The message identifies which operand (left-hand/right-hand, or First/Second/... argument for function 'F' operators) and its actual type.","triggerScenarios":"Matrix multiplication or solving in an MP expression with a non-square operand, e.g. 'mprod(A,B)' where A has 6 elements (2x3), or passing a vector sized 3 where a 4x4 matrix is expected.","commonSituations":"Loading matrix data from files with wrong dimensions; reshaping errors producing 1xN vectors; mixing rotation matrices of different orders (3x3 vs 4x4) in graphics code.","solutions":["Resize/reshape the operand to n*n elements before use, e.g. A.resize(n,n).","Verify vector sizes match the expected matrix order in the expression.","Check that file-loaded matrix data has the correct dimensions.","Split chained matrix operations so each operand is independently square."],"exampleFix":"// before\nimg.fill(\"mprod(A,B)\"); // A is 2x3\n// after\nA.resize(3,3);\nimg.fill(\"mprod(A,B)\");","handlingStrategy":"validation","validationCode":"if (vec.width()*vec.height() != n*n)\n  throw std::invalid_argument(\"operand is not a square matrix\");","typeGuard":"bool isSquareMatrix(const CImg<double>& m, unsigned n) { return m.size() == n*n; }","tryCatchPattern":"try { img.fill(expr); } catch (const cimg_library::CImgArgumentException& e) { /* reshape operand and retry */ }","preventionTips":["Assert operand sizes are perfect squares before matrix ops","Keep matrix orders consistent across the expression","Check dimensions after any reshape"],"tags":["cimg","math-parser","matrix","shape-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"}