[Input]
  _rsh_ should be Quat.
 [Output]
  return (outer products) multiplyed result as Quat.
760351
def *(rhs)
      Util3D.check_arg_type(Quat, rhs)

      pw = self.w; px = self.x; py = self.y; pz = self.z;
      qw = rhs.w ; qx = rhs.x ; qy = rhs.y ; qz = rhs.z;

      w = pw * qw - px * qx - py * qy - pz * qz
      x = pw * qx + px * qw + py * qz - pz * qy
      y = pw * qy - px * qz + py * qw + pz * qx
      z = pw * qz + px * qy - py * qx + pz * qw
      return Quat.new( x,y,z,w )
    end
866529
def dBinaryRochedy (r, D, q, F):
    
    return -r[1]*(r[0]*r[0]+r[1]*r[1]+r[2]*r[2])**-1.5 -q*r[1]*((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])**-1.5 + F*F*(1+q)*r[1]
150190
def conjugate(self):
        
        qr_c_xyzw = quaternion_conjugate(self._qr)
        qd_c_xyzw = quaternion_conjugate(self._qd)

        qr_c_wxyz = np.roll(qr_c_xyzw, 1)
        qd_c_wxyz = np.roll(qd_c_xyzw, 1)
        return DualQuaternion(qr_c_wxyz, qd_c_wxyz)
954059
def quat_rotate(rotation, vector):
    

    def quat_mult_point(q, w):
        return (q[3] * w[0] + q[1] * w[2] - q[2] * w[1],
                q[3] * w[1] + q[2] * w[0] - q[0] * w[2],
                q[3] * w[2] + q[0] * w[1] - q[1] * w[0],
                -q[0] * w[0] - q[1] * w[1] - q[2] * w[2])

    q = quat_mult_point(rotation, vector)
    q = tf.transformations.quaternion_multiply(
        q, tf.transformations.quaternion_inverse(rotation))
    return [q[0], q[1], q[2]]
1344686
def rshift_logical(self, shift_amount):
        

        lower, upper = self._pre_shift(shift_amount)

        # Shift the lower_bound and upper_bound by all possible amounts, and union all possible results

        ret = None

        for amount in xrange(lower, upper + 1):
            si_ = self._rshift_logical(amount)

            ret = si_ if ret is None else ret.union(si_)

        ret.normalize()
        ret.uninitialized = self.uninitialized
        return ret
116093
public Quaternionf nlerp(Quaternionfc q, float factor, Quaternionf dest) {
        float cosom = x * q.x() + y * q.y() + z * q.z() + w * q.w();
        float scale0 = 1.0f - factor;
        float scale1 = (cosom >= 0.0f) ? factor : -factor;
        dest.x = scale0 * x + scale1 * q.x();
        dest.y = scale0 * y + scale1 * q.y();
        dest.z = scale0 * z + scale1 * q.z();
        dest.w = scale0 * w + scale1 * q.w();
        float s = (float) (1.0 / Math.sqrt(dest.x * dest.x + dest.y * dest.y + dest.z * dest.z + dest.w * dest.w));
        dest.x *= s;
        dest.y *= s;
        dest.z *= s;
        dest.w *= s;
        return dest;
    }
675228
def quaternion_rotation(quat, vector):
    
    dp = np.dot(quat[1:], vector)
    cos = (2*quat[0]*quat[0] - 1)
    return np.array([
        2 * (quat[0] * (quat[2] * vector[2] - quat[3] * vector[1]) + quat[1] * dp) + cos * vector[0],
        2 * (quat[0] * (quat[3] * vector[0] - quat[1] * vector[2]) + quat[2] * dp) + cos * vector[1],
        2 * (quat[0] * (quat[1] * vector[1] - quat[2] * vector[0]) + quat[3] * dp) + cos * vector[2]
    ], float)
89504
def makeQ(r1, r2, r3, r4=0):
    
    Q = np.asarray([
        [r4, -r3, r2, r1],
        [r3, r4, -r1, r2],
        [-r2, r1, r4, r3],
        [-r1, -r2, -r3, r4]])
    return Q
1312443
def quaternion_transform(r):
    
    Wt_r = makeW(*r).T
    Q_r = makeQ(*r)
    rot = Wt_r.dot(Q_r)[:3, :3]
    return rot
173135
function hsl2rgb(h, m1, m2) {
  return (h < 60 ? m1 + (m2 - m1) * h / 60 : h < 180 ? m2 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 : m1) * 255;
}
190776
def nlerp_quat(from_quat, to_quat, percent):
    

    result = lerp_quat(from_quat, to_quat, percent)
    result.normalize()
    return result
956605
def isqrt(n):
    ''' 
    '''
    # TODO: replace with a more efficient implementation

    if n == 0:
        return n, 1
    if n < 0:
        raise ValueError('math domain error')

    a, b, c = 1, n, 1

    def divisors():
        yield 2
        yield 3
        k = 5
        while k * k <= b:
            yield k
            k += 2
            yield k
            k += 4
            
    for k in divisors():
        d, m = divmod(b, k * k)
        while m == 0:
            a *= k
            b = d
            d, m = divmod(b, k * k)
        if b % k == 0:
            b //= k
            c *= k

        k += 1
    return a, b*c
415596
function ptsub(q, n) {
        var eps;

        if (n === 1 && q > 0.001 && q < 0.01) {
            eps = 1.0e-4;
        } else if (n === 2 && q < 0.0001) {
            eps = 1.0e-4;
        } else if (n === 1 && q < 0.001) {
            eps = 1.0e-2;
        } else {
            eps = 1.0e-5;
        }

        s = 10000.0;
        w = 0.0;
        while (true) {
            w = w + s;

            if (s <= eps) { return w; }
            if ((qe = 2.0 - p_t(n, w) * 2.0 - q) === 0.0) { return w; }
            if (qe < 0.0) {
                w = w - s;
                s = s / 10.0;
            }
        }
    }
728280
def multiplyQuats(q1, q2):
    """"""
    return np.array([
            q1[0]*q2[0] - q1[1]*q2[1] - q1[2]*q2[2] - q1[3]*q2[3],
            q1[2]*q2[3] - q2[2]*q1[3] + q1[0]*q2[1] + q2[0]*q1[1],
            q1[3]*q2[1] - q2[3]*q1[1] + q1[0]*q2[2] + q2[0]*q1[2],
            q1[1]*q2[2] - q2[1]*q1[2] + q1[0]*q2[3] + q2[0]*q1[3]])
771954
def _f_A20(self, r_a, r_s):
        
        return r_a/(1+np.sqrt(1 + r_a**2)) - r_s/(1+np.sqrt(1 + r_s**2))
13506
def collective_dr_squared( self ):
        
        return sum( np.square( sum( [ atom.dr for atom in self.atoms ] ) ) )
903738
def rmatrixquaternion(q):
    
    assert np.allclose(math.sqrt(np.dot(q,q)), 1.0)

    x, y, z, w = q

    xx = x*x
    xy = x*y
    xz = x*z
    xw = x*w
    yy = y*y
    yz = y*z
    yw = y*w
    zz = z*z
    zw = z*w

    r00 = 1.0 - 2.0 * (yy + zz)
    r01 =       2.0 * (xy - zw)
    r02 =       2.0 * (xz + yw)

    r10 =       2.0 * (xy + zw)
    r11 = 1.0 - 2.0 * (xx + zz)
    r12 =       2.0 * (yz - xw)

    r20 =       2.0 * (xz - yw)
    r21 =       2.0 * (yz + xw)
    r22 = 1.0 - 2.0 * (xx + yy)

    R = np.array([[r00, r01, r02],
               [r10, r11, r12],
               [r20, r21, r22]], float)

    assert np.allclose(np.linalg.det(R), 1.0)
    return R