18 Y.
write(n_X, inds_X, vals_X);
32 int lens_X[3] = {n, n, m};
33 int lens_W[3] = {d, d, m};
43 int lens_X5[] = {n/d, d, n/d, d, m};
48 int lens_Y4[] = {n/d, d, n/d, d};
56 std::fill(vals_Rd, vals_Rd+d, 1.0);
57 for (
int i=0; i<d; i++){
58 inds_Rd[i] = ((i+1) % d) + i*d;
60 Rd.
write(d,inds_Rd,vals_Rd);
61 }
else Rd.
write(0,NULL,NULL);
68 std::fill(vals_Rn, vals_Rn+n, 1.0);
69 for (
int i=0; i<n; i++){
70 inds_Rn[i] = ((i+1) % n) + i*n;
72 Rn.
write(n,inds_Rn,vals_Rn);
73 }
else Rn.
write(0,NULL,NULL);
84 std::fill(vals_Rnd, vals_Rnd+n, 1.0);
85 for (
int i=0; i<n; i++){
86 inds_Rnd[i] = ((i+d) % n) + i*n;
88 Rnd.
write(n,inds_Rnd,vals_Rnd);
89 }
else Rnd.
write(0,NULL,NULL);
96 for (
int a=0;
a<d;
a++){
97 for (
int b=0;
b<d;
b++){
99 Y4[
"iajb"] += X5[
"iajbk"]*W[
"abk"];
101 W[
"abk"] = Rd[
"bc"]*W[
"ack"];
103 Y4[
"iajb"] = Rn4[
"jbkc"]*Y4[
"iakc"];
106 Y4[
"iajb"] = Rnd4[
"kcjb"]*Y4[
"iakc"];
108 W[
"abk"] = Rd[
"ac"]*W[
"cbk"];
110 Y4[
"iajb"] = Rn4[
"iakc"]*Y4[
"kcjb"];
113 Y4[
"iajb"] = Rnd4[
"kcia"]*Y4[
"kcjb"];
118 bool pass = Y.
norm2() >= 1.E-6;
122 printf(
"{ Neural network with sparse X } passed \n");
124 printf(
"{ Neural network with sparse X } failed \n");
134 char ** itr = std::find(begin, end, option);
135 if (itr != end && ++itr != end){
142 int main(
int argc,
char ** argv){
143 int rank,
np, n, m, d, pass;
145 int const in_num = argc;
146 char ** input_str = argv;
148 MPI_Init(&argc, &argv);
149 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
150 MPI_Comm_size(MPI_COMM_WORLD, &np);
153 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
158 m = atoi(
getCmdOption(input_str, input_str+in_num,
"-m"));
163 d = atoi(
getCmdOption(input_str, input_str+in_num,
"-d"));
168 sp = atof(
getCmdOption(input_str, input_str+in_num,
"-sp"));
173 World dw(argc, argv);
176 printf(
"Running neural network with dimensions %d*%d*%d and sparsity fraction %lf with dense filter of dimensions %d*%d*%d\n",n,n,m,sp,d,d,m);
178 pass =
neural(n, m, d, sp, dw);
char * getCmdOption(char **begin, char **end, const std::string &option)
Matrix class which encapsulates a 2D tensor.
int neural(int n, int m, int d, double sp, World &dw)
computes a neural network iteration for tensor n*n*m tensor X whose sparsity fraction is sp...
an instance of the CTF library (world) on a MPI communicator
dtype norm2()
computes the frobenius norm of the tensor (needs sqrt()!)
void fill_random(dtype rmin, dtype rmax)
fills local unique tensor elements to random values in the range [min,max] works only for dtype in {f...
int rank
rank of local processor
void fill_sp_random(dtype rmin, dtype rmax, double frac_sp)
generate roughly frac_sp*dense_tensor_size nonzeros between rmin and rmax, works only for dtype in {f...
int main(int argc, char **argv)
void get_local_data(int64_t *npair, int64_t **global_idx, dtype **data, bool nonzeros_only=false, bool unpack_sym=false) const
Gives the global indices and values associated with the local data.
an instance of a tensor within a CTF world
void fold_unfold(Tensor< dtype > &X, Tensor< dtype > &Y)
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...