symmetrization.h 5.13 KB
Newer Older
1 2 3 4 5
#ifndef __INT_SYMMETRIZATION_H__
#define __INT_SYMMETRIZATION_H__

#include "assert.h"
#include "../tensor/untyped_tensor.h"
6 7
#include "../summation/summation.h"
#include "../contraction/contraction.h"
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

namespace CTF_int {
  /**
   * \brief unfolds the data of a tensor
   * \param[in] sym_tsr starting symmetric tensor (where data starts)
   * \param[in] nonsym_tsr new tensor with a potentially unfolded symmetry
   * \param[in] is_C whether the tensor is an output of the operation
   */
  void desymmetrize(tensor * sym_tsr,
                    tensor * nonsym_tsr,
                    bool is_C);

  /**
   * \brief folds the data of a tensor
   * \param[in] sym_tsr starting symmetric tensor (where data ends)
   * \param[in] nonsym_tsr new tensor with a potentially unfolded symmetry
   */
  void symmetrize(tensor * sym_tsr,
                  tensor * nonsym_tsr);

  /**
   * \brief finds all permutations of a tensor according to a symmetry
   *
   * \param[in] ndim dimension of tensor
   * \param[in] sym symmetry specification of tensor
   * \param[out] nperm number of symmeitrc permutations to do
   * \param[out] perm the permutation
   * \param[out] sign sign of each permutation
   */
  void cmp_sym_perms(int          ndim,
                     int const *  sym,
                     int *        nperm,
                     int **       perm,
41
                     double *     sign);
42 43 44 45 46 47 48 49 50 51 52 53 54 55

  /**
   * \brief orders the summation indices of one tensor 
   *        that don't break summation symmetries
   *
   * \param[in,out] sum summation data (tensors and maps)
   * \param[in] idx_arr inverted summation index map
   * \param[in] off_A offset of A in inverted index map
   * \param[in] off_B offset of B in inverted index map
   * \param[in,out] add_sign sign of contraction
   * \param[in,out] mod 1 if permutation done
   */
  void order_perm(summation const & sum,
                                      int *                 idx_arr,
56 57
                                      int              off_A,
                                      int              off_B,
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
                                      int &               add_sign,
                                      int &                 mod);

  /**
   * \brief orders the contraction indices of one tensor 
   *        that don't break contraction symmetries
   *
   * \param[in,out] ctr contraction object with tensors and index maps
   * \param[in] idx_arr inverted contraction index map
   * \param[in] off_A offset of A in inverted index map
   * \param[in] off_B offset of B in inverted index map
   * \param[in] off_C offset of C in inverted index map
   * \param[in,out] add_sign sign of contraction
   * \param[in,out] mod 1 if permutation done
   */
  void order_perm(contraction & ctr,
                  int *                 idx_arr,
                  int             off_A,
                  int             off_B,
                  int             off_C,
                  int &               add_sign,
                  int &                 mod);


  /**
   * \brief puts a summation map into a nice ordering according to preserved
   *        symmetries, and adds it if it is distinct
   *
   * \param[in,out] perms the permuted summation specifications
   * \param[in,out] signs sign of each summation
   * \param[in] new_perm summation signature
   * \param[in] new_sign alpha
   */
  void add_sym_perm(std::vector<summation>&    perms,
                                        std::vector<int>&             signs, 
                                        summation const &          new_perm,
                                        int                     new_sign);

  /**
   * \brief puts a contraction map into a nice ordering according to preserved
   *        symmetries, and adds it if it is distinct
   *
   * \param[in,out] perms the permuted contraction specifications
   * \param[in,out] signs sign of each contraction
   * \param[in] new_perm contraction signature
   * \param[in] new_sign alpha
   */
  void add_sym_perm(std::vector<contraction>&    perms,
                                        std::vector<int>&             signs, 
                                        contraction const &          new_perm,
                                        int                     new_sign);




  /**
   * \brief finds all permutations of asummation 
   *        that must be done for a broken symmetry
   *
   * \param[in] sum summation specification
   * \param[out] perms the permuted summation specifications
   * \param[out] signs sign of each summation
   */
  void get_sym_perms(summation const & sum,
122 123
                               std::vector<summation>&     perms,
                               std::vector<int>&              signs);
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

  /**
   * \brief finds all permutations of acontraction 
   *        that must be done for a broken symmetry
   *
   * \param[in] type contraction specification
   * \param[in] alpha sign of contraction specification
   * \param[out] perms the permuted contraction specifications
   * \param[out] signs sign of each contraction
   */
  void get_sym_perms(summation const & tsum,
                     std::vector<summation>&     perms,
                     std::vector<int>&              signs);



}
#endif