text:
<?php
require_once 'parser.inc.php';

class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser {

    function setUp() {
        parent::setUp();
        $this->P->addMode('footnote',new Doku_Parser_Mode_Footnote());
    }

    function testFootnote() {
        $this->P->parse('Foo (( testing )) Bar');
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' testing ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testNotAFootnote() {
        $this->P->parse("Foo (( testing\n Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\nFoo (( testing\n Bar")),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteLinefeed() {
        $this->P->addMode('eol',new Doku_Parser_Mode_Eol());
        $this->P->parse("Foo (( testing\ntesting )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array('Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(" testing\ntesting ")),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteNested() {
        $this->P->parse('Foo (( x((y))z )) Bar');
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' x((y')),
              array('footnote_close',array()),
            ))),
            array('cdata',array('z )) Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteEol() {
        $this->P->addMode('eol',new Doku_Parser_Mode_Eol());
        $this->P->parse("Foo \nX(( test\ning ))Y\n Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array('Foo '.DOKU_PARSER_EOL.'X')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(" test\ning ")),
              array('footnote_close',array()),
            ))),
            array('cdata',array('Y'.DOKU_PARSER_EOL.' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteStrong() {
        $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong'));
        $this->P->parse('Foo (( **testing** )) Bar');
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' ')),
              array('strong_open',array()),
              array('cdata',array('testing')),
              array('strong_close',array()),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteHr() {
        $this->P->addMode('hr',new Doku_Parser_Mode_HR());
        $this->P->parse("Foo (( \n ---- \n )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' ')),
              array('hr',array()),
              array('cdata',array("\n ")),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteCode() {
        $this->P->addMode('code',new Doku_Parser_Mode_Code());
        $this->P->parse("Foo (( Test )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' ')),
              array('code',array('Test',null,null)),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnotePreformatted() {
        $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
        $this->P->parse("Foo (( \n  Test\n )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' ')),
              array('preformatted',array('Test')),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnotePreformattedEol() {
        $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
        $this->P->addMode('eol',new Doku_Parser_Mode_Eol());
        $this->P->parse("Foo (( \n  Test\n )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array('Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' ')),
              array('preformatted',array('Test')),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );

        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteUnformatted() {
        $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted());
        $this->P->parse("Foo (( <nowiki>Test</nowiki> )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' ')),
              array('unformatted',array('Test')),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteNotHeader() {
        $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted());
        $this->P->parse("Foo (( \n====Test====\n )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(" \n====Test====\n ")),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteTable() {
        $this->P->addMode('table',new Doku_Parser_Mode_Table());
        $this->P->parse("Foo ((
| Row 0 Col 1    | Row 0 Col 2     | Row 0 Col 3        |
| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
 )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('table_open',array(3, 2, 8)),
              array('tablerow_open',array()),
              array('tablecell_open',array(1,'left',1)),
              array('cdata',array(' Row 0 Col 1    ')),
              array('tablecell_close',array()),
              array('tablecell_open',array(1,'left',1)),
              array('cdata',array(' Row 0 Col 2     ')),
              array('tablecell_close',array()),
              array('tablecell_open',array(1,'left',1)),
              array('cdata',array(' Row 0 Col 3        ')),
              array('tablecell_close',array()),
              array('tablerow_close',array()),
              array('tablerow_open',array()),
              array('tablecell_open',array(1,'left',1)),
              array('cdata',array(' Row 1 Col 1    ')),
              array('tablecell_close',array()),
              array('tablecell_open',array(1,'left',1)),
              array('cdata',array(' Row 1 Col 2     ')),
              array('tablecell_close',array()),
              array('tablecell_open',array(1,'left',1)),
              array('cdata',array(' Row 1 Col 3        ')),
              array('tablecell_close',array()),
              array('tablerow_close',array()),
              array('table_close',array(123)),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteList() {
        $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock());
        $this->P->parse("Foo ((
  *A
    * B
  * C
 )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('listu_open',array()),
              array('listitem_open',array(1)),
              array('listcontent_open',array()),
              array('cdata',array("A")),
              array('listcontent_close',array()),
              array('listu_open',array()),
              array('listitem_open',array(2)),
              array('listcontent_open',array()),
              array('cdata',array(' B')),
              array('listcontent_close',array()),
              array('listitem_close',array()),
              array('listu_close',array()),
              array('listitem_close',array()),
              array('listitem_open',array(1)),
              array('listcontent_open',array()),
              array('cdata',array(' C')),
              array('listcontent_close',array()),
              array('listitem_close',array()),
              array('listu_close',array()),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );
        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteQuote() {
        $this->P->addMode('quote',new Doku_Parser_Mode_Quote());
        $this->P->parse("Foo ((
> def
>>ghi
 )) Bar");
        $calls = array (
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n".'Foo ')),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('quote_open',array()),
              array('cdata',array(" def")),
              array('quote_open',array()),
              array('cdata',array("ghi")),
              array('quote_close',array()),
              array('quote_close',array()),
              array('cdata',array(' ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(' Bar')),
            array('p_close',array()),
            array('document_end',array()),
        );

        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }

    function testFootnoteNesting() {
        $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong'));
        $this->P->parse("(( a ** (( b )) ** c ))");

        $calls = array(
            array('document_start',array()),
            array('p_open',array()),
            array('cdata',array("\n")),
            array('nest', array ( array (
              array('footnote_open',array()),
              array('cdata',array(' a ')),
              array('strong_open',array()),
              array('cdata',array(' (( b ')),
              array('footnote_close',array()),
            ))),
            array('cdata',array(" ")),
            array('strong_close',array()),
            array('cdata',array(" c ))")),
            array('p_close',array()),
            array('document_end',array()),
        );

        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
    }
}


text:
require 'sensu-plugin/check/cli'
require 'whois'

#
# Check Whois domain expiration
#
class WhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
  option :domain,
         short: '-d DOMAIN',
         long: '--domain DOMAIN',
         required: true,
         description: 'Domain to check'

  option :warning,
         short: '-w DAYS',
         long: '--warn DAYS',
         default: 30,
         description: 'Warn if fewer than DAYS away'

  option :critical,
         short: '-c DAYS',
         long: '--critical DAYS',
         default: 7,
         description: 'Critical if fewer than DAYS away'

  option :help,
         short: '-h',
         long: '--help',
         description: 'Show this message',
         on: :tail,
         boolean: true,
         show_options: true,
         exit: 0

  def check_days(num_days,
                 warning_days = config[:warning].to_i,
                 critical_days = config[:critical].to_i)
    case
    when num_days <= critical_days
      critical
    when num_days <= warning_days
      warning
    else
      ok
    end
  end

  def initialize
    super()
    whois = Whois.whois(config[:domain])
    @expires_on = DateTime.parse(whois.expires_on.to_s)
    @num_days = (@expires_on - DateTime.now).to_i
  end

  def run
    message "#{ config[:domain] } expires on #{ @expires_on.strftime('%m-%d-%Y') } (#{ @num_days } days away)"
    check_days @num_days
  end
end

redpajama_set_name: RedPajamaGithub


text:
Token::Token( TokenType aType, std::string aLexeme, int aLine, int aCol ) {
  type = aType;
  lexeme = aLexeme;
  line = aLine;
  col = aCol;
}

Token::Token( TokenType aType, int aLine, int aCol ) {
  type = aType;
  lexeme = "";
  line = aLine;
  col = aCol;
}

TokenType Token::getType() { return type; }
std::string Token::getLexeme() { return lexeme; }
int Token::getLine() { return line; }
int Token::getColumn() { return col; }

std::string Token::showType( TokenType aType ) {
  switch ( aType ) {
    case EOF_TOKEN: return "EOF";
    case SYMBOL: return "SYMBOL";
    case INTEGER: return "INT";
    case FLOAT: return "FLOAT";
    case BOOL: return "BOOL";
    case LAND: return "And";
    case LOR: return "Or";
    case LXOR: return "Xor";
    case ADD: return "Add";
    case MUL: return "Mul";
    case ASSIGN: return "Assign";
    case CMP: return "Relation";
    case CMP_EQ: return "Equality Relation";
    case FUNC: return "Func";
    case IF: return "If";
    case ELSE: return "Else";
    case DO: return "Do";
    case WHILE: return "While";
    case RETURN: return "Return";
    case IO_PRINT: return "Print";
    case IO_READ: return "Read";
    case PL: return "Open Parenthesis";
    case PR: return "Close Parenthesis";
    case BL: return "Open Brace";
    case BR: return "Close Brace";
    case COMMA: return "Comma";
    case SEMICOLON: return "Semicolon";
    case COLON: return "Colon";
    case TYPE: return "Type";

    default: return "ERR";
  }
}


text:
package com.tesshu.subsonic.client.fx.command.logic;

import com.tesshu.subsonic.client.fx.command.IParameter;
import com.tesshu.subsonic.client.fx.command.UpdateComponentLogic;
import com.tesshu.subsonic.client.fx.view.browsing.BrowsingContainer;

import java.util.concurrent.ExecutionException;

public interface BrowsingLogic<P extends IParameter> extends UpdateComponentLogic<BrowsingContainer, P> {

  void invoke(BrowsingContainer container) throws ExecutionException, InterruptedException, RuntimeException;

}


text:
import { getAvg } from './averageService';
import logoImg from './content/logo_1.png';

$('body').css('background-color', 'lightSkyBlue');

const scores = [90, 75, 60, 99, 94, 30];
const averageScore = getAvg(scores);
const messageToDisplay = `average score ${averageScore}`;

document.write(messageToDisplay);

const img = document.createElement('img');
img.src = logoImg;

document.getElementById('imgContainer').appendChild(img);


text:
<?xml version="1.0"?>
<ruleset name="Mess detection rules for Jenssegers\Date"
         xmlns="http://pmd.sf.net/ruleset/1.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
                     http://pmd.sf.net/ruleset_xml_schema.xsd"
         xsi:noNamespaceSchemaLocation="
                     http://pmd.sf.net/ruleset_xml_schema.xsd">
    <description>
        Mess detection rules for Jenssegers\Date
    </description>
    <rule ref="rulesets/codesize.xml" />
    <rule ref="rulesets/cleancode.xml" />
    <rule ref="rulesets/controversial.xml" />
    <rule ref="rulesets/design.xml" />
    <rule ref="rulesets/naming.xml/BooleanGetMethodName" />
    <rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
    <rule ref="rulesets/naming.xml/ConstantNamingConventions" />
    <rule ref="rulesets/naming.xml/LongVariable">
        <properties>
            <property name="maximum" value="25" />
        </properties>
    </rule>
    <rule ref="rulesets/naming.xml/ShortVariable" />
    <rule ref="rulesets/naming.xml/ShortMethodName" />
    <rule ref="rulesets/unusedcode.xml" />
</ruleset>


text:
import {Component, PropTypes, h,} from './Component';
import {Motion, spring,} from 'react-motion';

export default class PostStatus extends Component {

    awake({}) {
        this.state = {};
    }

    render({content, ...rest}) {
        const {owner, date, viewCount, voteCount}=content;
        return h('div', {
            ...rest,
            children: [
                h('div', {children: owner, key: 0}),
                h('div', {children: date, key: 1}),
                h('div', {children: viewCount, key: 2}),
                h('div', {children: voteCount, key: 3}),
            ]
        });
    }
}
PostStatus.propTypes = {};
PostStatus.defaultProps = {};


text:
package org.apache.jackrabbit.core.version;

import junit.framework.TestCase;

import java.util.Calendar;

/**
 * InternalVersionHistoryImplTest executes tests for
 * {@link InternalVersionHistoryImpl}.
 */
public class InternalVersionHistoryImplTest extends TestCase {

    /**
     * Checks if {@link InternalVersionHistoryImpl#getCurrentTime()} returns
     * monotonically increasing Calendar instances.
     */
    public void testGetCurrentTime() {
        Calendar last = InternalVersionHistoryImpl.getCurrentTime();
        for (int i = 0; i < 100; i++) {
            Calendar next = InternalVersionHistoryImpl.getCurrentTime();
            assertTrue("InternalVersionHistoryImpl.getCurrentTime() not monotonically increasing",
                    last.getTimeInMillis() < next.getTimeInMillis());
            last = next;
        }
    }
}


text:
// @comments:true
class WebControls {
    /**
     * Render a control
     */
    createControl(): any {
    }
}


text:
<?php

class Owebia_Shipping2_Model_Os2_Data_Cart extends Owebia_Shipping2_Model_Os2_Data_Abstract
{
    protected $_additionalAttributes = array('coupon_code', 'weight_unit', 'weight_for_charge', 'free_shipping');
    protected $_freeShipping;
    protected $_items;
    protected $_quote;
    protected $_options;

    public function __construct($arguments)
    {
        parent::__construct();
        $request = $arguments['request'];
        $this->_options = $arguments['options'];

        $this->_data = array(
            // Do not use quote to retrieve values, totals are not available
            // package_value and package_value_with_discount : Bad value in backoffice orders
            'price-tax+discount' => null,
            'price-tax-discount' => null,
            'price+tax+discount' => null,
            'price+tax-discount' => null,
            'weight' => $request->getData('package_weight'),
            'qty' => $request->getData('package_qty'),
            'free_shipping' => $request->getData('free_shipping'),
        );

        $cartItems = array();
        $items = $request->getAllItems();
        $quoteTotalCollected = false;
        $bundleProcessChildren = isset($this->_options['bundle']['process_children'])
            && $this->_options['bundle']['process_children'];
        foreach ($items as $item) {
            $product = $item->getProduct();
            if ($product instanceof Mage_Catalog_Model_Product) {
                $key = null;
                if ($item instanceof Mage_Sales_Model_Quote_Address_Item) { // Multishipping
                    $key = $item->getQuoteItemId();
                } else if ($item instanceof Mage_Sales_Model_Quote_Item) { // Onepage checkout
                    $key = $item->getId();
                }
                $cartItems[$key] = $item;
            }
        }

        // Do not use quote to retrieve values, totals are not available
        $totalInclTaxWithoutDiscount = 0;
        $totalExclTaxWithoutDiscount = 0;
        $totalInclTaxWithDiscount = 0;
        $totalExclTaxWithDiscount = 0;
        $this->_items = array();
        foreach ($cartItems as $item) {
            $type = $item->getProduct()->getTypeId();
            $parentItemId = $item->getData('parent_item_id');
            $parentItem = isset($cartItems[$parentItemId]) ? $cartItems[$parentItemId] : null;
            $parentType = isset($parentItem) ? $parentItem->getProduct()->getTypeId() : null;
            if ($type != 'configurable') {
                if ($type == 'bundle' && $bundleProcessChildren) {
                    $this->_data['qty'] -= $item->getQty();
                    continue;
                }
                if ($parentType == 'bundle') {
                    if (!$bundleProcessChildren) continue;
                    else $this->_data['qty'] += $item->getQty();
                }
                $this->_items[] = Mage::getModel(
                    'owebia_shipping2/Os2_Data_CartItem',
                    array('item' => $item, 'parent_item' => $parentItem, 'options' => $this->_options)
                );
            }
            $totalExclTaxWithoutDiscount += $item->getData('base_row_total');
            $totalExclTaxWithDiscount += $item->getData('base_row_total') - $item->getData('base_discount_amount');
            $totalInclTaxWithDiscount += $item->getData('base_row_total') - $item->getData('base_discount_amount')
                + $item->getData('tax_amount');
            $totalInclTaxWithoutDiscount += $item->getData('base_row_total_incl_tax');
        }
        $this->_data['price-tax+discount'] = $totalExclTaxWithDiscount;
        $this->_data['price-tax-discount'] = $totalExclTaxWithoutDiscount;
        $this->_data['price+tax+discount'] = $totalInclTaxWithDiscount;
        $this->_data['price+tax-discount'] = $totalInclTaxWithoutDiscount;
    }

    protected function _getQuote()
    {
        return Mage::getModel('owebia_shipping2/Os2_Data_Quote');
    }

    protected function _load($name)
    {
        switch ($name) {
            case 'weight_for_charge':
                $weightForCharge = $this->getData('weight');
                foreach ($this->_items as $item) {
                    if ($item->getData('free_shipping')) $weightForCharge -= $item->getData('weight');
                }
                return $weightForCharge;
            case 'coupon_code':
                $couponCode = null;
                $quote = $this->_getQuote();
                return $quote->getData('coupon_code');
            case 'weight_unit':
                return Mage::getStoreConfig('owebia_shipping2/general/weight_unit');
        }
        return parent::_load($name);
    }

    public function __set($name, $value)
    {
        switch ($name) {
            case 'items':
                return $this->_items = $value;
        }
        return parent::__set($name, $value);
    }

    public function getData($name)
    {
        switch ($name) {
            case 'items':
                return $this->_items;
            case 'free_shipping':
                if (isset($this->_freeShipping)) return $this->_freeShipping;
                $freeShipping = parent::getData('free_shipping');
                if (!$freeShipping) {
                    foreach ($this->_items as $item) {
                        $freeShipping = $item->getData('free_shipping');
                        if (!$freeShipping) break;
                    }
                }
                return $this->_freeShipping = $freeShipping;
        }
        return parent::getData($name);
    }
}


text:
import arcpy
import mds
import mds.messages
import numpy

class GetVariableStatistics(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Get Variable Statistics"
        self.description = "Calculates statistics for a variable in a " + \
        "multidimensional dataset, such as netCDF or HDF. "
        self.canRunInBackground = False
        # Statistics choices
        statistics_numpy = {'MAXIMUM':'amax', \
                               'MEAN':'mean', \
                            'MINIMUM':'amin', \
                              'RANGE':'ptp', \
                                'STD':'std', \
                                'SUM':'sum', \
                           'VARIANCE':'var'}
        statistics_categorical = {'MEDIAN':'median', \
                                'MAJORITY':'majority', \
                                  'MINORITY':'minority', \
                                   'VARIETY':'variety'}
        # List of dictionaries of statistics
        # Sublist elements indices:
        #   0: object
        #   1: dictionary defined by 'displayname':'methodname'
        #       where object.methodname() is valid and displayname is what is
        #       shown to the user
        #   2: boolean, indicating whether the given dictionary of statistics
        #       only operates on integer datatypes
        self.statistics = [[numpy, statistics_numpy, False], \
                           [self, statistics_categorical, True]]
        self.default_statistic = "MEAN"

    def getParameterInfo(self):
        """Define parameter definitions"""

        parameters = []

        # Input parameter
        parameters.append(arcpy.Parameter(
            displayName="Input File or URL String",
            name="in_file",
            datatype=["DEFile","GPString"],
            parameterType="Required",
            direction="Input"))

        # Variable parameter
        parameters.append(arcpy.Parameter(
            displayName="Variable",
            name="variable",
            datatype="GPString",
            parameterType="Required",
            direction="Input"))

        parameters[-1].parameterDependencies = [parameters[-2].name]

        # Type parameter
        parameters.append(arcpy.Parameter(
            displayName="Statistic Type",
            name="statistic_type",
            datatype="GPString",
            parameterType="Optional",
            direction="Input"))

        parameters[-1].filter.type = "ValueList"
        parameters[-1].filter.list = sorted([key for stat in \
            self.statistics for key in stat[1].keys()])
        parameters[-1].value = self.default_statistic

        # Derived output parameter
        parameters.append(arcpy.Parameter(
            displayName="Statistic",
            name="out_statistic",
            datatype="GPDouble",
            parameterType="Derived",
            direction="Output"))

        return parameters

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""

        input_parameter = parameters[0]
        variable_parameter = parameters[1]
        type_parameter = parameters[2]
        dataset = None

        # Open dataset and populate variable names
        if input_parameter.value is not None:
            try:
                dataset = mds.netcdf.Dataset(input_parameter.valueAsText, '')
            except RuntimeError, exception:
                if "No such file or directory" in str(exception) or \
                    "Invalid argument" in str(exception):
                    input_parameter.setErrorMessage(
                        mds.messages.INPUT_DATASET_DOES_NOT_RESOLVE_TO_FILENAME.format(
                            input_parameter.valueAsText))
                elif "Malformed or inaccessible DAP DDS" in str(exception):
                    input_parameter.setErrorMessage(
                        mds.messages.INPUT_DATASET_URL_MALFORMED.format(
                            input_parameter.valueAsText))
                else:
                    input_parameter.setErrorMessage(
                        mds.messages.INPUT_DATASET_GENERIC_ERROR.format(
                            input_parameter.valueAsText, str(exception)))
            except Exception, exception:
                input_parameter.setErrorMessage(
                    mds.messages.INPUT_DATASET_GENERIC_ERROR.format(
                        input_parameter.valueAsText, str(exception)))
            if dataset is not None:
                # Fill variable list
                variable_parameter.filter.type = "ValueList"
                variable_parameter.filter.list = list(dataset.variable_names())
        else:
            # Clear variable list if no input specified
            variable_parameter.filter.type = "ValueList"
            variable_parameter.filter.list = []
            variable_parameter.value = ""

        # Modify statistic choices based on variable type
        if (variable_parameter.value is not None) and (dataset is not None):
            if variable_parameter.valueAsText in dataset.variable_names():
                var = dataset.variable(variable_parameter.value)
                ispacked = hasattr(var,'scale_factor') or hasattr(var, 'add_offset')
                flag = ('int' in str(var.dtype)) and not ispacked
                type_parameter.filter.type = "ValueList"
                type_parameter.filter.list = sorted([key for stat in \
                    self.statistics if flag or not stat[2] for key in \
                    stat[1].keys()])

        return

    # ---------------------------------------------------------
    # Statistics

    def majority(self, var1):
        # Lowest value is returned in the case of ties.
        vunique = numpy.unique(var1)
        vcounts = numpy.zeros_like(vunique)
        for vindex in range(0, vunique.size):
            vcounts[vindex] = numpy.sum(var1 == vunique[vindex])
        return vunique[numpy.argmax(vcounts)]

    def minority(self, var1):
        # Lowest value is returned in the case of ties.
        vunique = numpy.unique(var1)
        vcounts = numpy.zeros_like(vunique)
        for vindex in range(0, vunique.size):
            vcounts[vindex] = numpy.sum(var1 == vunique[vindex])
        return vunique[numpy.argmax(vcounts)]

    def variety(self, var1):
        return numpy.unique(var1).size

    def calculate_statistic(self, variable, statistic):
        # Apply statistic
        for stat in self.statistics:
            if statistic in stat[1]:
                func = getattr(stat[0], stat[1][statistic])
                break
        else:
            # Default
            func = getattr(numpy, 'mean')
        return func(variable)

    # ---------------------------------------------------------

    def execute(self, parameters, messages):
        """The source code of the tool."""

        input_parameter = parameters[0]
        variable_parameter = parameters[1]
        type_parameter = parameters[2]

        dataset_name = input_parameter.valueAsText

        # Open dataset
        try:
            dataset = mds.netcdf.Dataset(dataset_name,'')
        except RuntimeError, exception:
            # Handle errors not detected by updateMessages.
            messages.addErrorMessage(str(exception))
            raise arcpy.ExecuteError

        # Variable of interest
        var1 = dataset.variable(variable_parameter.valueAsText)

        # Perform statistic
        result1 = self.calculate_statistic(var1[:], type_parameter.valueAsText)

        # Format output string
        str_modif = "squared " if type_parameter.valueAsText == "VARIANCE" else ""
        str_units = str(var1.units) if hasattr(var1, 'units') else "units"
        str_output = "%s: %s %s%s" % (
            variable_parameter.valueAsText, str(result1), str_modif, str_units)

        # Output results
        arcpy.AddMessage(str_output)
        arcpy.SetParameter(3, result1)

        return


text:
package com.impetus.kundera.cache;

import com.impetus.kundera.KunderaException;

/**
 * When something goes wrong in cache.
 *
 * @author animesh.kumar
 *
 */
public class CacheException extends KunderaException
{

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /**
     * Instantiates a new cache exception.
     *
     * @param s
     *            the s
     */
    public CacheException(final String s)
    {
        super(s);
    }

    /**
     * Instantiates a new cache exception.
     *
     * @param s
     *            the s
     * @param e
     *            the e
     */
    public CacheException(final String s, final Throwable e)
    {
        super(s, e);
    }

    /**
     * Instantiates a new cache exception.
     *
     * @param e
     *            the e
     */
    public CacheException(final Throwable e)
    {
        super(e);
    }
}


text:
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
                        unicode_literals, with_statement)

import fnmatch
import os

from six import string_types
from twitter.common.dirutil.fileset import Fileset

from pants.base.build_environment import get_buildroot
from pants.util.memo import memoized_property

def globs_matches(path, patterns):
  return any(fnmatch.fnmatch(path, pattern) for pattern in patterns)

def matches_filespec(path, spec):
  if spec is None:
    return False
  if not globs_matches(path, spec.get('globs', [])):
    return False
  for spec in spec.get('exclude', []):
    if matches_filespec(path, spec):
      return False
  return True

class FilesetWithSpec(object):
  """A set of files that keeps track of how we got it.

  The filespec is what globs or file list it came from.
  """

  def __init__(self, rel_root, filespec, files_calculator):
    self._rel_root = rel_root
    self.filespec = filespec
    self._files_calculator = files_calculator

  @memoized_property
  def files(self):
    return self._files_calculator()

  def __iter__(self):
    return self.files.__iter__()

  def __getitem__(self, index):
    return self.files[index]

class FilesetRelPathWrapper(object):

  def __init__(self, parse_context):
    self.rel_path = parse_context.rel_path

  def __call__(self, *args, **kwargs):
    root = os.path.join(get_buildroot(), self.rel_path)

    excludes = kwargs.pop('exclude', [])
    if isinstance(excludes, string_types):
        raise ValueError("Expected exclude parameter to be a list of globs, lists, or strings")

    for i, exclude in enumerate(excludes):
      if isinstance(exclude, string_types):
        # You can't subtract raw strings from globs
        excludes[i] = [exclude]

    for glob in args:
      if self._is_glob_dir_outside_root(glob, root):
        raise ValueError('Invalid glob {}, points outside BUILD file root dir {}'.format(glob, root))

    def files_calculator():
      result = self.wrapped_fn(root=root, *args, **kwargs)

      for exclude in excludes:
        result -= exclude

      return result

    buildroot = get_buildroot()
    rel_root = os.path.relpath(root, buildroot)
    filespec = self.to_filespec(args, root=rel_root, excludes=excludes)
    return FilesetWithSpec(rel_root, filespec, files_calculator)

  @staticmethod
  def _is_glob_dir_outside_root(glob, root):
    # The assumption is that a correct glob starts with the root,
    # even after normalizing.
    glob_path = os.path.normpath(os.path.join(root, glob))

    # Check if the glob path has the correct root.
    return os.path.commonprefix([root, glob_path]) != root

  def to_filespec(self, args, root='', excludes=None):
    """Return a dict representation of this glob list, relative to the buildroot.

    The format of the dict is {'globs': [ 'list', 'of' , 'strings' ]
                    (optional) 'exclude' : [{'globs' : ... }, ...] }

    The globs are in zglobs format.
    """
    result = {'globs': [os.path.join(root, arg) for arg in args]}
    if excludes:
      result['exclude'] = []
      for exclude in excludes:
        if hasattr(exclude, 'filespec'):
          result['exclude'].append(exclude.filespec)
        else:
          result['exclude'].append({'globs': [os.path.join(root, x) for x in exclude]})
    return result

class Globs(FilesetRelPathWrapper):
  """Returns Fileset containing matching files in same directory as this BUILD file.
  E.g., ``sources = globs('*java'),`` to get .java files in this directory.

  :param exclude: a list of {,r,z}globs objects, strings, or lists of
    strings to exclude.  E.g. ``globs('*',exclude=[globs('*.java'),
    'foo.py'])`` gives all files in this directory except ``.java``
    files and ``foo.py``.

  Deprecated:
  You might see that old code uses "math" on the return value of
  ``globs()``.  E.g., ``globs('*') - globs('*.java')`` gives all files
  in this directory *except* ``.java`` files.  Please use exclude
  instead, since pants is moving to make BUILD files easier to parse,
  and the new grammar will not support arithmetic.
  """
  wrapped_fn = Fileset.globs

class RGlobs(FilesetRelPathWrapper):
  """Recursive ``globs``, returns Fileset matching files in this directory and its descendents.

  E.g., ``bundle(fileset=rglobs('config/*')),`` to bundle up all files in
  the config, config/foo, config/foo/bar directories.

  :param exclude: a list of {,r,z}globs objects, strings, or lists of
    strings to exclude.  E.g. ``rglobs('config/*',exclude=[globs('config/*.java'),
    'config/foo.py'])`` gives all files under config except ``.java`` files and ``config/foo.py``.

  Deprecated:
  You might see that old code uses "math" on the return value of ``rglobs()``. E.g.,
  ``rglobs('config/*') - rglobs('config/foo/*')`` gives all files under `config` *except*
  those in ``config/foo``.  Please use exclude instead, since pants is moving to
  make BUILD files easier to parse, and the new grammar will not support arithmetic.
  """
  @staticmethod
  def rglobs_following_symlinked_dirs_by_default(*globspecs, **kw):
    if 'follow_links' not in kw:
      kw['follow_links'] = True
    return Fileset.rglobs(*globspecs, **kw)

  wrapped_fn = rglobs_following_symlinked_dirs_by_default

  def to_filespec(self, args, root='', excludes=None):
    # In rglobs, * at the beginning of a path component means "any
    # number of directories, including 0".  Unfortunately, "**" in
    # some other systems, e.g. git means "one or more directories".
    # So every time we see ^* or **, we need to output both
    # "**/whatever" and "whatever".
    rglobs = []
    for arg in args:
      components = arg.split(os.path.sep)
      out = []
      for component in components:
        if component == '**':
          if out and out[-1].startswith("**"):
            continue
          out.append(component)
        elif component[0] == '*':
          if out and out[-1].startswith("**"):
            # We want to translate **/*.py to **/*.py, not **/**/*.py
            out.append(component)
          else:
            out.append('**/' + component)
        else:
          out.append(component)

      def rglob_path(beginning, rest):
        if not rest:
          return [beginning]
        endings = []
        for i, item in enumerate(rest):
          if beginning and not beginning.endswith(os.path.sep):
            beginning += os.path.sep
          if item.startswith('**'):
            # .../**/*.java
            for ending in rglob_path(beginning + item, rest[i + 1:]):
              endings.append(ending)
            # .../*.java
            for ending in rglob_path(beginning + item[3:], rest[i + 1:]):
              endings.append(ending)
            return endings
          else:
            if beginning and not beginning.endswith(os.path.sep):
              beginning += os.path.sep + item
            else:
              beginning += item

        return [beginning]

      rglobs.extend(rglob_path('', out))

    return super(RGlobs, self).to_filespec(rglobs, root=root, excludes=excludes)

class ZGlobs(FilesetRelPathWrapper):
  """Returns a FilesetWithSpec that matches zsh-style globs, including ``**/`` for recursive globbing.

  Uses ``BUILD`` file's directory as the "working directory".
  """
  @staticmethod
  def zglobs_following_symlinked_dirs_by_default(*globspecs, **kw):
    if 'follow_links' not in kw:
      kw['follow_links'] = True
    return Fileset.zglobs(*globspecs, **kw)

  wrapped_fn = zglobs_following_symlinked_dirs_by_default


text:
namespace net {

TestServer::TestServer()
    : socket_(NULL),
      errors_(0) {
}

TestServer::~TestServer() {
  if (socket_) {
    socket_->Close();
    socket_ = NULL;
  }
}

bool TestServer::Start(int port) {
  IPAddressNumber ip_number;
  std::string ip_str("0.0.0.0");
  if (!ParseIPLiteralToNumber(ip_str, &ip_number)) {
    LOG(ERROR) << "Bad IP Address";
    return false;
  }
  IPEndPoint bind_address(ip_number, port);

  DCHECK(!socket_);
  socket_ = new CurveCPServerSocket(NULL, NetLog::Source());
  int rv = socket_->Listen(bind_address, this);
  if (rv < ERR_IO_PENDING) {
    LOG(ERROR) << "Listen on port " << port << " failed: " << rv;
    return false;
  }
  return true;
}

void TestServer::OnAccept(CurveCPServerSocket* new_socket) {
  DCHECK(new_socket);
  LOG(ERROR) << "Accepted socket! Starting Echo Server";
  EchoServer* new_server = new EchoServer();
  new_server->Start(new_socket);
}

EchoServer::EchoServer()
    : socket_(NULL),
      bytes_received_(0) {
}

EchoServer::~EchoServer() {
}

void EchoServer::Start(CurveCPServerSocket* socket) {
  DCHECK(!socket_);
  socket_ = socket;

  ReadData();
  // Note:  |this| could be deleted here.
}

void EchoServer::OnReadComplete(int result) {
  LOG(INFO) << "Read complete: " << result;
  if (result <= 0) {
    delete this;
    return;
  }

  bytes_received_ += result;
  LOG(INFO) << "Server received " << result << "(" << bytes_received_ << ")";

  if (!received_stream_.VerifyBytes(read_buffer_->data(), result)) {
    LOG(ERROR) << "Server Received corrupt receive data!";
    delete this;
    return;
  }

  // Echo the read data back here.
  DCHECK(!write_buffer_.get());
  write_buffer_ = new DrainableIOBuffer(read_buffer_, result);
  int rv = socket_->Write(write_buffer_, result,
                          base::Bind(&EchoServer::OnWriteComplete,
                                     base::Unretained(this)));
  if (rv == ERR_IO_PENDING)
    return;
  OnWriteComplete(rv);
}

void EchoServer::OnWriteComplete(int result) {
  if (result <= 0) {
    delete this;
    return;
  }

  write_buffer_->DidConsume(result);
  while (write_buffer_->BytesRemaining()) {
    int rv = socket_->Write(write_buffer_,
                            write_buffer_->BytesRemaining(),
                            base::Bind(&EchoServer::OnWriteComplete,
                                       base::Unretained(this)));
    if (rv == ERR_IO_PENDING)
      return;
    OnWriteComplete(rv);
  }

  // Now we can read more data.
  write_buffer_ = NULL;
  // read_buffer_ = NULL;
  // ReadData();
}

void EchoServer::ReadData() {
  DCHECK(!read_buffer_.get());
  read_buffer_ = new IOBuffer(kMaxMessage);

  int rv;
  do {
    rv = socket_->Read(read_buffer_, kMaxMessage,
                       base::Bind(&EchoServer::OnReadComplete,
                                  base::Unretained(this)));
    if (rv == ERR_IO_PENDING)
      return;
    OnReadComplete(rv);  // Complete the read manually
  } while (rv > 0);
}

}  // namespace net


text:
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>streamCQL</artifactId>
        <groupId>com.huawei.streaming</groupId>
        <version>2.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>cql</artifactId>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <skipIfEmpty>true</skipIfEmpty>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <excludes>
                        <exclude>com/huawei/streaming/cql/semanticanalyzer/parser/*.g4</exclude>
                        <exclude>streaming-site.xml</exclude>
                        <exclude>log4j2.xml</exclude>
                        <exclude>logback-console.xml</exclude>
                        <exclude>cqlclient</exclude>
                        <exclude>driver</exclude>
                        <exclude>excutor</exclude>
                        <exclude>parser</exclude>
                        <exclude>submitter</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jline</groupId>
            <artifactId>jline</artifactId>
            <version>2.11</version>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>com.huawei.streaming</groupId>
            <artifactId>streaming-base</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.yammer.metrics</groupId>
                    <artifactId>metrics-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.xerial.snappy</groupId>
                    <artifactId>snappy-java</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>net.sf.jopt-simple</groupId>
                    <artifactId>jopt-simple</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.101tec</groupId>
                    <artifactId>zkclient</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.huawei.streaming</groupId>
            <artifactId>stream-storm</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-runtime</artifactId>
            <version>4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.9.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-launcher</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-core</artifactId>
            <version>1.0.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.9</version>
            <exclusions>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>


text:
"""Training-related utilities.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import copy

import numpy as np

from tensorflow.python.data.ops import iterator_ops
from tensorflow.python.eager import context
from tensorflow.python.framework import tensor_util
from tensorflow.python.keras import backend as K
from tensorflow.python.keras import losses
from tensorflow.python.keras import metrics as metrics_module
from tensorflow.python.ops import math_ops

def check_num_samples(ins,
                      batch_size=None,
                      steps=None,
                      steps_name='steps'):
  """Determine the number of samples provided for training and evaluation.

  The number of samples is not defined when running with `steps`,
  in which case the number of samples is set to `None`.

  Arguments:
      ins: List of tensors to be fed to the Keras function.
      batch_size: Integer batch size or `None` if not defined.
      steps: Total number of steps (batches of samples)
          before declaring `_predict_loop` finished.
          Ignored with the default value of `None`.
      steps_name: The public API's parameter name for `steps`.

  Raises:
      ValueError: when `steps` is `None` and the attribute `ins.shape`
      does not exist. Also raises ValueError when `steps` is not `None`
      and `batch_size` is not `None` because they are mutually
      exclusive.

  Returns:
      When steps is `None`, returns the number of samples to be
      processed based on the size of the first dimension of the
      first input numpy array. When steps is not `None` and
      `batch_size` is `None`, returns `None`.

  Raises:
      ValueError: In case of invalid arguments.
  """
  if steps is not None and batch_size is not None:
    raise ValueError(
        'If ' + steps_name + ' is set, the `batch_size` must be None.')
  if check_steps_argument(ins, steps, steps_name):
    return None
  if hasattr(ins[0], 'shape'):
    return int(ins[0].shape[0])
  return None  # Edge case where ins == [static_learning_phase]

def standardize_single_array(x):
  if x is None:
    return None
  elif tensor_util.is_tensor(x):
    return x
  elif x.ndim == 1:
    x = np.expand_dims(x, 1)
  return x

def standardize_input_data(data,
                           names,
                           shapes=None,
                           check_batch_axis=True,
                           exception_prefix=''):
  """Normalizes inputs and targets provided by users.

  Users may pass data as a list of arrays, dictionary of arrays,
  or as a single array. We normalize this to an ordered list of
  arrays (same order as `names`), while checking that the provided
  arrays have shapes that match the network's expectations.

  Arguments:
      data: User-provided input data (polymorphic).
      names: List of expected array names.
      shapes: Optional list of expected array shapes.
      check_batch_axis: Boolean; whether to check that
          the batch axis of the arrays matches the expected
          value found in `shapes`.
      exception_prefix: String prefix used for exception formatting.

  Returns:
      List of standardized input arrays (one array per model input).

  Raises:
      ValueError: in case of improperly formatted user-provided data.
  """
  if not names:
    if data is not None and hasattr(data, '__len__') and len(data):
      raise ValueError('Error when checking model ' + exception_prefix + ': '
                       'expected no data, but got:', data)
    return []
  if data is None:
    return [None for _ in range(len(names))]

  if isinstance(data, dict):
    try:
      data = [
          data[x].values
          if data[x].__class__.__name__ == 'DataFrame' else data[x]
          for x in names
      ]
    except KeyError as e:
      raise ValueError('No data provided for "' + e.args[0] + '". Need data '
                       'for each key in: ' + str(names))
  elif isinstance(data, list):
    if isinstance(data[0], list):
      data = [np.asarray(d) for d in data]
    elif len(names) == 1 and isinstance(data[0], (float, int)):
      data = [np.asarray(data)]
    else:
      data = [
          x.values if x.__class__.__name__ == 'DataFrame' else x for x in data
      ]
  else:
    data = data.values if data.__class__.__name__ == 'DataFrame' else data
    data = [data]
  data = [standardize_single_array(x) for x in data]

  if len(data) != len(names):
    if data and hasattr(data[0], 'shape'):
      raise ValueError('Error when checking model ' + exception_prefix +
                       ': the list of Numpy arrays that you are passing to '
                       'your model is not the size the model expected. '
                       'Expected to see ' + str(len(names)) + ' array(s), '
                       'but instead got the following list of ' +
                       str(len(data)) + ' arrays: ' + str(data)[:200] + '...')
    elif len(names) > 1:
      raise ValueError(
          'Error when checking model ' + exception_prefix +
          ': you are passing a list as input to your model, '
          'but the model expects a list of ' + str(len(names)) +
          ' Numpy arrays instead. The list you passed was: ' + str(data)[:200])
    elif len(data) == 1 and not hasattr(data[0], 'shape'):
      raise TypeError('Error when checking model ' + exception_prefix +
                      ': data should be a Numpy array, or list/dict of '
                      'Numpy arrays. Found: ' + str(data)[:200] + '...')
    elif len(names) == 1:
      data = [np.asarray(data)]

  # Check shapes compatibility.
  if shapes:
    for i in range(len(names)):
      if shapes[i] is not None:
        if tensor_util.is_tensor(data[i]):
          tensorshape = data[i].get_shape()
          if not tensorshape:
            continue
          data_shape = tuple(tensorshape.as_list())
        else:
          data_shape = data[i].shape
        shape = shapes[i]
        if len(data_shape) != len(shape):
          raise ValueError('Error when checking ' + exception_prefix +
                           ': expected ' + names[i] + ' to have ' +
                           str(len(shape)) + ' dimensions, but got array '
                           'with shape ' + str(data_shape))
        if not check_batch_axis:
          data_shape = data_shape[1:]
          shape = shape[1:]
        for dim, ref_dim in zip(data_shape, shape):
          if ref_dim != dim and ref_dim is not None and dim is not None:
            raise ValueError(
                'Error when checking ' + exception_prefix + ': expected ' +
                names[i] + ' to have shape ' + str(shape) +
                ' but got array with shape ' + str(data_shape))
  return data

def standardize_sample_or_class_weights(x_weight, output_names, weight_type):
  """Maps `sample_weight` or `class_weight` to model outputs.

  Arguments:
      x_weight: User-provided `sample_weight` or `class_weight` argument.
      output_names: List of output names (strings) in the model.
      weight_type: A string used purely for exception printing.

  Returns:
      A list of `sample_weight` or `class_weight` where there are exactly
          one element per model output.

  Raises:
      ValueError: In case of invalid user-provided argument.
  """
  if x_weight is None or len(x_weight) == 0:  # pylint: disable=g-explicit-length-test
    return [None for _ in output_names]
  if len(output_names) == 1:
    if isinstance(x_weight, list) and len(x_weight) == 1:
      return x_weight
    if isinstance(x_weight, dict) and output_names[0] in x_weight:
      return [x_weight[output_names[0]]]
    else:
      return [x_weight]
  if isinstance(x_weight, list):
    if len(x_weight) != len(output_names):
      raise ValueError('Provided `' + weight_type + '` was a list of ' +
                       str(len(x_weight)) + ' elements, but the model has ' +
                       str(len(output_names)) + ' outputs. '
                       'You should provide one `' + weight_type + '`'
                       'array per model output.')
    return x_weight
  if isinstance(x_weight, dict):
    x_weights = []
    for name in output_names:
      x_weights.append(x_weight.get(name))
    return x_weights
  else:
    raise TypeError(
        'The model has multiple outputs, so `' + weight_type + '` '
        'should be either a list or a dict. '
        'Provided `' + weight_type + '` type not understood: ' + str(x_weight))

def standardize_class_weights(class_weight, output_names):
  return standardize_sample_or_class_weights(class_weight, output_names,
                                             'class_weight')

def standardize_sample_weights(sample_weight, output_names):
  return standardize_sample_or_class_weights(sample_weight, output_names,
                                             'sample_weight')

def check_array_lengths(inputs, targets, weights=None):
  """Does user input validation for numpy arrays.

  Arguments:
      inputs: list of Numpy arrays of inputs.
      targets: list of Numpy arrays of targets.
      weights: list of Numpy arrays of sample weights.

  Raises:
      ValueError: in case of incorrectly formatted data.
  """

  def set_of_lengths(x):
    # Returns a set with the variation between
    # different shapes, with None => 0
    if x is None:
      return {}
    else:
      return set([y.shape[0] for y in x
                  if y is not None and not tensor_util.is_tensor(y)])

  set_x = set_of_lengths(inputs)
  set_y = set_of_lengths(targets)
  set_w = set_of_lengths(weights)
  if len(set_x) > 1:
    raise ValueError('All input arrays (x) should have '
                     'the same number of samples. Got array shapes: ' +
                     str([x.shape for x in inputs]))
  if len(set_y) > 1:
    raise ValueError('All target arrays (y) should have '
                     'the same number of samples. Got array shapes: ' +
                     str([y.shape for y in targets]))
  if set_x and set_y and list(set_x)[0] != list(set_y)[0]:
    raise ValueError('Input arrays should have '
                     'the same number of samples as target arrays. '
                     'Found ' + str(list(set_x)[0]) + ' input samples '
                     'and ' + str(list(set_y)[0]) + ' target samples.')
  if len(set_w) > 1:
    raise ValueError('All sample_weight arrays should have '
                     'the same number of samples. Got array shapes: ' +
                     str([w.shape for w in weights]))
  if set_y and set_w and list(set_y)[0] != list(set_w)[0]:
    raise ValueError('Sample_weight arrays should have '
                     'the same number of samples as target arrays. Got ' +
                     str(list(set_y)[0]) + ' input samples and ' +
                     str(list(set_w)[0]) + ' target samples.')

def check_loss_and_target_compatibility(targets, loss_fns, output_shapes):
  """Does validation on the compatibility of targets and loss functions.

  This helps prevent users from using loss functions incorrectly. This check
  is purely for UX purposes.

  Arguments:
      targets: list of Numpy arrays of targets.
      loss_fns: list of loss functions.
      output_shapes: list of shapes of model outputs.

  Raises:
      ValueError: if a loss function or target array
          is incompatible with an output.
  """
  key_losses = {
      losses.mean_squared_error, losses.binary_crossentropy,
      losses.categorical_crossentropy
  }
  for y, loss, shape in zip(targets, loss_fns, output_shapes):
    if y is None or loss is None or tensor_util.is_tensor(y):
      continue
    if loss is losses.categorical_crossentropy:
      if y.shape[-1] == 1:
        raise ValueError('You are passing a target array of shape ' + str(
            y.shape) + ' while using as loss `categorical_crossentropy`. '
                         '`categorical_crossentropy` expects '
                         'targets to be binary matrices (1s and 0s) '
                         'of shape (samples, classes). '
                         'If your targets are integer classes, '
                         'you can convert them to the expected format via:\n'
                         '```\n'
                         'from keras.utils import to_categorical\n'
                         'y_binary = to_categorical(y_int)\n'
                         '```\n'
                         '\n'
                         'Alternatively, you can use the loss function '
                         '`sparse_categorical_crossentropy` instead, '
                         'which does expect integer targets.')
    if loss in key_losses:
      for target_dim, out_dim in zip(y.shape[1:], shape[1:]):
        if out_dim is not None and target_dim != out_dim:
          raise ValueError('A target array with shape ' + str(y.shape) +
                           ' was passed for an output of shape ' + str(shape) +
                           ' while using as loss `' + loss.__name__ + '`. '
                           'This loss expects '
                           'targets to have the same shape '
                           'as the output.')

def collect_metrics(metrics, output_names):
  """Maps metric functions to model outputs.

  Arguments:
      metrics: a list or dict of metric functions.
      output_names: a list of the names (strings) of model outputs.

  Returns:
      A list (one entry per model output) of lists of metric functions.
      For instance, if the model has 2 outputs, and for the first output
      we want to compute "binary_accuracy" and "binary_crossentropy",
      and just "binary_accuracy" for the second output,
      the list would look like:
          `[[binary_accuracy, binary_crossentropy], [binary_accuracy]]`

  Raises:
      TypeError: if an incorrect type is passed for the `metrics` argument.
  """
  if not metrics:
    return [[] for _ in output_names]
  if isinstance(metrics, list):
    # we then apply all metrics to all outputs.
    return [copy.copy(metrics) for _ in output_names]
  elif isinstance(metrics, dict):
    nested_metrics = []
    for name in output_names:
      output_metrics = metrics.get(name, [])
      if not isinstance(output_metrics, list):
        output_metrics = [output_metrics]
      nested_metrics.append(output_metrics)
    return nested_metrics
  else:
    raise TypeError('Type of `metrics` argument not understood. '
                    'Expected a list or dictionary, found: ' + str(metrics))

def batch_shuffle(index_array, batch_size):
  """Shuffles an array in a batch-wise fashion.

  Useful for shuffling HDF5 arrays
  (where one cannot access arbitrary indices).

  Arguments:
      index_array: array of indices to be shuffled.
      batch_size: integer.

  Returns:
      The `index_array` array, shuffled in a batch-wise fashion.
  """
  batch_count = int(len(index_array) / batch_size)
  # to reshape we need to be cleanly divisible by batch size
  # we stash extra items and reappend them after shuffling
  last_batch = index_array[batch_count * batch_size:]
  index_array = index_array[:batch_count * batch_size]
  index_array = index_array.reshape((batch_count, batch_size))
  np.random.shuffle(index_array)
  index_array = index_array.flatten()
  return np.append(index_array, last_batch)

def weighted_masked_objective(fn):
  """Adds support for masking and sample-weighting to an objective function.

  It transforms an objective function `fn(y_true, y_pred)`
  into a sample-weighted, cost-masked objective function
  `fn(y_true, y_pred, weights, mask)`.

  Arguments:
      fn: The objective function to wrap,
          with signature `fn(y_true, y_pred)`.

  Returns:
      A function with signature `fn(y_true, y_pred, weights, mask)`.
  """
  if fn is None:
    return None

  def weighted(y_true, y_pred, weights, mask=None):
    """Wrapper function.

    Arguments:
        y_true: `y_true` argument of `fn`.
        y_pred: `y_pred` argument of `fn`.
        weights: Weights tensor.
        mask: Mask tensor.

    Returns:
        Scalar tensor.
    """
    # score_array has ndim >= 2
    score_array = fn(y_true, y_pred)
    if mask is not None:
      # Cast the mask to floatX to avoid float64 upcasting in theano
      mask = math_ops.cast(mask, K.floatx())
      # mask should have the same shape as score_array
      score_array *= mask
      #  the loss per batch should be proportional
      #  to the number of unmasked samples.
      score_array /= K.mean(mask)

    # apply sample weighting
    if weights is not None:
      # reduce score_array to same ndim as weight array
      ndim = K.ndim(score_array)
      weight_ndim = K.ndim(weights)
      score_array = K.mean(score_array, axis=list(range(weight_ndim, ndim)))
      score_array *= weights
      score_array /= K.mean(
          math_ops.cast(math_ops.not_equal(weights, 0), K.floatx()))
    return K.mean(score_array)

  return weighted

def standardize_weights(y,
                        sample_weight=None,
                        class_weight=None,
                        sample_weight_mode=None):
  """Performs sample weight validation and standardization.

  Everything gets normalized to a single sample-wise (or timestep-wise)
  weight array.

  Arguments:
      y: Numpy array of model targets to be weighted.
      sample_weight: User-provided `sample_weight` argument.
      class_weight: User-provided `class_weight` argument.
      sample_weight_mode: One of `None` or `"temporal"`.
          `"temporal"` indicated that we expect 2D weight data
          that will be applied to the last 2 dimensions of
          the targets (i.e. we are weighting timesteps, not samples).

  Returns:
      A numpy array of target weights, one entry per sample to weight.

  Raises:
      ValueError: In case of invalid user-provided arguments.
  """
  if sample_weight_mode is not None:
    if sample_weight_mode != 'temporal':
      raise ValueError('"sample_weight_mode '
                       'should be None or "temporal". '
                       'Found: ' + str(sample_weight_mode))
    if len(y.shape) < 3:
      raise ValueError('Found a sample_weight array for '
                       'an input with shape ' + str(y.shape) + '. '
                       'Timestep-wise sample weighting (use of '
                       'sample_weight_mode="temporal") is restricted to '
                       'outputs that are at least 3D, i.e. that have '
                       'a time dimension.')
    if sample_weight is not None and len(sample_weight.shape) != 2:
      raise ValueError('Found a sample_weight array with shape ' +
                       str(sample_weight.shape) + '. '
                       'In order to use timestep-wise sample weighting, '
                       'you should pass a 2D sample_weight array.')
  else:
    if sample_weight is not None and len(sample_weight.shape) != 1:
      raise ValueError('Found a sample_weight array with shape ' +
                       str(sample_weight.shape) + '. '
                       'In order to use timestep-wise sample weights, '
                       'you should specify '
                       'sample_weight_mode="temporal" '
                       'in compile(). If you just mean to use '
                       'sample-wise weights, make sure your '
                       'sample_weight array is 1D.')

  if sample_weight is not None:
    if len(sample_weight.shape) > len(y.shape):
      raise ValueError(
          'Found a sample_weight with shape' + str(sample_weight.shape) + '.'
          'Expected sample_weight with rank '
          'less than or equal to ' + str(len(y.shape)))

    if y.shape[:sample_weight.ndim] != sample_weight.shape:
      raise ValueError(
          'Found a sample_weight array with shape ' + str(sample_weight.shape) +
          ' for an input with shape ' + str(y.shape) + '. '
          'sample_weight cannot be broadcast.')
    return sample_weight
  elif isinstance(class_weight, dict):
    if len(y.shape) > 2:
      raise ValueError('`class_weight` not supported for '
                       '3+ dimensional targets.')
    if y.shape[1] > 1:
      y_classes = np.argmax(y, axis=1)
    elif y.shape[1] == 1:
      y_classes = np.reshape(y, y.shape[0])
    else:
      y_classes = y

    weights = np.asarray(
        [class_weight[cls] for cls in y_classes if cls in class_weight])

    if len(weights) != len(y_classes):
      # subtract the sets to pick all missing classes
      existing_classes = set(y_classes)
      existing_class_weight = set(class_weight.keys())
      raise ValueError('`class_weight` must contain all classes in the data.'
                       ' The classes %s exist in the data but not in '
                       '`class_weight`.' %
                       (existing_classes - existing_class_weight))
    return weights
  else:
    return None

def has_symbolic_tensors(ls):
  if context.executing_eagerly():
    return False
  return has_tensors(ls)

def has_tensors(ls):
  if isinstance(ls, (list, tuple)):
    return any(tensor_util.is_tensor(v) for v in ls)
  return tensor_util.is_tensor(ls)

def populate_metric_names(model):
  for i in range(len(model.outputs)):
    metrics = model.nested_metrics[i]
    for metric in metrics:
      base_metric_name = get_base_metric_name(metric)
      add_metric_name(model, base_metric_name, i)

def get_base_metric_name(metric, weighted=False):
  """Returns the metric name given the metric function.

  Arguments:
      metric: Metric function name or reference.
      weighted: Boolean indicating if the metric for which we are adding
          names is weighted.

  Returns:
      a metric name.
  """
  metric_name_prefix = 'weighted_' if weighted else ''
  if metric in ('accuracy', 'acc', 'crossentropy', 'ce'):
    if metric in ('accuracy', 'acc'):
      suffix = 'acc'
    elif metric in ('crossentropy', 'ce'):
      suffix = 'ce'
    metric_name = metric_name_prefix + suffix
  else:
    metric_fn = metrics_module.get(metric)
    # Get metric name as string
    if hasattr(metric_fn, 'name'):
      metric_name = metric_fn.name
    else:
      metric_name = metric_fn.__name__
    metric_name = metric_name_prefix + metric_name

  return metric_name

def add_metric_name(model, metric_name, index):
  """Makes the metric name unique and adds it to the model's metric name list.

    If there are multiple outputs for which the metrics are calculated, the
    metric names have to be made unique by appending an integer.

  Arguments:
    model: Model to which we are adding metric names.
    metric_name: Metric name that corresponds to the metric specified by the
        user. For example: 'acc'
    index: The index of the model output for which the metric name is being
        added.
  """
  if len(model.output_names) > 1:
    metric_name = '%s_%s' % (model.output_names[index], metric_name)
  j = 1
  base_metric_name = metric_name
  while metric_name in model.metrics_names:
    metric_name = '%s_%d' % (base_metric_name, j)
    j += 1
  model.metrics_names.append(metric_name)

def validate_iterator_input(x, y, sample_weight, validation_split=None):
  """Validates user input arguments when a dataset iterator is passed.

  Arguments:
    x: Input data. A `tf.data` dataset iterator.
    y: Target data. It could be either Numpy array(s) or TensorFlow tensor(s).
        Expected to be `None` when `x` is a dataset iterator.
    sample_weight: An optional sample-weight array passed by the user to
        weight the importance of each sample in `x`. Expected to be `None` when
        `x` is a dataset iterator
    validation_split: Float between 0 and 1. Fraction of the training data to
        be used as validation data. Expected to be `None` when `x` is a dataset
        iterator.

  Raises:
    ValueError: if argument `y` or `sample_weight` or `validation_split` are
        provided by user.
  """
  if y is not None:
    raise ValueError('You passed a dataset or dataset iterator (%s) as '
                     'input `x` to your model. In that case, you should '
                     'not specify a target (`y`) argument, since the dataset '
                     'or dataset iterator generates both input data and '
                     'target data. '
                     'Received: %s' % (x, y))
  if sample_weight is not None:
    raise ValueError('`sample_weight` argument is not supported when input '
                     '`x` is a dataset or a dataset iterator. '
                     'Received: x=%s, sample_weight=%s' % (x, sample_weight))
  if validation_split is not None and validation_split != 0.0:
    raise ValueError(
        '`validation_split` argument is not supported when '
        'input `x` is a dataset or a dataset iterator. '
        'Received: x=%s, validation_split=%f' % (x, validation_split))

def check_steps_argument(input_data, steps, steps_name):
  """Validates `steps` argument based on input data's type.

  The cases when `steps` value must be provided are when
    1. input data passed is an iterator.
    2. model was built on top of symbolic tensors, input data is not
       required and is `None`.
    3. input data passed is a symbolic tensor.

  Arguments:
      input_data: Input data. Can be Numpy array(s) or TensorFlow tensor(s) or
        tf.data.Dataset iterator or `None`.
      steps: Integer or `None`. Total number of steps (batches of samples) to
        execute.
      steps_name: The public API's parameter name for `steps`.

  Returns:
    boolean, True if `steps` argument is required, else False.

  Raises:
      ValueError: if `steps` argument is required for given input data type
        but not provided.
  """

  is_x_iterator = (
      isinstance(input_data, iterator_ops.Iterator) or
      isinstance(input_data, iterator_ops.EagerIterator))

  if (input_data is None or is_x_iterator or has_symbolic_tensors(input_data) or
      (isinstance(input_data, list) and not input_data)):
    if steps is None:
      input_type_str = 'iterators' if is_x_iterator else 'data tensors'
      raise ValueError('When using {input_type} as input to a model, you should'
                       ' specify the `{steps_name}` argument.'.format(
                           input_type=input_type_str, steps_name=steps_name))
    return True
  return False

def cast_if_floating_dtype(x):
  """Casts the given data tensors to the default floating point type.

  Casts only if the input is already a floating point type.
  Args:
    x: tensor or list/tuple of tensors.

  Returns:
    Converted input.

  Raises:
    RuntimeError: if data isn't tensors.
  """
  if not has_tensors(x):
    raise RuntimeError(
        'Please provide tensors for casting, got: {x}'.format(x=x))

  if isinstance(x, (list, tuple)):
    return [
        math_ops.cast(val, dtype=K.floatx())
        if tensor_util.is_tensor(val) and val.dtype.is_floating else val
        for val in x
    ]
  return math_ops.cast(x, dtype=K.floatx()) if x.dtype.is_floating else x


text:
BOOST_AUTO_TEST_CASE(omp_GlobalPair_DebyeHuckel_calc_force)
{
    namespace test = mjolnir::test;
    constexpr double tol = 1e-8;
    mjolnir::LoggerManager::set_default_logger("test_omp_global_pair_debye_huckel_interaction.log");

    using omp_traits_type = mjolnir::OpenMPSimulatorTraits<double, mjolnir::UnlimitedBoundary>;
    using seq_traits_type = mjolnir::SimulatorTraits<double, mjolnir::UnlimitedBoundary>;

    using real_type        = double;
    using coordinate_type  = typename omp_traits_type::coordinate_type;
    using boundary_type    = typename omp_traits_type::boundary_type;
    using topology_type    = mjolnir::Topology;

    using potential_type   = mjolnir::DebyeHuckelPotential<real_type>;

    using omp_system_type         = mjolnir::System<omp_traits_type>;
    using omp_parameter_list_type = mjolnir::ParameterList<omp_traits_type, potential_type>;
    using omp_parameter_type      = typename mjolnir::DebyeHuckelParameterList<omp_traits_type>::parameter_type;
    using omp_partition_type      = mjolnir::UnlimitedGridCellList<omp_traits_type, potential_type>;
    using omp_interaction_type    = mjolnir::GlobalPairInteraction<omp_traits_type, potential_type>;

    using seq_parameter_list_type = mjolnir::ParameterList<seq_traits_type, potential_type>;
    using seq_parameter_type      = typename mjolnir::DebyeHuckelParameterList<seq_traits_type>::parameter_type;
    using seq_system_type         = mjolnir::System<seq_traits_type>;
    using seq_partition_type      = mjolnir::UnlimitedGridCellList<seq_traits_type, potential_type>;
    using seq_interaction_type    = mjolnir::GlobalPairInteraction<seq_traits_type, potential_type>;

    const int max_number_of_threads = omp_get_max_threads();
    BOOST_TEST_WARN(max_number_of_threads > 2);
    BOOST_TEST_MESSAGE("maximum number of threads = " << max_number_of_threads);

    std::mt19937 rng(123456789);

    const std::size_t N_particle = 64;
    for(int num_thread=1; num_thread<=max_number_of_threads; ++num_thread)
    {
        omp_set_num_threads(num_thread);
        BOOST_TEST_MESSAGE("maximum number of threads = " << omp_get_max_threads());

        std::vector<std::pair<std::size_t, omp_parameter_type>> omp_parameters(N_particle);
        for(std::size_t i=0; i<N_particle; ++i)
        {
            omp_parameters[i] = std::make_pair(i, omp_parameter_type{1.0});
        }
        std::vector<std::pair<std::size_t, seq_parameter_type>> seq_parameters(N_particle);
        for(std::size_t i=0; i<N_particle; ++i)
        {
            seq_parameters[i] = std::make_pair(i, seq_parameter_type{1.0});
        }

        potential_type potential(5.5);

        mjolnir::DebyeHuckelParameterList<omp_traits_type> omp_rule(omp_parameters, {},
            typename omp_parameter_list_type::ignore_molecule_type("Nothing"),
            typename omp_parameter_list_type::ignore_group_type   ({}));
        omp_parameter_list_type omp_parameter_list(mjolnir::make_unique<
            mjolnir::DebyeHuckelParameterList<omp_traits_type>>(std::move(omp_rule)));

        mjolnir::DebyeHuckelParameterList<seq_traits_type> seq_rule(seq_parameters, {},
            typename seq_parameter_list_type::ignore_molecule_type("Nothing"),
            typename seq_parameter_list_type::ignore_group_type   ({}));
        seq_parameter_list_type seq_parameter_list(mjolnir::make_unique<
            mjolnir::DebyeHuckelParameterList<seq_traits_type>>(std::move(seq_rule)));

        topology_type topol(N_particle);
        topol.construct_molecules();

        omp_system_type omp_sys(N_particle, boundary_type{});
        seq_system_type seq_sys(N_particle, boundary_type{});

        test::clear_everything(omp_sys);
        test::clear_everything(seq_sys);

        omp_sys.attribute("temperature")    = 300.0;
        omp_sys.attribute("ionic_strength") =   0.2;

        seq_sys.attribute("temperature")    = 300.0;
        seq_sys.attribute("ionic_strength") =   0.2;

        for(std::size_t i=0; i<omp_sys.size(); ++i)
        {
            const auto i_x = i % 4;
            const auto i_y = i / 4;
            const auto i_z = i / 16;

            omp_sys.position(i) = mjolnir::math::make_coordinate<coordinate_type>(i_x*2.0, i_y*2.0, i_z*2.0);
        }

        test::apply_random_perturbation(omp_sys, rng, 0.1);

        potential.initialize(omp_sys);

        for(std::size_t i=0; i<omp_sys.size(); ++i)
        {
            seq_sys.mass(i)     = omp_sys.mass(i);
            seq_sys.position(i) = omp_sys.position(i);
            seq_sys.velocity(i) = omp_sys.velocity(i);
            seq_sys.force(i)    = omp_sys.force(i);
            seq_sys.name(i)     = omp_sys.name(i);
            seq_sys.group(i)    = omp_sys.group(i);
        }

        omp_interaction_type omp_interaction(potential_type{potential},
            std::move(omp_parameter_list),
            mjolnir::SpatialPartition<omp_traits_type, potential_type>(
                mjolnir::make_unique<omp_partition_type>()));

        seq_interaction_type seq_interaction(potential_type{potential},
            std::move(seq_parameter_list),
            mjolnir::SpatialPartition<seq_traits_type, potential_type>(
                mjolnir::make_unique<seq_partition_type>()));

        omp_interaction.initialize(omp_sys, topol);
        seq_interaction.initialize(seq_sys, topol);

        test::check_force_consistency              (omp_sys, omp_interaction, seq_sys, seq_interaction, tol);
        test::check_force_and_energy_consistency   (omp_sys, omp_interaction, seq_sys, seq_interaction, tol);
        test::check_force_and_virial_consistency   (omp_sys, omp_interaction, seq_sys, seq_interaction, tol);
        test::check_force_energy_virial_consistency(omp_sys, omp_interaction, seq_sys, seq_interaction, tol);
        test::check_energy_consistency             (omp_sys, omp_interaction, seq_sys, seq_interaction, tol);
    }
}


text:
package goworker

import (
	"sync"
	"time"
)

// Dispatcher starts workers and route jobs for it
type Dispatcher struct {
	// A pool of workers channels that are registered with the goworker
	WorkerPool      chan chan GoJob
	Workers         chan *Worker
	maxWorkers      int
	jobsQueue       chan GoJob
	unperformedJobs []GoJob
	stop            chan bool
	stopped         chan bool
	wg              *sync.WaitGroup
	stopInProgress  bool
}

// NewDispatcher construct new Dispatcher
func NewDispatcher(maxWorkers int, jobsQueueSize uint) *Dispatcher {
	jobsQueue := make(chan GoJob, jobsQueueSize)
	var unperformedJobs []GoJob // when stop copy all jobs from jobsQueue to unperformedJobs
	pool := make(chan chan GoJob, maxWorkers)
	workers := make(chan *Worker, maxWorkers)
	return &Dispatcher{
		WorkerPool:      pool,
		Workers:         workers,
		maxWorkers:      maxWorkers,
		jobsQueue:       jobsQueue,
		unperformedJobs: unperformedJobs,
		stop:            make(chan bool, 1),
		stopped:         make(chan bool, 1),
		wg:              &sync.WaitGroup{},
		stopInProgress:  false,
	}
}

// Run dispatcher
func (d *Dispatcher) Run() {
	// clean
	d.CleanUnperformedJobs()
	// starting n number of workers
	for i := 0; i < d.maxWorkers; i++ {
		w := NewWorker(i, d.WorkerPool)
		w.Start(d.wg)
		d.Workers <- w
	}

	d.dispatch()
}

func (d *Dispatcher) dispatch() {
	defer func() {
		d.stopWorkers()

		d.wg.Wait()

		// move all jobs from input channel to unperformedJobs
		if len(d.jobsQueue) > 0 {
			for j := range d.jobsQueue {
				d.unperformedJobs = append(d.unperformedJobs, j)
				if len(d.jobsQueue) == 0 {
					break
				}
			}
		}

		d.stopInProgress = false
		d.stopped <- true
	}()

	for {
		select {
		// a job request has been received
		case job := <-d.jobsQueue:
			select {
			// try to obtain a worker job channel that is available.
			// this will block until a worker is idle
			case jobChannel := <-d.WorkerPool:
				// dispatch the job to the worker job channel
				jobChannel <- job
			case <-d.stop:
				// if need to exit save current job to unperformedJobs
				d.unperformedJobs = append(d.unperformedJobs, job)
				return
			}
		case <-d.stop:
			return
		}
	}
}

func (d *Dispatcher) stopWorkers() {
	defer func() {
		// clear WorkerPool
		for _ = range d.WorkerPool {
			if len(d.WorkerPool) == 0 {
				return
			}
		}
	}()

	for w := range d.Workers {
		w.Stop()
		if len(d.Workers) == 0 {
			return
		}
	}
}

// AddJob adds new job to dispatcher
func (d *Dispatcher) AddJob(job GoJob) {
	// add job to dispatcher, it's check is dispatcher Stop() in progress and try again

	// If method d.Stop() called you can't add new jobs before Stop() successfully completed
	// It's required for moving jobs from input channel to unperformedJobs when dispatcher Stop() method called.
	for {
		// loop while stopInProgress
		if d.stopInProgress == false {
			d.jobsQueue <- job
			break
		}
		time.Sleep(time.Microsecond)
	}
}

// Stop dispatcher
func (d *Dispatcher) Stop() {
	d.stopInProgress = true
	d.stop <- true
	<-d.stopped
}

// GetUnperformedJobs method returns a chan of GoJobs that have not been done before Stop() executed
func (d *Dispatcher) GetUnperformedJobs() []GoJob {
	return d.unperformedJobs
}

// CleanUnperformedJobs remove unperformedJobs
func (d *Dispatcher) CleanUnperformedJobs() {
	d.unperformedJobs = make([]GoJob, 0)
}

func (d *Dispatcher) CountJobs() int {
	return len(d.jobsQueue)
}


text:
package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"math/rand"
	"os"
	"strconv"
	"strings"
	"time"
)

type TagHist []uint
type Engine struct {
	generator RIGenerator
}
type OutputFormat string

var availableGenerators []RIGenerator = []RIGenerator{
	GlpkRIGenerator{},
	DummyRIGenerator{},
}

var diag *log.Logger

var (
	seed         int64
	tagHistogram TagHist     = nil
	params       VbmapParams = VbmapParams{
		Tags: nil,
	}
	engine       Engine       = Engine{availableGenerators[0]}
	outputFormat OutputFormat = "text"
	diagTo       string       = "stderr"
)

func (tags *TagMap) Set(s string) error {
	*tags = make(TagMap)

	for _, pair := range strings.Split(s, ",") {
		tagNode := strings.Split(pair, ":")
		if len(tagNode) != 2 {
			return fmt.Errorf("invalid tag-node pair (%s)", pair)
		}

		node, err := strconv.ParseUint(tagNode[0], 10, strconv.IntSize)
		if err != nil {
			return err
		}

		tag, err := strconv.ParseUint(tagNode[1], 10, strconv.IntSize)
		if err != nil {
			return err
		}

		(*tags)[Node(node)] = Tag(tag)
	}
	return nil
}

func (hist *TagHist) Set(s string) error {
	values := strings.Split(s, ",")
	*hist = make(TagHist, len(values))

	for i, v := range values {
		count, err := strconv.ParseUint(v, 10, strconv.IntSize)
		if err != nil {
			return err
		}

		(*hist)[i] = uint(count)
	}

	return nil
}

func (hist TagHist) String() string {
	return fmt.Sprintf("%v", []uint(hist))
}

func (engine *Engine) Set(s string) error {
	for _, gen := range availableGenerators {
		if s == gen.String() {
			*engine = Engine{gen}
			return nil
		}
	}

	return fmt.Errorf("unknown engine")
}

func (engine Engine) String() string {
	return engine.generator.String()
}

func (format *OutputFormat) Set(s string) error {
	switch s {
	case "text", "json", "ext-json":
		*format = OutputFormat(s)
	default:
		return fmt.Errorf("unrecognized output format")
	}

	return nil
}

func (format OutputFormat) String() string {
	return string(format)
}

func normalizeParams(params *VbmapParams) {
	if params.NumReplicas+1 > params.NumNodes {
		params.NumReplicas = params.NumNodes - 1
	}

	if params.NumSlaves >= params.NumNodes {
		params.NumSlaves = params.NumNodes - 1
	}

	if params.NumSlaves < params.NumReplicas {
		params.NumReplicas = params.NumSlaves
	}
}

func checkInput() {
	if params.NumNodes <= 0 || params.NumSlaves <= 0 || params.NumVBuckets <= 0 {
		fatal("num-nodes, num-slaves and num-vbuckets must be greater than zero")
	}

	if params.NumReplicas < 0 {
		fatal("num-replicas must be greater of equal than zero")
	}

	if params.Tags != nil && tagHistogram != nil {
		fatal("Options --tags and --tag-histogram are exclusive")
	}

	normalizeParams(&params)

	if params.Tags == nil && tagHistogram == nil {
		diag.Printf("Tags are not specified. Assuming every node on a separate tag.")
		tagHistogram = make(TagHist, params.NumNodes)

		for i := 0; i < params.NumNodes; i++ {
			tagHistogram[i] = 1
		}
	}

	if tagHistogram != nil {
		tag := 0
		params.Tags = make(TagMap)

		for i := 0; i < params.NumNodes; i++ {
			for tag < len(tagHistogram) && tagHistogram[tag] == 0 {
				tag += 1
			}
			if tag >= len(tagHistogram) {
				fatal("Invalid tag histogram. Counts do not add up.")
			}

			tagHistogram[tag] -= 1
			params.Tags[Node(i)] = Tag(tag)
		}

		if tag != len(tagHistogram)-1 || tagHistogram[tag] != 0 {
			fatal("Invalid tag histogram. Counts do not add up.")
		}
	}

	// each node should have a tag assigned
	for i := 0; i < params.NumNodes; i++ {
		_, present := params.Tags[Node(i)]
		if !present {
			fatal("Tag for node %v not specified", i)
		}
	}
}

func fatal(format string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, format+"\n", args...)
	os.Exit(1)
}

func main() {
	// TODO
	flag.IntVar(&params.NumNodes, "num-nodes", 25, "number of nodes")
	flag.IntVar(&params.NumSlaves, "num-slaves", 10, "number of slaves")
	flag.IntVar(&params.NumVBuckets, "num-vbuckets", 1024, "number of VBuckets")
	flag.IntVar(&params.NumReplicas, "num-replicas", 1, "number of replicas")
	flag.Var(&params.Tags, "tags", "tags")
	flag.Var(&tagHistogram, "tag-histogram", "tag histogram")
	flag.Var(&engine, "engine", "engine used to generate the topology")
	flag.Var(&outputFormat, "output-format", "output format")
	flag.StringVar(&diagTo, "diag", "stderr", "where to send diagnostics")

	flag.Int64Var(&seed, "seed", time.Now().UTC().UnixNano(), "random seed")

	flag.Parse()

	var diagSink io.Writer
	switch diagTo {
	case "stderr":
		diagSink = os.Stderr
	case "null":
		diagSink = ioutil.Discard
	default:
		diagFile, err := os.Create(diagTo)
		if err != nil {
			fatal("Couldn't create diagnostics file: %s", err.Error())
		}
		defer func() {
			diagFile.Close()
		}()
		diagSink = diagFile
	}

	diag = log.New(diagSink, "", 0)
	diag.Printf("Started as:\n  %s", strings.Join(os.Args, " "))

	diag.Printf("Using %d as a seed", seed)
	rand.Seed(seed)

	checkInput()

	diag.Printf("Finalized parameters")
	diag.Printf("  Number of nodes: %d", params.NumNodes)
	diag.Printf("  Number of slaves: %d", params.NumSlaves)
	diag.Printf("  Number of vbuckets: %d", params.NumVBuckets)
	diag.Printf("  Number of replicas: %d", params.NumReplicas)
	diag.Printf("  Tags assignments:")

	for i := 0; i < params.NumNodes; i++ {
		diag.Printf("    %d -> %v", i, params.Tags[Node(i)])
	}

	start := time.Now()

	solution, err := VbmapGenerate(params, engine.generator)
	if err != nil {
		fatal("ERROR: %s", err.Error())
	}

	duration := time.Since(start)
	diag.Printf("Generated vbucket map in %s (wall clock)", duration.String())

	switch outputFormat {
	case "text":
		fmt.Print(solution.String())
	case "json":
		json, err := json.Marshal(solution)
		if err != nil {
			fatal("Couldn't encode the solution: %s", err.Error())
		}
		fmt.Print(string(json))
	case "ext-json":
		extJsonMap := make(map[string]interface{})
		extJsonMap["numNodes"] = params.NumNodes
		extJsonMap["numSlaves"] = params.NumSlaves
		extJsonMap["numVBuckets"] = params.NumVBuckets
		extJsonMap["numReplicas"] = params.NumReplicas
		extJsonMap["map"] = solution

		tags := make([]Tag, params.NumNodes)
		extJsonMap["tags"] = tags

		for i, t := range params.Tags {
			tags[i] = t
		}

		json, err := json.Marshal(extJsonMap)
		if err != nil {
			fatal("Couldn't encode the solution: %s", err.Error())
		}
		fmt.Print(string(json))
	default:
		panic("should not happen")
	}
}


text:
require File.dirname(__FILE__) + '/../../../test/test_helper'
require File.dirname(__FILE__) + '/../../spec_helper'
require 'admin/users_controller'

# Re-raise errors caught by the controller.
class Admin::UsersController; def rescue_action(e) raise e end; end

describe Admin::CacheController, "rough port of the old functional test" do

  before(:each) do
    request.session = { :user => users(:tobi).id }
  end

  describe 'sweep_html action' do

    it 'should redirect to setting index' do
      get 'sweep_html'
      response.should redirect_to(:controller => '/admin/settings')
    end

  end

end


text:
//===--- AutoDiffSupport.h ------------------------------------*- C++ -*---===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2019 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_RUNTIME_AUTODIFF_SUPPORT_H
#define SWIFT_RUNTIME_AUTODIFF_SUPPORT_H

#include "swift/Runtime/HeapObject.h"
#include "swift/Runtime/Config.h"
#include "llvm/Support/Allocator.h"

namespace swift {

/// A data structure responsible for efficiently allocating closure contexts for
/// linear maps such as pullbacks, including recursive branching trace enum
/// case payloads.
class AutoDiffLinearMapContext : public HeapObject {
private:
  /// The underlying allocator.
  // TODO: Use a custom allocator so that the initial slab can be
  // tail-allocated.
  llvm::BumpPtrAllocator allocator;

public:
  /// Creates a linear map context.
  AutoDiffLinearMapContext();
  /// Returns the address of the tail-allocated top-level subcontext.
  void *projectTopLevelSubcontext() const;
  /// Allocates memory for a new subcontext.
  void *allocate(size_t size);
};

/// Creates a linear map context with a tail-allocated top-level subcontext.
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
AutoDiffLinearMapContext *swift_autoDiffCreateLinearMapContext(
    size_t topLevelSubcontextSize);

/// Returns the address of the tail-allocated top-level subcontext.
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
void *swift_autoDiffProjectTopLevelSubcontext(AutoDiffLinearMapContext *);

/// Allocates memory for a new subcontext.
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
void *swift_autoDiffAllocateSubcontext(AutoDiffLinearMapContext *, size_t size);

}

#endif /* SWIFT_RUNTIME_AUTODIFF_SUPPORT_H */