Yalantis/uCrop · error · CImgArgumentException

[cimg_appname_math_parser] CImg<%s>::%s: %s: Types of first

Error message

[cimg_appname_math_parser] CImg<%s>::%s: %s: Types of first and second arguments ('%s' and '%s') do not match with third argument 'nb_colsB=%u', in expression '%s'.

What it means

For matrix-product-style opcodes taking (A,B,nb_colsB), the parser checks dimension consistency: size(B) must equal arg5*p3 and size(A) must be a multiple of arg5, where p3 is nb_colsB. If these products do not reconstruct the operand sizes, the operands are incompatible with the given nb_colsB and compilation fails.

Source

Thrown at ucrop/src/main/jni/CImg.h:23485

              arg4 = 0;
              if (s2<se1) {
                s1 = ++s2; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
                arg3 = compile(s2,s1,depth1,0,block_flags);
                arg4 = s1<se1?compile(++s1,se1,depth1,0,block_flags):0;
              }
              _cimg_mp_check_type(arg1,1,2,0);
              _cimg_mp_check_type(arg2,2,2,0);
              _cimg_mp_check_const_scalar(arg3,3,3);
              _cimg_mp_check_type(arg4,4,1,0);

              p1 = size(arg1);
              p2 = size(arg2);
              p3 = (unsigned int)mem[arg3];
              arg5 = p2/p3;
              arg6 = p1/arg5;
              if (arg6*arg5!=p1 || arg5*p3!=p2) {
                _cimg_mp_strerr;
                throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                            "CImg<%s>::%s: %s: Types of first and second arguments ('%s' and '%s') "
                                            "do not match with third argument 'nb_colsB=%u', "
                                            "in expression '%s'.",
                                            pixel_type(),_cimg_mp_calling_function,s_op,
                                            s_type(arg1)._data,s_type(arg2)._data,p3,s0);
              }
              pos = vector(arg6*p3);
              CImg<ulongT>::vector((ulongT)mp_solve,pos,arg1,arg2,arg6,arg5,p3,arg4).move_to(code);
              return_comp = true;
              _cimg_mp_return(pos);
            }

            if (!std::strncmp(ss,"sort(",5)) { // Sort vector
              _cimg_mp_op("Function 'sort()'");
              s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
              arg1 = compile(ss5,s1,depth1,0,block_flags);
              arg2 = arg4 = 1; arg3 = ~0U; arg5 = 0;
              if (s1<se1) {

View on GitHub (pinned to f788b534b4)

Solutions

  1. Ensure size(B) is an exact multiple of nb_colsB (arg5 = size(B)/nb_colsB).
  2. Ensure arg5 also divides size(A) with no remainder.
  3. Recompute nb_colsB from the data instead of hard-coding it.
  4. Flatten operands consistently (same layout) before the call.

Example fix

// before: A size 6, B size 6, nb_colsB=4
'mul(A,B,4)'
// after
'mul(A,B,2)' // arg5=3; 3*2=6 for both operands
Defensive patterns

Strategy: validation

Validate before calling

const arg5 = Math.floor(b.length / nbColsB);
if (arg5 * nbColsB !== b.length || a.length % arg5 !== 0) throw new Error('Operand sizes incompatible with nb_colsB');

Try / catch

try { img.eval(expr); } catch (e) { if (/do not match with third argument 'nb_colsB/.test(e.message)) { /* recompute nb_colsB */ } else throw e; }

Prevention

When it happens

Trigger: Calling a matrix-multiply-style opcode with vector A of size n1, vector B of size n2, and nb_colsB=c where n2 is not divisible by c, or the resulting shared dimension does not divide size(A).

Common situations: Passing flattened matrices whose column count changed; using nb_colsB from a different matrix; mixing row-major/column-major assumptions.

Understand the failure class

Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/8aae2e4b4aff80b7. Report an issue: GitHub.