The line: if (rankIndex < 0 && rankIndex > dim) { should be if (rankIndex < 0 or rankIndex > dim) { or for the old-fashioned ones if (rankIndex < 0 || rankIndex > dim) { Christoph Bartoschek