Ejemplo n.º 1
0
    def _pinv_multithread(self, matrices):
        inv_matrices = []
        try:
            import anharmonic._forcefit as forcefit

            multi = len(matrices)
            row_nums = np.array([m.shape[0] for m in matrices], dtype='intc')
            info = np.zeros(len(row_nums), dtype='intc')
            max_row_num = max(row_nums)
            column_num = matrices[0].shape[1]
            mats_in = np.zeros((multi, max_row_num * column_num),
                               dtype='double')
            for i in range(multi):
                mats_in[i, :row_nums[i] * column_num] = matrices[i].flatten()
            mats_out = np.zeros_like(mats_in)
            forcefit.pinv_mt(mats_in, mats_out, row_nums, max_row_num,
                             column_num, self._pinv_cutoff, info)
            inv_matrices = [
                mats_out[i, :row_nums[i] * column_num].reshape(column_num, -1)
                for i in range(multi)
            ]
        except ImportError:
            for mat in matrices:
                inv_mat = np.linalg.pinv(mat)
                inv_matrices.append(inv_mat)
        return inv_matrices
Ejemplo n.º 2
0
    def _invert_displacements(self, rot_disps_set):
        try:
            import anharmonic._forcefit as forcefit
            row_nums = np.array([x.shape[0] for x in rot_disps_set],
                                dtype='intc')
            info = np.zeros(len(row_nums), dtype='intc')
            max_row_num = max(row_nums)
            column_num = rot_disps_set[0].shape[1]
            rot_disps = np.zeros((self._num_atom, max_row_num * column_num),
                                 dtype='double')
            for i in range(self._num_atom):
                rot_disps[i, :row_nums[i] *
                          column_num] = rot_disps_set[i].flatten()
            inv_disps = np.zeros_like(rot_disps)
            forcefit.pinv_mt(rot_disps, inv_disps, row_nums, max_row_num,
                             column_num, 1e-13, info)
            inv_disps_set = [
                inv_disps[i, :row_nums[i] * column_num].reshape(
                    column_num, -1) for i in range(self._num_atom)
            ]

        except ImportError:
            inv_disps_set = [np.linalg.pinv(d) for d in rot_disps_set]

        return inv_disps_set
Ejemplo n.º 3
0
    def _pinv_multithread(self, matrices):
        inv_matrices = []
        try:
            import anharmonic._forcefit as forcefit

            multi = len(matrices)
            row_nums = np.intc([m.shape[0] for m in matrices])
            info = np.zeros(len(row_nums), dtype='intc')
            max_row_num = max(row_nums)
            column_num = matrices[0].shape[1]
            mats_in = np.zeros((multi, max_row_num * column_num),
                               dtype='double')
            for i in range(multi):
                mats_in[i, :row_nums[i] * column_num] = matrices[i].flatten()
            mats_out = np.zeros_like(mats_in)
            forcefit.pinv_mt(mats_in,
                             mats_out,
                             row_nums,
                             max_row_num,
                             column_num,
                             self._pinv_cutoff,
                             info)
            inv_matrices = [
                mats_out[i, :row_nums[i] * column_num].reshape(column_num, -1)
                for i in range(multi)]
        except ImportError:
            for mat in matrices:
                inv_mat = np.linalg.pinv(mat)
                inv_matrices.append(inv_mat)
        return inv_matrices
Ejemplo n.º 4
0
 def _invert_displacements(self, rot_disps_set):
     try:
         import anharmonic._forcefit as forcefit
         row_nums = np.array([x.shape[0] for x in rot_disps_set],
                             dtype='intc')
         info = np.zeros(len(row_nums), dtype='intc')
         max_row_num = max(row_nums)
         column_num = rot_disps_set[0].shape[1]
         rot_disps = np.zeros((self._num_atom, max_row_num * column_num),
                              dtype='double')
         for i in range(self._num_atom):
             rot_disps[
                 i, :row_nums[i] * column_num] = rot_disps_set[i].flatten()
         inv_disps = np.zeros_like(rot_disps)
         forcefit.pinv_mt(rot_disps,
                          inv_disps,
                          row_nums,
                          max_row_num,
                          column_num,
                          1e-13,
                          info)
         inv_disps_set = [
             inv_disps[i, :row_nums[i] * column_num].reshape(column_num, -1)
             for i in range(self._num_atom)]
         
     except ImportError:
         inv_disps_set = [np.linalg.pinv(d) for d in rot_disps_set]
         
     return inv_disps_set