     ldc = result_->stride[2];
   }
 
-  if (batch1->stride[transpose_result ? 2 : 1] == 1)
+  if (batch1->stride[transpose_result ? 2 : 1] == 1 && 
+   batch1->stride[transpose_result ? 1 : 2] != 0)
   {
     transpose_batch1 = 'n';
     batch1_ = batch1;
     lda = batch1_->stride[transpose_result ? 1 : 2];
   }
-  else if (batch1->stride[transpose_result ? 1 : 2] == 1)
+  else if (batch1->stride[transpose_result ? 1 : 2] == 1 && 
+   batch1->stride[transpose_result ? 2 : 1] != 0)
   {
     transpose_batch1 = 't';
     batch1_ = batch1;

    lda = batch1_->stride[1];
  }

  if (batch2->stride[transpose_result ? 2 : 1] == 1)
  {
    transpose_batch2 = 'n';
    batch2_ = batch2;
    ldb = batch2_->stride[transpose_result ? 1 : 2];
  }
  else if (batch2->stride[transpose_result ? 1 : 2] == 1)
  {
    transpose_batch2 = 't';
    batch2_ = batch2;

    batch2_ = THCTensor_(newContiguous)(state, batch2);
    ldb = batch2_->stride[1];
  }
  long num_batches = result_->size[0];

#if defined(THC_REAL_IS_FLOAT) || defined(THC_REAL_IS_DOUBLE)
