Slice out the corresponding part of tensor given the pnum variable.
191820
def slice(self, tf_tensor, tensor_shape):
    """""""
    tensor_layout = self.tensor_layout(tensor_shape)

    if tensor_layout.is_fully_replicated:
      return self.LaidOutTensor([tf_tensor])
    else:
      slice_shape = self.slice_shape(tensor_shape)
      slice_begins = [
          self.slice_begin(tensor_shape, pnum) for pnum in xrange(self.size)
      ]
      slice_begins_tensor = tf.stack(slice_begins)
      # slice on source device
      selected_slice_begin = tf.gather(slice_begins_tensor, self.pnum_tensor)
      return self.LaidOutTensor(
          [tf.slice(tf_tensor, selected_slice_begin, slice_shape)])
1238132
def use_to_ned(tensor):
    '''
    
    '''
    return np.array(ROT_NED_USE.T * np.matrix(tensor) * ROT_NED_USE)
659422
def to_half(b:Collection[Tensor])->Collection[Tensor]:
    ""
    if is_listy(b): return [to_half(o) for o in b]
    return b.half() if b.dtype not in [torch.int64, torch.int32, torch.int16] else b
230515
def _get_float(data, position, dummy0, dummy1, dummy2):
    """"""
    end = position + 8
    return _UNPACK_FLOAT(data[position:end])[0], end
44533
def unwrap(tensor):
  
  while isinstance(tensor, (PrettyTensor, Loss)):
    tensor = tensor.tensor
  return tensor
574826
def __get_slice(data, slice_number, axis=0, flipH=False, flipV=False):
    
    if axis == 0:
        data2d =  data[slice_number, :, :]
    elif axis == 1:
        data2d = data[:, slice_number, :]
    elif axis == 2:
        data2d = data[:, :, slice_number]
    else:
        logger.error("axis number error")
        print("axis number error")
        return None

    if flipV:
        if data2d is not None:
            data2d = data2d[-1:0:-1,:]
    if flipH:
        if data2d is not None:
            data2d = data2d[:, -1:0:-1]
    return data2d
1253547
def _flip_lr(x):
    ""
    #return x.flip(2)
    if isinstance(x, ImagePoints):
        x.flow.flow[...,0] *= -1
        return x
    return tensor(np.ascontiguousarray(np.array(x)[...,::-1]))
1307321
def channel_view(x:Tensor)->Tensor:
    ""
    return x.transpose(0,1).contiguous().view(x.shape[1],-1)
271343
def _get_axis(self, array, axis, slice_num,
                  extended=False,
                  transpose=True):
        """"""

        slice_list = [slice(None)] * array.ndim
        slice_list[axis] = slice_num
        slice_data = array[tuple(slice_list)]
        if transpose:  # for proper orientation
            slice_data = slice_data.T

        if not extended:
            # return just the slice data
            return slice_data
        else:
            # additionally include which dim and which slice num
            return axis, slice_num, slice_data
323065
def combine_slices(self, slices, tensor_shape, device=None):
    
    if tensor_shape.ndims == 0:
      return slices[0]

    ret = slices[:]
    tensor_layout = self.tensor_layout(tensor_shape)
    for mesh_dim, tensor_axis in zip(
        self.shape, tensor_layout.mesh_axis_to_tensor_axis(self.ndims)):
      slice_size = len(ret) // mesh_dim.size
      if tensor_axis is None:
        ret = ret[:slice_size]
      else:
        if device:
          devices = [device] * slice_size
        else:
          devices = [ret[i].device for i in xrange(slice_size)]
        concat_inputs = []
        for i in xrange(slice_size):
          concat_inputs.append(
              [ret[i + slice_size * j] for j in xrange(mesh_dim.size)])
        ret = parallel(
            devices, tf.concat, concat_inputs,
            axis=[tensor_axis] * len(devices))
    assert len(ret) == 1
    return ret[0]
1285787
def spatial_slice_zeros(x):
  """"""
  return tf.cast(tf.reduce_all(tf.less_equal(x, 0.0), [0, 1, 2]),
                 tf.float32)
268075
function sliceOf(ars, i, parts) {
  return ars.slice(
    Math.floor(i/parts*ars.length),
    Math.floor((i+1)/parts*ars.length));
}
581579
private static TensorBuilder getTensorFromVariables(VariableNumMap variables) {
    // Get the dimensions and dimension sizes for the tensor.
    int[] dimensions = variables.getVariableNumsArray();
    int[] sizes = new int[dimensions.length];
    List<DiscreteVariable> varTypes = variables.getDiscreteVariables();
    for (int i = 0; i < varTypes.size(); i++) {
      sizes[i] = varTypes.get(i).numValues();
    }
    return new SparseTensorBuilder(dimensions, sizes);
  }
799277
def _parse_array(self, tensor_proto):
        """"""
        try:
            from onnx.numpy_helper import to_array
        except ImportError as e:
            raise ImportError("Unable to import onnx which is required {}".format(e))
        np_array = to_array(tensor_proto).reshape(tuple(tensor_proto.dims))
        return mx.nd.array(np_array)
254078
def slicenet_internal(inputs, targets, target_space, hparams, run_decoder=True):
  """"""
  with tf.variable_scope("slicenet"):
    # Project to hidden size if necessary
    if inputs.get_shape().as_list()[-1] != hparams.hidden_size:
      inputs = common_layers.conv_block(
          inputs,
          hparams.hidden_size, [((1, 1), (3, 3))],
          first_relu=False,
          padding="SAME",
          force2d=True)

    # Flatten inputs and encode.
    inputs = tf.expand_dims(common_layers.flatten4d3d(inputs), axis=2)
    inputs_mask = 1.0 - embedding_to_padding(inputs)
    inputs = common_layers.add_timing_signal(inputs)  # Add position info.
    target_space_emb = embed_target_space(target_space, hparams.hidden_size)
    extra_layers = int(hparams.num_hidden_layers * 1.5)
    inputs_encoded = multi_conv_res(
        inputs, "SAME", "encoder", extra_layers, hparams, mask=inputs_mask)
    if not run_decoder:
      return inputs_encoded
    # Do the middle part.
    decoder_start, similarity_loss = slicenet_middle(
        inputs_encoded, targets, target_space_emb, inputs_mask, hparams)
    # Decode.
    decoder_final = multi_conv_res(
        decoder_start,
        "LEFT",
        "decoder",
        hparams.num_hidden_layers,
        hparams,
        mask=inputs_mask,
        source=inputs_encoded)
    return decoder_final, tf.reduce_mean(similarity_loss)
311011
def get_axis(array, axis, slice_num):
    """"""

    slice_list = [slice(None)] * array.ndim
    slice_list[axis] = slice_num
    slice_data = array[tuple(slice_list)].T  # transpose for proper orientation

    return slice_data
43100
def split_last_dimension(x, n):
  
  x_shape = common_layers.shape_list(x)
  m = x_shape[-1]
  if isinstance(m, int) and isinstance(n, int):
    assert m % n == 0
  return tf.reshape(x, x_shape[:-1] + [n, m // n])