def testEncodeScalar(self):
    array_str = array_to_source.array_to_source('array', 4)
    expected_str = """array = np.array([
    4,
]).reshape(())
"""
    self.assertEqual(expected_str, array_str)
  def testEncodeArray(self):
    array_str = array_to_source.array_to_source('array', [1, 2, 3])
    expected_str = """array = np.array([
    1,
    2,
    3,
]).reshape((3,))
"""
    self.assertEqual(expected_str, array_str)
Exemple #3
0
def save_ground_truth_part(name, tuple_path, mean, sem, std, sestd):
    """Saves a ground truth part to strings.

  This is meant to be called with outputs of
  `nest.flatten_with_tuple_paths(ground_truth_mean)`.

  Args:
    name: Python `str`. Name of the sample transformation.
    tuple_path: Tuple path of the part of the ground truth we're saving. See
      `nest.flatten_with_tuple_paths`.
    mean: Ground truth mean, or `None` if it is absent.
    sem: Ground truth stadard error of the mean, or `None` if it is absent.
    std: Ground truth standard deviation, or `None` if it is absent.
    sestd: Ground truth mean, or `None` if it is absent.

  Returns:
    array_strs: Python list of strings, representing the encoded arrays (that
      were present). Typically these would be joined with a newline and written
      out to a module, which can then be passed to `load_ground_truth_part`.
  """

    array_strs = []
    mean_name, sem_name, std_name, sestd_name = _get_global_variable_names(
        name, tuple_path)

    if mean is not None:
        array_strs.append(array_to_source.array_to_source(mean_name, mean))

    if sem is not None:
        array_strs.append(array_to_source.array_to_source(sem_name, sem))

    if std is not None:
        array_strs.append(array_to_source.array_to_source(std_name, std))

    if sestd is not None:
        array_strs.append(array_to_source.array_to_source(sestd_name, sestd))

    return array_strs