Compute x^T * y (dot product)
9859
public static double dot(DoubleMatrix x, DoubleMatrix y) {
		//return NativeBlas.ddot(x.length, x.data, 0, 1, y.data, 0, 1);
		return JavaBlas.rdot(x.length, x.data, 0, 1, y.data, 0, 1);
	}
193884
def generate_ill_conditioned_dot_product(n, c, dps=100):
    
    # Algorithm 6.1 from
    #
    # ACCURATE SUM AND DOT PRODUCT,
    # TAKESHI OGITA, SIEGFRIED M. RUMP, AND SHIN'ICHI OISHI.
    assert n >= 6
    n2 = round(n / 2)
    x = numpy.zeros(n)
    y = numpy.zeros(n)

    b = math.log2(c)
    # vector of exponents between 0 and b/2:
    e = numpy.rint(numpy.random.rand(n2) * b / 2).astype(int)
    # make sure exponents b/2 and 0 actually occur in e
    # vectors x,y
    e[0] = round(b / 2) + 1
    e[-1] = 0

    # generate first half of vectors x, y
    rx, ry = numpy.random.rand(2, n2)
    x[:n2] = (2 * rx - 1) * 2 ** e
    y[:n2] = (2 * ry - 1) * 2 ** e

    def dot_exact(x, y):
        mp.dps = dps
        # convert to list first, see
        # <https://github.com/fredrik-johansson/mpmath/pull/385>
        return mp.fdot(x.tolist(), y.tolist())

    # for i=n2+1:n and v=1:i,
    #     generate x_i, y_i such that (*) x(v)’*y(v) ~ 2^e(i-n2)
    # generate exponents for second half
    e = numpy.rint(numpy.linspace(b / 2, 0, n - n2)).astype(int)
    rx, ry = numpy.random.rand(2, n2)
    for i in range(n2, n):
        # x_i random with generated exponent
        x[i] = (2 * rx[i - n2] - 1) * 2 ** e[i - n2]
        # y_i according to (*)
        y[i] = (
            (2 * ry[i - n2] - 1) * 2 ** e[i - n2] - dot_exact(x[: i + 1], y[: i + 1])
        ) / x[i]

    x, y = numpy.random.permutation((x, y))
    # the true dot product rounded to nearest floating point
    d = dot_exact(x, y)
    # the actual condition number
    C = 2 * dot_exact(abs(x), abs(y)) / abs(d)

    return x, y, d, C
805836
def compute(self, x, y):
        '''
        
        '''
        if x in self.__memo_dict:
            x_v = self.__memo_dict[x]
        else:
            x_v = self.__cost_functionable.compute(self.__params_arr[x, :])
            self.__memo_dict.setdefault(x, x_v)
        if y in self.__memo_dict:
            y_v = self.__memo_dict[y]
        else:
            y_v = self.__cost_functionable.compute(self.__params_arr[y, :])
            self.__memo_dict.setdefault(y, y_v)

        return abs(x_v - y_v)
893171
def outer_product(vec):
    
    """
    return (
        np.dot(vec[:, np.newaxis], vec[np.newaxis, :])
        if len(vec.shape) == 1 else
        np.dot(vec, vec.T)
        )
189750
def dot(v1, v2):
    '''
    '''
    x1, y1, z1 = v1
    x2, y2, z2 = v2
    return x1 * x2 + y1 * y2 + z1 * z2
1007463
def matmul_adjoint_y(dz, x, y, transpose_a, transpose_b):
  """"""
  if not transpose_a and not transpose_b:
    return tf.matmul(x, dz, transpose_a=True)
  elif not transpose_a and transpose_b:
    return tf.matmul(dz, x, transpose_a=True)
  elif transpose_a and not transpose_b:
    return tf.matmul(x, dz)
  else:  # transpose_a and transpose_b
    return tf.matmul(dz, x, transpose_a=True, transpose_b=True)
363199
def obfn_g(self, Y):
        
        """

        return self.obfn_g0(self.obfn_g0var()) + \
            self.obfn_g1(self.obfn_g1var())
724236
def eval_grad(self):
        """"""

        # Compute D^T(D Y - S)
        return self.D.T.dot(self.D.dot(self.Y) - self.S)
81410
function(x, y) {

    var r = {};

    var i = degree(x);
    var j = degree(y);
    var trace = [];

    while (i >= j) {

      var tmp = r[i - j] = FIELD['div'](x[i] || 0, y[j] || 0);

      for (var k in y) {
        x[+k + i - j] = FIELD['sub'](x[+k + i - j] || 0, FIELD['mul'](y[k] || 0, tmp));
      }

      if (Polynomial['trace'] !== null) {

        var tr = {};
        for (var k in y) {
          tr[+k + i - j] = FIELD['mul'](y[k] || 0, tmp);
        }
        trace.push(new Polynomial(tr));
      }

      i = degree(x);
    }

    // Add rest
    if (Polynomial['trace'] !== null) {
      trace.push(new Polynomial(x));
      Polynomial['trace'] = trace;
    }
    return r;
  }
1316091
private static double dotProduct(DoubleVector u,
                                     DoubleVector v) {
        double dot = 0;
        for (int i = 0; i < u.length(); ++i) {
            double a = u.get(i);
            double b = v.get(i);
            dot += u.get(i) * v.get(i);
        }
        return dot;
    }
282277
def _compute(self):
        """"""
        if self.xvals:
            if self.xrange:
                x_adapter = reduce(compose, self._x_adapters) if getattr(
                    self, '_x_adapters', None
                ) else ident

                xmin = x_adapter(self.xrange[0])
                xmax = x_adapter(self.xrange[1])

            else:
                xmin = min(self.xvals)
                xmax = max(self.xvals)
            xrng = (xmax - xmin)
        else:
            xrng = None

        if self.yvals:
            ymin = self._min
            ymax = self._max

            if self.include_x_axis:
                ymin = min(ymin or 0, 0)
                ymax = max(ymax or 0, 0)

            yrng = (ymax - ymin)
        else:
            yrng = None

        for serie in self.all_series:
            serie.points = serie.values
            if self.interpolate:
                vals = list(
                    zip(
                        *sorted(
                            filter(lambda t: None not in t, serie.points),
                            key=lambda x: x[0]
                        )
                    )
                )
                serie.interpolated = self._interpolate(vals[0], vals[1])

        if self.interpolate:
            self.xvals = [
                val[0] for serie in self.all_series
                for val in serie.interpolated
            ]
            self.yvals = [
                val[1] for serie in self.series for val in serie.interpolated
            ]
            if self.xvals:
                xmin = min(self.xvals)
                xmax = max(self.xvals)
                xrng = (xmax - xmin)
            else:
                xrng = None

        # these values can also be 0 (zero), so testing explicitly for None
        if xrng is not None:
            self._box.xmin, self._box.xmax = xmin, xmax

        if yrng is not None:
            self._box.ymin, self._box.ymax = ymin, ymax
1097008
def _ttm_me_compute(self, V, edims, sdims, transp):
        
        shapeY = np.copy(self.shape)

        # Determine size of Y
        for n in np.union1d(edims, sdims):
            shapeY[n] = V[n].shape[1] if transp else V[n].shape[0]

        # Allocate Y (final result) and v (vectors for elementwise computations)
        Y = zeros(shapeY)
        shapeY = array(shapeY)
        v = [None for _ in range(len(edims))]

        for i in range(np.prod(shapeY[edims])):
            rsubs = unravel_index(shapeY[edims], i)
882826
def _call(self, x):
        """"""
        if isinstance(self.domain, ProductSpace):
            norm = PointwiseNorm(self.domain, 2)(x)
        else:
            norm = x.ufuncs.absolute()

        if self.gamma > 0:
            tmp = norm.ufuncs.square()
            tmp *= 1 / (2 * self.gamma)

            index = norm.ufuncs.greater_equal(self.gamma)
            tmp[index] = norm[index] - self.gamma / 2
        else:
            tmp = norm

        return tmp.inner(tmp.space.one())
327056
def _compute(self):
        """"""
        if self.xvals:
            xmin = min(self.xvals)
            xmax = max(self.xvals)
            xrng = (xmax - xmin)
        else:
            xrng = None

        if self.yvals:
            ymin = min(min(self.yvals), self.zero)
            ymax = max(max(self.yvals), self.zero)
            yrng = (ymax - ymin)
        else:
            yrng = None

        for serie in self.all_series:
            serie.points = serie.values

        if xrng:
            self._box.xmin, self._box.xmax = xmin, xmax
        if yrng:
            self._box.ymin, self._box.ymax = ymin, ymax

        if self.range and self.range[0] is not None:
            self._box.ymin = self.range[0]

        if self.range and self.range[1] is not None:
            self._box.ymax = self.range[1]
432145
def _compute_prediction(self,X):
        
        A_pred = np.dot(X,self._Bhat)
        Y_pred = self._basis_object.inverse_transform(A_pred)
        return Y_pred
1131832
def TP0(dv, u):
    ''''''
    return np.linalg.norm(np.array(dv)) + np.linalg.norm(np.array(u))
553683
def calc_A(Ys):
    ''''''
    return sum(np.dot(np.reshape(Y, (3,1)), np.reshape(Y, (1, 3)))
            for Y in Ys)