Forces variables to respect dimensions
176809
def check_variables(self):
        
        
        self.count = len(self.fileid)
        self.size = np.size([np.size(self.__dict__.get(par)) for par in self.par_list])
        
        infos = zip(*(self.par_list.tolist(),self.dim_list.tolist()))
#        curDim, nself = self.get_currentDim()
        
        for enum in enumerate(infos):
            varSize = np.size(self.__dict__.get(enum[1][0]))
            varShape = np.shape(self.__dict__.get(enum[1][0]))[::-1] #Data and Netcdf dimensions are inverted (not allways?)
            
            dimSize = None
            if hasattr(self.__dict__.get(enum[1][0]),'_dimensions') :
                dumDim = self.__dict__.get(enum[1][0])._dimensions
                dumDim.pop('_ndims')
                dimSize = tuple(dumDim.values())
            elif isinstance(self.__dict__.get(enum[1][0]),dict):
                if self.__dict__.get(enum[1][0]).has_key('_dimensions'):
                    dumDim = self.__dict__.get(enum[1][0])['_dimensions']
                    dumDim.pop('_ndims')
                    dimSize = tuple(dumDim.values())
            
            if dimSize is None :
                if isinstance(self._dimensions,dimStr) :
                    dimSize = (self._dimensions).get(enum[1][1])
                else :
                    dimSize = tuple([(self._dimensions).get([d]) for d in enum[1][1]])
                
            masked = isinstance(self.__dict__.get(enum[1][0]), np.ma.masked_array)
            
            #Check mask consistency (mask length should be the same as data)
            if masked :
                if (self.__dict__.get(enum[1][0]).mask.size != self.__dict__.get(enum[1][0]).data.size): raise np.ma.core.MaskError("Mask length is not consistent with data")
            
            #Check dimensions
            self.message(4, 'checking variables -> {0}(N={1}) - {2}:{3}'.format(enum[1][0],varSize,enum[1][1],dimSize))
            for n,sh in enumerate(varShape) :
                if (sh > dimSize[n]) :
                    self.Error('Object variable {0} greater than corresponding dimension ({1})'.format(enum[1][0],enum[1][1]))
                elif (sh < dimSize[n]):
                    self.message(3, 'Variable {0}(N={1}) being extended to match dimension {2}:{3}'.format(enum[1][0],varSize,enum[1][1],dimSize))  
    #                self.__dict__[enum[1][0]] = np.ma.concatenate((self.__dict__[enum[1][0]], np.ma.masked_array(np.repeat(np.nan,dimSize - varSize),mask=np.zeros(dimSize - varSize,dtype='bool'))))
    
                    #Save additonnal attributes
                    attrStr={}
                    for a in set(self.__dict__[enum[1][0]].__dict__.keys()).difference(np.ma.empty(0,dtype=bool).__dict__.keys()):
                        attrStr.update({a:self.__dict__[enum[1][0]].__dict__[a]})
                    self.__dict__[enum[1][0]] = np.ma.masked_array( np.append(self.__dict__[enum[1][0]].data,np.repeat(self.__dict__[enum[1][0]].fill_value if hasattr(self.__dict__[enum[1][0]],'fill_value') else np.NaN,dimSize[n] - varSize)),
                                                                    mask=np.append(self.__dict__[enum[1][0]].mask,np.ones(dimSize[n] - varSize,dtype='bool')) )
                    self.__dict__[enum[1][0]].__dict__.update(attrStr)
347489
function(dimensions, usedDimensions, usedValues) {
        var activeDimensions = new Array(dimensions.length);
        var valueCounter = 1;
        for(var i=0; i<dimensions.length; i++) {
            var dimensionName;
            for(dimensionName in dimensions[i]){break}
            if(usedDimensions[dimensionName] === undefined) {
                activeDimensions[i] = 0;
                continue;
            }
            activeDimensions[i] = 1;
            this.dimensionsList.push(dimensionName);
            var labelCollector = {};
            valueCounter = this._dimensionWalk(dimensions[i][dimensionName], usedValues[dimensionName],
                valueCounter, [0], this.precedenceMap, labelCollector, this.numberToValue);
            this.valueToNumber[dimensionName] = labelCollector;
        }
        return activeDimensions;
    }
858184
private static int[] getDims(VarSet vars) {
        int[] dims = new int[vars.size()];
        for (int i=0; i<vars.size(); i++) {
            dims[i] = vars.get(i).getNumStates();
        }
        return dims;
    }
1121299
def ensure_dim(core, dim, dim_):
    """"""
    if dim is None:
        dim = dim_
    if not dim:
        return core, 1
    if dim_ == dim:
        return core, int(dim)

    if dim > dim_:
        key_convert = lambda vari: vari[:dim_]
    else:
        key_convert = lambda vari: vari + (0,)*(dim-dim_)

    new_core = {}
    for key, val in core.items():
        key_ = key_convert(key)
        if key_ in new_core:
            new_core[key_] += val
        else:
            new_core[key_] = val

    return new_core, int(dim)
993010
function(dimensions) {
   var simplex = new gamejs.math.noise.Simplex(Math);
   var surfaceData = [];
   for (var i=0;i<dimensions[0];i++) {
      surfaceData[i] = [];
      for (var j=0;j<dimensions[1];j++) {
         var val = simplex.get(i/50, j/50) * 255;
         surfaceData[i][j] = val;
      }
   }
   return surfaceData;
}
576106
def _bracket_dim_suggest(self, variable):
        """"""
        if variable is not None:
            #Look for <dimension> descriptors that are children of the variable
            #in its docstrings.
            dims = variable.doc_children("dimension", ["member", "parameter", "local"])
            descript = str(variable)
            if len(dims) > 0:
                descript += " | " + " ".join([DocElement.format_dimension(d) for d in dims])

            return dict(
                params=[variable.dimension],
                index=0,
                call_name=variable.name,
                description=descript,
            )        
        else:
            return []
436210
def _broadcast_compat_variables(*variables):
    
    dims = tuple(_unified_dims(variables))
    return tuple(var.set_dims(dims) if var.dims != dims else var
                 for var in variables)
232064
def dimensions
      height = self.count
      width = self.collect{|a| a.length}.max
      [width,height]
    end
419999
def _apply_over_vars_with_dim(func, self, dim=None, **kwargs):
    ''''''

    ds = type(self)(coords=self.coords, attrs=self.attrs)

    for name, var in self.data_vars.items():
        if dim in var.dims:
            ds[name] = func(var, dim=dim, **kwargs)
        else:
            ds[name] = var

    return ds
1043587
public static void validateBroadcastDims(INDArray x, INDArray y, INDArray z, int... dimensions){
        Preconditions.checkArgument(x == z || x.equalShapes(z), "X and Z arrays must be equal shape. X shape: %s, Z shape: %s",
                x.shape(), z.shape());
        long[] sx = x.shape();
        long[] sy = y.shape();
        //Possibility 1: equal ranks - dimensions must match
        if(dimensions.length == 1 && sy.length == 2 && (sy[0] == 1 || sy[1] == 1)) {
            //Edge case: x=[a,b,c], y=[1,b], dim=1 etc
            int d2 = dimensions[0] < 0 ? dimensions[0] + sx.length : dimensions[0]; //Handle negative dimensions
            if (sy[0] == 1) {
                Preconditions.checkState(sx[d2] == sy[1], "Shapes do not match: dimensions[0] - x[%s] must match y[%s], x shape %s, y shape %s, dimensions %s",
                        dimensions[0], 1, sx, sy, dimensions);
            } else {
                Preconditions.checkState(sx[d2] == sy[0], "Shapes do not match: dimensions[0] - x[%s] must match y[%s], x shape %s, y shape %s, dimensions %s",
                        dimensions[0], 0, sx, sy, dimensions);
            }
        } else if(sx.length == sy.length){
            for(int d : dimensions){
                int d2 = d < 0 ? d + sx.length : d; //Handle negative dimensions
                Preconditions.checkState(sx[d2] == sy[d2], "Dimensions mismatch on dimension %s: x shape %s, y shape %s", d, sx, sy);
            }
        } else if(dimensions.length == sy.length) {
            //Possibility 2: different ranks - for example, mul([a,b,c],[a,c], [0,2]) - dimensions refer to x
            for (int i = 0; i < dimensions.length; i++) {
                int d2 = dimensions[i] < 0 ? dimensions[i] + sx.length : dimensions[i]; //Handle negative dimensions
                Preconditions.checkState(sx[d2] == sy[i], "Shapes do not match: dimensions[%s] - x[%s] must match y[%s], x shape %s, y shape %s, dimensions %s",
                        i, d2, i, sx, sy, dimensions);
            }
        } else {
            throw new IllegalStateException("Invalid broadcast dimensions: x shape " + Arrays.toString(sx) + ", y shape " + Arrays.toString(sy)
                    + ", dimensions " + Arrays.toString(dimensions));
        }
    }
1179219
def _force_xyz(self,x,y,z,i):
        """"""
        return -4.*numpy.pi*self._b*self._c\
            *_forceInt(x,y,z,
                       lambda m: self._mdens(m),
                       self._b2,self._c2,i,glx=self._glx,glw=self._glw)
296250
def _force_float(v):
    
    try:
        return float(v)
    except Exception as exc:
        return float('nan')
        logger.warning('Failed to convert {} to float with {} error. Using 0 instead.'.format(v, exc))
374407
def bound_variables(xmrs):
    """"""
    bvs = set(
        ep.intrinsic_variable for ep in xmrs.eps()
        if ep.is_quantifier() and ep.intrinsic_variable is not None
    )
    return sorted(bvs, key=var_id)
1139270
def _attach_dim_scales(self):
        """"""
        for name, var in self.variables.items():
            if name not in self.dimensions:
                for n, dim in enumerate(var.dimensions):
                    var._h5ds.dims[n].attach_scale(self._all_h5groups[dim])

        for subgroup in self.groups.values():
            subgroup._attach_dim_scales()
468681
def broadcast_dimension_size(
    variables: List[Variable],
) -> 'OrderedDict[Any, int]':
    
    dims = OrderedDict()  # type: OrderedDict[Any, int]
    for var in variables:
        for dim, size in zip(var.dims, var.shape):
            if dim in dims and size != dims[dim]:
                raise ValueError('index %r not aligned' % dim)
            dims[dim] = size
    return dims
156797
def width(self, value):
        """"""
        if self._width != value and \
           isinstance(value, (int, float, long)):
            self._width = value
1317735
function buildConcepts(item, fullDimensions) {
  function isInitiallyActive(dimensionId, value, index) {
    if (!defined(item.selectedInitially)) {
      return index === 0;
    }
    var dimensionSelectedInitially = item.selectedInitially[dimensionId];
    if (!defined(dimensionSelectedInitially)) {
      return index === 0;
    }
    return dimensionSelectedInitially.indexOf(value.id) >= 0;
  }

  var conceptDimensions = getShownDimensions(
    item,
    fullDimensions,
    fullDimensions
  );
  fixSelectedInitially(item, conceptDimensions); // Note side-effect.
  var concepts = conceptDimensions.map(function(dimension, i) {
    var allowMultiple =
      item.allSingleValuedDimensionIds.indexOf(dimension.id) === -1;
    var concept = new DisplayVariablesConcept(dimension.name, {
      isOpen: false,
      allowMultiple: allowMultiple,
      requireSomeActive: true,
      exclusiveChildIds: getTotalValueIdsForDimensionId(item, dimension.id)
    });
    concept.id = dimension.id;
    concept.items = dimension.values.map(function(value, index) {
      return new VariableConcept(renameValue(item, value.name), {
        parent: concept,
        id: value.id,
        active: isInitiallyActive(concept.id, value, index)
      });
    });
    return concept;
  });
  if (concepts.length > 0) {
    return [new SummaryConcept(undefined, { items: concepts, isOpen: false })];
  }
  return [];
}