>>> gg = ggplot(diamonds, aes(x='cut', y='clarity'))
        >>> gg = gg + stat_sum(aes(group='cut'))
        >>> gg + scale_size(range=(3, 25))

        Note the different height sizes for the entries
199501
def _set_defaults(self):
        guide._set_defaults(self)

        nbreak = len(self.key)

        # rows and columns
        if self.nrow is not None and self.ncol is not None:
            if guide.nrow * guide.ncol < nbreak:
                raise PlotnineError(
                    "nrow x ncol need to be larger",
                    "than the number of breaks")

        if self.nrow is None and self.ncol is None:
            if self.direction == 'horizontal':
                self.nrow = int(np.ceil(nbreak/5))
            else:
                self.ncol = int(np.ceil(nbreak/20))

        self.nrow = self.nrow or int(np.ceil(nbreak/self.ncol))
        self.ncol = self.ncol or int(np.ceil(nbreak/self.nrow))

        # key width and key height for each legend entry
        #
        # Take a peak into data['size'] to make sure the
        # legend dimensions are big enough
        

        # FIXME: This should be in the geom instead of having
        # special case conditional branches
        def determine_side_length(initial_size):
            default_pad = initial_size * 0.5
            # default_pad = 0
            size = np.ones(nbreak) * initial_size
            for i in range(nbreak):
                for gl in self.glayers:
                    _size = 0
                    pad = default_pad
                    # Full size of object to appear in the
                    # legend key
                    with suppress(IndexError):
                        if 'size' in gl.data:
                            _size = gl.data['size'].iloc[i] * SIZE_FACTOR
                            if 'stroke' in gl.data:
                                _size += (2 * gl.data['stroke'].iloc[i] *
                                          SIZE_FACTOR)

                        # special case, color does not apply to
                        # border/linewidth
                        if issubclass(gl.geom, geom_text):
                            pad = 0
                            if _size < initial_size:
                                continue

                        try:
                            # color(edgecolor) affects size(linewidth)
                            # When the edge is not visible, we should
                            # not expand the size of the keys
                            if gl.data['color'].iloc[i] is not None:
                                size[i] = np.max([_size+pad, size[i]])
                        except KeyError:
                            break

            return size

        # keysize
        if self.keywidth is None:
            width = determine_side_length(
                self._default('legend_key_width', 18))
            if self.direction == 'vertical':
                width[:] = width.max()
            self._keywidth = width
        else:
            self._keywidth = [self.keywidth]*nbreak

        if self.keyheight is None:
            height = determine_side_length(
                self._default('legend_key_height', 18))
            if self.direction == 'horizontal':
                height[:] = height.max()
            self._keyheight = height
        else:
            self._keyheight = [self.keyheight]*nbreak
886471
def obfn_gvar(self):
        

        if self.opt['gEvalY']:
            return self.Y
        else:
            return self.cnst_A(None, self.Xf) - self.cnst_c()
783450
def pysal_G(self, **kwargs):
        
        if self.weights is None:
            self.raster_weights(**kwargs)
        rasterf = self.raster.flatten()
        rasterf = rasterf[rasterf.mask==False]
        self.G = pysal.G(rasterf, self.weights, **kwargs)
922425
private void calculateOutside(int spanStart, int spanEnd, CfgParseChart chart, double[] newValues) {
    Factor parentOutside = chart.getOutsideEntries(spanStart, spanEnd);
    Tensor parentWeights = parentOutside.coerceToDiscrete().getWeights();

    Tensor binaryDistributionWeights = binaryDistribution.coerceToDiscrete().getWeights();
    int parentIndex = Ints.indexOf(binaryDistributionWeights.getDimensionNumbers(), parentVar.getOnlyVariableNum());
    int leftIndex = Ints.indexOf(binaryDistributionWeights.getDimensionNumbers(), leftVar.getOnlyVariableNum());
    int rightIndex = Ints.indexOf(binaryDistributionWeights.getDimensionNumbers(), rightVar.getOnlyVariableNum());

    int length = newValues.length;
    double[] binaryDistributionValues = binaryDistributionWeights.getValues();
    for (int i = 0; i < spanEnd - spanStart; i++) {
      double[] leftInside = chart.getInsideEntriesArray(spanStart, spanStart + i);
      double[] rightInside = chart.getInsideEntriesArray(spanStart + i + 1, spanEnd);

      for (int j = 0; j < length; j++) {
        newValues[j] = binaryDistributionValues[j] * parentWeights.get(binaryDistributionWeights.indexToPartialDimKey(j, parentIndex));
        newValues[j] *= rightInside[binaryDistributionWeights.indexToPartialDimKey(j, rightIndex)];
      }
      chart.updateOutsideEntry(spanStart, spanStart + i, newValues, binaryDistribution, leftVar);
      
      for (int j = 0; j < length; j++) {
        newValues[j] *= leftInside[binaryDistributionWeights.indexToPartialDimKey(j, leftIndex)];
      }
      chart.updateBinaryRuleExpectations(newValues);

      for (int j = 0; j < length; j++) {
        if (newValues[j] != 0.0) {
          newValues[j] = newValues[j] / rightInside[binaryDistributionWeights.indexToPartialDimKey(j, rightIndex)];
        }
      }
      chart.updateOutsideEntry(spanStart + i + 1, spanEnd, newValues, binaryDistribution, rightVar);
    }
  }
1230232
function buildScales() {
            const [minX, minY] = [d3Array.min(dataPoints, ({ x }) => x), d3Array.min(dataPoints, ({ y }) => y)];
            const [maxX, maxY] = [d3Array.max(dataPoints, ({ x }) => x), d3Array.max(dataPoints, ({ y }) => y)];
            const yScaleBottomValue = Math.abs(minY) < 0 ? Math.abs(minY) : 0;

            xScale = d3Scale.scaleLinear()
                .domain([minX, maxX])
                .rangeRound([0, chartWidth])
                .nice();

            yScale = d3Scale.scaleLinear()
                .domain([yScaleBottomValue, maxY])
                .rangeRound([chartHeight, 0])
                .nice();

            colorScale = d3Scale.scaleOrdinal()
                .domain(dataPoints.map(getName))
                .range(colorSchema);

            areaScale = d3Scale.scaleSqrt()
                .domain([yScaleBottomValue, maxY])
                .range([0, maxCircleArea]);

            const colorRange = colorScale.range();

            /**
             * Maps data point category name to
             * each color of the given color scheme
             * {
             *     name1: 'color1',
             *     name2: 'color2',
             *     name3: 'color3',
             *     ...
             * }
             * @private
             */
            nameColorMap = colorScale.domain().reduce((accum, item, i) => {
                accum[item] = colorRange[i];

                return accum;
            }, {});
        }
474798
function (inData, outData, width, height) {
        var i, n = width * height * 4,
            gr1, gr2, gg1, gg2, gb1, gb2,
            data1 = [],
            data2 = [];

        convolve3x3(inData, data1, width, height,
            [
                [-1, 0, 1],
                [-2, 0, 2],
                [-1, 0, 1]
            ]);

        convolve3x3(inData, data2, width, height,
            [
                [-1, -2, -1],
                [ 0, 0, 0],
                [ 1, 2, 1]
            ]);

        for (i = 0; i < n; i += 4) {
            gr1 = data1[i];
            gr2 = data2[i];
            gg1 = data1[i + 1];
            gg2 = data2[i + 1];
            gb1 = data1[i + 2];
            gb2 = data2[i + 2];

            if (gr1 < 0) {
                gr1 = -gr1;
            }
            if (gr2 < 0) {
                gr2 = -gr2;
            }
            if (gg1 < 0) {
                gg1 = -gg1;
            }
            if (gg2 < 0) {
                gg2 = -gg2;
            }
            if (gb1 < 0) {
                gb1 = -gb1;
            }
            if (gb2 < 0) {
                gb2 = -gb2;
            }

            outData[i] = 255 - (gr1 + gr2) * 0.8;
            outData[i + 1] = 255 - (gg1 + gg2) * 0.8;
            outData[i + 2] = 255 - (gb1 + gb2) * 0.8;
            outData[i + 3] = inData[i + 3];
        }
    }
775202
function nestRollupAggregateSum(array) {
		// Note: we don't use d3.sum here because we want to end up with a null value for "holes"
		var sum = null, plus = null, minus = null, 
			d, v, i, len = array.length, groupId, scale, negate = false;
		for ( i = 0; i < len; i += 1 ) {
			d = array[i];
			v = d[parent.plotPropertyName];
			if ( v !== undefined ) {
				groupId = d[parent.internalPropName].groupId;
				scale = parent.scaleFactor(groupId);
				negate = negativeGroupMap[groupId] === true;
				if ( negate ) {
					minus += v * scale;
				} else {
					plus += v * scale;
				}
			}
		}
		if ( plus !== null || minus !== null ) {
			sum = plus - minus;
		}
		return { date : array[0].date, y : sum, plus : plus, minus : minus };
	}
23322
def fix_aggs(self):
        
        aggs = self.aggs
        for key in list(aggs.keys()):
            _type = aggs[key].get("_type", "unknown")
            if _type == "date_histogram":
                for entry in aggs[key].get("entries", []):
                    for k, v in list(entry.items()):
                        if k in ["count", "max", "min", "total_count", "mean", "total"]:
                            continue
                        if not isinstance(entry[k], datetime):
                            entry[k] = datetime.utcfromtimestamp(v / 1e3)
337141
def Kdiag(self, X, target):
        """"""
        ly=1/self.lengthscaleY
        lu=np.sqrt(3)/self.lengthscaleU
        #ly=self.lengthscaleY
        #lu=self.lengthscaleU
        
        k1 = (2*lu+ly)/(lu+ly)**2
        k2 = (ly-2*lu + 2*lu-ly ) / (ly-lu)**2 
        k3 = 1/(lu+ly) + (lu)/(lu+ly)**2 

        np.add(self.varianceU*self.varianceY*(k1+k2+k3), target, target)
1175795
def as_int(width, height):
    ""
    gcd = get_gcd(width, height)
    return int(width / gcd), int(height / gcd)
313995
function hsl2rgb(h, s, l) {
		// HSL 0 to 1 => RGB results from 0 to 255
		var r, g, b, var_1, var_2;

		if (s === 0) {
			r = l * 255;
			g = l * 255;
			b = l * 255;
		} else {
			var_2 = (l < 0.5) ? l * (1 + s) : ((l + s) - (s * l));
			var_1 = 2 * l - var_2;

			r = 255 * h2rgb(var_1, var_2, h + (1 / 3));
			g = 255 * h2rgb(var_1, var_2, h);
			b = 255 * h2rgb(var_1, var_2, h - (1 / 3));
		}

		return [r, g, b];
	}
160591
def _verify_arguments(self, kwargs):
        
        geom_stat_args = kwargs.keys() | self._stat._kwargs.keys()
        unknown = (geom_stat_args -
                   self.aesthetics() -                # geom aesthetics
                   self.DEFAULT_PARAMS.keys() -        # geom parameters
                   self._stat.aesthetics() -          # stat aesthetics
                   self._stat.DEFAULT_PARAMS.keys() -  # stat parameters
                   {'data', 'mapping',                # layer parameters
                    'show_legend', 'inherit_aes'})    # layer parameters
        if unknown:
            msg = ("Parameters {}, are not understood by "
                   "either the geom, stat or layer.")
            raise PlotnineError(msg.format(unknown))
703261
private static int getSizeNoH(Group g) {
		int size = 0;
		for (Atom a:g.getAtoms()) {
			if (a.getElement()!=Element.H)
				size++;
		}
		return size;
	}
1342671
function(g, x, y, z, w) {
		var n = g[0] * x + g[1] * y;
		if(z){
			n += g[2] * z;
			if(w){
				n += g[3] * w;
			}
		}
		return n;
	}
442663
def _g(self, h, xp, s):
        """"""

        nphi = sum(self.phi)

        return (nphi / 2.0) * log(2 * pi) + nphi * \
            log(s) + 0.5 * sum((h - xp) ** 2) / (s ** 2)
671753
private static void summarizeGLMModel(ModelSummary summary, hex.glm.GLMModel model) {
    // add generic fields such as column names
    summarizeModelCommonFields(summary, model);

    summary.model_algorithm = "GLM";

    JsonObject all_params = (model.get_params()).toJSON();
    summary.critical_parameters = whitelistJsonObject(all_params, GLM_critical_params);
    summary.secondary_parameters = whitelistJsonObject(all_params, GLM_secondary_params);
    summary.expert_parameters = whitelistJsonObject(all_params, GLM_expert_params);
  }
347113
function buildScales() {
            let yMax = d3Array.max(data.map(getValue));

            if (isHorizontal) {
                xScale = d3Scale.scaleLinear()
                    .domain([0, yMax])
                    .rangeRound([0, chartWidth - 1]);
                // 1 pix for edge tick

                yScale = d3Scale.scaleBand()
                    .domain(data.map(getName))
                    .rangeRound([chartHeight, 0])
                    .padding(0.1);

                yScale2 = d3Scale.scaleBand()
                    .domain(data.map(getGroup))
                    .rangeRound([yScale.bandwidth(), 0])
                    .padding(0.1);
            } else {
                xScale = d3Scale.scaleBand()
                    .domain(data.map(getName))
                    .rangeRound([0, chartWidth])
                    .padding(0.1);
                xScale2 = d3Scale.scaleBand()
                    .domain(data.map(getGroup))
                    .rangeRound([0, xScale.bandwidth()])
                    .padding(0.1);

                yScale = d3Scale.scaleLinear()
                    .domain([0, yMax])
                    .rangeRound([chartHeight, 0])
                    .nice();
            }

            colorScale = d3Scale.scaleOrdinal()
                .range(colorSchema)
                .domain(data.map(getGroup));

            categoryColorMap = colorScale
                .domain(data.map(getName)).domain()
                .reduce((memo, item) => {
                    data.forEach(function (v) {
                        if (getName(v) == item) {
                            memo[v.name] = colorScale(v.group)
                            memo[v.group] = colorScale(v.group)
                            memo[v.group + item] = colorScale(v.group)
                        }
                    })
                    return memo;
                }, {});
        }