Program: 3224
Project: 3224
Buggy source:
/** 
 * Merge the list of datasets in to one list. All the rows are merged in to one dataset
 * @param data the data to merge
 * @return a single dataset
 */
public static DataSet merge(List<DataSet> data){
  if (data.isEmpty())   throw new IllegalArgumentException("String_Node_Str");
  DataSet first=data.get(0);
  int rankFeatures=first.getFeatures().rank();
  int rankLabels=first.getLabels().rank();
  INDArray[] featuresToMerge=new INDArray[data.size()];
  INDArray[] labelsToMerge=new INDArray[data.size()];
  int count=0;
  boolean hasFeaturesMaskArray=false;
  boolean hasLabelsMaskArray=false;
  for (  DataSet ds : data) {
    featuresToMerge[count]=ds.getFeatureMatrix();
    labelsToMerge[count++]=ds.getLabels();
    if (rankFeatures == 3 || rankLabels == 3) {
      hasFeaturesMaskArray=hasFeaturesMaskArray | (ds.getFeaturesMaskArray() != null);
      hasLabelsMaskArray=hasLabelsMaskArray | (ds.getLabelsMaskArray() != null);
    }
  }
  INDArray featuresOut;
  INDArray labelsOut;
  INDArray featuresMaskOut;
  INDArray labelsMaskOut;
switch (rankFeatures) {
case 2:
    featuresOut=merge2d(featuresToMerge);
  featuresMaskOut=null;
break;
case 3:
INDArray[] featuresMasks=null;
if (hasFeaturesMaskArray) {
featuresMasks=new INDArray[featuresToMerge.length];
count=0;
for (DataSet ds : data) {
featuresMasks[count++]=ds.getFeaturesMaskArray();
}
}
INDArray[] temp=mergeTimeSeries(featuresToMerge,featuresMasks);
featuresOut=temp[0];
featuresMaskOut=temp[1];
break;
case 4:
featuresOut=merge4dCnnData(featuresToMerge);
featuresMaskOut=null;
break;
default :
throw new IllegalStateException("String_Node_Str" + Arrays.toString(data.get(0).getFeatureMatrix().shape()));
}
switch (rankLabels) {
case 2:
labelsOut=merge2d(labelsToMerge);
labelsMaskOut=null;
break;
case 3:
INDArray[] labelsMasks=null;
if (hasLabelsMaskArray) {
labelsMasks=new INDArray[labelsToMerge.length];
count=0;
for (DataSet ds : data) {
labelsMasks[count++]=ds.getLabelsMaskArray();
}
}
INDArray[] temp=mergeTimeSeries(labelsToMerge,labelsMasks);
labelsOut=temp[0];
labelsMaskOut=temp[1];
break;
case 4:
labelsOut=merge4dCnnData(featuresToMerge);
labelsMaskOut=null;
break;
default :
throw new IllegalStateException("String_Node_Str" + Arrays.toString(data.get(0).getLabels().shape()));
}
DataSet dataset=new DataSet(featuresOut,labelsOut,featuresMaskOut,labelsMaskOut);
List<Serializable> meta=null;
for (DataSet ds : data) {
if (ds.getExampleMetaData() == null || ds.getExampleMetaData().size() != ds.numExamples()) {
meta=null;
break;
}
if (meta == null) meta=new ArrayList<>();
meta.addAll(ds.getExampleMetaData());
}
if (meta != null) {
dataset.setExampleMetaData(meta);
}
return dataset;
}

Fixed version (ground truth):
/** 
 * Merge the list of datasets in to one list. All the rows are merged in to one dataset
 * @param data the data to merge
 * @return a single dataset
 */
public static DataSet merge(List<DataSet> data){
  if (data.isEmpty())   throw new IllegalArgumentException("String_Node_Str");
  DataSet first=data.get(0);
  int rankFeatures=first.getFeatures().rank();
  int rankLabels=first.getLabels().rank();
  INDArray[] featuresToMerge=new INDArray[data.size()];
  INDArray[] labelsToMerge=new INDArray[data.size()];
  int count=0;
  boolean hasFeaturesMaskArray=false;
  boolean hasLabelsMaskArray=false;
  for (  DataSet ds : data) {
    featuresToMerge[count]=ds.getFeatureMatrix();
    labelsToMerge[count++]=ds.getLabels();
    if (rankFeatures == 3 || rankLabels == 3) {
      hasFeaturesMaskArray=hasFeaturesMaskArray | (ds.getFeaturesMaskArray() != null);
      hasLabelsMaskArray=hasLabelsMaskArray | (ds.getLabelsMaskArray() != null);
    }
  }
  INDArray featuresOut;
  INDArray labelsOut;
  INDArray featuresMaskOut;
  INDArray labelsMaskOut;
switch (rankFeatures) {
case 2:
    featuresOut=merge2d(featuresToMerge);
  featuresMaskOut=null;
break;
case 3:
INDArray[] featuresMasks=null;
if (hasFeaturesMaskArray) {
featuresMasks=new INDArray[featuresToMerge.length];
count=0;
for (DataSet ds : data) {
featuresMasks[count++]=ds.getFeaturesMaskArray();
}
}
INDArray[] temp=mergeTimeSeries(featuresToMerge,featuresMasks);
featuresOut=temp[0];
featuresMaskOut=temp[1];
break;
case 4:
featuresOut=merge4dCnnData(featuresToMerge);
featuresMaskOut=null;
break;
default :
throw new IllegalStateException("String_Node_Str" + Arrays.toString(data.get(0).getFeatureMatrix().shape()));
}
switch (rankLabels) {
case 2:
labelsOut=merge2d(labelsToMerge);
labelsMaskOut=null;
break;
case 3:
INDArray[] labelsMasks=null;
if (hasLabelsMaskArray) {
labelsMasks=new INDArray[labelsToMerge.length];
count=0;
for (DataSet ds : data) {
labelsMasks[count++]=ds.getLabelsMaskArray();
}
}
INDArray[] temp=mergeTimeSeries(labelsToMerge,labelsMasks);
labelsOut=temp[0];
labelsMaskOut=temp[1];
break;
case 4:
labelsOut=merge4dCnnData(labelsToMerge);
labelsMaskOut=null;
break;
default :
throw new IllegalStateException("String_Node_Str" + Arrays.toString(data.get(0).getLabels().shape()));
}
DataSet dataset=new DataSet(featuresOut,labelsOut,featuresMaskOut,labelsMaskOut);
List<Serializable> meta=null;
for (DataSet ds : data) {
if (ds.getExampleMetaData() == null || ds.getExampleMetaData().size() != ds.numExamples()) {
meta=null;
break;
}
if (meta == null) meta=new ArrayList<>();
meta.addAll(ds.getExampleMetaData());
}
if (meta != null) {
dataset.setExampleMetaData(meta);
}
return dataset;
}