nus-yam/ex-repair huggingface dataset:
Program: 131297
Project: 131297
Buggy source:
public boolean equals(){
  throw new RuntimeException("String_Node_Str");
}

Fixed version (ground truth):
@Override public boolean equals(Object obj){
  if (this == obj)   return true;
  if (obj == null)   return false;
  if (getClass() != obj.getClass())   return false;
  NerMention other=(NerMention)obj;
  if (entitySubType == null) {
    if (other.entitySubType != null)     return false;
  }
 else   if (!entitySubType.equals(other.entitySubType))   return false;
  if (entityType == null) {
    if (other.entityType != null)     return false;
  }
 else   if (!entityType.equals(other.entityType))   return false;
  if (head != other.head)   return false;
  if (id == null) {
    if (other.id != null)     return false;
  }
 else   if (!id.equals(other.id))   return false;
  if (phraseType == null) {
    if (other.phraseType != null)     return false;
  }
 else   if (!phraseType.equals(other.phraseType))   return false;
  if (span == null) {
    if (other.span != null)     return false;
  }
 else   if (!span.equals(other.span))   return false;
  return true;
}
Program: 131298
Project: 131298
Buggy source:
@Override public int compareTo(NerMention other){
  if (this.span == null && other.span == null) {
    return 0;
  }
 else   if (this.span == null) {
    return -1;
  }
 else   if (other.span == null) {
    return 1;
  }
  return this.span.compareTo(other.span);
}

Fixed version (ground truth):
@Override public int compareTo(NerMention other){
  int diff=ObjectUtils.compare(this.span,other.span);
  if (diff != 0) {
    return diff;
  }
  diff=ObjectUtils.compare(this.entityType,other.entityType);
  if (diff != 0) {
    return diff;
  }
  diff=ObjectUtils.compare(this.entitySubType,other.entitySubType);
  if (diff != 0) {
    return diff;
  }
  diff=ObjectUtils.compare(this.phraseType,other.phraseType);
  if (diff != 0) {
    return diff;
  }
  diff=ObjectUtils.compare(this.head,other.head);
  if (diff != 0) {
    return diff;
  }
  diff=ObjectUtils.compare(this.id,other.id);
  return diff;
}
Program: 131299
Project: 131299
Buggy source:
/** 
 * Gets the span intervening between two spans.
 */
public static Span getSpanBtwn(Span span1,Span span2){
  Span btwn;
  if (span1.isBefore(span2)) {
    btwn=new Span(span1.end(),span2.start());
  }
 else {
    btwn=new Span(span2.end(),span1.start());
  }
  return btwn;
}

Fixed version (ground truth):
/** 
 * Gets the span intervening between two spans.
 */
public static Span getSpanBtwn(Span span1,Span span2){
  if (span1.end <= span2.start) {
    return new Span(span1.end,span2.start);
  }
 else   if (span2.end <= span1.start) {
    return new Span(span2.end,span1.start);
  }
 else {
    return new Span(span1.start,span1.start);
  }
}
Program: 131300
Project: 131300
Buggy source:
private static void checkGoldConfig(FactorGraph fg,VarConfig goldConfig){
  for (  Var var : fg.getVars()) {
    if (var.getType() != VarType.LATENT && goldConfig.getState(var,-1) == -1) {
      throw new IllegalStateException("String_Node_Str" + var);
    }
  }
}

Fixed version (ground truth):
private static void checkGoldConfig(FactorGraph fg,VarConfig goldConfig){
  for (  Var var : fg.getVars()) {
    if (var.getType() != VarType.LATENT && goldConfig.getState(var,-1) == -1) {
      int numNonLat=VarSet.getVarsOfType(fg.getVars(),VarType.OBSERVED).size() + VarSet.getVarsOfType(fg.getVars(),VarType.PREDICTED).size();
      log.error(String.format("String_Node_Str",numNonLat,goldConfig.size()));
      throw new IllegalStateException("String_Node_Str" + var);
    }
  }
}
Program: 131302
Project: 131302
Buggy source:
public static void checkForRequiredAnnotations(JointNlpEncoderPrm prm,AnnoSentenceCollection sents){
  AnnoSentence sent=sents.get(0);
  if (prm.fePrm.srlFePrm.fePrm.useTemplates) {
    if (prm.fgPrm.includeSrl) {
      TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.srlFePrm.fePrm.soloTemplates);
      TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.srlFePrm.fePrm.pairTemplates);
    }
  }
  if (prm.fgPrm.includeDp) {
    TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.dpFePrm.firstOrderTpls);
    if (prm.fgPrm.dpPrm.grandparentFactors || prm.fgPrm.dpPrm.siblingFactors) {
      TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.dpFePrm.secondOrderTpls);
    }
  }
  if (prm.fgPrm.includeRel) {
    TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fgPrm.relPrm.templates);
  }
}

Fixed version (ground truth):
public static void checkForRequiredAnnotations(JointNlpEncoderPrm prm,AnnoSentenceCollection sents){
  AnnoSentence sent=sents.get(0);
  if (prm.fePrm.srlFePrm.fePrm.useTemplates) {
    if (prm.fgPrm.includeSrl) {
      TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.srlFePrm.fePrm.soloTemplates);
      TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.srlFePrm.fePrm.pairTemplates);
    }
  }
  if (prm.fgPrm.includeDp) {
    TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.dpFePrm.firstOrderTpls);
    if (prm.fgPrm.dpPrm.grandparentFactors || prm.fgPrm.dpPrm.siblingFactors) {
      TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fePrm.dpFePrm.secondOrderTpls);
    }
  }
  if (prm.fgPrm.includeRel && prm.fgPrm.relPrm.templates != null) {
    TemplateLanguage.assertRequiredAnnotationTypes(sent,prm.fgPrm.relPrm.templates);
  }
}
Program: 131303
Project: 131303
Buggy source:
private static JointNlpFgExampleBuilderPrm getSrlFgExampleBuilderPrm(JointNlpEncoder.JointNlpFeatureExtractorPrm fePrm){
  JointNlpFgExampleBuilderPrm prm=new JointNlpFgExampleBuilderPrm();
  prm.fgPrm.dpPrm.linkVarType=linkVarType;
  prm.fgPrm.dpPrm.useProjDepTreeFactor=useProjDepTreeFactor;
  prm.fgPrm.dpPrm.unaryFactors=unaryFactors;
  prm.fgPrm.dpPrm.excludeNonprojectiveGrandparents=excludeNonprojectiveGrandparents;
  prm.fgPrm.dpPrm.grandparentFactors=grandparentFactors;
  prm.fgPrm.dpPrm.siblingFactors=siblingFactors;
  prm.fgPrm.dpPrm.pruneEdges=pruneByDist || pruneByModel;
  prm.fgPrm.srlPrm.makeUnknownPredRolesLatent=makeUnknownPredRolesLatent;
  prm.fgPrm.srlPrm.roleStructure=roleStructure;
  prm.fgPrm.srlPrm.allowPredArgSelfLoops=allowPredArgSelfLoops;
  prm.fgPrm.srlPrm.unaryFactors=unaryFactors;
  prm.fgPrm.srlPrm.binarySenseRoleFactors=binarySenseRoleFactors;
  prm.fgPrm.srlPrm.predictSense=predictSense;
  prm.fgPrm.srlPrm.predictPredPos=predictPredPos;
  if (includeRel) {
    prm.fgPrm.relPrm.templates=getFeatTpls(relFeatTpls);
    prm.fgPrm.relPrm.featureHashMod=featureHashMod;
  }
  prm.fgPrm.includeDp=includeDp;
  prm.fgPrm.includeSrl=includeSrl;
  prm.fgPrm.includeRel=includeRel;
  prm.fePrm=fePrm;
  prm.exPrm.cacheType=cacheType;
  prm.exPrm.gzipped=gzipCache;
  prm.exPrm.maxEntriesInMemory=maxEntriesInMemory;
  return prm;
}

Fixed version (ground truth):
private static JointNlpFgExampleBuilderPrm getSrlFgExampleBuilderPrm(JointNlpEncoder.JointNlpFeatureExtractorPrm fePrm){
  JointNlpFgExampleBuilderPrm prm=new JointNlpFgExampleBuilderPrm();
  prm.fgPrm.dpPrm.linkVarType=linkVarType;
  prm.fgPrm.dpPrm.useProjDepTreeFactor=useProjDepTreeFactor;
  prm.fgPrm.dpPrm.unaryFactors=unaryFactors;
  prm.fgPrm.dpPrm.excludeNonprojectiveGrandparents=excludeNonprojectiveGrandparents;
  prm.fgPrm.dpPrm.grandparentFactors=grandparentFactors;
  prm.fgPrm.dpPrm.siblingFactors=siblingFactors;
  prm.fgPrm.dpPrm.pruneEdges=pruneByDist || pruneByModel;
  prm.fgPrm.srlPrm.makeUnknownPredRolesLatent=makeUnknownPredRolesLatent;
  prm.fgPrm.srlPrm.roleStructure=roleStructure;
  prm.fgPrm.srlPrm.allowPredArgSelfLoops=allowPredArgSelfLoops;
  prm.fgPrm.srlPrm.unaryFactors=unaryFactors;
  prm.fgPrm.srlPrm.binarySenseRoleFactors=binarySenseRoleFactors;
  prm.fgPrm.srlPrm.predictSense=predictSense;
  prm.fgPrm.srlPrm.predictPredPos=predictPredPos;
  if (includeRel) {
    if (relFeatTpls != null) {
      prm.fgPrm.relPrm.templates=getFeatTpls(relFeatTpls);
    }
    prm.fgPrm.relPrm.featureHashMod=featureHashMod;
  }
  prm.fgPrm.includeDp=includeDp;
  prm.fgPrm.includeSrl=includeSrl;
  prm.fgPrm.includeRel=includeRel;
  prm.fePrm=fePrm;
  prm.exPrm.cacheType=cacheType;
  prm.exPrm.gzipped=gzipCache;
  prm.exPrm.maxEntriesInMemory=maxEntriesInMemory;
  return prm;
}
Program: 131304
Project: 131304
Buggy source:
@Test public void testToFromReal(){
  toFromCheck(1);
  toFromCheck(-1);
  toFromCheck(Double.POSITIVE_INFINITY);
  toFromCheck(Double.NEGATIVE_INFINITY);
  toFromCheck(Double.NaN);
  int i=0, j=0;
  double nan3=(double)i / j;
  toFromCheck(nan3);
}

Fixed version (ground truth):
@Test public void testToFromReal(){
  toFromCheck(1);
  toFromCheck(0);
  toFromCheck(-1);
  toFromCheck(Double.POSITIVE_INFINITY);
  toFromCheck(Double.NEGATIVE_INFINITY);
  toFromCheck(Double.NaN);
  int i=0, j=0;
  double nan3=(double)i / j;
  toFromCheck(nan3);
}
Program: 131305
Project: 131305
Buggy source:
@Override public double toLogProb(double nonReal){
  return fromReal(FastMath.log(toReal(nonReal)));
}

Fixed version (ground truth):
@Override public double toLogProb(double nonReal){
  return FastMath.log(toReal(nonReal));
}
Program: 131306
Project: 131306
Buggy source:
@Override public double fromLogProb(double logProb){
  return fromReal(FastMath.exp(toReal(logProb)));
}

Fixed version (ground truth):
@Override public double fromLogProb(double logProb){
  return fromReal(FastMath.exp(logProb));
}
Program: 131307
Project: 131307
Buggy source:
@Override public Module<Tensor> getDl(VarConfig goldConfig,ExpFamFactorsModule effm,Module<Beliefs> inf,int curIter,int maxIter){
  double temperature=getTemperature(curIter,maxIter);
  TensorIdentity temp=new TensorIdentity(Tensor.getScalarTensor(Algebras.REAL_ALGEBRA,temperature));
  if (annealMse) {
    double prop=(double)curIter / maxIter;
    Module<Tensor> mse=new MeanSquaredError(inf,goldConfig);
    Module<Tensor> dep=new DepParseDecodeLoss(inf,goldConfig,temp);
    Module<Tensor> lin=new ElemLinear(mse,dep,(1.0 - prop),prop);
    return new TopoOrder<Tensor>(Lists.getList(inf),lin);
  }
 else {
    return new DepParseDecodeLoss(inf,goldConfig,temp);
  }
}

Fixed version (ground truth):
@Override public Module<Tensor> getDl(VarConfig goldConfig,ExpFamFactorsModule effm,Module<Beliefs> inf,int curIter,int maxIter){
  double temperature=getTemperature(curIter,maxIter);
  TensorIdentity temp=new TensorIdentity(Tensor.getScalarTensor(Algebras.REAL_ALGEBRA,temperature));
  if (annealMse) {
    double prop=(double)curIter / maxIter;
    Module<Tensor> mse=new MeanSquaredError(inf,goldConfig);
    Module<Tensor> dep=new DepParseDecodeLoss(inf,goldConfig,temp);
    Module<Tensor> lin=new ElemLinear(mse,dep,(1.0 - prop),prop);
    return new TopoOrder<Tensor>(Lists.getList(inf,temp),lin);
  }
 else {
    return new DepParseDecodeLoss(inf,goldConfig,temp);
  }
}
Program: 131308
Project: 131308
Buggy source:
private void backwardSendMessage(FgEdge edge,VarTensor oldMsg){
  int i=edge.getId();
  msgs[i].newMessage=msgs[i].message;
  msgs[i].message=oldMsg;
  VarTensor tmp=msgsAdj[i].newMessage;
  tmp.multiply(0);
  msgsAdj[i].newMessage=msgsAdj[i].message;
  msgsAdj[i].message=tmp;
  logTraceMsgUpdate("String_Node_Str",msgsAdj[i].newMessage,edge);
}

Fixed version (ground truth):
private void backwardSendMessage(FgEdge edge,VarTensor oldMsg){
  int i=edge.getId();
  msgs[i].newMessage=msgs[i].message;
  msgs[i].message=oldMsg;
  VarTensor tmp=msgsAdj[i].newMessage;
  tmp.multiply(s.zero());
  msgsAdj[i].newMessage=msgsAdj[i].message;
  msgsAdj[i].message=tmp;
  logTraceMsgUpdate("String_Node_Str",msgsAdj[i].newMessage,edge);
}
Program: 131309
Project: 131309
Buggy source:
@Test public void testErmaCompareMessagesWithExplicitTreeFactor(){
  compareErmaMessagesWithExplicitTreeFactor(Algebras.REAL_ALGEBRA,true,false);
}

Fixed version (ground truth):
@Test public void testErmaCompareMessagesWithExplicitTreeFactor(){
  compareErmaMessagesWithExplicitTreeFactor(Algebras.REAL_ALGEBRA,true,false);
  compareErmaMessagesWithExplicitTreeFactor(Algebras.REAL_ALGEBRA,true,true);
  compareErmaMessagesWithExplicitTreeFactor(Algebras.LOG_SIGN_ALGEBRA,true,false);
  compareErmaMessagesWithExplicitTreeFactor(Algebras.LOG_SIGN_ALGEBRA,true,true);
}
Program: 131311
Project: 131311
Buggy source:
public void forwardAndBackward(FgNode parent,Messages[] msgs,Messages[] msgsAdj,boolean isForward){
  Algebra s=msgs[0].message.getAlgebra();
  Tensor tmTrueIn=getMsgs(parent,msgs,LinkVar.TRUE,CUR_MSG,IN_MSG,s);
  Tensor tmFalseIn=getMsgs(parent,msgs,LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  TensorIdentity mTrueIn=new TensorIdentity(tmTrueIn);
  TensorIdentity mFalseIn=new TensorIdentity(tmFalseIn);
  Algebra tmpS=(isForward) ? Algebras.LOG_SEMIRING : Algebras.LOG_SIGN_ALGEBRA;
  ProjDepTreeModule dep=new ProjDepTreeModule(mTrueIn,mFalseIn,tmpS);
  dep.forward();
  if (isForward) {
    Tensor pair=dep.getOutput();
    Tensor tmTrueOut=pair.select(0,1);
    Tensor tmFalseOut=pair.select(0,0);
    setMsgs(parent,msgs,tmTrueOut,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    setMsgs(parent,msgs,tmFalseOut,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
  }
 else {
    Tensor tTrue=getMsgs(parent,msgsAdj,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    Tensor tFalse=getMsgs(parent,msgsAdj,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
    Tensor pairAdj=dep.getOutputAdj();
    Tensor tmTrueOutAdj=pairAdj.select(0,1);
    Tensor tmFalseOutAdj=pairAdj.select(0,0);
    tmTrueOutAdj.elemAdd(tTrue);
    tmFalseOutAdj.elemAdd(tFalse);
    dep.backward();
    addMsgs(parent,msgsAdj,mTrueIn.getOutputAdj(),LinkVar.TRUE,CUR_MSG,IN_MSG,s);
    addMsgs(parent,msgsAdj,mFalseIn.getOutputAdj(),LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  }
}

Fixed version (ground truth):
public void forwardAndBackward(FgNode parent,Messages[] msgs,Messages[] msgsAdj,boolean isForward){
  Algebra s=msgs[0].message.getAlgebra();
  Tensor tmTrueIn=getMsgs(parent,msgs,LinkVar.TRUE,CUR_MSG,IN_MSG,s);
  Tensor tmFalseIn=getMsgs(parent,msgs,LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  TensorIdentity mTrueIn=new TensorIdentity(tmTrueIn);
  TensorIdentity mFalseIn=new TensorIdentity(tmFalseIn);
  Algebra tmpS=(isForward) ? Algebras.LOG_SEMIRING : Algebras.LOG_SIGN_ALGEBRA;
  ProjDepTreeModule dep=new ProjDepTreeModule(mTrueIn,mFalseIn,tmpS);
  dep.forward();
  if (isForward) {
    Tensor pair=dep.getOutput();
    Tensor tmTrueOut=pair.select(0,1);
    Tensor tmFalseOut=pair.select(0,0);
    setMsgs(parent,msgs,tmTrueOut,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    setMsgs(parent,msgs,tmFalseOut,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
  }
 else {
    Tensor tTrue=getMsgs(parent,msgsAdj,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    Tensor tFalse=getMsgs(parent,msgsAdj,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
    Tensor pairAdj=dep.getOutputAdj();
    pairAdj.addTensor(tTrue,0,1);
    pairAdj.addTensor(tFalse,0,0);
    dep.backward();
    addMsgs(parent,msgsAdj,mTrueIn.getOutputAdj(),LinkVar.TRUE,CUR_MSG,IN_MSG,s);
    addMsgs(parent,msgsAdj,mFalseIn.getOutputAdj(),LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  }
}
Program: 131312
Project: 131312
Buggy source:
public DepTensorToBeliefs(Module<Tensor> dep,Module<Beliefs> inf){
  super(dep.getAlgebra());
  this.depIn=dep;
  this.inf=inf;
}

Fixed version (ground truth):
/** 
 * Constructor.
 * @param dep The tensor representation of the edge marginals.
 * @param inf The reference beliefs used only to determine the correct set of variables.
 */
public DepTensorToBeliefs(Module<Tensor> dep,Module<Beliefs> inf){
  super(dep.getAlgebra());
  this.depIn=dep;
  this.inf=inf;
}
Program: 131313
Project: 131313
Buggy source:
@Override public Beliefs forward(){
}

Fixed version (ground truth):
/** 
 * Forward pass: b(e_{p,c} = True) = d_{p,c} b(e_{p,c} = False) = 1.0 - d_{p,c} Abbreviated: t_i = m_i f_i = 1.0 - m_i
 */
@Override public Beliefs forward(){
}
Program: 131314
Project: 131314
Buggy source:
@Override public void backward(){
}

Fixed version (ground truth):
/** 
 * Backward pass: dG/dm_i += dG/dt_i*dt_i/dm_i + dG/df_i*df_i/dm_i = dG/dt_i - dG/df_i
 */
@Override public void backward(){
}
Program: 131315
Project: 131315
Buggy source:
@Test public void testSimple(){
  Tensor t1=new Tensor(s,2,2);
  t1.setValuesOnly(TensorUtils.getVectorFromValues(s,.2,.3,.5,.7));
  TensorIdentity id1=new TensorIdentity(t1);
  BeliefsIdentity inf=DepTensorFromBeliefsTest.getBeliefsModule();
  DepTensorToBeliefs mod=new DepTensorToBeliefs(id1,inf);
  Beliefs out=mod.forward();
  assertEquals(null,out.varBeliefs[0]);
  assertEquals(null,out.varBeliefs[1]);
  assertEquals(.3,out.varBeliefs[2].getValue(0),1e-13);
  assertEquals(.7,out.varBeliefs[2].getValue(1),1e-13);
  assertEquals(.5,out.varBeliefs[3].getValue(0),1e-13);
  assertEquals(.5,out.varBeliefs[3].getValue(1),1e-13);
  Beliefs outAdj=mod.getOutputAdj();
  outAdj.fill(2.2);
  mod.backward();
  Tensor inAdj=id1.getOutputAdj();
  assertEquals(0.0,inAdj.get(0,0),1e-13);
  assertEquals(0.0,inAdj.get(0,1),1e-13);
  assertEquals(2.2,inAdj.get(1,0),1e-13);
  assertEquals(2.2,inAdj.get(1,1),1e-13);
}

Fixed version (ground truth):
@Test public void testSimple(){
  Tensor t1=new Tensor(s,2,2);
  t1.setValuesOnly(TensorUtils.getVectorFromValues(s,.2,.3,.5,.7));
  TensorIdentity id1=new TensorIdentity(t1);
  BeliefsIdentity inf=DepTensorFromBeliefsTest.getBeliefsModule();
  DepTensorToBeliefs mod=new DepTensorToBeliefs(id1,inf);
  Beliefs out=mod.forward();
  assertEquals(null,out.varBeliefs[0]);
  assertEquals(null,out.varBeliefs[1]);
  assertEquals(.3,out.varBeliefs[2].getValue(0),1e-13);
  assertEquals(.7,out.varBeliefs[2].getValue(1),1e-13);
  assertEquals(.5,out.varBeliefs[3].getValue(0),1e-13);
  assertEquals(.5,out.varBeliefs[3].getValue(1),1e-13);
  Beliefs outAdj=mod.getOutputAdj();
  outAdj.fill(0.0);
  outAdj.varBeliefs[2].set(2.2,1);
  outAdj.varBeliefs[3].set(2.2,0);
  mod.backward();
  Tensor inAdj=id1.getOutputAdj();
  assertEquals(0.0,inAdj.get(0,0),1e-13);
  assertEquals(0.0,inAdj.get(0,1),1e-13);
  assertEquals(-2.2,inAdj.get(1,0),1e-13);
  assertEquals(2.2,inAdj.get(1,1),1e-13);
}
Program: 131316
Project: 131316
Buggy source:
@Test public void testDotProduct(){
  Tensor t1=TensorUtils.getVectorFromValues(s,2,3,5);
  Tensor t2=TensorUtils.getVectorFromValues(s,-4,6,7);
  assertEquals(2 * -4 + 3 * 6 + 5 * 7,t1.getDotProduct(t2),1e-13);
}

Fixed version (ground truth):
@Test public void testDotProduct(){
  for (  Algebra s : two) {
    Tensor t1=TensorUtils.getVectorFromValues(s,s.fromReal(2),s.fromReal(3),s.fromReal(5));
    Tensor t2=TensorUtils.getVectorFromValues(s,s.fromReal(-4),s.fromReal(6),s.fromReal(7));
    assertEquals(s.fromReal(2 * -4 + 3 * 6 + 5 * 7),t1.getDotProduct(t2),1e-13);
  }
}
Program: 131317
Project: 131317
Buggy source:
@Test public void testValueOperations(){
  Tensor f1=new Tensor(s,2);
  f1.setValue(0,0);
  f1.setValue(1,1);
  f1.fill(2);
  JUnitUtils.assertArrayEquals(new double[]{2,2},f1.getValues(),1e-13);
  f1.setValue(0,1);
  f1.add(2);
  JUnitUtils.assertArrayEquals(new double[]{3,4},f1.getValues(),1e-13);
  f1.multiply(0.5);
  JUnitUtils.assertArrayEquals(new double[]{1.5,2},f1.getValues(),1e-13);
  assertEquals(1.5,f1.getValue(0),1e-13);
  assertEquals(2.0,f1.getValue(1),1e-13);
}

Fixed version (ground truth):
private void testValueOperations(Algebra s){
  Tensor f1=new Tensor(s,2);
  f1.setValue(0,s.fromReal(0));
  f1.setValue(1,s.fromReal(1));
  f1.fill(s.fromReal(2));
  JUnitUtils.assertArrayEquals(Algebras.getFromReal(new double[]{2,2},s),f1.getValues(),1e-13);
  f1.setValue(0,s.fromReal(1));
  f1.add(s.fromReal(2));
  JUnitUtils.assertArrayEquals(Algebras.getFromReal(new double[]{3,4},s),f1.getValues(),1e-13);
  f1.multiply(s.fromReal(0.5));
  JUnitUtils.assertArrayEquals(Algebras.getFromReal(new double[]{1.5,2},s),f1.getValues(),1e-13);
  assertEquals(s.fromReal(1.5),f1.getValue(0),1e-13);
  assertEquals(s.fromReal(2.0),f1.getValue(1),1e-13);
}
Program: 131318
Project: 131318
Buggy source:
@Test public void testGetSetAddSubWithIndices(){
  Tensor t1=new Tensor(s,2,3,5);
  double val;
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(0,t1.set(val++,i,j,k),1e-13);
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(val,t1.set(val,i,j,k),1e-13);
        val++;
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(val++,t1.get(i,j,k),1e-13);
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(val,t1.add(val,i,j,k),1e-13);
        assertEquals(val * 2,t1.get(i,j,k),1e-13);
        val++;
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(val * 2,t1.subtract(val,i,j,k),1e-13);
        assertEquals(val,t1.get(i,j,k),1e-13);
        val++;
      }
    }
  }
}

Fixed version (ground truth):
private void testGetSetAddSubWithIndices(Algebra s){
  Tensor t1=new Tensor(s,2,3,5);
  double val;
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(s.fromReal(0),t1.set(val++,i,j,k),1e-13);
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(val,t1.set(val,i,j,k),1e-13);
        val++;
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(val++,t1.get(i,j,k),1e-13);
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        assertEquals(val,t1.add(val,i,j,k),1e-13);
        double exp=s.times(s.fromReal(2),val);
        assertEquals(exp,t1.get(i,j,k),1e-13);
        val++;
      }
    }
  }
  val=0;
  for (int i=0; i < 2; i++) {
    for (int j=0; j < 3; j++) {
      for (int k=0; k < 5; k++) {
        double exp=s.times(s.fromReal(2),val);
        assertEquals(exp,t1.subtract(val,i,j,k),1e-13);
        assertEquals(val,t1.get(i,j,k),1e-13);
        val++;
      }
    }
  }
}
Program: 131319
Project: 131319
Buggy source:
@Test public void testFactorAddIdentical(){
  Tensor f1=new Tensor(s,2,3);
  f1.fill(1);
  f1.setValue(2,2);
  f1.setValue(3,3);
  Tensor f2=new Tensor(s,2,3);
  f2.fill(2);
  f2.setValue(2,5);
  f2.setValue(5,7);
  System.out.println("String_Node_Str" + f1);
  System.out.println("String_Node_Str" + f2);
  f1.elemAdd(f2);
  System.out.println("String_Node_Str" + f1);
  JUnitUtils.assertArrayEquals(new double[]{3.0,3.0,7.0,5.0,3.0,8.0},f1.getValues(),1e-13);
}

Fixed version (ground truth):
private void testFactorAddIdentical(Algebra s){
  Tensor f1=new Tensor(s,2,3);
  f1.fill(s.fromReal(1));
  f1.setValue(2,s.fromReal(2));
  f1.setValue(3,s.fromReal(3));
  Tensor f2=new Tensor(s,2,3);
  f2.fill(s.fromReal(2));
  f2.setValue(2,s.fromReal(5));
  f2.setValue(5,s.fromReal(7));
  System.out.println("String_Node_Str" + f1);
  System.out.println("String_Node_Str" + f2);
  f1.elemAdd(f2);
  System.out.println("String_Node_Str" + f1);
  JUnitUtils.assertArrayEquals(Algebras.getFromReal(new double[]{3.0,3.0,7.0,5.0,3.0,8.0},s),f1.getValues(),1e-13);
}
Program: 131320
Project: 131320
Buggy source:
public void forwardAndBackward(FgNode parent,Messages[] msgs,Messages[] msgsAdj,boolean isForward){
  Algebra s=msgs[0].message.getAlgebra();
  Tensor tmTrueIn=getMsgs(parent,msgs,LinkVar.TRUE,CUR_MSG,IN_MSG,s);
  Tensor tmFalseIn=getMsgs(parent,msgs,LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  TensorIdentity mTrueIn=new TensorIdentity(tmTrueIn);
  TensorIdentity mFalseIn=new TensorIdentity(tmFalseIn);
  Algebra tmpS=(isForward) ? new LogSemiring() : new LogSignAlgebra();
  ProjDepTreeModule dep=new ProjDepTreeModule(mTrueIn,mFalseIn,tmpS);
  dep.forward();
  if (isForward) {
    Tensor pair=dep.getOutput();
    Tensor tmTrueOut=pair.select(0,1);
    Tensor tmFalseOut=pair.select(0,0);
    setMsgs(parent,msgs,tmTrueOut,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    setMsgs(parent,msgs,tmFalseOut,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
  }
 else {
    Tensor tTrue=getMsgs(parent,msgsAdj,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    Tensor tFalse=getMsgs(parent,msgsAdj,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
    Tensor pairAdj=dep.getOutputAdj();
    Tensor tmTrueOutAdj=pairAdj.select(0,1);
    Tensor tmFalseOutAdj=pairAdj.select(0,0);
    tmTrueOutAdj.elemAdd(tTrue);
    tmFalseOutAdj.elemAdd(tFalse);
    dep.backward();
    addMsgs(parent,msgsAdj,mTrueIn.getOutputAdj(),LinkVar.TRUE,CUR_MSG,IN_MSG,s);
    addMsgs(parent,msgsAdj,mFalseIn.getOutputAdj(),LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  }
}

Fixed version (ground truth):
public void forwardAndBackward(FgNode parent,Messages[] msgs,Messages[] msgsAdj,boolean isForward){
  Algebra s=msgs[0].message.getAlgebra();
  Tensor tmTrueIn=getMsgs(parent,msgs,LinkVar.TRUE,CUR_MSG,IN_MSG,s);
  Tensor tmFalseIn=getMsgs(parent,msgs,LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  TensorIdentity mTrueIn=new TensorIdentity(tmTrueIn);
  TensorIdentity mFalseIn=new TensorIdentity(tmFalseIn);
  Algebra tmpS=(isForward) ? Algebras.LOG_SEMIRING : Algebras.LOG_SIGN_ALGEBRA;
  ProjDepTreeModule dep=new ProjDepTreeModule(mTrueIn,mFalseIn,tmpS);
  dep.forward();
  if (isForward) {
    Tensor pair=dep.getOutput();
    Tensor tmTrueOut=pair.select(0,1);
    Tensor tmFalseOut=pair.select(0,0);
    setMsgs(parent,msgs,tmTrueOut,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    setMsgs(parent,msgs,tmFalseOut,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
  }
 else {
    Tensor tTrue=getMsgs(parent,msgsAdj,LinkVar.TRUE,NEW_MSG,OUT_MSG,s);
    Tensor tFalse=getMsgs(parent,msgsAdj,LinkVar.FALSE,NEW_MSG,OUT_MSG,s);
    Tensor pairAdj=dep.getOutputAdj();
    Tensor tmTrueOutAdj=pairAdj.select(0,1);
    Tensor tmFalseOutAdj=pairAdj.select(0,0);
    tmTrueOutAdj.elemAdd(tTrue);
    tmFalseOutAdj.elemAdd(tFalse);
    dep.backward();
    addMsgs(parent,msgsAdj,mTrueIn.getOutputAdj(),LinkVar.TRUE,CUR_MSG,IN_MSG,s);
    addMsgs(parent,msgsAdj,mFalseIn.getOutputAdj(),LinkVar.FALSE,CUR_MSG,IN_MSG,s);
  }
}
Program: 131321
Project: 131321
Buggy source:
Module<Tensor> getModule(Module<Tensor> m1,Module<Tensor> m2);

Fixed version (ground truth):
Module<Y> getModule(Module<W> m1,Module<X> m2);
Program: 131322
Project: 131322
Buggy source:
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes one tensor as input, and will be tested on multiple semirings.
 */
public static void evalTensor1ByFiniteDiffs(Tensor1Factory fact,Module<Tensor> in1){
}

Fixed version (ground truth):
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes one tensor as input, and will be tested on multiple semirings.
 */
public static void evalTensor1ByFiniteDiffs(Tensor1Factory fact,Module<Tensor> in1){
  evalOneToOneByFiniteDiffs(fact,in1);
}
Program: 131323
Project: 131323
Buggy source:
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes two tensors as input, and will be tested on multiple semirings.
 */
public static void evalTensor2ByFiniteDiffs(Tensor2Factory fact,Module<Tensor> in1,Module<Tensor> in2){
}

Fixed version (ground truth):
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes two tensors as input, and will be tested on multiple semirings.
 */
public static void evalTensor2ByFiniteDiffs(Tensor2Factory fact,Module<Tensor> in1,Module<Tensor> in2){
  evalTwoToOneByFiniteDiffs(fact,in1,in2);
}
Program: 131324
Project: 131324
Buggy source:
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes two tensors as input, and will be tested on multiple semirings. NOTE: This method is just a variant of the one above which always makes the input to the tested module non-negative.
 */
public static void evalTensor2ByFiniteDiffsAbs(Tensor2Factory fact,Module<Tensor> in1,Module<Tensor> in2){
}

Fixed version (ground truth):
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes two tensors as input, and will be tested on multiple semirings. NOTE: This method is just a variant of the one above which always makes the input to the tested module non-negative.
 */
public static void evalTensor2ByFiniteDiffsAbs(Tensor2Factory fact,Module<Tensor> in1,Module<Tensor> in2){
  evalTwoToOneByFiniteDiffsAbs(fact,in1,in2);
}
Program: 131325
Project: 131325
Buggy source:
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes one tensor as input, and will be tested on multiple semirings. NOTE: This method is just a variant of the one above which always makes the input to the tested module non-negative.
 */
public static void evalTensor1ByFiniteDiffsAbs(Tensor1Factory fact,Module<Tensor> in1){
}

Fixed version (ground truth):
/** 
 * Evaluates a tensor module by finite differences. This tensor module takes one tensor as input, and will be tested on multiple semirings. NOTE: This method is just a variant of the one above which always makes the input to the tested module non-negative.
 */
public static void evalTensor1ByFiniteDiffsAbs(Tensor1Factory fact,Module<Tensor> in1){
  evalOneToOneByFiniteDiffsAbs(fact,in1);
}
Program: 131326
Project: 131326
Buggy source:
private static void evalTensor1(Tensor t1,Tensor expT1Adj,Tensor1Factory fact,Tensor expOut,double adjFill,Algebra tmpS){
  TensorIdentity id1=new TensorIdentity(t1);
  ConvertAlgebra id1Co=new ConvertAlgebra(id1,tmpS);
  Module<Tensor> ea=fact.getModule(id1Co);
  ConvertAlgebra eaCo=new ConvertAlgebra(ea,t1.getAlgebra());
  TopoOrder topo=new TopoOrder();
  topo.add(id1);
  topo.add(id1Co);
  topo.add(ea);
  topo.add(eaCo);
  Tensor out=topo.forward();
  assertTensorEqual(expOut,out,1e-10);
  assertTrue(out == topo.getOutput());
  topo.getOutputAdj().fill(adjFill);
  topo.backward();
  assertTensorEqual(expT1Adj,id1.getOutputAdj(),1e-10);
}

Fixed version (ground truth):
private static void evalTensor1(Tensor t1,Tensor expT1Adj,Tensor1Factory fact,Tensor expOut,double adjFill,Algebra tmpS){
  TensorIdentity id1=new TensorIdentity(t1);
  ConvertAlgebra<Tensor> id1Co=new ConvertAlgebra<Tensor>(id1,tmpS);
  Module<Tensor> ea=fact.getModule(id1Co);
  ConvertAlgebra<Tensor> eaCo=new ConvertAlgebra<Tensor>(ea,t1.getAlgebra());
  TopoOrder topo=new TopoOrder();
  topo.add(id1);
  topo.add(id1Co);
  topo.add(ea);
  topo.add(eaCo);
  Tensor out=topo.forward();
  assertTensorEqual(expOut,out,1e-10);
  assertTrue(out == topo.getOutput());
  topo.getOutputAdj().fill(adjFill);
  topo.backward();
  assertTensorEqual(expT1Adj,id1.getOutputAdj(),1e-10);
}
Program: 131327
Project: 131327
Buggy source:
private static void evalTensor2(Tensor t1,Tensor expT1Adj,Tensor t2,Tensor expT2Adj,Tensor2Factory fact,Tensor expOut,double adjFill,Algebra tmpS){
  Tensor.checkSameAlgebra(t1,t2);
  TensorIdentity id1=new TensorIdentity(t1);
  ConvertAlgebra id1Co=new ConvertAlgebra(id1,tmpS);
  TensorIdentity id2=new TensorIdentity(t2);
  ConvertAlgebra id2Co=new ConvertAlgebra(id2,tmpS);
  Module<Tensor> main=fact.getModule(id1Co,id2Co);
  ConvertAlgebra mainCo=new ConvertAlgebra(main,t1.getAlgebra());
  TopoOrder topo=new TopoOrder();
  topo.add(id1);
  topo.add(id1Co);
  topo.add(id2);
  topo.add(id2Co);
  topo.add(main);
  topo.add(mainCo);
  Tensor out=topo.forward();
  assertTensorEqual(expOut,out,1e-13);
  assertTrue(out == topo.getOutput());
  topo.getOutputAdj().fill(adjFill);
  topo.backward();
  assertTensorEqual(expT1Adj,id1.getOutputAdj(),1e-13);
  assertTensorEqual(expT2Adj,id2.getOutputAdj(),1e-13);
}

Fixed version (ground truth):
private static void evalTensor2(Tensor t1,Tensor expT1Adj,Tensor t2,Tensor expT2Adj,Tensor2Factory fact,Tensor expOut,double adjFill,Algebra tmpS){
  Tensor.checkSameAlgebra(t1,t2);
  TensorIdentity id1=new TensorIdentity(t1);
  ConvertAlgebra<Tensor> id1Co=new ConvertAlgebra<Tensor>(id1,tmpS);
  TensorIdentity id2=new TensorIdentity(t2);
  ConvertAlgebra<Tensor> id2Co=new ConvertAlgebra<Tensor>(id2,tmpS);
  Module<Tensor> main=fact.getModule(id1Co,id2Co);
  ConvertAlgebra<Tensor> mainCo=new ConvertAlgebra<Tensor>(main,t1.getAlgebra());
  TopoOrder topo=new TopoOrder();
  topo.add(id1);
  topo.add(id1Co);
  topo.add(id2);
  topo.add(id2Co);
  topo.add(main);
  topo.add(mainCo);
  Tensor out=topo.forward();
  assertTensorEqual(expOut,out,1e-13);
  assertTrue(out == topo.getOutput());
  topo.getOutputAdj().fill(adjFill);
  topo.backward();
  assertTensorEqual(expT1Adj,id1.getOutputAdj(),1e-13);
  assertTensorEqual(expT2Adj,id2.getOutputAdj(),1e-13);
}
Program: 131328
Project: 131328
Buggy source:
List<? extends Module<? extends ModuleTensor>> getInputs();

Fixed version (ground truth):
List<? extends Module<? extends ModuleTensor<?>>> getInputs();
Program: 131329
Project: 131329
Buggy source:
public void add(Module<? extends ModuleTensor> m){
  topoOrder.add(m);
  s=m.getAlgebra();
}

Fixed version (ground truth):
public void add(Module<? extends ModuleTensor<?>> m){
  topoOrder.add(m);
  s=m.getAlgebra();
}
Program: 131330
Project: 131330
Buggy source:
@Override public void backward(){
  List<Module<? extends ModuleTensor>> revTopo=Lists.reverse(topoOrder);
  for (  Module<? extends ModuleTensor> m : revTopo) {
    m.backward();
  }
}

Fixed version (ground truth):
@Override public void backward(){
  List<Module<? extends ModuleTensor<?>>> revTopo=Lists.reverse(topoOrder);
  for (  Module<? extends ModuleTensor<?>> m : revTopo) {
    m.backward();
  }
}
Program: 131331
Project: 131331
Buggy source:
@Override public List<Module<? extends ModuleTensor>> getInputs(){
  List inputs=new ArrayList();
  for (  Module m : topoOrder) {
    inputs.add(m);
  }
  return inputs;
}

Fixed version (ground truth):
@Override public List<Module<? extends ModuleTensor<?>>> getInputs(){
  List inputs=new ArrayList();
  for (  Module m : topoOrder) {
    inputs.add(m);
  }
  return inputs;
}
Program: 131332
Project: 131332
Buggy source:
public List<Module<? extends ModuleTensor>> getTopoOrder(){
  return topoOrder;
}

Fixed version (ground truth):
public List<Module<? extends ModuleTensor<?>>> getTopoOrder(){
  return topoOrder;
}
Program: 131333
Project: 131333
Buggy source:
public BeliefsIdentity(Beliefs b){
  super(b.s);
  this.b=b;
}

Fixed version (ground truth):
public BeliefsIdentity(Beliefs b){
  super(b.s);
  this.y=b;
}
Program: 131334
Project: 131334
Buggy source:
@Override public Beliefs forward(){
  return b;
}

Fixed version (ground truth):
@Override public Beliefs forward(){
  return y;
}
Program: 131335
Project: 131335
Buggy source:
@Override public void zeroOutputAdj(){
  mTrueOut.zeroOutputAdj();
  mFalseOut.zeroOutputAdj();
}

Fixed version (ground truth):
@Override public void zeroOutputAdj(){
  for (  Module<?> m : topoOrder) {
    m.zeroOutputAdj();
  }
}
Program: 131336
Project: 131336
Buggy source:
@Override public List<? extends Object> getInputs(){
  return Lists.getList(leftIn,rightIn);
}

Fixed version (ground truth):
@Override public List<Module<Tensor>> getInputs(){
  return Lists.getList(leftIn,rightIn);
}
Program: 131337
Project: 131337
Buggy source:
@Override public Pair<Tensor,Tensor> getOutputAdj(){
  return new Pair<Tensor,Tensor>(mTrueOut.getOutputAdj(),mFalseOut.getOutputAdj());
}

Fixed version (ground truth):
@Override public Tensor getOutputAdj(){
  return comb.getOutputAdj();
}
Program: 131338
Project: 131338
Buggy source:
@Override public Pair<Tensor,Tensor> getOutput(){
  return new Pair<Tensor,Tensor>(mTrueOut.getOutput(),mFalseOut.getOutput());
}

Fixed version (ground truth):
@Override public Tensor getOutput(){
  return comb.getOutput();
}
Program: 131339
Project: 131339
Buggy source:
/** 
 * @inheritDoc 
 */
@Override public void accum(FgModel model,int i,Accumulator ac){
  final Timer t0=new Timer();
  t0.start();
  final Timer t=new Timer();
  final LFgExample ex=data.get(i);
  final FactorGraph fg=ex.getFgLatPred();
  final VarConfig goldConfig=ex.getGoldConfig();
  Algebra s=infFactory.getAlgebra();
  t.reset();
  t.start();
  ExpFamFactorsModule effm=new ExpFamFactorsModule(fg,model,s);
  ErmaBp inf=(ErmaBp)infFactory.getInferencer(fg);
  inf.setEffm(effm);
  Module<Tensor> dl=dlFactory.getDl(fg,goldConfig,inf,ac.curIter,ac.maxIter);
  t.stop();
  initTimer.add(t);
  t.reset();
  t.start();
  effm.forward();
  t.stop();
  updTimer.add(t);
  t.reset();
  t.start();
  inf.forward();
  t.stop();
  infTimer.add(t);
  t.reset();
  t.start();
  dl.forward();
  t.stop();
  valTimer.add(t);
  if (ac.accumValue) {
    t.reset();
    t.start();
    ac.value+=dl.getOutput().get(0);
    t.stop();
    valTimer.add(t);
  }
  if (ac.accumGradient) {
    t.reset();
    t.start();
    dl.getOutputAdj().fill(1.0);
    dl.backward();
    inf.backward();
    effm.backward();
    ac.gradient.add(effm.getModelAdj());
    t.stop();
    gradTimer.add(t);
  }
  if (ac.accumWeight) {
    ac.weight+=ex.getWeight();
  }
  if (ac.accumTrainLoss) {
    ac.trainLoss+=dl.getOutput().get(0);
  }
  t0.stop();
  tot.add(t0);
}

Fixed version (ground truth):
/** 
 * @inheritDoc 
 */
@Override public void accum(FgModel model,int i,Accumulator ac){
  final Timer t0=new Timer();
  t0.start();
  final Timer t=new Timer();
  final LFgExample ex=data.get(i);
  final FactorGraph fg=ex.getFgLatPred();
  final VarConfig goldConfig=ex.getGoldConfig();
  t.reset();
  t.start();
  ExpFamFactorsModule effm=new ExpFamFactorsModule(fg,model,infFactory.getAlgebra());
  ErmaBp inf=(ErmaBp)infFactory.getInferencer(fg);
  inf.setEffm(effm);
  Module<Tensor> dl=dlFactory.getDl(fg,goldConfig,inf,ac.curIter,ac.maxIter);
  t.stop();
  initTimer.add(t);
  t.reset();
  t.start();
  effm.forward();
  t.stop();
  updTimer.add(t);
  t.reset();
  t.start();
  inf.forward();
  t.stop();
  infTimer.add(t);
  t.reset();
  t.start();
  dl.forward();
  t.stop();
  valTimer.add(t);
  Algebra outS=dl.getAlgebra();
  double loss=outS.toReal(dl.getOutput().get(0));
  if (ac.accumValue) {
    t.reset();
    t.start();
    ac.value+=loss;
    t.stop();
    valTimer.add(t);
  }
  if (ac.accumGradient) {
    t.reset();
    t.start();
    dl.getOutputAdj().fill(outS.one());
    dl.backward();
    inf.backward();
    effm.backward();
    ac.gradient.add(effm.getModelAdj());
    t.stop();
    gradTimer.add(t);
  }
  if (ac.accumWeight) {
    ac.weight+=ex.getWeight();
  }
  if (ac.accumTrainLoss) {
    ac.trainLoss+=loss;
  }
  t0.stop();
  tot.add(t0);
}
Program: 131340
Project: 131340
Buggy source:
/** 
 * Gets the strides for the given dimensions. The stride for dimension i (stride[i]) denotes the step forward in values array necessary to increase the index for that dimension by 1.
 */
private static int[] getStrides(int[] dims){
  int rightmost=dims.length - 1;
  int[] strides=new int[dims.length];
  strides[rightmost]=1;
  for (int i=rightmost - 1; i >= 0; i--) {
    strides[i]=dims[i + 1] * strides[i + 1];
  }
  return strides;
}

Fixed version (ground truth):
/** 
 * Gets the strides for the given dimensions. The stride for dimension i (stride[i]) denotes the step forward in values array necessary to increase the index for that dimension by 1.
 */
private static int[] getStrides(int[] dims){
  int rightmost=dims.length - 1;
  int[] strides=new int[dims.length];
  if (dims.length > 0) {
    strides[rightmost]=1;
    for (int i=rightmost - 1; i >= 0; i--) {
      strides[i]=dims[i + 1] * strides[i + 1];
    }
  }
  return strides;
}
Program: 131342
Project: 131342
Buggy source:
private void unnormalizeAdjInPlace(VarTensor dist,VarTensor distAdj,double unormSum){
  VarTensor unormAdj=distAdj;
  double dotProd=dist.getDotProduct(distAdj);
  unormAdj.subtract(dotProd);
  unormAdj.divide(unormSum);
  logTraceMsgUpdate("String_Node_Str",distAdj,null);
}

Fixed version (ground truth):
private void unnormalizeAdjInPlace(VarTensor dist,VarTensor distAdj,double unormSum){
  if (unormSum == s.zero()) {
    throw new IllegalArgumentException("String_Node_Str" + dist + "String_Node_Str"+ distAdj+ "String_Node_Str"+ unormSum);
  }
  VarTensor unormAdj=distAdj;
  double dotProd=dist.getDotProduct(distAdj);
  unormAdj.subtract(dotProd);
  unormAdj.divide(unormSum);
  logTraceMsgUpdate("String_Node_Str",distAdj,null);
}
Program: 131343
Project: 131343
Buggy source:
/** 
 * Gets this factor as a VarTensor. This will always return a new object. See also safeGetVarTensor(). 
 */
public static VarTensor safeNewVarTensor(Algebra s,Factor f){
  VarTensor factor;
  if (f instanceof VarTensor) {
    factor=((VarTensor)f).copyAndConvertAlgebra(s);
  }
 else {
    factor=new VarTensor(s,f.getVars());
    for (int c=0; c < factor.size(); c++) {
      factor.setValue(c,s.fromLogProb(f.getLogUnormalizedScore(c)));
    }
  }
  return factor;
}

Fixed version (ground truth):
/** 
 * Gets this factor as a VarTensor. This will always return a new object. See also safeGetVarTensor(). 
 */
public static VarTensor safeNewVarTensor(Algebra s,Factor f){
  VarTensor factor;
  factor=new VarTensor(s,f.getVars());
  for (int c=0; c < factor.size(); c++) {
    factor.setValue(c,s.fromLogProb(f.getLogUnormalizedScore(c)));
  }
  return factor;
}
Program: 131344
Project: 131344
Buggy source:
public ExpFamFactorsModule(FactorGraph fg,FgModel model,Algebra s){
  if (!(s.equals(Algebras.LOG_SEMIRING) || s.equals(Algebras.REAL_ALGEBRA))) {
    throw new IllegalArgumentException("String_Node_Str" + s);
  }
  this.fg=fg;
  this.model=model;
  this.s=s;
}

Fixed version (ground truth):
public ExpFamFactorsModule(FactorGraph fg,FgModel model,Algebra s){
  this.fg=fg;
  this.model=model;
  this.s=s;
}
Program: 131345
Project: 131345
Buggy source:
@Override public void backward(){
}

Fixed version (ground truth):
@Override public void backward(){
  modelAdj=model.getSparseZeroedCopy();
  for (int a=0; a < y.length; a++) {
    Factor factor=fg.getFactor(a);
    if (!(factor instanceof GlobalFactor)) {
      VarTensor factorMarginal=new VarTensor(yAdj[a]);
      factorMarginal.prod(y[a]);
      factorMarginal=factorMarginal.copyAndConvertAlgebra(Algebras.REAL_ALGEBRA);
      factor.addExpectedFeatureCounts(modelAdj,factorMarginal,Algebras.REAL_ALGEBRA.one());
    }
  }
}
Program: 131347
Project: 131347
Buggy source:
/** 
 * Computes the sum of the entries of the pointwise product of two tensors with identical domains. 
 */
public double getDotProduct(Tensor other){
  checkEqualSize(this,other);
  double dot=s.negInf();
  for (int c=0; c < this.values.length; c++) {
    dot=s.plus(dot,s.times(this.values[c],other.values[c]));
  }
  return dot;
}

Fixed version (ground truth):
/** 
 * Computes the sum of the entries of the pointwise product of two tensors with identical domains. 
 */
public double getDotProduct(Tensor other){
  checkEqualSize(this,other);
  double dot=s.zero();
  for (int c=0; c < this.values.length; c++) {
    dot=s.plus(dot,s.times(this.values[c],other.values[c]));
  }
  return dot;
}
Program: 131348
Project: 131348
Buggy source:
private void initVarToFactorAdj(int i,VarTensor[] facBeliefsAdj,int varId,int facId,FgEdge edge){
  Factor fac=fg.getFactor(facId);
  VarTensor prod=BruteForceInferencer.safeNewVarTensor(s,fac);
  prod.prod(facBeliefsAdj[facId]);
  getProductOfMessages(fg.getFactorNode(facId),prod,fg.getVarNode(varId));
  msgsAdj[i].message=prod.getMarginal(new VarSet(edge.getVar()),false);
}

Fixed version (ground truth):
private void initVarToFactorAdj(int i,VarTensor[] facBeliefsAdj,int varId,int facId,FgEdge edge){
  Factor fac=fg.getFactor(facId);
  VarTensor prod=BruteForceInferencer.safeNewVarTensor(s,fac);
  prod.prod(facBeliefsAdj[facId]);
  getProductOfMessages(fg.getFactorNode(facId),prod,fg.getVarNode(varId));
  msgsAdj[i].message=prod.getMarginal(new VarSet(edge.getVar()),false);
  logTraceMsgUpdate("String_Node_Str",msgsAdj[i].message,edge);
}
Program: 131349
Project: 131349
Buggy source:
private void backwardVarToFactor(FgEdge edgeIA,int i){
  for (  FgEdge edgeBI : fg.getVarNode(edgeIA.getVar().getId()).getInEdges()) {
    if (edgeBI != edgeIA.getOpposing()) {
      VarTensor prod=new VarTensor(msgsAdj[i].newMessage);
      getProductOfMessages(edgeIA.getParent(),prod,edgeIA.getChild(),edgeBI.getParent());
      msgsAdj[edgeBI.getId()].message.add(prod);
    }
  }
}

Fixed version (ground truth):
private void backwardVarToFactor(FgEdge edgeIA,int i){
  for (  FgEdge edgeBI : fg.getVarNode(edgeIA.getVar().getId()).getInEdges()) {
    if (edgeBI != edgeIA.getOpposing()) {
      VarTensor prod=new VarTensor(msgsAdj[i].newMessage);
      getProductOfMessages(edgeIA.getParent(),prod,edgeIA.getChild(),edgeBI.getParent());
      msgsAdj[edgeBI.getId()].message.add(prod);
      logTraceMsgUpdate("String_Node_Str",msgsAdj[edgeBI.getId()].message,edgeBI);
    }
  }
}
Program: 131350
Project: 131350
Buggy source:
private void backwardFactorToVar(FgEdge edgeAI,int i){
  Factor factor=edgeAI.getFactor();
  int facId=factor.getId();
{
    VarTensor prod=new VarTensor(msgsAdj[i].newMessage);
    getProductOfMessages(edgeAI.getParent(),prod,edgeAI.getChild());
    potentialsAdj[facId].add(prod);
  }
  for (  FgEdge edgeJA : fg.getFactorNode(facId).getInEdges()) {
    if (edgeJA != edgeAI.getOpposing()) {
      VarTensor prod=BruteForceInferencer.safeNewVarTensor(s,factor);
      getProductOfMessages(edgeAI.getParent(),prod,edgeAI.getChild(),edgeJA.getParent());
      prod.prod(msgsAdj[i].newMessage);
      VarSet varJ=msgsAdj[edgeJA.getId()].message.getVars();
      msgsAdj[edgeJA.getId()].message.add(prod.getMarginal(varJ,false));
    }
  }
}

Fixed version (ground truth):
private void backwardFactorToVar(FgEdge edgeAI,int i){
  Factor factor=edgeAI.getFactor();
  int facId=factor.getId();
{
    VarTensor prod=new VarTensor(msgsAdj[i].newMessage);
    getProductOfMessages(edgeAI.getParent(),prod,edgeAI.getChild());
    potentialsAdj[facId].add(prod);
    logTraceMsgUpdate("String_Node_Str",potentialsAdj[facId],null);
  }
  for (  FgEdge edgeJA : fg.getFactorNode(facId).getInEdges()) {
    if (edgeJA != edgeAI.getOpposing()) {
      VarTensor prod=BruteForceInferencer.safeNewVarTensor(s,factor);
      getProductOfMessages(edgeAI.getParent(),prod,edgeAI.getChild(),edgeJA.getParent());
      prod.prod(msgsAdj[i].newMessage);
      VarSet varJ=msgsAdj[edgeJA.getId()].message.getVars();
      msgsAdj[edgeJA.getId()].message.add(prod.getMarginal(varJ,false));
      logTraceMsgUpdate("String_Node_Str",msgsAdj[edgeJA.getId()].message,edgeJA);
    }
  }
}
Program: 131351
Project: 131351
Buggy source:
private void initFactorToVarAdj(int i,VarTensor[] varBeliefsAdj,int varId,int facId){
  msgsAdj[i].message=new VarTensor(varBeliefsAdj[varId]);
  getProductOfMessages(fg.getVarNode(varId),msgsAdj[i].message,fg.getFactorNode(facId));
}

Fixed version (ground truth):
private void initFactorToVarAdj(int i,VarTensor[] varBeliefsAdj,int varId,int facId){
  msgsAdj[i].message=new VarTensor(varBeliefsAdj[varId]);
  getProductOfMessages(fg.getVarNode(varId),msgsAdj[i].message,fg.getFactorNode(facId));
  logTraceMsgUpdate("String_Node_Str",msgsAdj[i].message,fg.getEdge(i));
}
Program: 131352
Project: 131352
Buggy source:
private void unnormalizeAdjInPlace(VarTensor dist,VarTensor distAdj,double unormSum){
  VarTensor unormAdj=distAdj;
  double dotProd=dist.getDotProduct(distAdj);
  unormAdj.subtract(dotProd);
  unormAdj.divide(unormSum);
}

Fixed version (ground truth):
private void unnormalizeAdjInPlace(VarTensor dist,VarTensor distAdj,double unormSum){
  VarTensor unormAdj=distAdj;
  double dotProd=dist.getDotProduct(distAdj);
  unormAdj.subtract(dotProd);
  unormAdj.divide(unormSum);
  logTraceMsgUpdate("String_Node_Str",distAdj,null);
}