//
//  XHRadarPointView.m
//  XHRadarView
//
//  Created by 邱星豪 on 14/10/27.
//  Copyright (c) 2014年 邱星豪. All rights reserved.
//

#import "XHRadarPointView.h"

@implementation XHRadarPointView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

#pragma mark - select point
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];

    if(touch.tapCount == 1)
    {
        if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectItemRadarPointView:)]) {
            [self.delegate didSelectItemRadarPointView:self];
        }
    }
}

@end

{'repo_name': 'heartfly/XHRadarView', 'stars': '109', 'repo_language': 'Objective-C', 'file_name': 'XHRadarViewDemo.xccheckout', 'mime_type': 'text/xml', 'hash': -3227112956295412625, 'source_dataset': 'data'}


/**
 * jQRangeSlider
 * A javascript slider selector that supports dates
 *
 * Copyright (C) Guillaume Gautreau 2012
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 */

(function($, undefined){
	"use strict";

	$.widget("ui.dateRangeSliderHandle", $.ui.rangeSliderHandle, {
		_steps: false,
		_boundsValues: {},

		_create: function(){
			this._createBoundsValues();
			$.ui.rangeSliderHandle.prototype._create.apply(this);
		},

		_getValueForPosition: function(position){

			var raw = this._getRawValueForPositionAndBounds(position, this.options.bounds.min.valueOf(), this.options.bounds.max.valueOf());

			return this._constraintValue(new Date(raw));
		},

		_setOption: function(key, value){
			if (key === "step"){
				this.options.step = value;
				this._createSteps();
				this.update();
				return;
			}

			$.ui.rangeSliderHandle.prototype._setOption.apply(this, [key, value]);

			if (key === "bounds"){
				this._createBoundsValues();
			}
		},

		_createBoundsValues: function(){
			this._boundsValues = {
					min: this.options.bounds.min.valueOf(),
					max: this.options.bounds.max.valueOf()
			};
		},

		_bounds: function(){
			return this._boundsValues;
		},

		_createSteps: function(){
			if (this.options.step === false || !this._isValidStep()){
				this._steps = false;
				return;
			}

			var minDate = new Date(this.options.bounds.min.valueOf()),
				maxDate = new Date(this.options.bounds.max.valueOf()),
				stepDate = minDate,
				i = 0,
				previous = new Date();

			this._steps = [];

			while (stepDate <= maxDate && (i === 1 || previous.valueOf() !== stepDate.valueOf())){
				previous = stepDate;
				this._steps.push(stepDate.valueOf());

				stepDate = this._addStep(minDate, i, this.options.step);
				i++;
			}

			if (previous.valueOf() === stepDate.valueOf()){
				this._steps = false;
			}
		},

		_isValidStep: function(){
			return typeof this.options.step === "object";
		},

		_addStep: function(reference, factor, step){
			var result = new Date(reference.valueOf());

			result = this._addThing(result, "FullYear", factor, step.years);
			result = this._addThing(result, "Month", factor, step.months);
			result = this._addThing(result, "Date", factor, step.weeks * 7);
			result = this._addThing(result, "Date", factor, step.days);
			result = this._addThing(result, "Hours", factor, step.hours);
			result = this._addThing(result, "Minutes", factor, step.minutes);
			result = this._addThing(result, "Seconds", factor, step.seconds);

			return result;
		},

		_addThing: function(date, thing, factor, base){
			if (factor === 0 || (base || 0) === 0){
				return date;
			}

			date["set" + thing](
				date["get" + thing]() + factor * (base || 0)
				);

			return date;
		},

		_round: function(value){
			if (this._steps === false){
				return value;
			}

			var max = this.options.bounds.max.valueOf(),
				min = this.options.bounds.min.valueOf(),
				ratio = Math.max(0, (value - min) / (max - min)),
				index = Math.floor(this._steps.length * ratio),
				before, after;

			while (this._steps[index] > value){
				index--;
			}

			while (index + 1 < this._steps.length && this._steps[index + 1] <= value){
				index++;
			}

			if (index >= this._steps.length - 1){
				return this._steps[this._steps.length - 1];
			} else if (index === 0){
				return this._steps[0];
			}

			before = this._steps[index];
			after = this._steps[index + 1];

			if (value - before < after - value){
				return before;
			}

			return after;
		},

		update: function(){
			this._createBoundsValues();
			this._createSteps();
			$.ui.rangeSliderHandle.prototype.update.apply(this);
		},

		add: function(date, step){
			return this._addStep(new Date(date), 1, step).valueOf();
		},

		substract: function(date, step){
			return this._addStep(new Date(date), -1, step).valueOf();
		},

		stepsBetween: function(date1, date2){
			if (this.options.step === false){
				return date2 - date1;
			}

			var min = Math.min(date1, date2),
				max = Math.max(date1, date2),
				steps = 0,
				negative = false,
				negativeResult = date1 > date2;

			if (this.add(min, this.options.step) - min < 0){
				negative = true;
			}

			while (min < max){
				if (negative){
					max = this.add(max, this.options.step);
				}else{
					min = this.add(min, this.options.step);
				}

				steps++;
			}

			return negativeResult ? -steps : steps;
		},

		multiplyStep: function(step, factor){
			var result = {};

			for (var name in step){
				if (step.hasOwnProperty(name)){
					result[name] = step[name] * factor;
				}
			}

			return result;
		},

		stepRatio: function(){
			if (this.options.step === false){
				return 1;
			}else{
				var steps = this._steps.length;
				return this.cache.parent.width / steps;
			}
		}
	});
}(jQuery));

{'repo_name': 'cuemacro/chartpy', 'stars': '389', 'repo_language': 'Python', 'file_name': 'chartpy.mplstyle', 'mime_type': 'text/plain', 'hash': 1358341337739317304, 'source_dataset': 'data'}


/* ========================================
 *  HighImpact - HighImpact.h
 *  Created 8/12/11 by SPIAdmin
 *  Copyright (c) 2011 __MyCompanyName__, All rights reserved
 * ======================================== */

#ifndef __HighImpact_H
#define __HighImpact_H

#ifndef __audioeffect__
#include "audioeffectx.h"
#endif

#include <set>
#include <string>
#include <math.h>

enum {
	kParamA = 0,
	kParamB = 1,
	kParamC = 2,
  kNumParameters = 3
}; //

const int kNumPrograms = 0;
const int kNumInputs = 2;
const int kNumOutputs = 2;
const unsigned long kUniqueId = 'himp';    //Change this to what the AU identity is!

class HighImpact :
    public AudioEffectX
{
public:
    HighImpact(audioMasterCallback audioMaster);
    ~HighImpact();
    virtual bool getEffectName(char* name);                       // The plug-in name
    virtual VstPlugCategory getPlugCategory();                    // The general category for the plug-in
    virtual bool getProductString(char* text);                    // This is a unique plug-in string provided by Steinberg
    virtual bool getVendorString(char* text);                     // Vendor info
    virtual VstInt32 getVendorVersion();                          // Version number
    virtual void processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames);
    virtual void processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames);
    virtual void getProgramName(char *name);                      // read the name from the host
    virtual void setProgramName(char *name);                      // changes the name of the preset displayed in the host
	virtual VstInt32 getChunk (void** data, bool isPreset);
	virtual VstInt32 setChunk (void* data, VstInt32 byteSize, bool isPreset);
    virtual float getParameter(VstInt32 index);                   // get the parameter value at the specified index
    virtual void setParameter(VstInt32 index, float value);       // set the parameter at index to value
    virtual void getParameterLabel(VstInt32 index, char *text);  // label for the parameter (eg dB)
    virtual void getParameterName(VstInt32 index, char *text);    // name of the parameter
    virtual void getParameterDisplay(VstInt32 index, char *text); // text description of the current value
    virtual VstInt32 canDo(char *text);
private:
    char _programName[kVstMaxProgNameLen + 1];
    std::set< std::string > _canDo;

	long double fpNShapeL;
	long double fpNShapeR;
	//default stuff

	double lastSampleL;
	double lastSampleR;

    float A;
    float B;
    float C;

};

#endif

{'repo_name': 'airwindows/airwindows', 'stars': '156', 'repo_language': 'C++', 'file_name': 'InfoPlist.strings', 'mime_type': 'text/plain', 'hash': -2441283806953143665, 'source_dataset': 'data'}


SubDir TOP libraries RF24Network examples sensornet ;

LOCATE_SOURCE = $(SUBDIR)/$(PINS) ;
LOCATE_TARGET = $(SUBDIR)/$(PINS) ;

ArduinoWithLibs Main : RF24Network RF24 Tictocs SPI ;

{'repo_name': 'digistump/DigistumpArduino', 'stars': '484', 'repo_language': 'C', 'file_name': 'TinySoftwareSPI.cpp', 'mime_type': 'text/x-c', 'hash': 8042661452687627476, 'source_dataset': 'data'}


let fluid;

function setup() {
  createCanvas(300, 300);
  frameRate(22);
  fluid = new Fluid(0.2, 0, 0.0000001);
}

function draw() {
  stroke(51);
  strokeWeight(2);

  let cx = int((0.5 * width) / SCALE);
  let cy = int((0.5 * height) / SCALE);
  for (let i = -1; i <= 1; i++) {
    for (let j = -1; j <= 1; j++) {
      fluid.addDensity(cx + i, cy + j, random(50, 150));
    }
  }

  for (let i = 0; i < 2; i++) {
    let angle = noise(t) * TWO_PI * 2;
    let v = p5.Vector.fromAngle(angle);
    v.mult(0.2);
    t += 0.01;
    fluid.addVelocity(cx, cy, v.x, v.y);
  }

  fluid.step();
  fluid.renderD();
}

{'repo_name': 'CodingTrain/website', 'stars': '4523', 'repo_language': 'JavaScript', 'file_name': 'sketch.js', 'mime_type': 'text/plain', 'hash': 4950134819597642670, 'source_dataset': 'data'}


/*
 * 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.
 */

/**
 * <p>
 * This package contains some implementations of the {@code Configuration}
 * interface that are useful in web environments.
 * </p>
 *
 */
package org.apache.commons.configuration2.web;

{'repo_name': 'apache/commons-configuration', 'stars': '105', 'repo_language': 'Java', 'file_name': 'checkstyle.xml', 'mime_type': 'text/xml', 'hash': -5950163283026414558, 'source_dataset': 'data'}


<!DOCTYPE html>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>vue-demo</title>

      We're sorry but vue-demo doesn't work properly without JavaScript enabled. Please enable it to continue.

{'repo_name': 'shengxinjing/my_blog', 'stars': '1070', 'repo_language': 'HTML', 'file_name': 'index.html', 'mime_type': 'text/html', 'hash': -110122075115237415, 'source_dataset': 'data'}


# red_flask

#### 项目介绍

Restful framework base on flask without blueprint.

一个基于Flask搭建的Restful_Api服务框架,实现了路由分离的功能但无需依赖于Flask的蓝本。提供了常用的http请求类型和文件传输类型的相关接口。

提供了较简单的异步任务分发方案。提供了最常用的用户密码校验模块和token验证模块(集成Oauth2)。集成了Gunicorn+Gevent的服务器自动配置方案。数据库端使用

Sqlalchemy和Redis。提供了Flask作为Https服务的解决方案。解决了Flask跨域问题。双系统生产化部署(windows/linux)。

#### 通过PIP快速构建redflask工程

1. pip install redflask==0.1.5
2. redflask -b [your_project_name]

#### 通过github获取源码

1. 使用 git clone 命令将项目复制到本地
2. pip install -r requirements.txt 安装所有依赖

#### 使用说明

1. 本地调试，直接python run.py (请在setting.yaml中配置IP为localhost)
2. 部署调试，chmod +x test.sh  然后 ./test.sh
3. 部署生产, chmod +x start.sh 然后 ./start.sh

#### 软件架构

controller : 路由控制器，用来注解并分配工程的api地址和分发对应的接口任务，其作用类似于Java SpringBoot 中的restcontroller.子下的文件目录根据对应业务类型进行区分

database: 包含各类数据库链接和对象映射的基本配置，以及数据库其他模式（如主从、池化、分布式等）的配置都在此处生效。

Exceptions: 用来自定义继承或重写python的错误类型，并编写特定的处理方式。

Resource: 用于存放工程中使用到的各类静态文本数据和多媒体数据，还有机器学习模型。

Service: 用于编写API实际业务逻辑的文件目录，Controller下的api接口一般会从此处调用具体服务，其目录结构与controller相似。

Utils: 泛用工具类及全局装饰器的存储目录。

其他工程文件详解:

test_case 测试案例写在这里

__init__.py  red_flask工程的基本配置文件，各项配置须在此初始化

requirements.txt  记录依赖模块 方便pip安装

run.py  服务启动入口，wsgi配置文件

start.sh  服务启动脚本

test.sh 测试脚本

configm.py  Gunicorn网络模型配置脚本

setting.yaml  用于自适应部署的配置文件

#### 参与贡献

感谢航小妈提供的部分架构思路

#### 版本更新日志

## 20190802

1  添加常用的正则校验工具  utils/common/regex_matcher.py

2  添加redis常用的操作函数 utils/common/redisor.py

3  添加文本相似度通用算法工具  utils/common/text_similarity.py

4  添加xls，excel文本读写工具  utils/common/xls_tool.py

5  添加Flask框架对用户请求的参数校验工具及错误类型封包 utils/http/responser.py

## 20191202

1 添加常用的消息队列、分布式任务框架案例，celery+rabbitMQ。 utils/msg_queue

2 添加一个快捷日志纪录工具。 utils/common/logger.py

## 20200416

1 service中添加了一个常规的系统用户表CRUD操作，并在controller中实现了对应接口，对应的数据库已转存为.sql文件存放在 database/sql_bak目录下

2 utils/decorator 目录下添加了目前最常用的基于token的Oauth2认证装饰器，区别于之前将token存储于浏览器cookie中的方案，客户端可以自由选择如何存储token.

3 contorller/service 中 提供了使用http_resonser的案例，可以对接口传参进行自动校验并返回对应的错误码。

4 添加zip解析工具

5 为windows环境下的生产化部署提供了新的方案，基于tornado做一层转发，性能未知。

6 配置文件新增了部署端口、数据库常量配置、系统超时时间、加密方式等字段

## 设计理念

我并打算把这个框架做的很细致全面，尽管他在企业级应用中已经有了许多复杂的变化。
我只是想分享这个框架的设计思路，所以尽量保留一个简介的版本。
框架的目的是使多人合作开发的过程中，每个人能很清楚代码的结构，快速定位自己coding的模块。

{'repo_name': 'redtreeai/red-flask', 'stars': '138', 'repo_language': 'Python', 'file_name': 'README.md', 'mime_type': 'text/plain', 'hash': -1643359688299224850, 'source_dataset': 'data'}


import math
import warnings
from collections import OrderedDict
from typing import List

import torch
from torch import nn

from pytorch_toolbelt.modules import Swish
from .common import EncoderModule, make_n_channel_input, _take

__all__ = [
    "B0Encoder",
    "B1Encoder",
    "B2Encoder",
    "B3Encoder",
    "B4Encoder",
    "B5Encoder",
    "B6Encoder",
    "B7Encoder",
    "MixNetXLEncoder",
    "HRNetW32Encoder",
    "HRNetW18Encoder",
    "HRNetW48Encoder",
    "SKResNet18Encoder",
    "SKResNeXt50Encoder",
    "SWSLResNeXt101Encoder",
    "TResNetMEncoder",
]

def make_n_channel_input_conv2d_same(conv: nn.Conv2d, in_channels: int, mode="auto"):
    assert isinstance(conv, nn.Conv2d)
    if conv.in_channels == in_channels:
        warnings.warn("make_n_channel_input call is spurious")
        return conv

    from timm.models.layers import Conv2dSame

    new_conv = Conv2dSame(
        in_channels,
        out_channels=conv.out_channels,
        kernel_size=conv.kernel_size,
        stride=conv.stride,
        padding=conv.padding,
        dilation=conv.dilation,
        groups=conv.groups,
        bias=conv.bias is not None,
    )

    w = conv.weight
    if in_channels > conv.in_channels:
        n = math.ceil(in_channels / float(conv.in_channels))
        w = torch.cat([w] * n, dim=1)
        w = w[:, :in_channels, ...]
        new_conv.weight = nn.Parameter(w, requires_grad=True)
    else:
        w = w[:, 0:in_channels, ...]
        new_conv.weight = nn.Parameter(w, requires_grad=True)

    return new_conv

class B0Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b0_ns

        encoder = tf_efficientnet_b0_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.05
        )
        strides = [2, 4, 8, 16, 32]

        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8

        super().__init__([16, 24, 40, 112, 320], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class B1Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b1_ns

        encoder = tf_efficientnet_b1_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.05
        )
        strides = [2, 4, 8, 16, 32]
        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8
        super().__init__([16, 24, 40, 112, 320], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class B2Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b2_ns

        encoder = tf_efficientnet_b2_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.1
        )
        strides = [2, 4, 8, 16, 32]
        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8
        super().__init__([16, 24, 48, 120, 352], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class B3Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b3_ns

        encoder = tf_efficientnet_b3_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.1
        )
        strides = [2, 4, 8, 16, 32]
        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8
        super().__init__([24, 32, 48, 136, 384], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class B4Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b4_ns

        encoder = tf_efficientnet_b4_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.2
        )
        strides = [2, 4, 8, 16, 32]
        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8
        super().__init__([24, 32, 56, 160, 448], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class B5Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b5_ns

        encoder = tf_efficientnet_b5_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.2
        )
        strides = [2, 4, 8, 16, 32]
        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8
        super().__init__([24, 40, 64, 176, 512], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class B6Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b6_ns

        encoder = tf_efficientnet_b6_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.2
        )
        strides = [2, 4, 8, 16, 32]
        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8
        super().__init__([32, 40, 72, 200, 576], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class B7Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish, no_stride=False):
        from timm.models.efficientnet import tf_efficientnet_b7_ns

        encoder = tf_efficientnet_b7_ns(
            pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.2
        )
        strides = [2, 4, 8, 16, 32]
        if no_stride:
            encoder.blocks[5][0].conv_dw.stride = (1, 1)
            encoder.blocks[5][0].conv_dw.dilation = (2, 2)

            encoder.blocks[3][0].conv_dw.stride = (1, 1)
            encoder.blocks[3][0].conv_dw.dilation = (2, 2)
            strides[3] = 8
            strides[4] = 8
        super().__init__([32, 48, 80, 224, 640], strides, layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class MixNetXLEncoder(EncoderModule):
    def __init__(self, pretrained=True, layers=[1, 2, 3, 4], act_layer=Swish):
        from timm.models.efficientnet import mixnet_xl

        encoder = mixnet_xl(pretrained=pretrained, features_only=True, act_layer=act_layer, drop_path_rate=0.2)
        super().__init__([40, 48, 64, 192, 320], [2, 4, 8, 16, 32], layers)
        self.encoder = encoder

    def forward(self, x):
        features = self.encoder(x)
        return _take(features, self._layers)

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv_stem = make_n_channel_input_conv2d_same(self.encoder.conv_stem, input_channels, mode)
        return self

class TResNetMEncoder(EncoderModule):
    def __init__(self, pretrained=True, layers=None):
        if layers is None:
            layers = [1, 2, 3, 4]
        from timm.models import tresnet_m

        encoder = tresnet_m(pretrained=pretrained)

        super().__init__([64, 64, 128, 1024, 2048], [4, 4, 8, 16, 32], layers)
        self.stem = nn.Sequential(encoder.body.SpaceToDepth, encoder.body.conv1)

        self.layer1 = encoder.body.layer1
        self.layer2 = encoder.body.layer2
        self.layer3 = encoder.body.layer3
        self.layer4 = encoder.body.layer4

    @property
    def encoder_layers(self) -> List[nn.Module]:
        return [self.stem, self.layer1, self.layer2, self.layer3, self.layer4]

class SKResNet18Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=None, no_first_max_pool=False):
        if layers is None:
            layers = [1, 2, 3, 4]
        from timm.models import skresnet18

        encoder = skresnet18(pretrained=pretrained, features_only=True)
        super().__init__([64, 64, 128, 256, 512], [2, 4, 8, 16, 32], layers)
        self.stem = nn.Sequential(
            OrderedDict([("conv1", encoder.conv1), ("bn1", encoder.bn1), ("act1", encoder.act1)])
        )

        self.layer1 = nn.Sequential(
            nn.Conv2d(64, 64, kernel_size=3, padding=1, stride=2) if no_first_max_pool else encoder.maxpool,
            encoder.layer1,
        )
        self.layer2 = encoder.layer2
        self.layer3 = encoder.layer3
        self.layer4 = encoder.layer4

    @property
    def encoder_layers(self) -> List[nn.Module]:
        return [self.stem, self.layer1, self.layer2, self.layer3, self.layer4]

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.stem.conv1 = make_n_channel_input(self.stem.conv1, input_channels, mode)
        return self

class SKResNeXt50Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=None):
        if layers is None:
            layers = [1, 2, 3, 4]
        from timm.models import skresnext50_32x4d

        encoder = skresnext50_32x4d(pretrained=pretrained)
        super().__init__([64, 256, 512, 1024, 2048], [2, 4, 8, 16, 32], layers)
        self.stem = nn.Sequential(encoder.conv1, encoder.bn1, encoder.act1)

        self.layer1 = nn.Sequential(encoder.maxpool, encoder.layer1)
        self.layer2 = encoder.layer2
        self.layer3 = encoder.layer3
        self.layer4 = encoder.layer4

    @property
    def encoder_layers(self) -> List[nn.Module]:
        return [self.stem, self.layer1, self.layer2, self.layer3, self.layer4]

class SWSLResNeXt101Encoder(EncoderModule):
    def __init__(self, pretrained=True, layers=None):
        if layers is None:
            layers = [1, 2, 3, 4]
        from timm.models.resnet import swsl_resnext101_32x8d

        encoder = swsl_resnext101_32x8d(pretrained=pretrained)
        super().__init__([64, 256, 512, 1024, 2048], [2, 4, 8, 16, 32], layers)
        self.stem = nn.Sequential(encoder.conv1, encoder.bn1, encoder.act1)

        self.layer1 = nn.Sequential(encoder.maxpool, encoder.layer1)
        self.layer2 = encoder.layer2
        self.layer3 = encoder.layer3
        self.layer4 = encoder.layer4

    @property
    def encoder_layers(self) -> List[nn.Module]:
        return [self.stem, self.layer1, self.layer2, self.layer3, self.layer4]

class HRNetW18Encoder(EncoderModule):
    def __init__(self, pretrained=True):
        from timm.models import hrnet

        encoder = hrnet.hrnet_w18(pretrained=pretrained, features_only=True, out_indices=(1, 2, 3, 4))
        super().__init__([128, 256, 512, 1024], [4, 8, 16, 32], [0, 1, 2, 3])
        self.encoder = encoder

    def forward(self, x):
        y = self.encoder.forward(x)
        return y

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv1 = make_n_channel_input(self.encoder.conv1, input_channels, mode)
        return self

class HRNetW32Encoder(EncoderModule):
    def __init__(self, pretrained=True):
        from timm.models import hrnet

        encoder = hrnet.hrnet_w32(pretrained=pretrained, features_only=True, out_indices=(1, 2, 3, 4))
        super().__init__([128, 256, 512, 1024], [4, 8, 16, 32], [0, 1, 2, 3])
        self.encoder = encoder

    def forward(self, x):
        y = self.encoder.forward(x)
        return y

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv1 = make_n_channel_input(self.encoder.conv1, input_channels, mode)
        return self

class HRNetW48Encoder(EncoderModule):
    def __init__(self, pretrained=True):
        from timm.models import hrnet

        encoder = hrnet.hrnet_w48(pretrained=pretrained, features_only=True, out_indices=(1, 2, 3, 4))
        super().__init__([128, 256, 512, 1024], [4, 8, 16, 32], [0, 1, 2, 3])
        self.encoder = encoder

    def forward(self, x):
        y = self.encoder.forward(x)
        return y

    def change_input_channels(self, input_channels: int, mode="auto"):
        self.encoder.conv1 = make_n_channel_input(self.encoder.conv1, input_channels, mode)
        return self

{'repo_name': 'BloodAxe/pytorch-toolbelt', 'stars': '766', 'repo_language': 'Python', 'file_name': 'test_modules.py', 'mime_type': 'text/x-python', 'hash': 909931303891453318, 'source_dataset': 'data'}


<?php
/*
 * Copyright 2014 Google Inc.
 *
 * Licensed 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.
 */

class Google_Service_ShoppingContent_LiasettingsRequestInventoryVerificationResponse extends Google_Model
{
  public $kind;

  public function setKind($kind)
  {
    $this->kind = $kind;
  }
  public function getKind()
  {
    return $this->kind;
  }
}

{'repo_name': 'googleapis/google-api-php-client-services', 'stars': '842', 'repo_language': 'PHP', 'file_name': 'ServiceTest.php', 'mime_type': 'text/x-php', 'hash': -7449518892953040273, 'source_dataset': 'data'}


/*
 *  drivers/extcon/extcon_class.c
 *
 *  External connector (extcon) class driver
 *
 * Copyright (C) 2012 Samsung Electronics
 * Author: Donggeun Kim <dg77.kim@samsung.com>
 * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
 *
 * based on android/drivers/switch/switch_class.c
 * Copyright (C) 2008 Google, Inc.
 * Author: Mike Lockwood <lockwood@android.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
*/

#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/err.h>
#include <linux/extcon.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/sysfs.h>

/*
 * extcon_cable_name suggests the standard cable names for commonly used
 * cable types.
 *
 * However, please do not use extcon_cable_name directly for extcon_dev
 * struct's supported_cable pointer unless your device really supports
 * every single port-type of the following cable names. Please choose cable
 * names that are actually used in your extcon device.
 */
const char extcon_cable_name[][CABLE_NAME_MAX + 1] = {
	[EXTCON_USB]		= "USB",
	[EXTCON_USB_HOST]	= "USB-Host",
	[EXTCON_TA]		= "TA",
	[EXTCON_FAST_CHARGER]	= "Fast-charger",
	[EXTCON_SLOW_CHARGER]	= "Slow-charger",
	[EXTCON_CHARGE_DOWNSTREAM]	= "Charge-downstream",
	[EXTCON_HDMI]		= "HDMI",
	[EXTCON_MHL]		= "MHL",
	[EXTCON_DVI]		= "DVI",
	[EXTCON_VGA]		= "VGA",
	[EXTCON_DOCK]		= "Dock",
	[EXTCON_LINE_IN]	= "Line-in",
	[EXTCON_LINE_OUT]	= "Line-out",
	[EXTCON_MIC_IN]		= "Microphone",
	[EXTCON_HEADPHONE_OUT]	= "Headphone",
	[EXTCON_SPDIF_IN]	= "SPDIF-in",
	[EXTCON_SPDIF_OUT]	= "SPDIF-out",
	[EXTCON_VIDEO_IN]	= "Video-in",
	[EXTCON_VIDEO_OUT]	= "Video-out",
	[EXTCON_MECHANICAL]	= "Mechanical",
};

static struct class *extcon_class;
#if defined(CONFIG_ANDROID)
static struct class_compat *switch_class;
#endif /* CONFIG_ANDROID */

static LIST_HEAD(extcon_dev_list);
static DEFINE_MUTEX(extcon_dev_list_lock);

/**
 * check_mutually_exclusive - Check if new_state violates mutually_exclusive
 *			      condition.
 * @edev:	the extcon device
 * @new_state:	new cable attach status for @edev
 *
 * Returns 0 if nothing violates. Returns the index + 1 for the first
 * violated condition.
 */
static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
{
	int i = 0;

	if (!edev->mutually_exclusive)
		return 0;

	for (i = 0; edev->mutually_exclusive[i]; i++) {
		int weight;
		u32 correspondants = new_state & edev->mutually_exclusive[i];

		/* calculate the total number of bits set */
		weight = hweight32(correspondants);
		if (weight > 1)
			return i + 1;
	}

	return 0;
}

static ssize_t state_show(struct device *dev, struct device_attribute *attr,
			  char *buf)
{
	int i, count = 0;
	struct extcon_dev *edev = dev_get_drvdata(dev);

	if (edev->print_state) {
		int ret = edev->print_state(edev, buf);

		if (ret >= 0)
			return ret;
		/* Use default if failed */
	}

	if (edev->max_supported == 0)
		return sprintf(buf, "%u\n", edev->state);

	for (i = 0; i < SUPPORTED_CABLE_MAX; i++) {
		if (!edev->supported_cable[i])
			break;
		count += sprintf(buf + count, "%s=%d\n",
				 edev->supported_cable[i],
				 !!(edev->state & (1 << i)));
	}

	return count;
}

static ssize_t state_store(struct device *dev, struct device_attribute *attr,
			   const char *buf, size_t count)
{
	u32 state;
	ssize_t ret = 0;
	struct extcon_dev *edev = dev_get_drvdata(dev);

	ret = sscanf(buf, "0x%x", &state);
	if (ret == 0)
		ret = -EINVAL;
	else
		ret = extcon_set_state(edev, state);

	if (ret < 0)
		return ret;

	return count;
}
static DEVICE_ATTR_RW(state);

static ssize_t name_show(struct device *dev, struct device_attribute *attr,
		char *buf)
{
	struct extcon_dev *edev = dev_get_drvdata(dev);

	/* Optional callback given by the user */
	if (edev->print_name) {
		int ret = edev->print_name(edev, buf);
		if (ret >= 0)
			return ret;
	}

	return sprintf(buf, "%s\n", dev_name(&edev->dev));
}
static DEVICE_ATTR_RO(name);

static ssize_t cable_name_show(struct device *dev,
			       struct device_attribute *attr, char *buf)
{
	struct extcon_cable *cable = container_of(attr, struct extcon_cable,
						  attr_name);

	return sprintf(buf, "%s\n",
		       cable->edev->supported_cable[cable->cable_index]);
}

static ssize_t cable_state_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct extcon_cable *cable = container_of(attr, struct extcon_cable,
						  attr_state);

	return sprintf(buf, "%d\n",
		       extcon_get_cable_state_(cable->edev,
					       cable->cable_index));
}

/**
 * extcon_update_state() - Update the cable attach states of the extcon device
 *			   only for the masked bits.
 * @edev:	the extcon device
 * @mask:	the bit mask to designate updated bits.
 * @state:	new cable attach status for @edev
 *
 * Changing the state sends uevent with environment variable containing
 * the name of extcon device (envp[0]) and the state output (envp[1]).
 * Tizen uses this format for extcon device to get events from ports.
 * Android uses this format as well.
 *
 * Note that the notifier provides which bits are changed in the state
 * variable with the val parameter (second) to the callback.
 */
int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
{
	char name_buf[120];
	char state_buf[120];
	char *prop_buf;
	char *envp[3];
	int env_offset = 0;
	int length;
	unsigned long flags;

	spin_lock_irqsave(&edev->lock, flags);

	if (edev->state != ((edev->state & ~mask) | (state & mask))) {
		u32 old_state = edev->state;

		if (check_mutually_exclusive(edev, (edev->state & ~mask) |
						   (state & mask))) {
			spin_unlock_irqrestore(&edev->lock, flags);
			return -EPERM;
		}

		edev->state &= ~mask;
		edev->state |= state & mask;

		raw_notifier_call_chain(&edev->nh, old_state, edev);
		/* This could be in interrupt handler */
		prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
		if (prop_buf) {
			length = name_show(&edev->dev, NULL, prop_buf);
			if (length > 0) {
				if (prop_buf[length - 1] == '\n')
					prop_buf[length - 1] = 0;
				snprintf(name_buf, sizeof(name_buf),
					"NAME=%s", prop_buf);
				envp[env_offset++] = name_buf;
			}
			length = state_show(&edev->dev, NULL, prop_buf);
			if (length > 0) {
				if (prop_buf[length - 1] == '\n')
					prop_buf[length - 1] = 0;
				snprintf(state_buf, sizeof(state_buf),
					"STATE=%s", prop_buf);
				envp[env_offset++] = state_buf;
			}
			envp[env_offset] = NULL;
			/* Unlock early before uevent */
			spin_unlock_irqrestore(&edev->lock, flags);

			kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
			free_page((unsigned long)prop_buf);
		} else {
			/* Unlock early before uevent */
			spin_unlock_irqrestore(&edev->lock, flags);

			dev_err(&edev->dev, "out of memory in extcon_set_state\n");
			kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
		}
	} else {
		/* No changes */
		spin_unlock_irqrestore(&edev->lock, flags);
	}

	return 0;
}
EXPORT_SYMBOL_GPL(extcon_update_state);

/**
 * extcon_set_state() - Set the cable attach states of the extcon device.
 * @edev:	the extcon device
 * @state:	new cable attach status for @edev
 *
 * Note that notifier provides which bits are changed in the state
 * variable with the val parameter (second) to the callback.
 */
int extcon_set_state(struct extcon_dev *edev, u32 state)
{
	return extcon_update_state(edev, 0xffffffff, state);
}
EXPORT_SYMBOL_GPL(extcon_set_state);

/**
 * extcon_find_cable_index() - Get the cable index based on the cable name.
 * @edev:	the extcon device that has the cable.
 * @cable_name:	cable name to be searched.
 *
 * Note that accessing a cable state based on cable_index is faster than
 * cable_name because using cable_name induces a loop with strncmp().
 * Thus, when get/set_cable_state is repeatedly used, using cable_index
 * is recommended.
 */
int extcon_find_cable_index(struct extcon_dev *edev, const char *cable_name)
{
	int i;

	if (edev->supported_cable) {
		for (i = 0; edev->supported_cable[i]; i++) {
			if (!strncmp(edev->supported_cable[i],
				cable_name, CABLE_NAME_MAX))
				return i;
		}
	}

	return -EINVAL;
}
EXPORT_SYMBOL_GPL(extcon_find_cable_index);

/**
 * extcon_get_cable_state_() - Get the status of a specific cable.
 * @edev:	the extcon device that has the cable.
 * @index:	cable index that can be retrieved by extcon_find_cable_index().
 */
int extcon_get_cable_state_(struct extcon_dev *edev, int index)
{
	if (index < 0 || (edev->max_supported && edev->max_supported <= index))
		return -EINVAL;

	return !!(edev->state & (1 << index));
}
EXPORT_SYMBOL_GPL(extcon_get_cable_state_);

/**
 * extcon_get_cable_state() - Get the status of a specific cable.
 * @edev:	the extcon device that has the cable.
 * @cable_name:	cable name.
 *
 * Note that this is slower than extcon_get_cable_state_.
 */
int extcon_get_cable_state(struct extcon_dev *edev, const char *cable_name)
{
	return extcon_get_cable_state_(edev, extcon_find_cable_index
						(edev, cable_name));
}
EXPORT_SYMBOL_GPL(extcon_get_cable_state);

/**
 * extcon_set_cable_state_() - Set the status of a specific cable.
 * @edev:		the extcon device that has the cable.
 * @index:		cable index that can be retrieved by
 *			extcon_find_cable_index().
 * @cable_state:	the new cable status. The default semantics is
 *			true: attached / false: detached.
 */
int extcon_set_cable_state_(struct extcon_dev *edev,
			int index, bool cable_state)
{
	u32 state;

	if (index < 0 || (edev->max_supported && edev->max_supported <= index))
		return -EINVAL;

	state = cable_state ? (1 << index) : 0;
	return extcon_update_state(edev, 1 << index, state);
}
EXPORT_SYMBOL_GPL(extcon_set_cable_state_);

/**
 * extcon_set_cable_state() - Set the status of a specific cable.
 * @edev:		the extcon device that has the cable.
 * @cable_name:		cable name.
 * @cable_state:	the new cable status. The default semantics is
 *			true: attached / false: detached.
 *
 * Note that this is slower than extcon_set_cable_state_.
 */
int extcon_set_cable_state(struct extcon_dev *edev,
			const char *cable_name, bool cable_state)
{
	return extcon_set_cable_state_(edev, extcon_find_cable_index
					(edev, cable_name), cable_state);
}
EXPORT_SYMBOL_GPL(extcon_set_cable_state);

/**
 * extcon_get_extcon_dev() - Get the extcon device instance from the name
 * @extcon_name:	The extcon name provided with extcon_dev_register()
 */
struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
{
	struct extcon_dev *sd;

	mutex_lock(&extcon_dev_list_lock);
	list_for_each_entry(sd, &extcon_dev_list, entry) {
		if (!strcmp(sd->name, extcon_name))
			goto out;
	}
	sd = NULL;
out:
	mutex_unlock(&extcon_dev_list_lock);
	return sd;
}
EXPORT_SYMBOL_GPL(extcon_get_extcon_dev);

static int _call_per_cable(struct notifier_block *nb, unsigned long val,
			   void *ptr)
{
	struct extcon_specific_cable_nb *obj = container_of(nb,
			struct extcon_specific_cable_nb, internal_nb);
	struct extcon_dev *edev = ptr;

	if ((val & (1 << obj->cable_index)) !=
	    (edev->state & (1 << obj->cable_index))) {
		bool cable_state = true;

		obj->previous_value = val;

		if (val & (1 << obj->cable_index))
			cable_state = false;

		return obj->user_nb->notifier_call(obj->user_nb,
				cable_state, ptr);
	}

	return NOTIFY_OK;
}

/**
 * extcon_register_interest() - Register a notifier for a state change of a
 *				specific cable, not an entier set of cables of a
 *				extcon device.
 * @obj:		an empty extcon_specific_cable_nb object to be returned.
 * @extcon_name:	the name of extcon device.
 *			if NULL, extcon_register_interest will register
 *			every cable with the target cable_name given.
 * @cable_name:		the target cable name.
 * @nb:			the notifier block to get notified.
 *
 * Provide an empty extcon_specific_cable_nb. extcon_register_interest() sets
 * the struct for you.
 *
 * extcon_register_interest is a helper function for those who want to get
 * notification for a single specific cable's status change. If a user wants
 * to get notification for any changes of all cables of a extcon device,
 * he/she should use the general extcon_register_notifier().
 *
 * Note that the second parameter given to the callback of nb (val) is
 * "old_state", not the current state. The current state can be retrieved
 * by looking at the third pameter (edev pointer)'s state value.
 */
int extcon_register_interest(struct extcon_specific_cable_nb *obj,
			     const char *extcon_name, const char *cable_name,
			     struct notifier_block *nb)
{
	if (!obj || !cable_name || !nb)
		return -EINVAL;

	if (extcon_name) {
		obj->edev = extcon_get_extcon_dev(extcon_name);
		if (!obj->edev)
			return -ENODEV;

		obj->cable_index = extcon_find_cable_index(obj->edev,
							  cable_name);
		if (obj->cable_index < 0)
			return obj->cable_index;

		obj->user_nb = nb;

		obj->internal_nb.notifier_call = _call_per_cable;

		return raw_notifier_chain_register(&obj->edev->nh,
						  &obj->internal_nb);
	} else {
		struct class_dev_iter iter;
		struct extcon_dev *extd;
		struct device *dev;

		if (!extcon_class)
			return -ENODEV;
		class_dev_iter_init(&iter, extcon_class, NULL, NULL);
		while ((dev = class_dev_iter_next(&iter))) {
			extd = dev_get_drvdata(dev);

			if (extcon_find_cable_index(extd, cable_name) < 0)
				continue;

			class_dev_iter_exit(&iter);
			return extcon_register_interest(obj, extd->name,
						cable_name, nb);
		}

		return -ENODEV;
	}
}
EXPORT_SYMBOL_GPL(extcon_register_interest);

/**
 * extcon_unregister_interest() - Unregister the notifier registered by
 *				  extcon_register_interest().
 * @obj:	the extcon_specific_cable_nb object returned by
 *		extcon_register_interest().
 */
int extcon_unregister_interest(struct extcon_specific_cable_nb *obj)
{
	if (!obj)
		return -EINVAL;

	return raw_notifier_chain_unregister(&obj->edev->nh, &obj->internal_nb);
}
EXPORT_SYMBOL_GPL(extcon_unregister_interest);

/**
 * extcon_register_notifier() - Register a notifiee to get notified by
 *				any attach status changes from the extcon.
 * @edev:	the extcon device.
 * @nb:		a notifier block to be registered.
 *
 * Note that the second parameter given to the callback of nb (val) is
 * "old_state", not the current state. The current state can be retrieved
 * by looking at the third pameter (edev pointer)'s state value.
 */
int extcon_register_notifier(struct extcon_dev *edev,
			struct notifier_block *nb)
{
	return raw_notifier_chain_register(&edev->nh, nb);
}
EXPORT_SYMBOL_GPL(extcon_register_notifier);

/**
 * extcon_unregister_notifier() - Unregister a notifiee from the extcon device.
 * @edev:	the extcon device.
 * @nb:		a registered notifier block to be unregistered.
 */
int extcon_unregister_notifier(struct extcon_dev *edev,
			struct notifier_block *nb)
{
	return raw_notifier_chain_unregister(&edev->nh, nb);
}
EXPORT_SYMBOL_GPL(extcon_unregister_notifier);

static struct attribute *extcon_attrs[] = {
	&dev_attr_state.attr,
	&dev_attr_name.attr,
	NULL,
};
ATTRIBUTE_GROUPS(extcon);

static int create_extcon_class(void)
{
	if (!extcon_class) {
		extcon_class = class_create(THIS_MODULE, "extcon");
		if (IS_ERR(extcon_class))
			return PTR_ERR(extcon_class);
		extcon_class->dev_groups = extcon_groups;

#if defined(CONFIG_ANDROID)
		switch_class = class_compat_register("switch");
		if (WARN(!switch_class, "cannot allocate"))
			return -ENOMEM;
#endif /* CONFIG_ANDROID */
	}

	return 0;
}

static void extcon_dev_release(struct device *dev)
{
}

static const char *muex_name = "mutually_exclusive";
static void dummy_sysfs_dev_release(struct device *dev)
{
}

/*
 * extcon_dev_allocate() - Allocate the memory of extcon device.
 * @supported_cable:	Array of supported cable names ending with NULL.
 *			If supported_cable is NULL, cable name related APIs
 *			are disabled.
 *
 * This function allocates the memory for extcon device without allocating
 * memory in each extcon provider driver and initialize default setting for
 * extcon device.
 *
 * Return the pointer of extcon device if success or ERR_PTR(err) if fail
 */
struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
{
	struct extcon_dev *edev;

	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
	if (!edev)
		return ERR_PTR(-ENOMEM);

	edev->max_supported = 0;
	edev->supported_cable = supported_cable;

	return edev;
}

/*
 * extcon_dev_free() - Free the memory of extcon device.
 * @edev:	the extcon device to free
 */
void extcon_dev_free(struct extcon_dev *edev)
{
	kfree(edev);
}
EXPORT_SYMBOL_GPL(extcon_dev_free);

static int devm_extcon_dev_match(struct device *dev, void *res, void *data)
{
	struct extcon_dev **r = res;

	if (WARN_ON(!r || !*r))
		return 0;

	return *r == data;
}

static void devm_extcon_dev_release(struct device *dev, void *res)
{
	extcon_dev_free(*(struct extcon_dev **)res);
}

/**
 * devm_extcon_dev_allocate - Allocate managed extcon device
 * @dev:		device owning the extcon device being created
 * @supported_cable:	Array of supported cable names ending with NULL.
 *			If supported_cable is NULL, cable name related APIs
 *			are disabled.
 *
 * This function manages automatically the memory of extcon device using device
 * resource management and simplify the control of freeing the memory of extcon
 * device.
 *
 * Returns the pointer memory of allocated extcon_dev if success
 * or ERR_PTR(err) if fail
 */
struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
					    const char **supported_cable)
{
	struct extcon_dev **ptr, *edev;

	ptr = devres_alloc(devm_extcon_dev_release, sizeof(*ptr), GFP_KERNEL);
	if (!ptr)
		return ERR_PTR(-ENOMEM);

	edev = extcon_dev_allocate(supported_cable);
	if (IS_ERR(edev)) {
		devres_free(ptr);
		return edev;
	}

	edev->dev.parent = dev;

	*ptr = edev;
	devres_add(dev, ptr);

	return edev;
}
EXPORT_SYMBOL_GPL(devm_extcon_dev_allocate);

void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev)
{
	WARN_ON(devres_release(dev, devm_extcon_dev_release,
			       devm_extcon_dev_match, edev));
}
EXPORT_SYMBOL_GPL(devm_extcon_dev_free);

/**
 * extcon_dev_register() - Register a new extcon device
 * @edev	: the new extcon device (should be allocated before calling)
 *
 * Among the members of edev struct, please set the "user initializing data"
 * in any case and set the "optional callbacks" if required. However, please
 * do not set the values of "internal data", which are initialized by
 * this function.
 */
int extcon_dev_register(struct extcon_dev *edev)
{
	int ret, index = 0;

	if (!extcon_class) {
		ret = create_extcon_class();
		if (ret < 0)
			return ret;
	}

	if (edev->supported_cable) {
		/* Get size of array */
		for (index = 0; edev->supported_cable[index]; index++)
			;
		edev->max_supported = index;
	} else {
		edev->max_supported = 0;
	}

	if (index > SUPPORTED_CABLE_MAX) {
		dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n");
		return -EINVAL;
	}

	edev->dev.class = extcon_class;
	edev->dev.release = extcon_dev_release;

	edev->name = edev->name ? edev->name : dev_name(edev->dev.parent);
	if (IS_ERR_OR_NULL(edev->name)) {
		dev_err(&edev->dev,
			"extcon device name is null\n");
		return -EINVAL;
	}
	dev_set_name(&edev->dev, "%s", edev->name);

	if (edev->max_supported) {
		char buf[10];
		char *str;
		struct extcon_cable *cable;

		edev->cables = kzalloc(sizeof(struct extcon_cable) *
				       edev->max_supported, GFP_KERNEL);
		if (!edev->cables) {
			ret = -ENOMEM;
			goto err_sysfs_alloc;
		}
		for (index = 0; index < edev->max_supported; index++) {
			cable = &edev->cables[index];

			snprintf(buf, 10, "cable.%d", index);
			str = kzalloc(sizeof(char) * (strlen(buf) + 1),
				      GFP_KERNEL);
			if (!str) {
				for (index--; index >= 0; index--) {
					cable = &edev->cables[index];
					kfree(cable->attr_g.name);
				}
				ret = -ENOMEM;

				goto err_alloc_cables;
			}
			strcpy(str, buf);

			cable->edev = edev;
			cable->cable_index = index;
			cable->attrs[0] = &cable->attr_name.attr;
			cable->attrs[1] = &cable->attr_state.attr;
			cable->attrs[2] = NULL;
			cable->attr_g.name = str;
			cable->attr_g.attrs = cable->attrs;

			sysfs_attr_init(&cable->attr_name.attr);
			cable->attr_name.attr.name = "name";
			cable->attr_name.attr.mode = 0444;
			cable->attr_name.show = cable_name_show;

			sysfs_attr_init(&cable->attr_state.attr);
			cable->attr_state.attr.name = "state";
			cable->attr_state.attr.mode = 0444;
			cable->attr_state.show = cable_state_show;
		}
	}

	if (edev->max_supported && edev->mutually_exclusive) {
		char buf[80];
		char *name;

		/* Count the size of mutually_exclusive array */
		for (index = 0; edev->mutually_exclusive[index]; index++)
			;

		edev->attrs_muex = kzalloc(sizeof(struct attribute *) *
					   (index + 1), GFP_KERNEL);
		if (!edev->attrs_muex) {
			ret = -ENOMEM;
			goto err_muex;
		}

		edev->d_attrs_muex = kzalloc(sizeof(struct device_attribute) *
					     index, GFP_KERNEL);
		if (!edev->d_attrs_muex) {
			ret = -ENOMEM;
			kfree(edev->attrs_muex);
			goto err_muex;
		}

		for (index = 0; edev->mutually_exclusive[index]; index++) {
			sprintf(buf, "0x%x", edev->mutually_exclusive[index]);
			name = kzalloc(sizeof(char) * (strlen(buf) + 1),
				       GFP_KERNEL);
			if (!name) {
				for (index--; index >= 0; index--) {
					kfree(edev->d_attrs_muex[index].attr.
					      name);
				}
				kfree(edev->d_attrs_muex);
				kfree(edev->attrs_muex);
				ret = -ENOMEM;
				goto err_muex;
			}
			strcpy(name, buf);
			sysfs_attr_init(&edev->d_attrs_muex[index].attr);
			edev->d_attrs_muex[index].attr.name = name;
			edev->d_attrs_muex[index].attr.mode = 0000;
			edev->attrs_muex[index] = &edev->d_attrs_muex[index]
							.attr;
		}
		edev->attr_g_muex.name = muex_name;
		edev->attr_g_muex.attrs = edev->attrs_muex;

	}

	if (edev->max_supported) {
		edev->extcon_dev_type.groups =
			kzalloc(sizeof(struct attribute_group *) *
				(edev->max_supported + 2), GFP_KERNEL);
		if (!edev->extcon_dev_type.groups) {
			ret = -ENOMEM;
			goto err_alloc_groups;
		}

		edev->extcon_dev_type.name = dev_name(&edev->dev);
		edev->extcon_dev_type.release = dummy_sysfs_dev_release;

		for (index = 0; index < edev->max_supported; index++)
			edev->extcon_dev_type.groups[index] =
				&edev->cables[index].attr_g;
		if (edev->mutually_exclusive)
			edev->extcon_dev_type.groups[index] =
				&edev->attr_g_muex;

		edev->dev.type = &edev->extcon_dev_type;
	}

	ret = device_register(&edev->dev);
	if (ret) {
		put_device(&edev->dev);
		goto err_dev;
	}
#if defined(CONFIG_ANDROID)
	if (switch_class)
		ret = class_compat_create_link(switch_class, &edev->dev, NULL);
#endif /* CONFIG_ANDROID */

	spin_lock_init(&edev->lock);

	RAW_INIT_NOTIFIER_HEAD(&edev->nh);

	dev_set_drvdata(&edev->dev, edev);
	edev->state = 0;

	mutex_lock(&extcon_dev_list_lock);
	list_add(&edev->entry, &extcon_dev_list);
	mutex_unlock(&extcon_dev_list_lock);

	return 0;

err_dev:
	if (edev->max_supported)
		kfree(edev->extcon_dev_type.groups);
err_alloc_groups:
	if (edev->max_supported && edev->mutually_exclusive) {
		for (index = 0; edev->mutually_exclusive[index]; index++)
			kfree(edev->d_attrs_muex[index].attr.name);
		kfree(edev->d_attrs_muex);
		kfree(edev->attrs_muex);
	}
err_muex:
	for (index = 0; index < edev->max_supported; index++)
		kfree(edev->cables[index].attr_g.name);
err_alloc_cables:
	if (edev->max_supported)
		kfree(edev->cables);
err_sysfs_alloc:
	return ret;
}
EXPORT_SYMBOL_GPL(extcon_dev_register);

/**
 * extcon_dev_unregister() - Unregister the extcon device.
 * @edev:	the extcon device instance to be unregistered.
 *
 * Note that this does not call kfree(edev) because edev was not allocated
 * by this class.
 */
void extcon_dev_unregister(struct extcon_dev *edev)
{
	int index;

	mutex_lock(&extcon_dev_list_lock);
	list_del(&edev->entry);
	mutex_unlock(&extcon_dev_list_lock);

	if (IS_ERR_OR_NULL(get_device(&edev->dev))) {
		dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n",
				dev_name(&edev->dev));
		return;
	}

	device_unregister(&edev->dev);

	if (edev->mutually_exclusive && edev->max_supported) {
		for (index = 0; edev->mutually_exclusive[index];
				index++)
			kfree(edev->d_attrs_muex[index].attr.name);
		kfree(edev->d_attrs_muex);
		kfree(edev->attrs_muex);
	}

	for (index = 0; index < edev->max_supported; index++)
		kfree(edev->cables[index].attr_g.name);

	if (edev->max_supported) {
		kfree(edev->extcon_dev_type.groups);
		kfree(edev->cables);
	}

#if defined(CONFIG_ANDROID)
	if (switch_class)
		class_compat_remove_link(switch_class, &edev->dev, NULL);
#endif
	put_device(&edev->dev);
}
EXPORT_SYMBOL_GPL(extcon_dev_unregister);

static void devm_extcon_dev_unreg(struct device *dev, void *res)
{
	extcon_dev_unregister(*(struct extcon_dev **)res);
}

/**
 * devm_extcon_dev_register() - Resource-managed extcon_dev_register()
 * @dev:	device to allocate extcon device
 * @edev:	the new extcon device to register
 *
 * Managed extcon_dev_register() function. If extcon device is attached with
 * this function, that extcon device is automatically unregistered on driver
 * detach. Internally this function calls extcon_dev_register() function.
 * To get more information, refer that function.
 *
 * If extcon device is registered with this function and the device needs to be
 * unregistered separately, devm_extcon_dev_unregister() should be used.
 *
 * Returns 0 if success or negaive error number if failure.
 */
int devm_extcon_dev_register(struct device *dev, struct extcon_dev *edev)
{
	struct extcon_dev **ptr;
	int ret;

	ptr = devres_alloc(devm_extcon_dev_unreg, sizeof(*ptr), GFP_KERNEL);
	if (!ptr)
		return -ENOMEM;

	ret = extcon_dev_register(edev);
	if (ret) {
		devres_free(ptr);
		return ret;
	}

	*ptr = edev;
	devres_add(dev, ptr);

	return 0;
}
EXPORT_SYMBOL_GPL(devm_extcon_dev_register);

/**
 * devm_extcon_dev_unregister() - Resource-managed extcon_dev_unregister()
 * @dev:	device the extcon belongs to
 * @edev:	the extcon device to unregister
 *
 * Unregister extcon device that is registered with devm_extcon_dev_register()
 * function.
 */
void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev)
{
	WARN_ON(devres_release(dev, devm_extcon_dev_unreg,
			       devm_extcon_dev_match, edev));
}
EXPORT_SYMBOL_GPL(devm_extcon_dev_unregister);

#ifdef CONFIG_OF
/*
 * extcon_get_edev_by_phandle - Get the extcon device from devicetree
 * @dev - instance to the given device
 * @index - index into list of extcon_dev
 *
 * return the instance of extcon device
 */
struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
{
	struct device_node *node;
	struct extcon_dev *edev;

	if (!dev->of_node) {
		dev_err(dev, "device does not have a device node entry\n");
		return ERR_PTR(-EINVAL);
	}

	node = of_parse_phandle(dev->of_node, "extcon", index);
	if (!node) {
		dev_err(dev, "failed to get phandle in %s node\n",
			dev->of_node->full_name);
		return ERR_PTR(-ENODEV);
	}

	mutex_lock(&extcon_dev_list_lock);
	list_for_each_entry(edev, &extcon_dev_list, entry) {
		if (edev->dev.parent && edev->dev.parent->of_node == node) {
			mutex_unlock(&extcon_dev_list_lock);
			return edev;
		}
	}
	mutex_unlock(&extcon_dev_list_lock);

	return ERR_PTR(-EPROBE_DEFER);
}
#else
struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
{
	return ERR_PTR(-ENOSYS);
}
#endif /* CONFIG_OF */
EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle);

static int __init extcon_class_init(void)
{
	return create_extcon_class();
}
module_init(extcon_class_init);

static void __exit extcon_class_exit(void)
{
#if defined(CONFIG_ANDROID)
	class_compat_unregister(switch_class);
#endif
	class_destroy(extcon_class);
}
module_exit(extcon_class_exit);

MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
MODULE_DESCRIPTION("External connector (extcon) class driver");
MODULE_LICENSE("GPL");

{'repo_name': 'figozhang/runninglinuxkernel_4.0', 'stars': '310', 'repo_language': 'C', 'file_name': 'op-reset.c', 'mime_type': 'text/x-c', 'hash': 8148147469058999372, 'source_dataset': 'data'}


import React from 'react';
import PropTypes from 'prop-types';
import URIUtil from '../../../utils/URIUtil';
/**
Default component to display object values
*/
class BasicIndividualView extends React.Component {
    render() {
        let val, outputDIV;
        let cstyle={direction: 'ltr'};
        val = this.props.spec.value;
        if(this.props.spec.valueType === 'uri'){
            if(this.props.config){
                if(this.props.config.truncateURI || this.props.truncateURI){
                    val = '<' + URIUtil.truncateMiddle(val, 50, '') + '>';
                }else if (this.props.config.shortenURI || this.props.shortenURI) {
                    val = '<' + URIUtil.getURILabel(val) + '>';
                }
            }
            outputDIV =  {val} ;
        }else{
            if(this.props.config){
                if(this.props.config.decodeURIComponent || this.props.decodeURIComponent){
                    val = decodeURIComponent(val);
                }else if (this.props.config.encodeURIComponent || this.props.encodeURIComponent) {
                    val = encodeURIComponent(val);
                }
                //allow view RightToLeft languages
                if (this.props.config.rtl || this.props.rtl) {
                    cstyle.direction= 'rtl';
                }
            }
            outputDIV =  {val} ;
        }
        return (

                {outputDIV}

        );
    }
}
BasicIndividualView.propTypes = {
    /**
    truncate URI from the middle
    */
    truncateURI: PropTypes.bool,
    /**
    only show the last part of the URI
    */
    shortenURI: PropTypes.bool,
    /**
    LD-R Configurations object
    */
    config: PropTypes.object,
    /**
    LD-R spec
    */
    spec: PropTypes.object
};
export default BasicIndividualView;

{'repo_name': 'ali1k/ld-r', 'stars': '108', 'repo_language': 'JavaScript', 'file_name': 'loadDataset.js', 'mime_type': 'text/x-java', 'hash': 5557324749315468279, 'source_dataset': 'data'}


/*
    TiMidity++ -- MIDI to WAVE converter and player
    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
    Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    au_a.c

    Functions to output Sun audio file (*.au).
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>

#ifdef __W32__
#include <stdlib.h>
#include <io.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */

#ifdef STDC_HEADERS
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#elif HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif

#ifdef __FreeBSD__
#include <stdio.h>
#endif

#include "timidity.h"
#include "common.h"
#include "output.h"
#include "controls.h"
#include "instrum.h"
#include "playmidi.h"
#include "readmidi.h"

static int open_output(void); /* 0=success, 1=warning, -1=fatal error */
static void close_output(void);
static int output_data(char *buf, int32 bytes);
static int acntl(int request, void *arg);
static int write_u32(uint32 value);

/* export the playback mode */

#define dpm au_play_mode

PlayMode dpm = {
    8000, PE_MONO|PE_ULAW, PF_PCM_STREAM,
    -1,
    {0,0,0,0,0},
    "Sun audio file", 'u',
    NULL,
    open_output,
    close_output,
    output_data,
    acntl
};

/*************************************************************************/

#define UPDATE_HEADER_STEP (128*1024) /* 128KB */
static uint32 bytes_output, next_bytes;
static int already_warning_lseek;

static int write_u32(uint32 value)
{
    int n;
    value = BE_LONG(value);
    if((n = write(dpm.fd, &value, 4)) == -1)
    {
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: write: %s",
		  dpm.name, strerror(errno));
	close_output();
	return -1;
    }
    return n;
}

static int write_str(const char *s)
{
    int n;
    if((n = write(dpm.fd, s, strlen(s))) == -1)
    {
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: write: %s",
		  dpm.name, strerror(errno));
	close_output();
	return -1;
    }
    return n;
}

/* Sun Audio File Encoding Tags */
#define AUDIO_FILE_ENCODING_MULAW_8     1      /* 8-bit ISDN u-law */
#define AUDIO_FILE_ENCODING_LINEAR_8    2      /* 8-bit linear PCM */
#define AUDIO_FILE_ENCODING_LINEAR_16   3      /* 16-bit linear PCM */
#define AUDIO_FILE_ENCODING_LINEAR_24   4      /* 24-bit linear PCM */
#define AUDIO_FILE_ENCODING_ALAW_8      27     /* 8-bit ISDN A-law */

static int au_output_open(const char *fname, const char *comment)
{
  int t;

  if(strcmp(fname, "-") == 0) {
    dpm.fd = 1; /* data to stdout */
    if(comment == NULL)
      comment = "(stdout)";
  } else {
    /* Open the audio file */
    dpm.fd = open(fname, FILE_OUTPUT_MODE);
    if(dpm.fd < 0) {
      ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
		fname, strerror(errno));
      return -1;
    }
    if(comment == NULL)
      comment = fname;
  }

  /* magic */
  if(write_str(".snd") == -1) return -1;

  /* header size */
  if(write_u32((uint32)(24 + strlen(comment))) == -1) return -1;

  /* sample data size */
  if(write_u32((uint32)0xffffffff) == -1) return -1;

  /* audio file encoding */
  if(dpm.encoding & PE_ULAW)
    t = AUDIO_FILE_ENCODING_MULAW_8;
  else if(dpm.encoding & PE_ALAW)
    t = AUDIO_FILE_ENCODING_ALAW_8;
  else if(dpm.encoding & PE_24BIT)
    t = AUDIO_FILE_ENCODING_LINEAR_24;
  else if(dpm.encoding & PE_16BIT)
    t = AUDIO_FILE_ENCODING_LINEAR_16;
  else
    t = AUDIO_FILE_ENCODING_LINEAR_8;
  if(write_u32((uint32)t) == -1) return -1;

  /* sample rate */
  if(write_u32((uint32)dpm.rate) == -1) return -1;

  /* number of channels */
  if(dpm.encoding & PE_MONO) {
    if(write_u32((uint32)1) == -1) return -1;
  } else {
    if(write_u32((uint32)2) == -1) return -1;
  }

  /* comment */
  if(write_str(comment) == -1) return -1;

  bytes_output = 0;
  next_bytes = bytes_output + UPDATE_HEADER_STEP;
  already_warning_lseek = 0;

  return 0;
}

static int auto_au_output_open(const char *input_filename)
{
  char *output_filename = (char *)safe_malloc(strlen(input_filename) + 5);
  char *ext, *p;

  strcpy(output_filename, input_filename);
  if((ext = strrchr(output_filename, '.')) == NULL)
    ext = output_filename + strlen(output_filename);
  else {
    /* strip ".gz" */
    if(strcasecmp(ext, ".gz") == 0) {
      *ext = '\0';
      if((ext = strrchr(output_filename, '.')) == NULL)
	ext = output_filename + strlen(output_filename);
    }
  }

  /* replace '.' and '#' before ext */
  for(p = output_filename; p < ext; p++)
    if(*p == '.' || *p == '#')
      *p = '_';

  if(*ext && isupper(*(ext + 1)))
    strcpy(ext, ".AU");
  else
    strcpy(ext, ".au");
  if(au_output_open(output_filename, input_filename) == -1) {
    free(output_filename);
    return -1;
  }
  if(dpm.name != NULL)
    free(dpm.name);
  dpm.name = output_filename;
  ctl->cmsg(CMSG_INFO, VERB_NORMAL, "Output %s", dpm.name);
  return 0;
}

static int open_output(void)
{
    int include_enc, exclude_enc;

    include_enc = exclude_enc = 0;
    if(dpm.encoding & (PE_16BIT | PE_24BIT))
    {
#ifdef LITTLE_ENDIAN
	include_enc = PE_BYTESWAP;
#else
	exclude_enc = PE_BYTESWAP;
#endif /* LITTLE_ENDIAN */
	include_enc |= PE_SIGNED;
    }
    else if(!(dpm.encoding & (PE_ULAW|PE_ALAW)))
    {
	/* is 8 bit au unsigned ? */
	exclude_enc = PE_SIGNED;
    }

    dpm.encoding = validate_encoding(dpm.encoding, include_enc, exclude_enc);

    if(dpm.name == NULL) {
      dpm.flag |= PF_AUTO_SPLIT_FILE;
      dpm.name = NULL;
    } else {
      dpm.flag &= ~PF_AUTO_SPLIT_FILE;
      if(au_output_open(dpm.name, NULL) == -1)
	return -1;
    }

    return 0;
}

static int update_header(void)
{
    off_t save_point;

    if(already_warning_lseek)
	return 0;

    save_point = lseek(dpm.fd, 0, SEEK_CUR);
    if(save_point == -1 || lseek(dpm.fd, 8, SEEK_SET) == -1)
    {
	ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,
		  "Warning: %s: %s: Can't make valid header",
		  dpm.name, strerror(errno));
	already_warning_lseek = 1;
	return 0;
    }

    if(write_u32(bytes_output) == -1) return -1;
    lseek(dpm.fd, save_point, SEEK_SET);
    ctl->cmsg(CMSG_INFO, VERB_DEBUG,
	      "%s: Update au header (size=%d)", dpm.name, bytes_output);
    return 0;
}

static int output_data(char *buf, int32 bytes)
{
    int n;

    if(dpm.fd == -1)
      return -1;

    while(((n = write(dpm.fd, buf, bytes)) == -1) && errno == EINTR)
	;
    if(n == -1)
    {
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
		  dpm.name, strerror(errno));
	return -1;
    }

    bytes_output += bytes;

#if UPDATE_HEADER_STEP > 0
    if(bytes_output >= next_bytes)
    {
	if(update_header() == -1) return -1;
	next_bytes = bytes_output + UPDATE_HEADER_STEP;
    }
#endif /* UPDATE_HEADER_STEP */
    return n;
}

static void close_output(void)
{
  if(dpm.fd != 1 && /* We don't close stdout */
     dpm.fd != -1) {
    update_header();
    close(dpm.fd);
    dpm.fd = -1;
  }
}

static int acntl(int request, void *arg)
{
  switch(request) {
  case PM_REQ_PLAY_START:
    if(dpm.flag & PF_AUTO_SPLIT_FILE)
      return auto_au_output_open(current_file_info->filename);
    break;
  case PM_REQ_PLAY_END:
    if(dpm.flag & PF_AUTO_SPLIT_FILE) {
      close_output();
      return 0;
    }
    break;
  case PM_REQ_DISCARD:
    return 0;
  }
  return -1;
}

{'repo_name': 'quarnster/boxeebox-xbmc', 'stars': '117', 'repo_language': 'C++', 'file_name': 'strings.po', 'mime_type': 'text/x-po', 'hash': -5275331651993205598, 'source_dataset': 'data'}


DEAL::0.00000 0
DEAL::0.250000 0.250000
DEAL::0.250000 0.250000
DEAL::0.500000 0.500000
DEAL::0.500000 0.500000
DEAL::0.750000 0.750000
DEAL::0.750000 0.750000
DEAL::1.00000 1.00000
DEAL::0.00000 0.00000 0
DEAL::0.250000 0.00000 0
DEAL::0.00000 0.250000 0
DEAL::0.250000 0.250000 0.0625000
DEAL::0.250000 0.00000 0
DEAL::0.500000 0.00000 0
DEAL::0.250000 0.250000 0.0625000
DEAL::0.500000 0.250000 0.125000
DEAL::0.00000 0.250000 0
DEAL::0.250000 0.250000 0.0625000
DEAL::0.00000 0.500000 0
DEAL::0.250000 0.500000 0.125000
DEAL::0.250000 0.250000 0.0625000
DEAL::0.500000 0.250000 0.125000
DEAL::0.250000 0.500000 0.125000
DEAL::0.500000 0.500000 0.250000
DEAL::0.500000 0.00000 0
DEAL::0.750000 0.00000 0
DEAL::0.500000 0.250000 0.125000
DEAL::0.750000 0.250000 0.187500
DEAL::0.750000 0.00000 0
DEAL::1.00000 0.00000 0
DEAL::0.750000 0.250000 0.187500
DEAL::1.00000 0.250000 0.250000
DEAL::0.500000 0.250000 0.125000
DEAL::0.750000 0.250000 0.187500
DEAL::0.500000 0.500000 0.250000
DEAL::0.750000 0.500000 0.375000
DEAL::0.750000 0.250000 0.187500
DEAL::1.00000 0.250000 0.250000
DEAL::0.750000 0.500000 0.375000
DEAL::1.00000 0.500000 0.500000
DEAL::0.00000 0.500000 0
DEAL::0.250000 0.500000 0.125000
DEAL::0.00000 0.750000 0
DEAL::0.250000 0.750000 0.187500
DEAL::0.250000 0.500000 0.125000
DEAL::0.500000 0.500000 0.250000
DEAL::0.250000 0.750000 0.187500
DEAL::0.500000 0.750000 0.375000
DEAL::0.00000 0.750000 0
DEAL::0.250000 0.750000 0.187500
DEAL::0.00000 1.00000 0
DEAL::0.250000 1.00000 0.250000
DEAL::0.250000 0.750000 0.187500
DEAL::0.500000 0.750000 0.375000
DEAL::0.250000 1.00000 0.250000
DEAL::0.500000 1.00000 0.500000
DEAL::0.500000 0.500000 0.250000
DEAL::0.750000 0.500000 0.375000
DEAL::0.500000 0.750000 0.375000
DEAL::0.750000 0.750000 0.562500
DEAL::0.750000 0.500000 0.375000
DEAL::1.00000 0.500000 0.500000
DEAL::0.750000 0.750000 0.562500
DEAL::1.00000 0.750000 0.750000
DEAL::0.500000 0.750000 0.375000
DEAL::0.750000 0.750000 0.562500
DEAL::0.500000 1.00000 0.500000
DEAL::0.750000 1.00000 0.750000
DEAL::0.750000 0.750000 0.562500
DEAL::1.00000 0.750000 0.750000
DEAL::0.750000 1.00000 0.750000
DEAL::1.00000 1.00000 1.00000
DEAL::0.00000 0.00000 0.00000 0
DEAL::0.250000 0.00000 0.00000 0
DEAL::0.00000 0.250000 0.00000 0
DEAL::0.250000 0.250000 0.00000 0
DEAL::0.00000 0.00000 0.250000 0
DEAL::0.250000 0.00000 0.250000 0
DEAL::0.00000 0.250000 0.250000 0
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.250000 0.00000 0.00000 0
DEAL::0.500000 0.00000 0.00000 0
DEAL::0.250000 0.250000 0.00000 0
DEAL::0.500000 0.250000 0.00000 0
DEAL::0.250000 0.00000 0.250000 0
DEAL::0.500000 0.00000 0.250000 0
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.00000 0.250000 0.00000 0
DEAL::0.250000 0.250000 0.00000 0
DEAL::0.00000 0.500000 0.00000 0
DEAL::0.250000 0.500000 0.00000 0
DEAL::0.00000 0.250000 0.250000 0
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.00000 0.500000 0.250000 0
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.250000 0.250000 0.00000 0
DEAL::0.500000 0.250000 0.00000 0
DEAL::0.250000 0.500000 0.00000 0
DEAL::0.500000 0.500000 0.00000 0
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.00000 0.00000 0.250000 0
DEAL::0.250000 0.00000 0.250000 0
DEAL::0.00000 0.250000 0.250000 0
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.00000 0.00000 0.500000 0
DEAL::0.250000 0.00000 0.500000 0
DEAL::0.00000 0.250000 0.500000 0
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.250000 0.00000 0.250000 0
DEAL::0.500000 0.00000 0.250000 0
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.250000 0.00000 0.500000 0
DEAL::0.500000 0.00000 0.500000 0
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.00000 0.250000 0.250000 0
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.00000 0.500000 0.250000 0
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.00000 0.250000 0.500000 0
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.00000 0.500000 0.500000 0
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.250000 0.250000 0.250000 0.0156250
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.500000 0.00000 0.00000 0
DEAL::0.750000 0.00000 0.00000 0
DEAL::0.500000 0.250000 0.00000 0
DEAL::0.750000 0.250000 0.00000 0
DEAL::0.500000 0.00000 0.250000 0
DEAL::0.750000 0.00000 0.250000 0
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::0.750000 0.00000 0.00000 0
DEAL::1.00000 0.00000 0.00000 0
DEAL::0.750000 0.250000 0.00000 0
DEAL::1.00000 0.250000 0.00000 0
DEAL::0.750000 0.00000 0.250000 0
DEAL::1.00000 0.00000 0.250000 0
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::1.00000 0.250000 0.250000 0.0625000
DEAL::0.500000 0.250000 0.00000 0
DEAL::0.750000 0.250000 0.00000 0
DEAL::0.500000 0.500000 0.00000 0
DEAL::0.750000 0.500000 0.00000 0
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::0.750000 0.250000 0.00000 0
DEAL::1.00000 0.250000 0.00000 0
DEAL::0.750000 0.500000 0.00000 0
DEAL::1.00000 0.500000 0.00000 0
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::1.00000 0.250000 0.250000 0.0625000
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::1.00000 0.500000 0.250000 0.125000
DEAL::0.500000 0.00000 0.250000 0
DEAL::0.750000 0.00000 0.250000 0
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::0.500000 0.00000 0.500000 0
DEAL::0.750000 0.00000 0.500000 0
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::0.750000 0.00000 0.250000 0
DEAL::1.00000 0.00000 0.250000 0
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::1.00000 0.250000 0.250000 0.0625000
DEAL::0.750000 0.00000 0.500000 0
DEAL::1.00000 0.00000 0.500000 0
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::1.00000 0.250000 0.500000 0.125000
DEAL::0.500000 0.250000 0.250000 0.0312500
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::0.750000 0.250000 0.250000 0.0468750
DEAL::1.00000 0.250000 0.250000 0.0625000
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::1.00000 0.500000 0.250000 0.125000
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::1.00000 0.250000 0.500000 0.125000
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::1.00000 0.500000 0.500000 0.250000
DEAL::0.00000 0.500000 0.00000 0
DEAL::0.250000 0.500000 0.00000 0
DEAL::0.00000 0.750000 0.00000 0
DEAL::0.250000 0.750000 0.00000 0
DEAL::0.00000 0.500000 0.250000 0
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.00000 0.750000 0.250000 0
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.250000 0.500000 0.00000 0
DEAL::0.500000 0.500000 0.00000 0
DEAL::0.250000 0.750000 0.00000 0
DEAL::0.500000 0.750000 0.00000 0
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.00000 0.750000 0.00000 0
DEAL::0.250000 0.750000 0.00000 0
DEAL::0.00000 1.00000 0.00000 0
DEAL::0.250000 1.00000 0.00000 0
DEAL::0.00000 0.750000 0.250000 0
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.00000 1.00000 0.250000 0
DEAL::0.250000 1.00000 0.250000 0.0625000
DEAL::0.250000 0.750000 0.00000 0
DEAL::0.500000 0.750000 0.00000 0
DEAL::0.250000 1.00000 0.00000 0
DEAL::0.500000 1.00000 0.00000 0
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.250000 1.00000 0.250000 0.0625000
DEAL::0.500000 1.00000 0.250000 0.125000
DEAL::0.00000 0.500000 0.250000 0
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.00000 0.750000 0.250000 0
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.00000 0.500000 0.500000 0
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.00000 0.750000 0.500000 0
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.250000 0.500000 0.250000 0.0312500
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.00000 0.750000 0.250000 0
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.00000 1.00000 0.250000 0
DEAL::0.250000 1.00000 0.250000 0.0625000
DEAL::0.00000 0.750000 0.500000 0
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.00000 1.00000 0.500000 0
DEAL::0.250000 1.00000 0.500000 0.125000
DEAL::0.250000 0.750000 0.250000 0.0468750
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.250000 1.00000 0.250000 0.0625000
DEAL::0.500000 1.00000 0.250000 0.125000
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.250000 1.00000 0.500000 0.125000
DEAL::0.500000 1.00000 0.500000 0.250000
DEAL::0.500000 0.500000 0.00000 0
DEAL::0.750000 0.500000 0.00000 0
DEAL::0.500000 0.750000 0.00000 0
DEAL::0.750000 0.750000 0.00000 0
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::0.750000 0.500000 0.00000 0
DEAL::1.00000 0.500000 0.00000 0
DEAL::0.750000 0.750000 0.00000 0
DEAL::1.00000 0.750000 0.00000 0
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::1.00000 0.500000 0.250000 0.125000
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::1.00000 0.750000 0.250000 0.187500
DEAL::0.500000 0.750000 0.00000 0
DEAL::0.750000 0.750000 0.00000 0
DEAL::0.500000 1.00000 0.00000 0
DEAL::0.750000 1.00000 0.00000 0
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::0.500000 1.00000 0.250000 0.125000
DEAL::0.750000 1.00000 0.250000 0.187500
DEAL::0.750000 0.750000 0.00000 0
DEAL::1.00000 0.750000 0.00000 0
DEAL::0.750000 1.00000 0.00000 0
DEAL::1.00000 1.00000 0.00000 0
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::1.00000 0.750000 0.250000 0.187500
DEAL::0.750000 1.00000 0.250000 0.187500
DEAL::1.00000 1.00000 0.250000 0.250000
DEAL::0.500000 0.500000 0.250000 0.0625000
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::0.750000 0.500000 0.250000 0.0937500
DEAL::1.00000 0.500000 0.250000 0.125000
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::1.00000 0.750000 0.250000 0.187500
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::1.00000 0.500000 0.500000 0.250000
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::1.00000 0.750000 0.500000 0.375000
DEAL::0.500000 0.750000 0.250000 0.0937500
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::0.500000 1.00000 0.250000 0.125000
DEAL::0.750000 1.00000 0.250000 0.187500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::0.500000 1.00000 0.500000 0.250000
DEAL::0.750000 1.00000 0.500000 0.375000
DEAL::0.750000 0.750000 0.250000 0.140625
DEAL::1.00000 0.750000 0.250000 0.187500
DEAL::0.750000 1.00000 0.250000 0.187500
DEAL::1.00000 1.00000 0.250000 0.250000
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::1.00000 0.750000 0.500000 0.375000
DEAL::0.750000 1.00000 0.500000 0.375000
DEAL::1.00000 1.00000 0.500000 0.500000
DEAL::0.00000 0.00000 0.500000 0
DEAL::0.250000 0.00000 0.500000 0
DEAL::0.00000 0.250000 0.500000 0
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.00000 0.00000 0.750000 0
DEAL::0.250000 0.00000 0.750000 0
DEAL::0.00000 0.250000 0.750000 0
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.250000 0.00000 0.500000 0
DEAL::0.500000 0.00000 0.500000 0
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.250000 0.00000 0.750000 0
DEAL::0.500000 0.00000 0.750000 0
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.00000 0.250000 0.500000 0
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.00000 0.500000 0.500000 0
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.00000 0.250000 0.750000 0
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.00000 0.500000 0.750000 0
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.250000 0.250000 0.500000 0.0312500
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.00000 0.00000 0.750000 0
DEAL::0.250000 0.00000 0.750000 0
DEAL::0.00000 0.250000 0.750000 0
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.00000 0.00000 1.00000 0
DEAL::0.250000 0.00000 1.00000 0
DEAL::0.00000 0.250000 1.00000 0
DEAL::0.250000 0.250000 1.00000 0.0625000
DEAL::0.250000 0.00000 0.750000 0
DEAL::0.500000 0.00000 0.750000 0
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.250000 0.00000 1.00000 0
DEAL::0.500000 0.00000 1.00000 0
DEAL::0.250000 0.250000 1.00000 0.0625000
DEAL::0.500000 0.250000 1.00000 0.125000
DEAL::0.00000 0.250000 0.750000 0
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.00000 0.500000 0.750000 0
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.00000 0.250000 1.00000 0
DEAL::0.250000 0.250000 1.00000 0.0625000
DEAL::0.00000 0.500000 1.00000 0
DEAL::0.250000 0.500000 1.00000 0.125000
DEAL::0.250000 0.250000 0.750000 0.0468750
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.250000 0.250000 1.00000 0.0625000
DEAL::0.500000 0.250000 1.00000 0.125000
DEAL::0.250000 0.500000 1.00000 0.125000
DEAL::0.500000 0.500000 1.00000 0.250000
DEAL::0.500000 0.00000 0.500000 0
DEAL::0.750000 0.00000 0.500000 0
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::0.500000 0.00000 0.750000 0
DEAL::0.750000 0.00000 0.750000 0
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::0.750000 0.00000 0.500000 0
DEAL::1.00000 0.00000 0.500000 0
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::1.00000 0.250000 0.500000 0.125000
DEAL::0.750000 0.00000 0.750000 0
DEAL::1.00000 0.00000 0.750000 0
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::1.00000 0.250000 0.750000 0.187500
DEAL::0.500000 0.250000 0.500000 0.0625000
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::0.750000 0.250000 0.500000 0.0937500
DEAL::1.00000 0.250000 0.500000 0.125000
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::1.00000 0.500000 0.500000 0.250000
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::1.00000 0.250000 0.750000 0.187500
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::1.00000 0.500000 0.750000 0.375000
DEAL::0.500000 0.00000 0.750000 0
DEAL::0.750000 0.00000 0.750000 0
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::0.500000 0.00000 1.00000 0
DEAL::0.750000 0.00000 1.00000 0
DEAL::0.500000 0.250000 1.00000 0.125000
DEAL::0.750000 0.250000 1.00000 0.187500
DEAL::0.750000 0.00000 0.750000 0
DEAL::1.00000 0.00000 0.750000 0
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::1.00000 0.250000 0.750000 0.187500
DEAL::0.750000 0.00000 1.00000 0
DEAL::1.00000 0.00000 1.00000 0
DEAL::0.750000 0.250000 1.00000 0.187500
DEAL::1.00000 0.250000 1.00000 0.250000
DEAL::0.500000 0.250000 0.750000 0.0937500
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::0.500000 0.250000 1.00000 0.125000
DEAL::0.750000 0.250000 1.00000 0.187500
DEAL::0.500000 0.500000 1.00000 0.250000
DEAL::0.750000 0.500000 1.00000 0.375000
DEAL::0.750000 0.250000 0.750000 0.140625
DEAL::1.00000 0.250000 0.750000 0.187500
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::1.00000 0.500000 0.750000 0.375000
DEAL::0.750000 0.250000 1.00000 0.187500
DEAL::1.00000 0.250000 1.00000 0.250000
DEAL::0.750000 0.500000 1.00000 0.375000
DEAL::1.00000 0.500000 1.00000 0.500000
DEAL::0.00000 0.500000 0.500000 0
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.00000 0.750000 0.500000 0
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.00000 0.500000 0.750000 0
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.00000 0.750000 0.750000 0
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.250000 0.500000 0.500000 0.0625000
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.00000 0.750000 0.500000 0
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.00000 1.00000 0.500000 0
DEAL::0.250000 1.00000 0.500000 0.125000
DEAL::0.00000 0.750000 0.750000 0
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.00000 1.00000 0.750000 0
DEAL::0.250000 1.00000 0.750000 0.187500
DEAL::0.250000 0.750000 0.500000 0.0937500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.250000 1.00000 0.500000 0.125000
DEAL::0.500000 1.00000 0.500000 0.250000
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.250000 1.00000 0.750000 0.187500
DEAL::0.500000 1.00000 0.750000 0.375000
DEAL::0.00000 0.500000 0.750000 0
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.00000 0.750000 0.750000 0
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.00000 0.500000 1.00000 0
DEAL::0.250000 0.500000 1.00000 0.125000
DEAL::0.00000 0.750000 1.00000 0
DEAL::0.250000 0.750000 1.00000 0.187500
DEAL::0.250000 0.500000 0.750000 0.0937500
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.250000 0.500000 1.00000 0.125000
DEAL::0.500000 0.500000 1.00000 0.250000
DEAL::0.250000 0.750000 1.00000 0.187500
DEAL::0.500000 0.750000 1.00000 0.375000
DEAL::0.00000 0.750000 0.750000 0
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.00000 1.00000 0.750000 0
DEAL::0.250000 1.00000 0.750000 0.187500
DEAL::0.00000 0.750000 1.00000 0
DEAL::0.250000 0.750000 1.00000 0.187500
DEAL::0.00000 1.00000 1.00000 0
DEAL::0.250000 1.00000 1.00000 0.250000
DEAL::0.250000 0.750000 0.750000 0.140625
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.250000 1.00000 0.750000 0.187500
DEAL::0.500000 1.00000 0.750000 0.375000
DEAL::0.250000 0.750000 1.00000 0.187500
DEAL::0.500000 0.750000 1.00000 0.375000
DEAL::0.250000 1.00000 1.00000 0.250000
DEAL::0.500000 1.00000 1.00000 0.500000
DEAL::0.500000 0.500000 0.500000 0.125000
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::0.750000 0.500000 0.500000 0.187500
DEAL::1.00000 0.500000 0.500000 0.250000
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::1.00000 0.750000 0.500000 0.375000
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::1.00000 0.500000 0.750000 0.375000
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::1.00000 0.750000 0.750000 0.562500
DEAL::0.500000 0.750000 0.500000 0.187500
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::0.500000 1.00000 0.500000 0.250000
DEAL::0.750000 1.00000 0.500000 0.375000
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::0.500000 1.00000 0.750000 0.375000
DEAL::0.750000 1.00000 0.750000 0.562500
DEAL::0.750000 0.750000 0.500000 0.281250
DEAL::1.00000 0.750000 0.500000 0.375000
DEAL::0.750000 1.00000 0.500000 0.375000
DEAL::1.00000 1.00000 0.500000 0.500000
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::1.00000 0.750000 0.750000 0.562500
DEAL::0.750000 1.00000 0.750000 0.562500
DEAL::1.00000 1.00000 0.750000 0.750000
DEAL::0.500000 0.500000 0.750000 0.187500
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::0.500000 0.500000 1.00000 0.250000
DEAL::0.750000 0.500000 1.00000 0.375000
DEAL::0.500000 0.750000 1.00000 0.375000
DEAL::0.750000 0.750000 1.00000 0.562500
DEAL::0.750000 0.500000 0.750000 0.281250
DEAL::1.00000 0.500000 0.750000 0.375000
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::1.00000 0.750000 0.750000 0.562500
DEAL::0.750000 0.500000 1.00000 0.375000
DEAL::1.00000 0.500000 1.00000 0.500000
DEAL::0.750000 0.750000 1.00000 0.562500
DEAL::1.00000 0.750000 1.00000 0.750000
DEAL::0.500000 0.750000 0.750000 0.281250
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::0.500000 1.00000 0.750000 0.375000
DEAL::0.750000 1.00000 0.750000 0.562500
DEAL::0.500000 0.750000 1.00000 0.375000
DEAL::0.750000 0.750000 1.00000 0.562500
DEAL::0.500000 1.00000 1.00000 0.500000
DEAL::0.750000 1.00000 1.00000 0.750000
DEAL::0.750000 0.750000 0.750000 0.421875
DEAL::1.00000 0.750000 0.750000 0.562500
DEAL::0.750000 1.00000 0.750000 0.562500
DEAL::1.00000 1.00000 0.750000 0.750000
DEAL::0.750000 0.750000 1.00000 0.562500
DEAL::1.00000 0.750000 1.00000 0.750000
DEAL::0.750000 1.00000 1.00000 0.750000
DEAL::1.00000 1.00000 1.00000 1.00000

{'repo_name': 'dealii/dealii', 'stars': '644', 'repo_language': 'C++', 'file_name': 'check_01_cpu_features.cmake', 'mime_type': 'text/x-c++', 'hash': 8516193801532938643, 'source_dataset': 'data'}


/**********************************************************************************************************************
This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
Licensed under the BSD-2 license (see LICENSE file in main directory)
**********************************************************************************************************************/

#pragma once

#ifdef CPPADCG

#include <ct/core/core.h>
#include <memory>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/algorithm/string.hpp>

#include "CostFunctionQuadratic.hpp"
#include "utility/utilities.hpp"

#include "term/TermLoadMacros.hpp"

namespace ct {
namespace optcon {

/**
 * \ingroup CostFunction
 *
 * \brief Cost Function with Auto-Diff support
 *
 * This cost function can work with both, analytical terms as well as
 * auto-diff terms. For analytical terms it will use provided derivatives
 * and for auto-diff terms derivatives will be computed using auto-diff.
 *
 * Unit test \ref ADTest.cpp illustrates the use of a CostFunctionAD.
 */
template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
class CostFunctionAD : public CostFunctionQuadratic<STATE_DIM, CONTROL_DIM, SCALAR>
{
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW

    typedef core::DerivativesCppadJIT<STATE_DIM + CONTROL_DIM + 1, 1> JacCG;
    typedef typename JacCG::CG_SCALAR CGScalar;
    typedef Eigen::Matrix<CGScalar, 1, 1> MatrixCg;

    typedef Eigen::Matrix<SCALAR, STATE_DIM, STATE_DIM> state_matrix_t;
    typedef Eigen::Matrix<SCALAR, CONTROL_DIM, CONTROL_DIM> control_matrix_t;
    typedef Eigen::Matrix<SCALAR, CONTROL_DIM, STATE_DIM> control_state_matrix_t;

    typedef core::StateVector<STATE_DIM, SCALAR> state_vector_t;
    typedef core::ControlVector<CONTROL_DIM, SCALAR> control_vector_t;
    typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> VectorXs;
    typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> MatrixXs;

    /**
	 * \brief Basic constructor
	 */
    CostFunctionAD();

    /**
	 * \brief Constructor loading function from file
	 * @param filename config file location
	 * @param verbose flag enabling printouts
	 */
    CostFunctionAD(const std::string& filename, bool verbose = false);

    /**
	 * Deep-cloning of cost function
	 * @return base pointer to clone
	 */
    CostFunctionAD<STATE_DIM, CONTROL_DIM, SCALAR>* clone() const override;

    /**
	 * \brief Copy constructor
	 * @param arg cost function to copy
	 */
    CostFunctionAD(const CostFunctionAD& arg);

    /**
	 * \brief Destructor
	 */
    virtual ~CostFunctionAD();

    /**
	 * @brief      Initializes the AD costfunction, generates and compiles
	 *             source code
	 */
    virtual void initialize() override;

    /**
	 * \brief Add an intermediate, auto-differentiable term
	 *
	 * Use this function to add an auto-differentiable, intermediate term to the cost function.
	 *
	 * @param term The term to be added
	 * @param verbose Flag enabling printouts
	 * @return
	 */
    void addIntermediateADTerm(std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>> term,
        bool verbose = false) override;

    /**
	 * \brief Add a final, auto-differentiable term
	 *
	 * Use this function to add an auto-differentiable, final term to the cost function.
	 *
	 * @param term The term to be added
	 * @param verbose Flag enabling printouts
	 * @return
	 */
    void addFinalADTerm(std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>> term,
        bool verbose = false) override;

    void setCurrentStateAndControl(const state_vector_t& x, const control_vector_t& u, const SCALAR& t = 0.0) override;

    void loadFromConfigFile(const std::string& filename, bool verbose = false) override;

    SCALAR evaluateIntermediate() override;
    SCALAR evaluateTerminal() override;

    state_vector_t stateDerivativeIntermediate() override;
    state_vector_t stateDerivativeTerminal() override;

    control_vector_t controlDerivativeIntermediate() override;
    control_vector_t controlDerivativeTerminal() override;

    state_matrix_t stateSecondDerivativeIntermediate() override;
    state_matrix_t stateSecondDerivativeTerminal() override;

    control_matrix_t controlSecondDerivativeIntermediate() override;
    control_matrix_t controlSecondDerivativeTerminal() override;

    control_state_matrix_t stateControlDerivativeIntermediate() override;
    control_state_matrix_t stateControlDerivativeTerminal() override;

    std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>> getIntermediateADTermById(const size_t id);

    std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>> getFinalADTermById(const size_t id);

    std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>> getIntermediateADTermByName(
        const std::string& name);

    std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>> getFinalADTermByName(const std::string& name);

private:
    MatrixCg evaluateIntermediateCg(const Eigen::Matrix<CGScalar, STATE_DIM + CONTROL_DIM + 1, 1>& stateInputTime);
    MatrixCg evaluateTerminalCg(const Eigen::Matrix<CGScalar, STATE_DIM + CONTROL_DIM + 1, 1>& stateInputTime);

    //! combined state, control and time vector
    Eigen::Matrix<SCALAR, STATE_DIM + CONTROL_DIM + 1, 1> stateControlTime_;

    //! intermediate AD terms
    std::vector<std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>>> intermediateTerms_;
    //! final AD terms
    std::vector<std::shared_ptr<TermBase<STATE_DIM, CONTROL_DIM, SCALAR, CGScalar>>> finalTerms_;

    //! generated jacobians
    std::shared_ptr<JacCG> intermediateCostCodegen_;
    std::shared_ptr<JacCG> finalCostCodegen_;

    //! cppad functions
    typename JacCG::FUN_TYPE_CG intermediateFun_;
    typename JacCG::FUN_TYPE_CG finalFun_;
};

}  // namespace optcon
}  // namespace ct

#endif

{'repo_name': 'ethz-adrl/control-toolbox', 'stars': '363', 'repo_language': 'C++', 'file_name': 'ct_modelsConfig.cmake', 'mime_type': 'text/plain', 'hash': 916991139997424294, 'source_dataset': 'data'}