Yalantis/uCrop · error · CImgArgumentException
[" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of sec
Error message
[" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of second arguments ('%s') does not match with fourth argument 'nb_channelsP=%u', in expression '%s'. What it means
In the CImg math parser, an operator (e.g. a matrix multiplication-style op) requires the first argument's element count to factor exactly as rows*nb_colsB where nb_colsB is the third argument, and the second argument to factor nb_colsB*cols. When p1 is not divisible as required (arg4*arg5!=p1 || arg5*p3!=p2), the parser throws this CImgArgumentException because the matrix dimensions of the two operands are incompatible for the operation.
Source
Thrown at ucrop/src/main/jni/CImg.h:22550
if (!std::strncmp(ss,"mul(",4)) { // Matrix multiplication
_cimg_mp_op("Function 'mul()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,block_flags);
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,block_flags);
arg3 = s2<se1?compile(++s2,se1,depth1,0,block_flags):1;
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_type(arg2,2,2,0);
_cimg_mp_check_const_scalar(arg3,3,3);
p1 = size(arg1);
p2 = size(arg2);
p3 = (unsigned int)mem[arg3];
arg5 = p2/p3;
arg4 = p1/arg5;
if (arg4*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(arg4*p3);
CImg<ulongT>::vector((ulongT)mp_matrix_mul,pos,arg1,arg2,arg4,arg5,p3).move_to(code);
return_comp = true;
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"mirror(",7)) { // Mirror image
_cimg_mp_op("Function 'mirror()'");
s1 = ss7; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss7,s1,depth1,0,block_flags);
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,block_flags);View on GitHub (pinned to f788b534b4)
Solutions
- Check that size of argument1 divided by nb_colsP yields an integer and size of argument2 equals nb_colsP*k
- Print the actual vector sizes with a debug expression (e.g. print(size(#ind)) or 'l' the vector geometry) before the failing op
- Adjust the column-count argument or resize/reshape one operand with 'resize()' / 'unroll()' so dimensions match
- Use the correct operator if a plain elementwise op (e.g. '*' not matrix product) was intended
Example fix
// before (size(A)=6, nb_colsB=4 -> 6 not divisible by 4) mprod(A,B,4) // after mprod(A,B,3) // 6 = 2*3, and size(B)=3*k
Defensive patterns
Strategy: validation
Validate before calling
// G'MIC/CImg expression-level guard before using mprod-like op: // ensure size(A) % cols == 0 and size(B) == cols * rowsB if size(A)%cols!=0 || size(B)%cols!=0 error "operand sizes incompatible with nb_colsB="cols fi
Try / catch
try { run(expr) } catch (CImgArgumentException &e) { std::cerr << "dim mismatch: " << e.what(); } Prevention
- Verify divisibility of operand sizes by the column-count constant
- Print vector geometries with size()/print() during development
- Keep matrix column counts as named variables, not magic numbers
When it happens
Trigger: Using a math-parser operator that multiplies/combines two vectors as matrices when the declared column counts (nb_colsB) do not divide the operand sizes: e.g. calling an expression like 'mprod(A,B,nb_colsB)' where size(A) is not divisible by nb_colsB or size(B) is not nb_colsB*k.
Common situations: Hand-written G'MIC/CImg formulas with wrong column-count constants, vectors reshaped from images whose channel count changed, or copy-pasted expressions between differently sized images.
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
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of fir
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of thi
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of fir
- operator*(): Invalid multiplication of instance by specified
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Too much specif
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/4e410cefd627d582.
Report an issue: GitHub.