If value is a vector or array, this function will return the single scalar value contained or throw an error if the length is not 1. If value isn't a vector or array, it is simply returned.
483075
function ensureScalar(value) {
  if (isUndefined(value) || value === null) {
    return value;
  }
  var length = 1;
  var description = 'a scalar';
  if (value.type === vectorProto.type) {
    length = value.size();
    value = value.values[0];
    description = 'a vector';
  } else if (Array.isArray(value)) {
    length = value.length;
    value = value[0];
    description = 'an array';
  }
  if (length !== 1) {
    throw new Error('expected a single scalar value but got ' +
      description + ' of length ' + length);
  }
  return value;
}
474293
def is_array(self, data_type):
    '''
    '''

    # Split off any brackets
    data_type = data_type.split('[')[0].strip()

    return data_type.lower() in self.array_types
479547
def APEValue(value, kind):
    

    try:
        type_ = _get_value_type(kind)
    except ValueError:
        raise ValueError("kind must be TEXT, BINARY, or EXTERNAL")
    else:
        return type_(value)
56405
def scalar(value):
    
    if isinstance(value, (list, tuple)) and len(value) == 1:
        return value[0]
    return value
827517
def _contains(expr, value):
    
    return composite_op(expr, ListContains, df_types.boolean, _value=_scalar(value))
362704
def validate(self, instance, value):
        
        if isinstance(value, string_types):
            if (
                    value.upper() not in VECTOR_DIRECTIONS or
                    value.upper() in ('Z', '-Z', 'UP', 'DOWN')
            ):
                self.error(instance, value)
            value = VECTOR_DIRECTIONS[value.upper()][:2]

        return super(Vector2, self).validate(instance, value)
1367328
def asscalar(a):
    
    # Do we want to check that the value is numeric?
    #if   isinstance(value, (int, long, float)): return value
    try:
        return np.asscalar(a)
    except AttributeError as e:
        return np.asscalar(np.asarray(a))
1099937
function value(val, buf, simple) {
  buf = buf || new Buffer(0);
  var type = typeof val;

  // coerce booleans to integers
  val = type === 'boolean' ? Number(val) : val;

  // treat floats as strings
  if(type === 'number' && parseInt(val) !== val) {
    val = '' + val;
  }

  // String instances are treated as simple strings
  if(val instanceof String) {
    simple = true;
    val = val.toString();
  }

  // re-evaluate type after coercion
  type = typeof val;

  if(val instanceof Buffer) {
    buf = _bst(buf, val);
  }else if(val === null) {
    buf = _nil(buf);
  }else if(Array.isArray(val)) {
    buf = _arr(buf, val);
  }else if(type === 'number'){
    buf = _int(buf, val);
  }else if(type === 'string') {
    buf = simple ? _str(buf, val) : _bst(buf, val);
  }else if(val instanceof Error) {
    buf = _err(buf, val);
  }else{
    assert(false, 'invalid encoder type: ' + type);
  }
  return buf;
}
286815
def _is_simple_type(value):
    '''
    
    '''
    return isinstance(value, six.string_types) or isinstance(value, int) or isinstance(value, float) or isinstance(value, bool)
714673
def check_inputs_not_arrays(func):
    
    @wraps(func)
    def func_wrapper(self, R, z, phi, t):
        if (hasattr(R, '__len__') and len(R) > 1) \
                or (hasattr(z, '__len__') and len(z) > 1) \
                or (hasattr(phi, '__len__') and len(phi) > 1) \
                or (hasattr(t, '__len__') and len(t) > 1):
            raise TypeError('Methods in SpiralArmsPotential do not accept array inputs. Please input scalars.')
        return func(self, R, z, phi, t)

    return func_wrapper
807783
def is_int_vector(l):
    

    """
    if isinstance(l, np.ndarray):
        if l.ndim == 1 and (l.dtype.kind == 'i' or l.dtype.kind == 'u'):
            return True
    return False
997952
def one(self):
        """"""
        # See zero() for remarks
        def one_vec(x, out=None, **kwargs):
            """One function, vectorized."""
            if is_valid_input_meshgrid(x, self.domain.ndim):
                scalar_out_shape = out_shape_from_meshgrid(x)
            elif is_valid_input_array(x, self.domain.ndim):
                scalar_out_shape = out_shape_from_array(x)
            else:
                raise TypeError('invalid input type')

            out_shape = self.out_shape + scalar_out_shape

            if out is None:
                return np.ones(out_shape, dtype=self.scalar_out_dtype)
            else:
                fill_value = np.ones(1, dtype=self.scalar_out_dtype)[0]
                out.fill(fill_value)

        return self.element_type(self, one_vec)
874591
@Override
    public INDArray scalar(Number value, long offset) {
        if (Nd4j.dataType() == DataType.DOUBLE)
            return scalar(value.doubleValue(), offset);
        if (Nd4j.dataType() == DataType.FLOAT || Nd4j.dataType() == DataType.HALF)
            return scalar(value.floatValue(), offset);
        if (Nd4j.dataType() == DataType.INT)
            return scalar(value.intValue(), offset);
        throw new IllegalStateException("Illegal data opType " + Nd4j.dataType());
    }
898400
function(scalar)
	{
		scalar = this.trim(scalar);
		
		var raw = null;
		var cast = null;

		if (	( 'null' == scalar.toLowerCase() ) ||
				( '' == scalar ) ||
				( '~' == scalar ) )
			return null;
		if ( (scalar+'').indexOf('!str ') == 0 )
			return (''+scalar).substring(5);
		if ( (scalar+'').indexOf('! ') == 0 )
			return parseInt(this.parseScalar((scalar+'').substr(2)));
		if ( /^\d+$/.test(scalar) )
		{
			raw = scalar;
			cast = parseInt(scalar);
			return '0' == scalar.charAt(0) ? this.octdec(scalar) : (( ''+raw == ''+cast ) ? cast : raw);
		}
		if ( 'true' == (scalar+'').toLowerCase() )
			return true;
		if ( 'false' == (scalar+'').toLowerCase() )
			return false;
		if ( this.isNumeric(scalar) )
			return '0x' == (scalar+'').substr(0, 2) ? this.hexdec(scalar) : parseFloat(scalar);
		if ( scalar.toLowerCase() == '.inf' )
			return Infinity;
		if ( scalar.toLowerCase() == '.nan' )
			return NaN;
		if ( scalar.toLowerCase() == '-.inf' )
			return -Infinity;
		if ( /^(-|\+)?[0-9,]+(\.[0-9]+)?$/.test(scalar) )
			return parseFloat(scalar.split(',').join(''));
		if ( this.getTimestampRegex().test(scalar) )
			return new Date(this.strtotime(scalar));
		//else
			return ''+scalar;
	}
1068121
@Override
    public INDArray scalar(float value) {
        if (Nd4j.dataType() == DataType.FLOAT || Nd4j.dataType() == DataType.HALF)
            return create(new float[] {value}, new int[0], new int[0], 0);
        else if (Nd4j.dataType() == DataType.DOUBLE)
            return scalar((double) value);
        else
            return scalar((int) value);
    }
751748
function contains( arr, value ) {
	var len, i;
	if ( !isArray( arr ) ) {
		throw new TypeError( 'contains()::invalid input argument. First argument must be an array. Value: `' + arr + '`.' );
	}
	len = arr.length;
	if ( isnan( value ) ) {
		for ( i = 0; i < len; i++ ) {
			if ( isnan( arr[ i ] ) ) {
				return true;
			}
		}
		return false;
	}
	for ( i = 0; i < len; i++ ) {
		if ( arr[ i ] === value ) {
			return true;
		}
	}
	return false;
}
854489
function() {
    var value = this.inputValue;

    if (value instanceof Array) {
      return value.length;
    }

    if (typeof value === 'number') {
      return value;
    }

    if (this.validator._hasNumericRule(this.attribute)) {
      return parseFloat(value, 10);
    }

    return value.length;
  }