Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
partition.cxx
Go to the documentation of this file.
1 #include "partition.h"
2 #include "../shared/util.h"
3 
4 namespace CTF {
5  Partition::Partition(int order_, int const * lens_){
6  order = order_;
7  lens = (int*)CTF_int::alloc(order*sizeof(int));
8  memcpy(lens, lens_, order*sizeof(int));
9  }
10 
12  order = 0;
13  lens = NULL;
14  }
15 
18  }
19 
21  order = other.order;
22  lens = (int*)CTF_int::alloc(order*sizeof(int));
23  memcpy(lens, other.lens, order*sizeof(int));
24  }
25 
26  void Partition::operator=(Partition const & other){
27  order = other.order;
28  lens = (int*)CTF_int::alloc(order*sizeof(int));
29  memcpy(lens, other.lens, order*sizeof(int));
30  }
31 
32 
34  return Idx_Partition(*this, idx);
35  }
36 
38  part = Partition(0, NULL);
39  idx = NULL;
40  }
41 
42  Idx_Partition::Idx_Partition(Partition const & part_, char const * idx_){
43  part = part_;
44  idx = (char*)malloc(part.order*sizeof(char));
45  memcpy(idx, idx_, part.order*sizeof(char));
46  }
47 
49  if (idx != NULL){
50  free(idx);
51  idx = NULL;
52  }
53  }
54 
56  int * new_lens = (int*)malloc(part.order*sizeof(int));
57  int new_order = 0;
58  char * new_idx = (char*)malloc(part.order);
59  for (int i=0; i<part.order; i++){
60  if (part.lens[i] != 1){
61  new_lens[new_order] = part.lens[i];
62  new_idx[new_order] = idx[i];
63  new_order++;
64  }
65  }
66  Idx_Partition p = Partition(new_order, new_lens)[new_idx];
67  free(new_idx);
68  free(new_lens);
69  return p;
70  }
71 
72 }
void operator=(Partition const &other)
Definition: partition.cxx:26
void * alloc(int64_t len)
alloc abstraction
Definition: memcontrol.cxx:365
Idx_Partition operator[](char const *idx)
Definition: partition.cxx:33
int cdealloc(void *ptr)
free abstraction
Definition: memcontrol.cxx:480
Definition: apsp.cxx:17
Idx_Partition reduce_order() const
extracts non-trivial part of partition by ommitting unit dimensions
Definition: partition.cxx:55