Generator over all |CoarseGrains| for the given blackbox.

    If a box has multiple outputs, those outputs are partitioned into the same
    coarse-grain macro-element.
349026
def all_coarse_grains_for_blackbox(blackbox):
    
    for partition in all_partitions(blackbox.output_indices):
        for grouping in all_groupings(partition):
            coarse_grain = CoarseGrain(partition, grouping)
            try:
                validate.blackbox_and_coarse_grain(blackbox, coarse_grain)
            except ValueError:
                continue
            yield coarse_grain
579414
function generate(base, tuple, index) {
    var name = dims[index],
        v = vals[index++],
        k, key;

    for (k in v) {
      tuple[name] = v[k];
      key = base ? base + '|' + k : k;
      if (index < n) generate(key, tuple, index);
      else if (!curr[key]) aggr.cell(key, tuple);
    }
  }
304680
def _granularities(self):
        
        keep = False
        for g in GRANULARITIES:
            if g == app_settings.MIN_GRANULARITY and not keep:
                keep = True
            elif g == app_settings.MAX_GRANULARITY and keep:
                keep = False
                yield g
            if keep:
                yield g
1214494
def gen_mul(src1, src2, dst):
        
        assert src1.size == src2.size

        return ReilBuilder.build(ReilMnemonic.MUL, src1, src2, dst)
85522
def generator(self, output, target):
        ""
        fake_pred = self.gan_model.critic(output)
        return self.loss_funcG(fake_pred, target, output)
704815
def flatten_check(out:Tensor, targ:Tensor) -> Tensor:
    ""
    out,targ = out.contiguous().view(-1),targ.contiguous().view(-1)
    assert len(out) == len(targ), f"Expected output and target to have the same number of elements but got {len(out)} and {len(targ)}."
    return out,targ
1110315
def run_tpm(system, steps, blackbox):
    
    # Generate noised TPM
    # Noise the connections from every output element to elements in other
    # boxes.
    node_tpms = []
    for node in system.nodes:
        node_tpm = node.tpm_on
        for input_node in node.inputs:
            if not blackbox.in_same_box(node.index, input_node):
                if input_node in blackbox.output_indices:
                    node_tpm = marginalize_out([input_node], node_tpm)

        node_tpms.append(node_tpm)

    noised_tpm = rebuild_system_tpm(node_tpms)
    noised_tpm = convert.state_by_node2state_by_state(noised_tpm)

    tpm = convert.state_by_node2state_by_state(system.tpm)

    # Muliply by noise
    tpm = np.dot(tpm, np.linalg.matrix_power(noised_tpm, steps - 1))

    return convert.state_by_state2state_by_node(tpm)
651773
def genOutputs(self, code, match):
        

        out = sorted((k, match.output(m)) for (k, m) in
                     self.collectTriggers(match.match, code).items())
        out = list(map(lambda a: a[1], out))
        return out
899011
def build_iters(data_dir, max_records, q, horizon, splits, batch_size):
    
    # Read in data as numpy array
    df = pd.read_csv(os.path.join(data_dir, "electricity.txt"), sep=",", header=None)
    feature_df = df.iloc[:, :].astype(float)
    x = feature_df.as_matrix()
    x = x[:max_records] if max_records else x

    # Construct training examples based on horizon and window
    x_ts = np.zeros((x.shape[0] - q, q, x.shape[1]))
    y_ts = np.zeros((x.shape[0] - q, x.shape[1]))
    for n in range(x.shape[0]):
        if n + 1 < q:
            continue
        elif n + 1 + horizon > x.shape[0]:
            continue
        else:
            y_n = x[n + horizon, :]
            x_n = x[n + 1 - q:n + 1, :]
        x_ts[n-q] = x_n
        y_ts[n-q] = y_n

    # Split into training and testing data
    training_examples = int(x_ts.shape[0] * splits[0])
    valid_examples = int(x_ts.shape[0] * splits[1])
    x_train, y_train = x_ts[:training_examples], \
                       y_ts[:training_examples]
    x_valid, y_valid = x_ts[training_examples:training_examples + valid_examples], \
                       y_ts[training_examples:training_examples + valid_examples]
    x_test, y_test = x_ts[training_examples + valid_examples:], \
                     y_ts[training_examples + valid_examples:]

    #build iterators to feed batches to network
    train_iter = mx.io.NDArrayIter(data=x_train,
                                   label=y_train,
                                   batch_size=batch_size)
    val_iter = mx.io.NDArrayIter(data=x_valid,
                                 label=y_valid,
                                 batch_size=batch_size)
    test_iter = mx.io.NDArrayIter(data=x_test,
                                  label=y_test,
                                  batch_size=batch_size)
    return train_iter, val_iter, test_iter
19748
public static void imageToTensor(Planar<GrayF32> input , Tensor_F32 output , int miniBatch) {
		if( input.isSubimage())
			throw new RuntimeException("Subimages not accepted");
		if( output.getDimension() != 4 )
			throw new IllegalArgumentException("Output should be 4-DOF.  batch + spatial (channel,height,width)");
		if( output.length(1) != input.getNumBands() )
			throw new IllegalArgumentException("Number of bands don't match");
		if( output.length(2) != input.getHeight() )
			throw new IllegalArgumentException("Spatial height doesn't match");
		if( output.length(3) != input.getWidth() )
			throw new IllegalArgumentException("Spatial width doesn't match");

		for (int i = 0; i < input.getNumBands(); i++) {
			GrayF32 band = input.getBand(i);
			int indexOut = output.idx(miniBatch,i,0,0);

			int length = input.width*input.height;
			System.arraycopy(band.data, 0,output.d,indexOut,length);
		}
	}
559665
def combine(self, blocks, copy=True):
        
        if len(blocks) == 0:
            return self.make_empty()

        # FIXME: optimization potential
        indexer = np.sort(np.concatenate([b.mgr_locs.as_array
                                          for b in blocks]))
        inv_indexer = lib.get_reverse_indexer(indexer, self.shape[0])

        new_blocks = []
        for b in blocks:
            b = b.copy(deep=copy)
            b.mgr_locs = algos.take_1d(inv_indexer, b.mgr_locs.as_array,
                                       axis=0, allow_fill=False)
            new_blocks.append(b)

        axes = list(self.axes)
        axes[0] = self.items.take(indexer)

        return self.__class__(new_blocks, axes, do_integrity_check=False)
900690
def each
      if block_given?
        length.times do |n|
          yield build_coordinate(n)
        end
        self
      else
        length.times.collect { |n|
          build_coordinate(n)
        }.to_enum
      end
    end
467163
def _generate_examples(self, archive, validation_labels=None):
    """"""
    if validation_labels:  # Validation split
      for example in self._generate_examples_validation(archive,
                                                        validation_labels):
        yield example
    # Training split. Main archive contains archives names after a synset noun.
    # Each sub-archive contains pictures associated to that synset.
    for fname, fobj in archive:
      label = fname[:-4]  # fname is something like 'n01632458.tar'
      # TODO(b/117643231): in py3, the following lines trigger tarfile module
      # to call `fobj.seekable()`, which Gfile doesn't have. We should find an
      # alternative, as this loads ~150MB in RAM.
      fobj_mem = io.BytesIO(fobj.read())
      for image_fname, image_fobj in tfds.download.iter_archive(
          fobj_mem, tfds.download.ExtractMethod.TAR):
        yield {
            'file_name': image_fname,
            'image': image_fobj,
            'label': label,
        }
1135644
def blackbox(blackbox):
    """"""
    if tuple(sorted(blackbox.output_indices)) != blackbox.output_indices:
        raise ValueError('Output indices {} must be ordered'.format(
            blackbox.output_indices))

    partition(blackbox.partition)

    for part in blackbox.partition:
        if not set(part) & set(blackbox.output_indices):
            raise ValueError(
                'Every blackbox must have an output - {} does not'.format(
                    part))
597278
def map_vectors!
      return to_enum(:map_vectors!) unless block_given?

      vectors.dup.each do |n|
        self[n] = should_be_vector!(yield(self[n]))
      end

      self
    end
1109387
def _split_generators(self, dl_manager):
    """"""
    root_url = "http://images.cocodataset.org/"
    urls = {
        # Train/validation set
        "train_images": "zips/train2014.zip",
        "val_images": "zips/val2014.zip",
        "trainval_annotations": "annotations/annotations_trainval2014.zip",
        # Testing set (no annotations) (2014)
        "test_images": "zips/test2014.zip",
        "test_annotations": "annotations/image_info_test2014.zip",
        # Testing set (no annotations) (2015)
        "test2015_images": "zips/test2015.zip",
        "test2015_annotations": "annotations/image_info_test2015.zip",
    }
    extracted_paths = dl_manager.download_and_extract({
        key: root_url + url for key, url in urls.items()
    })

    return [
        tfds.core.SplitGenerator(
            name=tfds.Split.TRAIN,
            num_shards=10,
            gen_kwargs=dict(
                image_dir=extracted_paths["train_images"],
                annotation_dir=extracted_paths["trainval_annotations"],
                split_type="train2014",
            )),
        tfds.core.SplitGenerator(
            name=tfds.Split.VALIDATION,
            num_shards=10,
            gen_kwargs=dict(
                image_dir=extracted_paths["val_images"],
                annotation_dir=extracted_paths["trainval_annotations"],
                split_type="val2014",
            )),
        # Warning: Testing split only contains the images without any annotation
        tfds.core.SplitGenerator(
            name=tfds.Split.TEST,
            num_shards=10,
            gen_kwargs=dict(
                image_dir=extracted_paths["test_images"],
                annotation_dir=extracted_paths["test_annotations"],
                split_type="test2014",
                has_annotation=False,
            )),
        tfds.core.SplitGenerator(
            name="test2015",
            num_shards=10,
            gen_kwargs=dict(
                image_dir=extracted_paths["test2015_images"],
                annotation_dir=extracted_paths["test2015_annotations"],
                split_type="test2015",
                has_annotation=False,
            )),
    ]
1355899
def macro2blackbox_outputs(self, macro_indices):
        
        if not self.blackbox:
            raise ValueError('System is not blackboxed')

        return tuple(sorted(set(
            self.macro2micro(macro_indices)
        ).intersection(self.blackbox.output_indices)))