Gather all of the information related to the patterns
353850
public static function gather($options = array()) {

		// set default vars
		$exportClean        = (isset($options["exportClean"])) ? $options["exportClean"] : false;
		$exportFiles        = (isset($options["exportClean"])) ? $options["exportFiles"] : false;
		$dispatcherInstance = Dispatcher::getInstance();

		// cleaning the var for use below, i know this is stupid
		$options = array();

		// dispatch that the data gather has started
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.gatherStart",$event);

		// load up the rules for parsing patterns and the directories
		self::loadRules($options);

		// dispatch that the rules are loaded
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.rulesLoaded",$event);

		// iterate over the patterns & related data and regenerate the entire site if they've changed
		// seems a little silly to use symfony finder here. not really giving me any power
		if (!is_dir(Config::getOption("patternSourceDir"))) {
			Console::writeError("having patterns is important. please make sure you've installed a starterkit and/or that ".Console::getHumanReadablePath(Config::getOption("patternSourceDir"))." exists...");
		}

		$patternSourceDir = Config::getOption("patternSourceDir");
		$patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);

		// sort the returned objects
		$patternObjects = iterator_to_array($patternObjects);
		ksort($patternObjects);

		/**
     * @var string $name
     * @var \SplFileInfo $object
     */
    foreach ($patternObjects as $name => $object) {

			$ext      = $object->getExtension();
			$isDir    = $object->isDir();
			$isFile   = $object->isFile();

			$path     = str_replace($patternSourceDir.DIRECTORY_SEPARATOR,"",$object->getPath());
			$pathName = str_replace($patternSourceDir.DIRECTORY_SEPARATOR,"",$object->getPathname());
			$name     = $object->getFilename();
			$depth    = substr_count($pathName,DIRECTORY_SEPARATOR);

			// iterate over the rules and see if the current file matches one, if so run the rule
			foreach (self::$rules as $rule) {
				if ($rule->test($depth, $ext, $isDir, $isFile, $name)) {
					$rule->run($depth, $ext, $path, $pathName, $name);
				}
			}

		}

		// dispatch that the data is loaded
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.dataLoaded",$event);

		// make sure all of the appropriate pattern data is pumped into $this->d for rendering patterns
		$dataLinkExporter       = new DataLinkExporter();
		$dataLinkExporter->run();

		// make sure all of the appropriate pattern data is pumped into $this->d for rendering patterns
		$dataMergeExporter       = new DataMergeExporter();
		$dataMergeExporter->run();

		// dispatch that the raw pattern helper is about to start
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.rawPatternHelperStart",$event);

		// add the lineage info to PatternData::$store
		$rawPatternHelper        = new RawPatternHelper();
		$rawPatternHelper->run();

		// dispatch that the raw pattern helper is ended
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.rawPatternHelperEnd",$event);

		// dispatch that the lineage helper is about to start
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.lineageHelperStart",$event);

		// add the lineage info to PatternData::$store
		$lineageHelper           = new LineageHelper();
		$lineageHelper->run();

		// dispatch that the lineage helper is ended
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.lineageHelperEnd",$event);


		// dispatch that the pattern state helper is about to start
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.patternStateHelperStart",$event);

		// using the lineage info update the pattern states on PatternData::$store
		$patternStateHelper      = new PatternStateHelper();
		$patternStateHelper->run();

		// dispatch that the pattern state helper is ended
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.patternStateHelperEnd",$event);

		// set-up code pattern paths
		$ppdExporter             = new PatternPathSrcExporter();
		$patternPathSrc          = $ppdExporter->run();
		$options                 = array();
		$options["patternPaths"] = $patternPathSrc;

		// dispatch that the code helper is about to start
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.codeHelperStart",$event);

		// render out all of the patterns and store the generated info in PatternData::$store
		$options["exportFiles"]  = $exportFiles;
		$options["exportClean"]  = $exportClean;
		$patternCodeHelper       = new PatternCodeHelper($options);
		$patternCodeHelper->run();

		// dispatch that the pattern code helper is ended
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.patternCodeHelperEnd",$event);

		// dispatch that the gather has ended
		$event = new PatternDataEvent($options);
		$dispatcherInstance->dispatch("patternData.gatherEnd",$event);

	}
206735
def collect(self):
        

        # Initialize results
        results = {}

        if os.access(self.PROC, os.R_OK):

            # Open File
            file = open(self.PROC)
            # Build Regular Expression
            greed = ''
            if str_to_bool(self.config['greedy']):
                greed = '\S*'

            exp = (('^(?:\s*)((?:%s)%s):(?:\s*)' +
                    '(?P<rx_bytes>\d+)(?:\s*)' +
                    '(?P<rx_packets>\w+)(?:\s*)' +
                    '(?P<rx_errors>\d+)(?:\s*)' +
                    '(?P<rx_drop>\d+)(?:\s*)' +
                    '(?P<rx_fifo>\d+)(?:\s*)' +
                    '(?P<rx_frame>\d+)(?:\s*)' +
                    '(?P<rx_compressed>\d+)(?:\s*)' +
                    '(?P<rx_multicast>\d+)(?:\s*)' +
                    '(?P<tx_bytes>\d+)(?:\s*)' +
                    '(?P<tx_packets>\w+)(?:\s*)' +
                    '(?P<tx_errors>\d+)(?:\s*)' +
                    '(?P<tx_drop>\d+)(?:\s*)' +
                    '(?P<tx_fifo>\d+)(?:\s*)' +
                    '(?P<tx_colls>\d+)(?:\s*)' +
                    '(?P<tx_carrier>\d+)(?:\s*)' +
                    '(?P<tx_compressed>\d+)(?:.*)$') %
                   (('|'.join(self.config['interfaces'])), greed))
            reg = re.compile(exp)
            # Match Interfaces
            for line in file:
                match = reg.match(line)
                if match:
                    device = match.group(1)
                    results[device] = match.groupdict()
            # Close File
            file.close()
        else:
            if not psutil:
                self.log.error('Unable to import psutil')
                self.log.error('No network metrics retrieved')
                return None

            network_stats = psutil.network_io_counters(True)
            for device in network_stats.keys():
                network_stat = network_stats[device]
                results[device] = {}
                results[device]['rx_bytes'] = network_stat.bytes_recv
                results[device]['tx_bytes'] = network_stat.bytes_sent
                results[device]['rx_packets'] = network_stat.packets_recv
                results[device]['tx_packets'] = network_stat.packets_sent

        for device in results:
            stats = results[device]
            for s, v in stats.items():
                # Get Metric Name
                metric_name = '.'.join([device, s])
                # Get Metric Value
                metric_value = self.derivative(metric_name,
                                               long(v),
                                               diamond.collector.MAX_COUNTER)

                # Convert rx_bytes and tx_bytes
                if s == 'rx_bytes' or s == 'tx_bytes':
                    convertor = diamond.convertor.binary(value=metric_value,
                                                         unit='byte')

                    for u in self.config['byte_unit']:
                        # Public Converted Metric
                        self.publish(metric_name.replace('bytes', u),
                                     convertor.get(unit=u), 2)
                else:
                    # Publish Metric Derivative
                    self.publish(metric_name, metric_value)

        return None
1135736
def get_keywords(self, pattern="*"):
        

        sql = """SELECT collection.collection_id, collection.name,
                        keyword.name, keyword.doc, keyword.args
                 FROM collection_table as collection
                 JOIN keyword_table as keyword
                 WHERE collection.collection_id == keyword.collection_id
                 AND keyword.name like ?
                 ORDER by collection.name, keyword.name
             """
        pattern = self._glob_to_sql(pattern)
        cursor = self._execute(sql, (pattern,))
        result = [(row[0], row[1], row[2], row[3], row[4])
                  for row in cursor.fetchall()]
        return list(set(result))
195548
def pattern_of(index):
    ''''''
    return np.array([[index & 2**0,index & 2**1,index & 2**2],
                     [index & 2**3,index & 2**4,index & 2**5],
                     [index & 2**6,index & 2**7,index & 2**8]], bool)
1110623
def get_stats(self, pattern):
        
        if not self.cache:
            return
        key_list = self.cache.get(Conf.Q_STAT)
        if not key_list or len(key_list) == 0:
            return []
        stats = []
        for key in key_list:
            stat = self.cache.get(key)
            if stat:
                stats.append(stat)
            else:
                key_list.remove(key)
        self.cache.set(Conf.Q_STAT, key_list)
        return stats
452819
public void mapColumns() {
            //System.err.print("Patterns found: ");
            //System.err.println(pattern_list.size());
        
            int index = 0;
            //NOTE: occurrences can be used as Sigma X<k,j> when calculating Entropy
            for (InterveningWordsPattern a_pattern : pattern_list.keySet()) {
                //int val = a_pattern.getOccurrences();
                //System.err.println(a_pattern.getPattern() + " " + val);
                matrix_column_map.put(new Integer(index), a_pattern);
                index++;
                InterveningWordsPattern b_pattern = new InterveningWordsPattern(a_pattern.getPattern());
                b_pattern.setOccurrences(a_pattern.getOccurrences());
                b_pattern.setReverse(true);
                matrix_column_map.put(new Integer(index), b_pattern);
                index++;
            }
    }
330206
def __extract_pattern_nodes(graph):
    
    tp_nodes = graph.subjects(RDF.type, AGORA.TriplePattern)
    for tpn in tp_nodes:
        subject = list(graph.objects(tpn, AGORA.subject)).pop()
        predicate = list(graph.objects(tpn, AGORA.predicate)).pop()
        obj = list(graph.objects(tpn, AGORA.object)).pop()
        subject_str = list(graph.objects(subject, RDFS.label)).pop().toPython()
        predicate_str = graph.qname(predicate)
        if (obj, RDF.type, AGORA.Variable) in graph:
            object_str = list(graph.objects(obj, RDFS.label)).pop().toPython()
        else:
            object_str = list(graph.objects(obj, AGORA.value)).pop().toPython()
        __plan_patterns[tpn] = '{} {} {}'.format(subject_str, predicate_str, object_str)
1099125
private void doExtraction(GatherExtractionInfo info) {
    // Insert a global temp if we are using the USE_GLOBAL_TEMP pattern.
    if (pattern == Pattern.USE_GLOBAL_TEMP) {
      Node injectionPoint = compiler.getNodeForCodeInsertion(null);

      Node var = NodeUtil.newVarNode(PROTOTYPE_ALIAS, null)
          .useSourceInfoIfMissingFromForTree(injectionPoint);

      injectionPoint.addChildToFront(var);
      compiler.reportChangeToEnclosingScope(var);
    }
    // Go through all extraction instances and extract each of them.
    for (ExtractionInstance instance : info.instances) {
      extractInstance(instance);
    }
  }
191399
function (source, pattern) {
    var results = [], match;
    while ((match = pattern.exec(source)) !== null)
      results.push(match[1]);
    return results;
  }
426761
function findAllIndices() {
  var needle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : mandatory();
  var haystack = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mandatory();

  var indices = [];
  for (var i = 0; i < haystack.length; i++) {
    if (haystack.substr(i, needle.length) === needle) {
      indices.push(i);
    }
  }

  if (indices.length) {
    return indices;
  } else {
    return -1;
  }
}
140822
def iter(self):
        """"""
        if self.patterns:
            patterns = list(self.patterns)
            for pattern in patterns:
                yield pattern
216546
def find(pattern, path='.', exclude=None, recursive=True):
    """"""
    import fnmatch
    import os

    if recursive:
        for root, dirnames, filenames in os.walk(path):
            for pat in _to_list(pattern):
                for filename in fnmatch.filter(filenames, pat):
                    filepath = join(abspath(root), filename)
                    for excl in _to_list(exclude):
                        if excl and fnmatch.fnmatch(filepath, excl):
                            break
                    else:
                        yield filepath
    else:
        for pat in _to_list(pattern):
            for filename in fnmatch.filter(list(path), pat):
                filepath = join(abspath(path), filename)
                for excl in _to_list(exclude):
                    if excl and fnmatch.fnmatch(filepath, excl):
                        break
                    else:
                        yield filepath
1037403
def all_gather(data):
    
    world_size = get_world_size()
    if world_size == 1:
        return [data]

    # serialized to a Tensor
    buffer = pickle.dumps(data)
    storage = torch.ByteStorage.from_buffer(buffer)
    tensor = torch.ByteTensor(storage).to("cuda")

    # obtain Tensor size of each rank
    local_size = torch.IntTensor([tensor.numel()]).to("cuda")
    size_list = [torch.IntTensor([0]).to("cuda") for _ in range(world_size)]
    dist.all_gather(size_list, local_size)
    size_list = [int(size.item()) for size in size_list]
    max_size = max(size_list)

    # receiving Tensor from all ranks
    # we pad the tensor because torch all_gather does not support
    # gathering tensors of different shapes
    tensor_list = []
    for _ in size_list:
        tensor_list.append(torch.ByteTensor(size=(max_size,)).to("cuda"))
    if local_size != max_size:
        padding = torch.ByteTensor(size=(max_size - local_size,)).to("cuda")
        tensor = torch.cat((tensor, padding), dim=0)
    dist.all_gather(tensor_list, tensor)

    data_list = []
    for size, tensor in zip(size_list, tensor_list):
        buffer = tensor.cpu().numpy().tobytes()[:size]
        data_list.append(pickle.loads(buffer))

    return data_list
1314169
def info(self):
        
        for key, value in self.dataset['info'].items():
            print('{}: {}'.format(key, value))
213804
def GetPattern(self):
    """"""
    stoptimes = self.GetStopTimes()
    return tuple(st.stop for st in stoptimes)
406506
public void findPatterns() 
        throws Exception {
        HashSet<String> patterns = new HashSet<String>();
        for (String phrase : filtered_phrases) {
            String phrase_arr[] = phrase.split(":");
            String A = phrase_arr[0];
            String B = phrase_arr[1];
            //System.err.println(A + ": " + B);

            patterns.addAll(searchDirectoryForPattern(new File(DATA_DIR), A, B));
        }
        Iterator iter = patterns.iterator();
        while (iter.hasNext()) {
            String curr_pattern_str = (String)iter.next();
            String[] curr_pattern = curr_pattern_str.split("\\s");
            int curr_length = curr_pattern.length;
            //System.err.println("length of pattern: " + curr_length);
            //do a for loop with all combinatorials of wildcard patterns
            //for each iteration do a wildcard search
            for (int comb = 0; comb < (int)Math.pow(2.0,(double)curr_length); comb++) {
                String comb_pattern = "\\s" + combinatorialPatternMaker(curr_pattern, curr_length, comb);
                try {
                    int score = countWildcardPhraseFrequencies(new File(DATA_DIR), ".*" + comb_pattern + ".*");
                    InterveningWordsPattern db_pattern = new InterveningWordsPattern(comb_pattern);
                    db_pattern.setOccurrences(score);
                    pattern_list.put(db_pattern, score); //insert the pattern into database (only if it has a high enough score)

                    //System.err.println(comb_pattern + ": " + score);
                } catch (Exception e) {
                    System.err.println("could not perform wildcard search");
                }
            }
        }
    }
669813
def get_all(self):
        
        res = self.es.search(index=self.index, doc_type=self.doc_type, body={'query': {'match_all': {}}})
        if not res['hits']['total']:
            return []
        return [Visualization.from_kibana(hit) for hit in res['hits']['hits']]