Calculate's a given elastic tensor's contribution to the
        stress using Einstein summation

        Args:
            strain (3x3 array-like): matrix corresponding to strain
321457
def calculate_stress(self, strain):
        
        strain = np.array(strain)
        if strain.shape == (6,):
            strain = Strain.from_voigt(strain)
        assert strain.shape == (3, 3), "Strain must be 3x3 or voigt-notation"
        stress_matrix = self.einsum_sequence([strain]*(self.order - 1)) \
                / factorial(self.order - 1)
        return Stress(stress_matrix)
503280
def _calc_mod_reduc(self, strains, strain_ref, x_1, x_1_mean, x_2,
                        x_2_mean, x_3, x_3_mean):
        """"""

        ones = np.ones_like(strains)
        # Predictor
        x_4 = np.log(self._lab_consol_ratio) * ones
        x = np.c_[ones, x_1, x_2, x_3, x_4, (x_1 - x_1_mean) * (
            x_2 - x_2_mean), (x_1 - x_1_mean) * (x_3 - x_3_mean), (
                x_2 - x_2_mean) * (x_3 - x_3_mean), (x_1 - x_1_mean) * (
                    x_2 - x_2_mean) * (x_3 - x_3_mean)]
        # Coefficients
        denom = np.log(1 / strain_ref + strains / strain_ref)  # TODO: is this percent or decimal?
        b = np.c_[5.11 * ones, -0.729 * ones, (1 - 0.37 * x_3_mean * (1 + ((
            np.log(strain_ref) - x_1_mean) / denom))), -0.693 * ones, 0.8 - 0.4
                  * x_3, 0.37 * x_3_mean / denom, 0.0 * ones, -0.37 * (1 + (
                      np.log(strain_ref) - x_1_mean) / denom), 0.37 / denom, ]
        ln_shear_mod = (b * x).sum(axis=1)
        shear_mod = np.exp(ln_shear_mod)
        mod_reduc = shear_mod / shear_mod[0]
        return mod_reduc
914764
public void setTensor( TrifocalTensor tensor ) {
		this.tensor = tensor;
		if( !svd.decompose(tensor.T1) )
			throw new RuntimeException("SVD failed?!");

		SingularOps_DDRM.nullVector(svd, true, v1);
		SingularOps_DDRM.nullVector(svd, false,u1);

//		DMatrixRMaj zero = new DMatrixRMaj(3,1);
//		CommonOps_DDRM.mult(tensor.T1,v1,zero);zero.print();
//		CommonOps_DDRM.multTransA(u1,tensor.T1,zero);zero.print();

		if( !svd.decompose(tensor.T2) )
			throw new RuntimeException("SVD failed?!");
		SingularOps_DDRM.nullVector(svd,true,v2);
		SingularOps_DDRM.nullVector(svd,false,u2);
//		CommonOps_DDRM.mult(tensor.T2,v2,zero);zero.print();
//		CommonOps_DDRM.multTransA(u2,tensor.T2,zero);zero.print();

		if( !svd.decompose(tensor.T3) )
			throw new RuntimeException("SVD failed?!");
		SingularOps_DDRM.nullVector(svd,true,v3);
		SingularOps_DDRM.nullVector(svd,false,u3);
//		CommonOps_DDRM.mult(tensor.T3,v3,zero);zero.print();
//		CommonOps_DDRM.multTransA(u3,tensor.T3,zero);zero.print();

		for( int i = 0; i < 3; i++ ) {
			U.set(i,0,u1.get(i));
			U.set(i,1,u2.get(i));
			U.set(i,2,u3.get(i));

			V.set(i, 0, v1.get(i));
			V.set(i, 1, v2.get(i));
			V.set(i, 2, v3.get(i));
		}

		svd.decompose(U);
		SingularOps_DDRM.nullVector(svd, false, tempE);
		e2.set(tempE.get(0), tempE.get(1), tempE.get(2));

		svd.decompose(V);
		SingularOps_DDRM.nullVector(svd, false, tempE);
		e3.set(tempE.get(0), tempE.get(1), tempE.get(2));
	}
1080956
def _sumindex(self, index=None):
        """"""
        try:
            ndim = len(index)
        except TypeError:
            # turn index into a 1-tuple
            index = (index,)
            ndim = 1
        if len(self.shape) != ndim:
            raise ValueError("Index to %d-dimensional array %s has too %s dimensions" %
                (len(self.shape), self.name, ["many","few"][len(self.shape) > ndim]))
        sumindex = 0
        for i in range(ndim-1,-1,-1):
            index1 = index[i]
            if index1 < 0 or index1 >= self.shape[i]:
                raise ValueError("Dimension %d index for array %s is out of bounds (value=%d)" %
                    (i+1, self.name, index1))
            sumindex = index1 + sumindex*self.shape[i]
        return sumindex
1178318
def derivativeX(self,*args):
        '''
        
        '''
        if self.n_dims >= 4:
            j = 1
        else:
            j = 0
        if self.i_dim == j:
            return np.ones_like(*args[0])
        else:
            return np.zeros_like(*args[0])
992216
def calculate_flatten_output_shapes(operator):
    '''
    
    '''
    check_input_and_output_numbers(operator, input_count_range=1, output_count_range=1)
    check_input_and_output_types(operator, good_input_types=[FloatTensorType])

    input = operator.inputs[0]
    output = operator.outputs[0]

    if len(input.type.shape) not in [2, 4]:
        raise RuntimeError('Input must be 2-D or 4-D float tensor')

    input_shape = input.type.shape
    output_shape = [input_shape[0], 1]

    # Calculate the multiplication of C, H, and W.
    for i in input_shape[1:]:
        if i != 'None':
            output_shape[1] *= i
        else:
            # If any of C, H, W-dimensions is unknown, the flatten C-dimension is unknown
            output_shape[1] = 'None'
            break

    output.type.shape = output_shape
494567
def sg_log(tensor, opt):
    
    """
    return tf.log(tensor + tf.sg_eps, name=opt.name)
1285746
def sum(x, weights=None):
    '''
    
    '''
    x = to_potential(x)
    if is_const_potential(x): return PotentialConstant(np.sum(x.c))
    else:                     return PotentialSum(x, weights=weights)
1109909
function computeDimension(topLeft, topRight, bottomLeft, matrix) {
        const moduleSize = (sum(countBlackWhiteRun(topLeft, bottomLeft, matrix, 5)) / 7 + // Divide by 7 since the ratio is 1:1:3:1:1
            sum(countBlackWhiteRun(topLeft, topRight, matrix, 5)) / 7 +
            sum(countBlackWhiteRun(bottomLeft, topLeft, matrix, 5)) / 7 +
            sum(countBlackWhiteRun(topRight, topLeft, matrix, 5)) / 7) / 4;
        if (moduleSize < 1) {
            throw new Error("Invalid module size");
        }
        const topDimension = Math.round(distance(topLeft, topRight) / moduleSize);
        const sideDimension = Math.round(distance(topLeft, bottomLeft) / moduleSize);
        let dimension = Math.floor((topDimension + sideDimension) / 2) + 7;
        switch (dimension % 4) {
            case 0:
                dimension++;
                break;
            case 2:
                dimension--;
                break;
        }
        return { dimension, moduleSize };
    }
1113302
function(a, b, r1, r2, k1, k2)
{
    // calculate mass matrix
    // If I wasn't lazy and wrote a proper matrix class, this wouldn't be so gross...
    var k11, k12, k21, k22;
    var m_sum = a.m_inv + b.m_inv;
    
    // start with I*m_sum
    k11 = m_sum; k12 = 0;
    k21 = 0;     k22 = m_sum;
    
    // add the influence from r1
    var a_i_inv = a.i_inv;
    var r1xsq =  r1.x * r1.x * a_i_inv;
    var r1ysq =  r1.y * r1.y * a_i_inv;
    var r1nxy = -r1.x * r1.y * a_i_inv;
    k11 += r1ysq; k12 += r1nxy;
    k21 += r1nxy; k22 += r1xsq;
    
    // add the influnce from r2
    var b_i_inv = b.i_inv;
    var r2xsq =  r2.x * r2.x * b_i_inv;
    var r2ysq =  r2.y * r2.y * b_i_inv;
    var r2nxy = -r2.x * r2.y * b_i_inv;
    k11 += r2ysq; k12 += r2nxy;
    k21 += r2nxy; k22 += r2xsq;
    
    // invert
    var determinant = k11*k22 - k12*k21;
    assertSoft(determinant !== 0, "Unsolvable constraint.");
    
    var det_inv = 1/determinant;

    k1.x =  k22*det_inv; k1.y = -k12*det_inv;
    k2.x = -k21*det_inv; k2.y =  k11*det_inv;
}
866630
def strain_in_plane(self, **kwargs):
        '''
        
        '''
        if self._strain_out_of_plane is not None:
            return ((self._strain_out_of_plane / -2.) *
                    (self.unstrained.c11(**kwargs) /
                     self.unstrained.c12(**kwargs)  )  )
        else:
            return 1 - self.unstrained.a(**kwargs) / self.substrate.a(**kwargs)
82162
def von_mises_strain(self):
        
        eps = self - 1/3 * np.trace(self) * np.identity(3)

        return np.sqrt(np.sum(eps * eps) * 2/3)
1167095
def g_reuss(self):
        
        return 15. / (8. * self.compliance_tensor.voigt[:3, :3].trace() -
                      4. * np.triu(self.compliance_tensor.voigt[:3, :3]).sum() +
                      3. * self.compliance_tensor.voigt[3:, 3:].trace())
324750
def eigendecompose(tensor, normalise=False):
    '''
    
    '''
    if normalise:
        tensor, tensor_norm = normalise_tensor(tensor)
    else:
        tensor_norm = 1.

    eigvals, eigvects = np.linalg.eigh(tensor, UPLO='U')

    isrt = np.argsort(eigvals)
    eigenvalues = eigvals[isrt] * tensor_norm
    eigenvectors = eigvects[:, isrt]
    return eigenvalues, eigenvectors
589311
def cnst_AT(self, X):
        
        """

        Xf = sl.rfftn(X, axes=self.axes)
        return np.sum(sl.irfftn(np.conj(self.GAf)*Xf, self.axsz,
                                axes=self.axes), axis=self.Y.ndim-1)
857844
def energy_density(self, strain, convert_GPa_to_eV=True):
        
        e_density = np.sum(self.calculate_stress(strain)*strain) / self.order
        if convert_GPa_to_eV:
            e_density *= self.GPa_to_eV_A3  # Conversion factor for GPa to eV/A^3
        return e_density
897271
def get_averaged_interaction(self):
        

        # v[triplet, band0, band, band]
        v = self._interaction_strength
        w = self._weights_at_q
        v_sum = np.dot(w, v.sum(axis=2).sum(axis=2))
        return v_sum / np.prod(v.shape[2:])