14 if (order == 0)
return 1;
20 for (i = 0;i < order;i++){
29 if (i < order - 1) mp = len[i + 1];
38 int64_t
packed_size(
const int order,
const int* len,
const int* sym){
43 if (order == 0)
return 1;
52 for (i = 0;i < order;i++){
64 if (i < order - 1) mp = len[i + 1];
77 int64_t idx_rem = idx;
78 memset(idx_arr, 0, order*
sizeof(
int));
80 if (idx_rem == 0)
break;
83 idx_arr[
dim] = idx_rem/lda;
84 idx_rem -= idx_arr[
dim]*lda;
87 memcpy(plen, lens, (
dim+1)*
sizeof(
int));
90 while (
dim >= sg && sym[
dim-sg] !=
NS) { sg++; fsg*=sg; }
92 double fsg_idx = (((double)idx_rem)*fsg)/lda;
93 int kidx = (int)pow(fsg_idx,1./sg);
98 for (
int idim=
dim-sg+1; idim<=
dim; idim++){
105 for (; mkidx >= 0; mkidx--){
106 for (
int idim=
dim-sg+1; idim<=
dim; idim++){
110 if (midx <= idx_rem)
break;
112 if (midx == 0) mkidx = 0;
113 idx_arr[
dim] = mkidx;
126 int64_t idx_rem = idx;
127 memset(idx_arr, 0, order*
sizeof(
int));
129 if (idx_rem == 0)
break;
132 idx_arr[
dim] = idx_rem/lda;
133 idx_rem -= idx_arr[
dim]*lda;
136 memcpy(plen, lens, (
dim+1)*
sizeof(
int));
139 while (
dim >= sg && sym[
dim-sg] !=
NS) { sg++; fsg*=sg; }
141 double fsg_idx = (((double)idx_rem)*fsg)/lda;
142 int kidx = (int)pow(fsg_idx,1./sg);
147 for (
int idim=
dim-sg+1; idim<=
dim; idim++){
148 plen[idim] = mkidx+1;
154 for (; mkidx >= 0; mkidx--){
155 for (
int idim=
dim-sg+1; idim<=
dim; idim++){
159 if (midx <= idx_rem)
break;
161 if (midx == 0) mkidx = 0;
162 idx_arr[
dim] = mkidx;
176 for (i=2; i<=n; i++){
191 for (i=2; i<=n; i++){
212 for (i=0; i<order; i++){
213 swap[i] = arr[perm[i]];
215 for (i=0; i<order; i++){
229 for (i=0; i<order; i++){
230 swap[i] = arr[perm[i]];
232 for (i=0; i<order; i++){
244 int64_t
const * sizes_a,
246 int64_t *& offsets_b){
247 sizes_b = (int64_t*)
alloc(
sizeof(int64_t)*m*n);
248 offsets_b = (int64_t*)
alloc(
sizeof(int64_t)*m*n);
250 int64_t last_offset = 0;
251 for (
int i=0; i<n; i++){
252 for (
int j=0; j<m; j++){
253 sizes_b[lda_b*i+j] = sizes_a[lda_a*i+j];
254 offsets_b[lda_b*i+j] = last_offset;
255 last_offset = last_offset+sizes_a[lda_a*i+j];
264 int64_t
const * sizes_a,
265 int64_t
const * offsets_a,
267 int64_t
const * sizes_b,
268 int64_t
const * offsets_b,
270 for (
int i=0; i<n; i++){
271 for (
int j=0; j<m; j++){
272 memcpy(b+offsets_b[lda_b*i+j],a+offsets_a[lda_a*i+j],sizes_a[lda_a*i+j]);
279 for (int64_t i=1; i<=n; i++){
289 void get_choice(int64_t n, int64_t k, int64_t ch,
int * chs){
296 std::fill(lens, lens+k, n);
298 std::fill(sym, sym+k-1,
SH);
void calc_idx_arr(int order, int const *lens, int const *sym, int64_t idx, int *idx_arr)
void permute(int order, int const *perm, int *arr)
permute an array
void get_choice(int64_t n, int64_t k, int64_t ch, int *chs)
void * alloc(int64_t len)
alloc abstraction
int alloc_ptr(int64_t len, void **const ptr)
alloc abstraction
void sy_calc_idx_arr(int order, int const *lens, int const *sym, int64_t idx, int *idx_arr)
same as above except assumes sym only NS or SY
void permute_target(int order, int const *perm, int *arr)
permutes a permutation array
void socopy(int64_t m, int64_t n, int64_t lda_a, int64_t lda_b, int64_t const *sizes_a, int64_t *&sizes_b, int64_t *&offsets_b)
int cdealloc(void *ptr)
free abstraction
int64_t choose(int64_t n, int64_t k)
void factorize(int n, int *nfactor, int **factor)
computes the size of a tensor in packed symmetric layout
int64_t packed_size(int order, const int *len, const int *sym)
computes the size of a tensor in packed symmetric (SY, SH, or AS) layout
int64_t chchoose(int64_t n, int64_t k)
int64_t sy_packed_size(int order, const int *len, const int *sym)
computes the size of a tensor in SY (NOT HOLLOW) packed symmetric layout
void spcopy(int64_t m, int64_t n, int64_t lda_a, int64_t lda_b, int64_t const *sizes_a, int64_t const *offsets_a, char const *a, int64_t const *sizes_b, int64_t const *offsets_b, char *b)