Converts 1.0 and 0.0 qvalues to 1 and 0 respectively. Used to maintain
 consistency across qvalue methods.
491258
def normalize_qvalue(q)
      (q == 1 || q == 0) && q.is_a?(Float) ? q.to_i : q
    end
946441
def clean_with_zeros(self,x):
        
        x[~np.any(np.isnan(x) | np.isinf(x),axis=1)] = 0
        return x
188468
@Pure
	public static float min(float... values) {
		if (values == null || values.length == 0) {
			return Float.NaN;
		}
		float min = values[0];
		for (final float v : values) {
			if (v < min) {
				min = v;
			}
		}
		return min;
	}
1293501
def _strip_trailing_zeros(value):
        
        return list(
           reversed(
              list(itertools.dropwhile(lambda x: x == 0, reversed(value)))
           )
        )
399936
def convert(self, values, nan_rep, encoding, errors):
        

        self.values = Int64Index(np.arange(self.table.nrows))
        return self
1263352
public static int binarySearchValueOrHigher(ListNumber values, double value) {
        if (value <= values.getDouble(0)) {
            return 0;
        }
        if (value >= values.getDouble(values.size() -1)) {
            return values.size() - 1;
        }
        
        int index = binarySearch(0, values.size() - 1, values, value);
        
        while (index != values.size() - 1 && value > values.getDouble(index)) {
            index++;
        }
        
        while (index != values.size() - 1 && value == values.getDouble(index + 1)) {
            index++;
        }
        
        return index;
    }
45030
def percentOfTotal(self, value, values):
        
        try:
            return float(values.index(value) + 1) / len(values)
        except (ZeroDivisionError, ValueError):
            return 0.0
706998
def interpretDQvalue(input):
    

    nbits = 16
    # We will only support integer values up to 2**128
    for iexp in [16, 32, 64, 128]:
        # Find out whether the input value is less than 2**iexp
        if (input // (2 ** iexp)) == 0:
            # when it finally is, we have identified how many bits can be used to
            # describe this input bitvalue
            nbits = iexp
            break

    # Find out how 'dtype' values are described on this machine
    a = np.zeros(1, dtype='int16')
    atype_descr = a.dtype.descr[0][1]
    # Use this description to build the description we need for our input integer
    dtype_str = atype_descr[:2] + str(nbits // 8)
    result = np.zeros(nbits + 1, dtype=dtype_str)

    # For each bit, determine whether it has been set in the input value or not
    for n in range(nbits + 1):
        i = 2 ** n
        if input & i > 0:
            # record which bit has been set as the power-of-2 integer
            result[n] = i

    # Return the non-zero unique values as a Python list
    return np.delete(np.unique(result), 0).tolist()
178082
def to_decimal(value, ctx):
    
    if isinstance(value, bool):
        return Decimal(1) if value else Decimal(0)
    elif isinstance(value, int):
        return Decimal(value)
    elif isinstance(value, Decimal):
        return value
    elif isinstance(value, str):
        try:
            return Decimal(value)
        except Exception:
            pass

    raise EvaluationError("Can't convert '%s' to a decimal" % str(value))
581329
def _convert_value(val):
    
    def _is_number(x, op):
        try:
            op(x)
            return True
        except ValueError:
            return False
    if isinstance(val, (list, tuple)):
        return [_convert_value(x) for x in val]
    elif val is None:
        return val
    elif _is_number(val, int):
        return int(val)
    elif _is_number(val, float):
        return float(val)
    elif val.find(";;") >= 0:
        return [_convert_value(v) for v in val.split(";;")]
    elif val.startswith(("{", "[")):
        # Can get ugly JSON output from CWL with unicode and ' instead of "
        # This tries to fix it so parsed correctly by json loader
        return json.loads(val.replace("u'", "'").replace("'", '"'))
    elif val.lower() == "true":
        return True
    elif val.lower() == "false":
        return False
    else:
        return val
852825
private ReturnCodes parseQValue(byte[] data, int start) {
        // 414433 - redo the qvalue parsing to handle more error conditions

        ReturnCodes rc = new ReturnCodes(false);
        int len = data.length;
        int index = skipWhiteSpace(data, start);
        // we should be pointing at "q=X"
        // technically it's supposed to be just 'q', but check uppercase too
        if (index >= len || ('q' != data[index] && 'Q' != data[index])) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Non qvalue found");
            }
            rc.setIntValue(index);
            return rc;
        }
        index++;
        index = skipWhiteSpace(data, index);
        if (index >= len || HttpBaseMessage.EQUALS != data[index]) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Qvalue missing equals");
            }
            rc.setIntValue(index);
            return rc;
        }
        index++;
        index = skipWhiteSpace(data, index);
        // now we should be pointing at a float value
        if (index < len && ('1' == data[index] || '0' == data[index])) {
            // default the "approval" flag based on leading digit
            boolean leadingOne = ('1' == data[index]);
            rc.setBooleanValue(leadingOne);
            if (++index >= len || ',' == data[index]) {
                // reached end of data, single digit
            } else if (' ' == data[index] || '\t' == data[index]) {
                // whitespace, scan for the comma
                index = skipWhiteSpace(data, index);
                if (index < len && ',' != data[index]) {
                    // nonwhitespace found [q=1 q] invalid
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Invalid char after trailing whitespace (1) ["
                                     + data[index] + "]");
                    }
                    rc.setBooleanValue(false);
                }
            } else if ('.' != data[index]) {
                // required to be a period for the float
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Non-period found after leading digit");
                }
                rc.setBooleanValue(false);
            } else {
                // now we must only have up to 3 digits, or 1.000
                // stop at eol, whitespace, or comma
                int numDigits = 0;
                while (++index < len && ',' != data[index]) {
                    if ('0' <= data[index] && '9' >= data[index]) {
                        numDigits++;
                        if ('0' != data[index]) {
                            if (leadingOne) {
                                // 1.000 is the only valid 1* value
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "Non-zero after a leading one");
                                }
                                rc.setBooleanValue(false);
                                break; // out of while
                            }
                            rc.setBooleanValue(true);
                        }
                    } else {
                        // non-digit found
                        break; // out of while
                    }
                } // while not end of data
                if (3 < numDigits) {
                    // too many digits
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Too many digits in float (" + numDigits + ")");
                    }
                    rc.setBooleanValue(false);
                } else if (index >= len || ',' == data[index]) {
                    // end of qvalue found
                } else if (' ' == data[index] || '\t' == data[index]) {
                    // whitespace, scan for the comma
                    index = skipWhiteSpace(data, ++index);
                    if (index < len && ',' != data[index]) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Invalid char after trailing whitespace (2) ["
                                         + data[index] + "]");
                        }
                        rc.setBooleanValue(false);
                    }
                } else {
                    // invalid character found
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Invalid char after number [" + data[index] + "]");
                    }
                    rc.setBooleanValue(false);
                }
            }
        } // starts with a digit

        // index is pointing to the last char looked at
        rc.setIntValue(index);
        return rc;
    }
584705
def qvalue(encoding)
      m = matches(encoding)
      if m.empty?
        encoding == 'identity' ? 1 : 0
      else
        normalize_qvalue(@qvalues[m.first])
      end
    end
492016
def clean(self, value):
        """"""
        if not value:
            return None

        # if any value exists, then add "0" as a placeholder to the remaining
        # values.
        if isinstance(value, list) and any(value):
            for i, item in enumerate(value):
                if not item:
                    value[i] = '0'

        return super(MultipleDecimalField, self).clean(value)
24824
public static int binarySearchValueOrLower(ListNumber values, double value) {
        if (value <= values.getDouble(0)) {
            return 0;
        }
        if (value >= values.getDouble(values.size() -1)) {
            return values.size() - 1;
        }
        
        int index = binarySearch(0, values.size() - 1, values, value);
        
        while (index != 0 && value == values.getDouble(index - 1)) {
            index--;
        }
        
        return index;
    }
1026353
public int getQuality() {
        int qvalue, sum = 0, quality = 0, tempQ[];

        for (int i = 0; i < qTables.length; i++) {
            if (qTables[i] != null) {
                tempQ = qTables[i].getQ();
                for (int j = 0; j < 64; j++) {
                    sum += tempQ[j];
                }
            }
        }

        if ((qTables[0] != null) && (qTables[1] != null)) {

            qvalue = (int) (qTables[0].getQ()[2] + qTables[0].getQ()[53] + qTables[1].getQ()[0] + qTables[1].getQ()[63]);

            for (int i = 0; i < 100; i++) {
                if ((qvalue < DOUBLE_QUANT_HASH[i]) && (sum < DOUBLE_QUANT_SUMS[i])) {
                    continue;
                }

                if (((qvalue <= DOUBLE_QUANT_HASH[i]) && (sum <= DOUBLE_QUANT_SUMS[i])) || (i >= 50)) {
                    quality = i + 1;
                }

                break;
            }
        } else if (qTables[0] != null) {

            qvalue = (qTables[0].getQ()[2] + qTables[0].getQ()[53]);

            for (int i = 0; i < 100; i++) {
                if ((qvalue < SINGLE_QUANT_HASH[i]) && (sum < SINGLE_QUANT_SUMS[i])) {
                    continue;
                }

                if (((qvalue <= SINGLE_QUANT_HASH[i]) && (sum <= SINGLE_QUANT_SUMS[i])) || (i >= 50)) {
                    quality = i + 1;
                }

                break;
            }
        }

        return quality;
    }
754544
def fix_decimals(obj):
    
    if isinstance(obj, list):
        for i in range(len(obj)):
            obj[i] = fix_decimals(obj[i])
        return obj

    elif isinstance(obj, dict):
        for key, value in obj.items():
            obj[key] = fix_decimals(value)
        return obj

    elif isinstance(obj, decimal.Decimal):
        if obj % 1 == 0:
            return int(obj)
        else:
            return float(obj)

    else:
        return obj
1179424
def convert(values):
    

    dtype = values.dtype

    if is_categorical_dtype(values):
        return values

    elif is_object_dtype(dtype):
        return values.ravel().tolist()

    if needs_i8_conversion(dtype):
        values = values.view('i8')
    v = values.ravel()

    if compressor == 'zlib':
        _check_zlib()

        # return string arrays like they are
        if dtype == np.object_:
            return v.tolist()

        # convert to a bytes array
        v = v.tostring()
        return ExtType(0, zlib.compress(v))

    elif compressor == 'blosc':
        _check_blosc()

        # return string arrays like they are
        if dtype == np.object_:
            return v.tolist()

        # convert to a bytes array
        v = v.tostring()
        return ExtType(0, blosc.compress(v, typesize=dtype.itemsize))

    # ndarray (on original dtype)
    return ExtType(0, v.tostring())