def get_diagonal_subtensor_view(x, i0, i1):
 i0 = int(i0)
 i1 = int(i1)
 if (x.shape[i0] < x.shape[i1]):
  raise NotImplementedError('is this allowed?')
 idx = ([slice(None)] * x.ndim)
 idx[i0] = slice((x.shape[i1] - 1), None, None)
 xview = x.__getitem__(tuple(idx))
 strides = list(xview.strides)
 if (x.shape[i1] != 1):
  strides[i1] -= strides[i0]
  xview.strides = strides
 return xview

def get_diagonal_subtensor_view ( x , i0 , i1 ) : i0 = int ( i0 ) i1 = int ( i1 ) if ( x . shape [ i0 ] < x . shape [ i1 ] ) : raise NotImplementedError ( 'is this allowed?' ) idx = ( [ slice ( None ) ] * x . ndim ) idx [ i0 ] = slice ( ( x . shape [ i1 ] - 1 ) , None , None ) xview = x . __getitem__ ( tuple ( idx ) ) strides = list ( xview . strides ) if ( x . shape [ i1 ] != 1 ) : strides [ i1 ] -= strides [ i0 ] xview . strides = strides return xview
helper function for diagonalsubtensor and incdiagonalsubtensor .