def _reshape(arg, shape):
 if isinstance(arg, tuple):
  raise TypeError('Composite batches not supported.')
 assert (not isinstance(arg, list))
 if isinstance(arg, (np.ndarray, theano.tensor.TensorVariable)):
  return arg.reshape(shape)
 elif isinstance(arg, theano.sparse.SparseVariable):
  warnings.warn('Using pylearn2.space._reshape(), which is a memory-inefficient hack for reshaping sparse tensors. Do not use this on large tensors. This will eventually be replaced by a proper Theano Op for sparse reshaping, once that is written.')
  dense = theano.sparse.dense_from_sparse(arg)
  dense = dense.reshape(shape)
  if (arg.format == 'csr'):
   return theano.sparse.csr_from_dense(dense)
  elif (arg.format == 'csc'):
   return theano.sparse.csc_from_dense(dense)
  else:
   raise ValueError(('Unexpected sparse format "%s".' % arg.format))
 else:
  raise TypeError(('Unexpected batch type "%s"' % str(type(arg))))

def _reshape ( arg , shape ) : if isinstance ( arg , tuple ) : raise TypeError ( 'Composite batches not supported.' ) assert ( not isinstance ( arg , list ) ) if isinstance ( arg , ( np . ndarray , theano . tensor . TensorVariable ) ) : return arg . reshape ( shape ) elif isinstance ( arg , theano . sparse . SparseVariable ) : warnings . warn ( 'Using pylearn2.space._reshape(), which is a memory-inefficient hack for reshaping sparse tensors. Do not use this on large tensors. This will eventually be replaced by a proper Theano Op for sparse reshaping, once that is written.' ) dense = theano . sparse . dense_from_sparse ( arg ) dense = dense . reshape ( shape ) if ( arg . format == 'csr' ) : return theano . sparse . csr_from_dense ( dense ) elif ( arg . format == 'csc' ) : return theano . sparse . csc_from_dense ( dense ) else : raise ValueError ( ( 'Unexpected sparse format "%s".' % arg . format ) ) else : raise TypeError ( ( 'Unexpected batch type "%s"' % str ( type ( arg ) ) ) )
reshapes a tensor .