module rotate; export all; use ArrayArith: {<,==,+,-,*}; int[+] rotate (int dimension, int count, int[+] A) \ { \ int array_elem; \ \ if(count == 0) { \ result = A; \ } else { \ max_rotate = _sel_( [dimension], _shape_(A)); \ if( max_rotate == 0) { \ result = A; \ } else { \ count = _mod_( count, max_rotate); \ if (_lt_(count, 0)) { \ count = _add_SxS_( count, max_rotate); \ } \ \ offset = _modarray_( _mul_SxA_( 0, _shape_(A)), [dimension], count); \ slice_shp = _modarray_(_shape_(A), [dimension], count); \ \ result = with (offset <= iv <= .) { \ array_elem = _sel_(iv-offset, A); \ } \ modarray( A, iv, array_elem); \ \ result = with (. <= iv < slice_shp) { \ array_elem = _sel_(_shape_(A)-slice_shp+iv, A); \ } \ modarray( result, iv, array_elem); \ } \ } \ return(result); \ } int[*] rotate (int[.] counts, int[+] A) \ { \ int offset; \ \ for( i=0; i <_sel_([0],_shape_(counts)); i=i +1) { \ offset = _sel_([i],counts); \ A = rotate( i, offset, A); \ } \ \ return(A); \ }