Unit Constructor
558169
function Unit(desc){
	if (!(this instanceof Unit)) return new Unit(desc);

	this.$unitAttached = true;
	this.$unitHandlers = {};
	this.$unitPrefix = '';
	if (Unit.$prototyping) return this;
	if (desc){
		this.extendUnit(desc);
		this.setupUnit();
	}
	return this;
}
554103
void init() {
    numnegative = new int[numSamples() + 1];
    numpositive = new int[numSamples() + 1];
    numnegative[0] = 0;
    numpositive[0] = 0;
    int num = numSamples();
    for (int i = 1; i <= num; i++) {
      numnegative[i] = numnegative[i - 1] + (classes[i - 1] == 0 ? 1 : 0);
    }
    for (int i = 1; i <= num; i++) {
      numpositive[i] = numpositive[i - 1] + (classes[num - i] == 0 ? 0 : 1);
    }
    System.err.println("total positive " + numpositive[num] + " total negative " + numnegative[num] + " total " + num);
    for (int i = 1; i < numpositive.length; i++) {
      //System.out.println(i + " positive " + numpositive[i] + " negative " + numnegative[i] + " classes " + classes[i - 1] + " " + classes[num - i]);
    }
  }
88793
public static void dumpUnit(CompilationUnit unit) {
    String relativeOutputPath = unit.getMainTypeName().replace('.', '/') + ".ast";
    File outputFile = new File(
        unit.getEnv().options().fileUtil().getOutputDirectory(), relativeOutputPath);
    outputFile.getParentFile().mkdirs();

    try (FileOutputStream fout = new FileOutputStream(outputFile);
        OutputStreamWriter out = new OutputStreamWriter(fout, "UTF-8")) {
      out.write(dump(unit));
    } catch (IOException e) {
      ErrorUtil.fatalError(e, outputFile.getPath());
    }
  }
857719
def declare_units(out_units, **units_by_name):
    """"""

    def dec(func):
        # Match the signature of the function to the arguments given to the decorator
        sig = signature(func)
        bound_units = sig.bind_partial(**units_by_name)

        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            # Match all passed in value to their proper arguments so we can check units
            bound_args = sig.bind(*args, **kwargs)
            for name, val in bound_args.arguments.items():
                _check_units(val, bound_units.arguments.get(name, None))

            out = func(*args, **kwargs)

            # In the generic case, we use the default units that should have been propagated by the computation.
            if '[' in out_units:
                _check_units(out, out_units)

            # Otherwise, we specify explicitly the units.
            else:
                out.attrs['units'] = out_units
            return out

        return wrapper

    return dec
1236748
def generate_py_units(data):
  """"""
  units = collections.defaultdict(list)
  for unit in sorted(data.units, key=lambda a: a.name):
    if unit.unit_id in static_data.UNIT_TYPES:
      units[unit.race].append(unit)

  def print_race(name, race):
    print("class %s(enum.IntEnum):" % name)
    print('  """%s units."""' % name)
    for unit in units[race]:
      print("  %s = %s" % (unit.name, unit.unit_id))
    print("\n")

  print_race("Neutral", sc_common.NoRace)
  print_race("Protoss", sc_common.Protoss)
  print_race("Terran", sc_common.Terran)
  print_race("Zerg", sc_common.Zerg)
635498
function getValueOfUnit(unitInput) {
  const unit = unitInput ? unitInput.toLowerCase() : 'ether';
  var unitValue = unitMap[unit]; // eslint-disable-line

  if (typeof unitValue !== 'string') {
    throw new Error(`[ethjs-unit] the unit provided ${unitInput} doesn't exists, please use the one of the following units ${JSON.stringify(unitMap, null, 2)}`);
  }

  return new BN(unitValue, 10);
}
369377
private void init() {
        writers.put(Boolean.class, new BooleanDataWriter());
        writers.put(Calendar.class, new CalendarDataWriter());
        writers.put(Date.class, new DateDataWriter());
        writers.put(Enum.class, new EnumDataWriter());
        writers.put(Number.class, new NumberDataWriter());
        writers.put(String.class, new StringDataWriter());
    }
147731
private ArrayList<Unit> unit( CssFormatter formatter, ArrayList<Unit> list ){
        for( int i = 0; i < operands.size(); i++ ) {
            Expression exp = operands.get( i );
            if( exp.getClass() == Operation.class ) {
                Operation op = (Operation)exp;
                switch( op.operator ) {
                    case '*':
                    case '/':
                        list = op.unit( formatter, list );
                        break;
                    default:
                }
            } else {
                String unitStr = exp.unit( formatter );
                if( !unitStr.isEmpty() ) {
                    if( list == null ) {
                        list = new ArrayList<>();
                    }
                    Unit unit = null;
                    for( int j = 0; j < list.size(); j++ ) {
                        Unit unitLoop = list.get( j );
                        if( unitLoop.unit.equals( unitStr ) ) {
                            unit = unitLoop;
                            break;
                        }
                    }
                    if( unit == null ) {
                        unit = new Unit( unitStr );
                        list.add( unit );
                    }
                    if( i == 0 || operator == '*' ) {
                        unit.numerator++;
                    } else {
                        unit.denominator++;
                    }
                }
            }
        }
        return list;
    }
889384
protected void addUnit(final IAnnotationUnit unit) {
		int raterIdx = unit.getRaterIdx();
		if (raterIdx >= units.size()) {
			for (int i = units.size(); i < raterIdx; i++) {
                units.add(null);
            }
			units.add(unit);
		}
        else {
            units.set(raterIdx, unit);
        }

		if (unit.getCategory() != null) {
            nonNullCount++;
        }
	}
863887
def create_unit(type, attributes: {})
      "#{self.class.name.split('::').first}::#{type.to_s.camelize}".constantize
        .new(options: unit_options, logger: logger).tap do |unit|
        {src: :source, dst: :destination}.each do |k, v|
          unit.send "#{v}=".to_sym, attributes[k] unless attributes[k].nil?
        end

        UNIT_ATTRIBUTES[type].each do |v|
          unit.send "#{v}=".to_sym, defaults[v] unless defaults[v].nil?
          unit.send "#{v}=".to_sym, attributes[v] unless attributes[v].nil?
        end
      end
    end
719633
def set_unit(self, unit):
        
        # accept all core time units
        if unit is None or (isinstance(unit, units.NamedUnit) and
                            unit.physical_type == 'time'):
            self._unit = unit
            return
        # convert float to custom unit in seconds
        if isinstance(unit, Number):
            unit = units.Unit(unit * units.second)
        # otherwise, should be able to convert to a time unit
        try:
            unit = units.Unit(unit)
        except ValueError as exc:
            # catch annoying plurals
            try:
                unit = units.Unit(str(unit).rstrip('s'))
            except ValueError:
                raise exc
        # decompose and check that it's actually a time unit
        dec = unit.decompose()
        if dec.bases != [units.second]:
            raise ValueError("Cannot set GPS unit to %s" % unit)
        # check equivalent units
        for other in TIME_UNITS:
            if other.decompose().scale == dec.scale:
                self._unit = other
                return
        raise ValueError("Unrecognised unit: %s" % unit)
1225976
def initScenario(controller, scenario, thisPlayerID, debug=False):
    """"""
    ############################################################################
    def createUnitsWithTags(unitList, existingUnits={}, maxTries=25):
        """create each unit of unitList in game, identified by their tag"""
        createCmds = debugCmds.create(*unitList)
        controller.debug(*createCmds) # send create cmd via controller
        triesRemaining = maxTries
        getGameState = controller.observe # function that observes what's changed since the prior gameloop(s)
        numNeededNewUnits = len(unitList)
        newUnits = {}
        while len(newUnits) < numNeededNewUnits and triesRemaining > 0: # wait until new units are created
            units = getGameState().observation.raw_data.units
            for i, unit in enumerate(unitList): # match new unit tags with their originating units
                if unit.tag: continue # already found a matching tag for this unit
                for liveUnit in units: # identify new units and their tags
                    if liveUnit.unit_type != unit.code:     continue # can't match a unit of a different type
                    if liveUnit.owner     != unit.owner:    continue # can't match units with different owners
                    if liveUnit.tag       in existingUnits: continue # don't match against previously existing or new units
                    unit.tag = liveUnit.tag # found a match; sync tags + decalre this unit matched
                    existingUnits[unit.tag] = liveUnit # remember this association between unit and its properties
                    newUnits[unit.tag] = unit # distinguish the new units from the existing units
                    break # once a match is made, stop searching
                #if not unit.tag:  print("%02d.  missing: %s"%(maxTries-triesRemaining, unit))
            triesRemaining -= 1
        return newUnits
    ############################################################################
    def detectCurrentUnits(**filters):
        """identify all units currently visible by the player"""
        detectedUnits = {}
        getGameState = controller.observe # function that observes what's changed since the prior gameloop(s)
        while True:
            obs = getGameState()
            if obs.observation.game_loop <= 1: continue
            foundNewUnit = False
            for u in obs.observation.raw_data.units: # identify existing units (requieres no fog to be disabled?)
                if u.tag in detectedUnits: continue
                foundNewUnit = True
                detectedUnits[u.tag] = u
            if foundNewUnit: continue # ensure that two consecutive gameloops have identical units
            if detectedUnits: break # wait until units are found in the raw observations
        if filters:  return filterUnits(detectedUnits, **filters)
        else:        return detectedUnits
    ############################################################################
    def filterUnits(unitDict, noNeutral=False, ownedOnly=False):
        """select the desired types of units from unitDict"""
        ########################################################################
        def allow(unit):
            if noNeutral:
                if unit.alliance == c.NEUTRAL:              return False # ignore neutral units visible via snapshot to start the game
                if unit.mineral_contents:                   return False # don't include mineral nodes
                if unit.vespene_contents:                   return False # don't include vespene nodes
            if ownedOnly and unit.owner != thisPlayerID:    return False
            return True
        ########################################################################
        if not (noNeutral or ownedOnly): return unitDict # must select filters to get something different
        return {unit.tag : unit for unit in unitDict.values() if allow(unit)}
    ############################################################################
    def removeUnitsByKey(originalUnits=None, keepTags=[], **filters):
        """remove all detected units"""
        if originalUnits:
            units = filterUnits(originalUnits, **filters) # potentially filter an existing unit list
        else:
            originalUnits = detectCurrentUnits(**filters) # query currently existing units and filter appropriately
            units = originalUnits
        rmTags = list(units.keys())
        for keeper in keepTags:
            try:    rmTags.remove(keeper)
            except: pass
        return removeUnitsByTag(*rmTags, knownUnits=originalUnits)
    ############################################################################
    def removeUnitsByTag(*rmUnitTags, knownUnits={}):
        """remove specific units"""
        for rmTag in rmUnitTags:
            try:    del knownUnits[rmTag]
            except:
                if not knownUnits: break # already removed all monitored units
        if rmUnitTags:
            rmCmd = debugCmds.remove(*rmUnitTags) # create command to remove existing units
            controller.debug(rmCmd) # send remove cmd to remove existing units
        return knownUnits
    ############################################################################
    def wait(delay, msg):
        """control timing and messaging around delayed timing"""
        if debug: print(msg)
        while True:
            time.sleep(1)
            delay -= 1
            if delay > 0:
                if debug: print("%d..."%delay)
                continue
            break
    ############################################################################
    knownUnits = detectCurrentUnits(noNeutral=True) # all initial units, including misc units
    for pIdx, p in scenario.players.items():
        baseUnits = scenario.newBaseUnits(pIdx)
        newUs = createUnitsWithTags(p.baseUnits, existingUnits=knownUnits)
    wait(2, "delay before default unit deletion; %d remain"%len(newUs))
    if scenario.units: # remove initial units, but only if custom units are specified
        rmTags = []
        keepUnits = {19, 60, 95, 137} # supply depot, pylon, nydus network and burrowed creep tumor
        for unit in knownUnits.values():
            if unit.unit_type in keepUnits: continue # don't remove the main building
            rmTags.append(unit.tag) # collect all tags to remove them in a single command, all at once
        removeUnitsByTag(*rmTags, knownUnits=knownUnits) # skip 'knownUnits' option since initial units has already excluded rmTags
        wait(1, "idle for unit kills (keep %d)"%len(knownUnits))
        removeUnitsByKey(keepTags=knownUnits.keys(), noNeutral=True) # attempt again because zerg building deaths produce broodlings
    if debug:  print("%d remaining initial, known units"%len(knownUnits))
    initialUnits = dict(knownUnits)
    if thisPlayerID == 1: # this is the host (enable cheats for all players)
        controller.debug(debugCmds.disableAllCosts(), # enable cheats
                         debugCmds.allowEnemyControl(),
                         debugCmds.fastProduction())
    wait(0.5, "delay before creation") # wait before sending more commands
    actionLists = []
    nonActionLists = []
    newU = {}
    for playerID, upgrades in scenario.upgrades.items(): # set upgrades when appropriately specified in the scenario
        if not upgrades: continue
        reqs = scenario.players[playerID].upgradeReqs
        producingUnits = reqs.keys()
        if playerID == thisPlayerID:
            if debug: print("preparing %d upgrades for player #%d"%(len(upgrades), playerID))
            newU = createUnitsWithTags(producingUnits, existingUnits=knownUnits) # new units are created with in-game tags
        for unit, toDoActions in reqs.items():
            for i, ability in enumerate(toDoActions): # convert ability into requisite upgrade protocol action
                while len(actionLists) <= i:
                    actionLists.append([])
                    nonActionLists.append([])
                action = Action()
                uCmd = action.action_raw.unit_command
                uCmd.unit_tags.append(unit.tag)
                uCmd.queue_command = True
                uCmd.ability_id, ignoreTargetType = ability.getGameCmd() # upgrade abilities are targetless; therefore ignore target type of the action
                if playerID == thisPlayerID:    actionLists[i].append(action)
                else:                        nonActionLists[i].append(action)
    for i, (al, nal) in enumerate(zip(actionLists, nonActionLists)): # units that perform subsequent research commands must issue them consecutively
        if debug:  print("upgrade action list #%d commands: %d"%(i+1, len(al)))
        if al:  controller.actions(RequestAction(actions=al))
        elif not nal: continue # no player has any upgrade actions to perform for this tech level
        if   i == 0:  wait(6, "wait for all player's level 1 upgrades")
        elif i == 1:  wait(7, "wait for all player's level 2 upgrades")
        elif i == 2:  wait(8, "wait for all player's level 3 upgrades")
    if thisPlayerID == 1: # this is the host (disable cheats for all players)
        controller.debug(debugCmds.disableAllCosts(), # disable cheats
                         debugCmds.allowEnemyControl(),
                         debugCmds.fastProduction())
    wait(0.5, "wait to disable cheats before proceeding")
    if thisPlayerID == 1:
        removeUnitsByKey(keepTags=initialUnits, noNeutral=True) # remove tech researching units (and any other unit the player happened to create during research time
        wait(1.0, "idle for unit kills")
        knownUnits = removeUnitsByKey(keepTags=initialUnits, noNeutral=True) # attempt again in case zerg units produced broodlings
    cameraMv = Action()
    playerLoc = scenario.players[thisPlayerID].loc # set camera location to player's location
    playerLoc.assignIntoInt(cameraMv.action_raw.camera_move.center_world_space)
    controller.actions(RequestAction(actions=[cameraMv]))
    if debug: print("repositioned camera")
    scenarioUnits = {}
    for p in scenario.players.values(): # create the new scenario units only (not base units)
        newUnits = createUnitsWithTags(p.units, existingUnits=knownUnits)
        scenarioUnits.update(newUnits)
    modifyCmds = debugCmds.modify(*scenarioUnits.values()) # create command to set properties of in-game units
    controller.debug(*modifyCmds) # send modify cmd via controller
    wait(0.1, "allow modifications to finish")
    controller.debug(debugCmds.revealMap()) # reenable fog of war
    if debug:  print("scenario setup is finished")
1102509
def as(unit)
      unit = UOM::Unit.for(unit.to_sym) if String === unit or Symbol === unit
      return self if @unit == unit
      Measurement.new(unit, @unit.as(quantity, unit))
    end
627359
function init(parent, name) {  // {{{2
/**
 * Millitime field constructor
 *
 * @method constructor
 */

  this.min = 0;
  this.decimal = 0;
  this.unit = 'millisecond';

  O.inherited(this)(parent, name);
}
1297249
def unit(self, unit):
        
        allowed_values = ["cm", "inch", "foot"]  # noqa: E501
        if unit is not None and unit not in allowed_values:
            raise ValueError(
                "Invalid value for `unit` ({0}), must be one of {1}"  # noqa: E501
                .format(unit, allowed_values)
            )

        self._unit = unit
675392
function normalizeUnit(unit) {
    unit = toStr(unit);

    if (unitShorthandMap[unit]) return unitShorthandMap[unit];

    return unit.toLowerCase().replace(regEndS, '');
}
207754
def unit(self, value):
        

        if isinstance(value, TimeUnit):
            self._unit = value
        else:
            self._unit = TimeUnit(value)