Adding two tensors
173651
def add(attrs, inputs, proto_obj):
    """"""
    new_attr = {}

    if 'broadcast' in attrs and attrs['broadcast'] == 1:
        broadcast_axis = attrs['axis']
        op_value = translation_utils._fix_broadcast('broadcast_add', inputs,
                                                    broadcast_axis, proto_obj)
        return op_value, new_attr, inputs
    return 'broadcast_add', new_attr, inputs
1181941
def _pad_tensors_to_same_length(x, y):
  """"""
  with tf.name_scope("pad_to_same_length"):
    x_length = tf.shape(x)[1]
    y_length = tf.shape(y)[1]

    max_length = tf.maximum(x_length, y_length)

    x = tf.pad(x, [[0, 0], [0, max_length - x_length], [0, 0]])
    y = tf.pad(y, [[0, 0], [0, max_length - y_length]])
    return x, y
86493
function add(v1, v2) {
    if (!isAVector(v1)) throw new Error("v1 must be a vector.");
    if (!isAVector(v2)) throw new Error("v2 must be a vector.");
    return Vector.zip(v1,v2,(e1, e2) => e1 + e2);
}
910063
def forward_tensor(self, x):
        
        fwd = vec_to_tri(x, self.N)
        return tf.squeeze(fwd, axis=0) if self.squeeze else fwd
77899
def image2np(image:Tensor)->np.ndarray:
    ""
    res = image.cpu().permute(1,2,0).numpy()
    return res[...,0] if res.shape[2]==1 else res
857080
def inner(tensor0: BKTensor, tensor1: BKTensor) -> BKTensor:
    """"""
    N = torch.numel(tensor0[0])
    tensor0_real = tensor0[0].contiguous().view(N)
    tensor0_imag = tensor0[1].contiguous().view(N)
    tensor1_real = tensor1[0].contiguous().view(N)
    tensor1_imag = tensor1[1].contiguous().view(N)

    res = (torch.matmul(tensor0_real, tensor1_real)
           + torch.matmul(tensor0_imag, tensor1_imag),
           torch.matmul(tensor0_real, tensor1_imag)
           - torch.matmul(tensor0_imag, tensor1_real))

    return _DTYPE(res)
915964
private void addMsgs(VarTensor[] msgs, Tensor t, int tf) {
        assert msgs[0].getAlgebra().equals(t.getAlgebra());
        EdgeScores es = EdgeScores.tensorToEdgeScores(t);
        for (VarTensor msg : msgs) {
            LinkVar link = (LinkVar) msg.getVars().get(0);
            double val = es.getScore(link.getParent(), link.getChild());
            msg.addValue(tf, val);
        }
    }
461974
def interpolate(v1, v2, t):
    '''
    '''
    return add(v1, mul(sub(v2, v1), t))
441798
def concatenate(self, tpl, axis=None):
        
        if axis is None:
            raise NotImplementedError(
                'Sparse tensor concatenation without axis argument is not supported'
            )
        T = self
        for i in range(1, len(tpl)):
            T = _single_concatenate(T, tpl[i], axis=axis)
        return T
876640
@Override
    public void backward() {
        Tensor xAdj = modIn.getOutputAdj();
        xAdj.addTensor(yAdj, dim, idx);
    }
310120
def add_vectors(vec_a, vec_b, periodic):
    '''

    '''
    moved = noperiodic(np.array([vec_a, vec_b]), periodic)
    return vec_a + vec_b
249794
def _dist(self, x1, x2):
        """"""
        return self.tspace._dist(x1.tensor, x2.tensor)
455891
function combine(m1, m2) {
  return [
    m1[0]*m2[0] + m1[2]*m2[1],
    m1[1]*m2[0] + m1[3]*m2[1],
    m1[0]*m2[2] + m1[2]*m2[3],
    m1[1]*m2[2] + m1[3]*m2[3],
    m1[0]*m2[4] + m1[2]*m2[5] + m1[4],
    m1[1]*m2[4] + m1[3]*m2[5] + m1[5]
  ];
}
479620
def inner(tensor0: BKTensor, tensor1: BKTensor) -> BKTensor:
    """"""
    # Note: Relying on fact that vdot flattens arrays
    N = rank(tensor0)
    axes = list(range(N))
    return tf.tensordot(tf.math.conj(tensor0), tensor1, axes=(axes, axes))
1134096
def set_tensor_final(self, tensor_name):
    
    tensor = self._name_to_tensor(tensor_name)
    self._final_tensors.add(tensor)
935463
@Override
    public void backward() {
        Tensor xAdj = modIn.getOutputAdj();
        xAdj.add(yAdj.getValue(0));
    }
177497
def _lincomb(self, a, x1, b, x2, out):
        """"""
        self.tspace._lincomb(a, x1.tensor, b, x2.tensor, out.tensor)