Index reduce ( ) { Index c = this ; for ( int ii = 0 ; ii < rank ; ii ++ ) if ( shape [ ii ] == 1 ) { // do this on the first one you find Index newc = c . reduce ( ii ) ; return newc . reduce ( ) ; // any more to do? } return c ; }
Create a new Index based on current one by eliminating any dimensions with length one .