Determine if another `Vec2`'s components match this one's also accepts 2 scalars
505842
function(v, w) {
      if (w === undef) {
        w = v.y;
        v = v.x;
      }

      return (Vec2.clean(v) === this.x && Vec2.clean(w) === this.y);
    }
1256457
def ave_list_v3(vec_list):
    """"""

    vec = Vec3(0, 0, 0)
    for v in vec_list:
        vec += v
    num_vecs = float(len(vec_list))
    vec = Vec3(vec.x / num_vecs, vec.y / num_vecs, vec.z / num_vecs)
    return vec
1108755
def cosine_similarity_vec(num_tokens, num_removed_vec):
    
    remaining = -np.array(num_removed_vec) + num_tokens
    return remaining / (np.sqrt(num_tokens + 1e-6) * np.sqrt(remaining + 1e-6))
1127369
def vector_projection(v1, v2):
    '''
    '''
    return scalar_projection(v1, v2) * v2 / np.linalg.norm(v2)
699991
@Override
    public double dot(Vec v)
    {
        if(v instanceof  ShiftedVec)
        {
            ShiftedVec other = (ShiftedVec) v;
            return this.base.dot(other.base) + other.base.sum()*this.shift + this.base.sum()*other.shift + this.length()*this.shift*other.shift;
        }
        return base.dot(v) + v.sum()*shift;
    }
1093652
def component_div(vec1, vec2):
        """"""
        new_vec = Vector2()
        new_vec.X = vec1.X / vec2.X
        new_vec.Y = vec1.Y / vec2.Y
        return new_vec
1075607
public static float[] vMad(float[] v1, float[] v2, float s) {
        float[] dest = new float[3];
        dest[0] = v1[0] + v2[0] * s;
        dest[1] = v1[1] + v2[1] * s;
        dest[2] = v1[2] + v2[2] * s;
        return dest;
    }
444497
def cross(r1, r2):
    
    if r1.size != r2.size:
        raise ValueError("Both arguments must have the same input size.")
    if r1.deriv != r2.deriv:
        raise ValueError("Both arguments must have the same deriv.")
    result = Vector3(r1.size, r1.deriv)
    result.x = r1.y*r2.z - r1.z*r2.y
    result.y = r1.z*r2.x - r1.x*r2.z
    result.z = r1.x*r2.y - r1.y*r2.x
    return result
602784
def scalar_projection(v1, v2):
    '''
    '''
    return np.dot(v1, v2) / np.linalg.norm(v2)
928336
def scale_v2(vec, amount):
    """"""

    return Vec2(vec.x * amount, vec.y * amount)
5148
def _trivial_mult(A, B):
    
    if len(B) == 1:
        A, B = B, A  # so that we can reuse the code below :)
    if len(A) == 1:
        a_vals = A.sign_extended(len(B))

        # keep the wirevector len consistent
        return pyrtl.concat_list([a_vals & B, pyrtl.Const(0)])
818419
def matched(self, other):
        
        mods = ["allocatable", "pointer"]
        return (self.kind.lower() == other.kind.lower() and
                self.dtype.lower() == other.dtype.lower() and
                self.D == other.D and
                all([m in other.modifiers for m in self.modifiers if m in mods]))
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)
        )
635430
def dot(a, b):
    """
    if isinstance(a, Mul):
        a = a.expand()
        avect = 1
        aivect = -1
        for ai, fact in enumerate(a.args):
            if isinstance(fact, Vector3D):
                avect = fact
                aivect = ai
                break

        acoef = a.args[:aivect] + a.args[aivect+1:]
        acoef = Mul(*acoef)
        return acoef*dot(avect, b)

    if isinstance(b, Mul):
        b = b.expand()
        bvect = 1
        bivect = -1
        for bi, fact in enumerate(b.args):
            if isinstance(fact, Vector3D):
                bvect = fact
                bivect = bi
                break

        bcoef = b.args[:bivect] + b.args[bivect+1:]
        bcoef = Mul(*bcoef)
        return bcoef*dot(a, bvect)

    if isinstance(a, Vector3D) and isinstance(b, Vector3D):
        return DotProduct(a, b)

    if hasattr(a, "shape") and hasattr(b, "shape"):
        return cartesian_dot_product(a, b)

    print a, b, type(a), type(b),
    print isinstance(a, Vector3D), isinstance(b, Vector3D)
    raise NotImplementedError("could not catch these instances in dot!")
1035571
def splay(vec):
    
    N2 = 2 ** int(numpy.log2( len(vec) ) / 2)
    N1 = len(vec) / N2
    return N1, N2
310120
def add_vectors(vec_a, vec_b, periodic):
    '''

    '''
    moved = noperiodic(np.array([vec_a, vec_b]), periodic)
    return vec_a + vec_b
429762
def *(other)
      case other
      when Mat3    then mul_mat3(other)
      when Vec3    then mul_vec3(other)
      when Numeric then mul_scalar(other)
      else raise ArgumentError, "Don't know how to multiply Mat3 with object: #{other.inspect}"
      end
    end