def repeat(x, repeats, axis=None):
 repeats = tensor.as_tensor_variable(repeats)
 if (repeats.ndim > 1):
  raise ValueError('The dimension of repeats should not exceed 1.')
 if ((repeats.ndim == 1) and (not repeats.broadcastable[0])):
  return RepeatOp(axis=axis)(x, repeats)
 else:
  if (repeats.ndim == 1):
   repeats = repeats[0]
  if (x.dtype == 'uint64'):
   raise TypeError("theano.tensor.repeat don't support dtype uint64")
  if (axis is None):
   axis = 0
   x = x.flatten()
  else:
   if (axis >= x.ndim):
    raise ValueError('Axis should not exceed x.ndim-1.')
   if (axis < 0):
    axis = (x.ndim + axis)
  shape = [x.shape[i] for i in xrange(x.ndim)]
  shape_ = shape[:]
  shape_.insert((axis + 1), repeats)
  shape[axis] = (shape[axis] * repeats)
  dims_ = list(numpy.arange(x.ndim))
  dims_.insert((axis + 1), 'x')
  z = tensor.alloc(x.dimshuffle(*dims_), *shape_).reshape(shape)
  return z

def repeat ( x , repeats , axis = None ) : repeats = tensor . as_tensor_variable ( repeats ) if ( repeats . ndim > 1 ) : raise ValueError ( 'The dimension of repeats should not exceed 1.' ) if ( ( repeats . ndim == 1 ) and ( not repeats . broadcastable [ 0 ] ) ) : return RepeatOp ( axis = axis ) ( x , repeats ) else : if ( repeats . ndim == 1 ) : repeats = repeats [ 0 ] if ( x . dtype == 'uint64' ) : raise TypeError ( "theano.tensor.repeat don't support dtype uint64" ) if ( axis is None ) : axis = 0 x = x . flatten ( ) else : if ( axis >= x . ndim ) : raise ValueError ( 'Axis should not exceed x.ndim-1.' ) if ( axis < 0 ) : axis = ( x . ndim + axis ) shape = [ x . shape [ i ] for i in xrange ( x . ndim ) ] shape_ = shape [ : ] shape_ . insert ( ( axis + 1 ) , repeats ) shape [ axis ] = ( shape [ axis ] * repeats ) dims_ = list ( numpy . arange ( x . ndim ) ) dims_ . insert ( ( axis + 1 ) , 'x' ) z = tensor . alloc ( x . dimshuffle ( * dims_ ) , * shape_ ) . reshape ( shape ) return z
repeat a 2d tensor .