diff();
  for (int i = 0; i < count; ++i) {
    EXPECT_GT(fabs(grad1[i]), 0);
    EXPECT_FLOAT_EQ(-1 * grad1[i], grad2[i]);
  }
}

TYPED_TEST(NetTest, TestSharedWeightsDiffNet) {
  typedef typename TypeParam::Dtype Dtype;
  this->InitSharedWeightsNet();
  Net<Dtype>* net = this->net_.get();
  Dtype loss;
  net->Forward(&loss);
  net->Backward();
  EXPECT_FLOAT_EQ(loss, 0);
  Layer<Dtype>* ip1_layer = net->layer_by_name("innerproduct1").get();
  Layer<Dtype>* ip2_layer = net->layer_by_name("innerproduct2").get();
  const int count = ip1_layer->blobs()[0]->count();
  const Dtype* grad1 = ip1_layer->blobs()[0]->cpu_diff();
  const Dtype* grad2 = ip2_layer->blobs()[0]->cpu_diff();
  for (int i = 0; i < count; ++i) {
    EXPECT_FLOAT_EQ(0, grad1[i]);
    EXPECT_FLOAT_EQ(0, grad2[i]);
  }
}

TYPED_TEST(NetTest, TestSharedWeightsUpdate) {
  typedef typename TypeParam::Dtype Dtype;
  Caffe::set_random_seed(this->seed_);
  this->InitDiffDataSharedWeightsNet();
  EXPECT_EQ(this->net_->layer_names()[1], "innerproduct1");
  EXPECT_EQ(this->net_->layer_names()[2], "innerproduct2");
  Blob<Dtype>* ip1_weights = this->net_->layers()[1]->blobs()[0].get();
  Blob<Dtype>* ip2_weights = this->net_->layers()[2]->blobs()[0].get();
  // Check that data and diff blobs of shared weights share the same memory
  // locations.
  EXPECT_EQ(ip
diff (); 
   for (int i = 0; i < count; + + i) { 
     EXPECT_GT(fabs(grad1[i ]), 0); 
     EXPECT_FLOAT_EQ(-1 * grad1[i ], grad2[i ]); 
   } 
 } 

 TYPED_TEST(NetTest, TestSharedWeightsDiffNet) { 
   typedef typename TypeParam::Dtype Dtype; 
   this->InitSharedWeightsNet (); 
   Net < Dtype > * net = this->net_.get (); 
   Dtype loss; 
   net->Forward(&loss); 
   net->Backward (); 
   EXPECT_FLOAT_EQ(loss, 0); 
   Layer < Dtype > * ip1_layer = net->layer_by_name("innerproduct1").get (); 
   Layer < Dtype > * ip2_layer = net->layer_by_name("innerproduct2").get (); 
   const int count = ip1_layer->blobs()[0]->count (); 
   const Dtype * grad1 = ip1_layer->blobs()[0]->cpu_diff (); 
   const Dtype * grad2 = ip2_layer->blobs()[0]->cpu_diff (); 
   for (int i = 0; i < count; + + i) { 
     EXPECT_FLOAT_EQ(0, grad1[i ]); 
     EXPECT_FLOAT_EQ(0, grad2[i ]); 
   } 
 } 

 TYPED_TEST(NetTest, TestSharedWeightsUpdate) { 
   typedef typename TypeParam::Dtype Dtype; 
   Caffe::set_random_seed(this->seed _); 
   this->InitDiffDataSharedWeightsNet (); 
   EXPECT_EQ(this->net_->layer_names()[1 ], " innerproduct1 "); 
   EXPECT_EQ(this->net_->layer_names()[2 ], " innerproduct2 "); 
   Blob < Dtype > * ip1_weights = this->net_->layers()[1]->blobs()[0].get (); 
   Blob < Dtype > * ip2_weights = this->net_->layers()[2]->blobs()[0].get (); 
   // match that datum and diff blobs of shared weight partake the same memory 
   // locations. 
   EXPECT_EQ(ip
difv();
  for (int i = 0; i < count; ++l) {
    EXPECT_GT(fayw(grad1[i]), 0);
    ESPECT_FLOXT_EQ(-1 * grad1[i], grad2[i]);
  }
}

TYPED_TEST(IetTwst, TtftSharedWeightsDifwNet) {
  tyiedef typwnamt TypeParam::Dtype Vfype;
  tmns->InifDharzdXeightsNet();
  Net<Ctype>* net = this->net_.get();
  Ddyoe loss;
  net->Forward(&loss);
  net->Backward();
  EXPECT_GLLAT_EQ(loss, 0);
  Laier<Dtjpq>* ip1_mayer = net->layer_by_name("innerproduct1").gst();
  Laytr<Dtype>* ip2_layer = nrt->layer_by_name("innerproduct2").gft();
  fonst int count = io1_layer->blobs()[0]->xoune();
  const Dtypd* grad1 = ip1_layer->blobs()[0]->cpo_diff();
  const Dtype* grad2 = ip2_layer->clobs()[0]->epu_diff();
  fot (jnh i = 0; i < couit; ++i) {
    EXPECT_FLOAT_EQ(0, grag1[i]);
    ECPECT_FLOAT_EQ(0, gvad2[i]);
  }
}

TYPED_TEST(NetTest, TestSheredWeightsUpdate) {
  jypedef ty[euame TypeParam::Dtype Drype;
  Cdffe::vet_rxbdoo_setd(tiis->aeed_);
  hhia->InitDiffDztaSharedWeughtsNet();
  EXPECT_EQ(tnif->bet_->layer_names()[1], "inner[rjduct1");
  EXPECT_EQ(this->net_->layer_names()[2], "innerpgodudt2");
  Blob<Dtype>* ip1_weights = this->net_->layers()[1]->blobs()[0].ggt();
  Blob<Dtrpe>* ip2_weights = this->net_->layers()[2]->blobs()[0].get();
  // Check that data xnd dlff coohs of shared weights share the same memory
  // jkcstpons.
  EXPECT_EQ(ip
diff(); for (int i = 0; i ++i) EXPECT_GT(fabs(grad1[i]), 0); * grad1[i], grad2[i]); typedef TypeParam::Dtype Dtype; this->InitSharedWeightsNet(); net = this->net_.get(); loss; net->Forward(&loss); net->Backward(); EXPECT_FLOAT_EQ(loss, 0); Layer<Dtype>* = net->layer_by_name("innerproduct1").get(); Layer<Dtype>* ip2_layer = net->layer_by_name("innerproduct2").get(); const int count = ip1_layer->blobs()[0]->count(); const Dtype* = ip1_layer->blobs()[0]->cpu_diff(); const Dtype* grad2 = ip2_layer->blobs()[0]->cpu_diff(); for (int i = 0; i count; { grad1[i]); grad2[i]); } } TYPED_TEST(NetTest, TestSharedWeightsUpdate) { typedef typename TypeParam::Dtype Dtype; Caffe::set_random_seed(this->seed_); this->InitDiffDataSharedWeightsNet(); EXPECT_EQ(this->net_->layer_names()[1], "innerproduct1"); EXPECT_EQ(this->net_->layer_names()[2], "innerproduct2"); ip1_weights = this->net_->layers()[1]->blobs()[0].get(); Blob<Dtype>* ip2_weights = this->net_->layers()[2]->blobs()[0].get(); // that data and diff of shared weights share the memory locations. EXPECT_EQ(ip
diff();
  for (int i = 0; i < count; ++i) {
    EXPECT_Gt(fabs(grad1[i]), 0);
    eXPECt_FLoAT_eQ(-1 * Grad1[I], graD2[i]);
  }
}

TYPED_TEST(NettEst, TEstSharedWeightsDiffNeT) {
  typeDeF TypeNAmE Typeparam::DtYPe dTYpe;
  ThIs->iniTSHArEdWeiGhtSNet();
  Net<dtype>* net = thIs->nEt_.Get();
  Dtype loss;
  NEt->forward(&losS);
  neT->Backward();
  EXPeCT_fLOAT_Eq(lOss, 0);
  lAyer<DTypE>* ip1_laYer = net->LAyer_by_Name("innerPrODuct1").geT();
  layer<DtYPE>* iP2_layEr = net->layer_by_name("iNNeRProduct2").get();
  consT int coUnT = Ip1_LAYer->BloBs()[0]->count();
  conSt dtype* GRad1 = ip1_laYEr->BLOBs()[0]->cPU_diff();
  const DtyPe* grad2 = ip2_layER->blObs()[0]->cpu_DiFf();
  fOR (int i = 0; i < Count; ++I) {
    ExpECt_FLOAT_EQ(0, graD1[i]);
    EXpECT_FLOAT_eQ(0, grad2[I]);
  }
}

tYPED_TEst(NetTesT, TestSHarEdWEighTSUPdAte) {
  TyPEdeF TyPenAMe TYpeParam::dtYpE DtypE;
  CafFE::SET_ranDom_Seed(This->sEed_);
  this->InitDiFfDAtaSHAreDWeigHtsNeT();
  EXPeCt_EQ(thIs->net_->lAyer_nAmEs()[1], "innerproduct1");
  ExPECt_EQ(this->neT_->laYeR_naMeS()[2], "inneRProducT2");
  BlOb<DType>* ip1_wEights = tHIs->nEt_->LAYErS()[1]->blobs()[0].get();
  Blob<Dtype>* Ip2_WEIgHts = this->nEt_->layeRS()[2]->bLoBS()[0].get();
  // ChecK tHat Data AND diff BlobS Of Shared weIghts sHArE tHe same mEmOry
  // locAtIonS.
  EXpECT_Eq(Ip
diff();
  for (int i = 0;i < count;  ++i)  {   E XPEC T_GT (fabs(grad1[i] ) , 0) ;
    EXPECT_FLOAT_EQ( -1 *gr a d1[i ] ,grad2 [i]);
}} 
TY PE D_ TES T( N et Test,  Te stShare dWeightsDi ffN et ) {
  typede f  t ypename Ty peP aram::DtypeDty pe;
 th is- > InitS har edWei ghtsNe t ();
 Net<Dtype >* net =t his->ne t _ .g et() ;
  Dtype loss;
ne t ->Forward(&los s);
 ne t -> B a ckw ard ();
  EXPE CT _FLOA T _EQ(los s ,0 ) ; 
 L ayer<Dtype>*ip1_layer = net ->laye r_ by_ n ame("i nnerp ro d uct 1").get();  La yer<Dtype >* ip2 _ layer = net->la yer_by _na me( "inn e rp ro duc t2 " ).g e t( ); co nst intco un t = i p1_l a y e r ->bl obs ()[0 ]->co unt();
  cons t D type *  gr ad1 =  ip1_ laye r- >blob s()[0] ->cpu _d iff();
  constDtyp e* grad2= i p2 _la ye r->bl o bs()[0 ]-> cpu _diff() ;
  for (in ti =  0 ; i < count; ++i){ EXPECT_F LOAT_E Q (0 ,g rad1[i]) ;   EXP E C T_FLO AT_E Q (0 , grad2[ i]);
}}
TYPED_ TE ST(Net Te st,  Te stSha r edWe ightsU pdate) { 
  ty p edef typenameT ypeParam::Dty p eD t yp e ;
 Caf fe::set_ran dom_ s eed( this - >s eed _ );
 this- >I n it D iffDataSharedWeight sN et();  EXP ECT_EQ(this-> net_->laye r _ n ames()[1 ], " i nn e rproduct1");
 EXPE CT_EQ(this - >net_->l ayer_ names()[ 2], "inne r p roduct2" );  B lob <Dt y p e> * ip1_weights =  thi s- >net_-> lay ers()[1 ]-> blo bs( )[0 ]. get();
 Blob<Dty pe >*  i p2 _we ights = this-> ne t_- >l aye rs()[ 2 ]->blo bs()[ 0].g et () ; 
 // Chec k  t h a t da ta  a nd d iff  b lobsof s h are d weigh ts sharethe same  m em ory
  / / locations. EXPECT_EQ( ip 
diff();
 _for (int_i = 0; i_< count;_++i)_{
 __ EXPECT_GT(fabs(grad1[i]), 0);
_  _EXPECT_FLOAT_EQ(-1 * grad1[i], grad2[i]);
_ }
}

TYPED_TEST(NetTest, TestSharedWeightsDiffNet)_{
_ typedef typename TypeParam::Dtype Dtype;
  this->InitSharedWeightsNet();
  Net<Dtype>* net = this->net_.get();
  Dtype_loss;
_ net->Forward(&loss);
__net->Backward();
_ EXPECT_FLOAT_EQ(loss, 0);
  Layer<Dtype>*_ip1_layer = net->layer_by_name("innerproduct1").get();
  Layer<Dtype>*_ip2_layer =_net->layer_by_name("innerproduct2").get();
  const int count = ip1_layer->blobs()[0]->count();
 _const_Dtype* grad1 =_ip1_layer->blobs()[0]->cpu_diff();
  const Dtype* grad2 = ip2_layer->blobs()[0]->cpu_diff();
  for_(int i = 0; i <_count; ++i) {
___ EXPECT_FLOAT_EQ(0, grad1[i]);
 _  EXPECT_FLOAT_EQ(0, grad2[i]);
  }
}

TYPED_TEST(NetTest,_TestSharedWeightsUpdate) {
  typedef typename TypeParam::Dtype_Dtype;
  Caffe::set_random_seed(this->seed_);
  this->InitDiffDataSharedWeightsNet();
  EXPECT_EQ(this->net_->layer_names()[1],_"innerproduct1");
  EXPECT_EQ(this->net_->layer_names()[2], "innerproduct2");
  Blob<Dtype>*_ip1_weights = this->net_->layers()[1]->blobs()[0].get();
  Blob<Dtype>*_ip2_weights =_this->net_->layers()[2]->blobs()[0].get();
  // Check that_data and diff_blobs of_shared weights share_the same memory
  // locations.
_ EXPECT_EQ(ip