Skip to content

Commit 1fc2038

Browse files
author
Yori Zwols
committed
Added some more comments to THTensorLapack.c, and fixed two error messages
1 parent f3bea73 commit 1fc2038

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

generic/THTensorLapack.c

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ void THTensor_(gesv)(THTensor *rb_, THTensor *ra_, THTensor *b, THTensor *a)
8181
{
8282
int n, nrhs, lda, ldb, info;
8383
THIntTensor *ipiv;
84-
THTensor *ra__;
85-
THTensor *rb__;
84+
THTensor *ra__; // working version of A matrix to be passed into lapack GELS
85+
THTensor *rb__; // working version of B matrix to be passed into lapack GELS
8686

87-
int clonea;
88-
int cloneb;
89-
int destroya;
90-
int destroyb;
87+
int clonea; // set to 1 if ra__ should be copied into ra_ at return
88+
int cloneb; // set to 1 if rb__ should be copied into rb_ at return
89+
int destroya; // set to 1 if ra__ needs to be destroyed at return
90+
int destroyb; // set to 1 if rb__ needs to be destroyed at return
9191

9292

9393
if (a == NULL || ra_ == a) /* possibly destroy the inputs */
@@ -97,7 +97,7 @@ void THTensor_(gesv)(THTensor *rb_, THTensor *ra_, THTensor *b, THTensor *a)
9797
clonea = THTensor_(lapackClone)(ra__,ra_,0);
9898
destroya = 1;
9999
}
100-
else /*we want to definitely clone and use ra_ and rb_ as computational space*/
100+
else /*we want to definitely clone and use ra_ as computational space*/
101101
{
102102
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
103103
clonea = THTensor_(lapackClone)(ra_,a,1);
@@ -111,7 +111,7 @@ void THTensor_(gesv)(THTensor *rb_, THTensor *ra_, THTensor *b, THTensor *a)
111111
cloneb = THTensor_(lapackClone)(rb__,rb_,0);
112112
destroyb = 1;
113113
}
114-
else /*we want to definitely clone and use ra_ and rb_ as computational space*/
114+
else /*we want to definitely clone and use rb_ as computational space*/
115115
{
116116
THArgCheck(b->nDimension == 2, 2, "B should be 2 dimensional");
117117
cloneb = THTensor_(lapackClone)(rb_,b,1);
@@ -355,22 +355,22 @@ void THTensor_(syev)(THTensor *re_, THTensor *rv_, THTensor *a, const char *jobz
355355
THTensor *rv__ = NULL;
356356
THTensor *re__ = NULL;
357357

358-
int clonea;
359-
int destroy;
358+
int clonev; // set to 1 if rv__ should be copied into rv_ at return
359+
int destroyv; // set to 1 if rv__ needs to be destroyed at return
360360

361361
if (a == NULL) /* possibly destroy the inputs */
362362
{
363363
THArgCheck(rv_->nDimension == 2, 1, "A should be 2 dimensional");
364364
rv__ = THTensor_(new)();
365-
clonea = THTensor_(lapackClone)(rv__,rv_,0);
366-
destroy = 1;
365+
clonev = THTensor_(lapackClone)(rv__,rv_,0);
366+
destroyv = 1;
367367
}
368368
else /*we want to definitely clone and use ra_ and rb_ as computational space*/
369369
{
370370
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
371-
clonea = THTensor_(lapackClone)(rv_,a,1);
371+
clonev = THTensor_(lapackClone)(rv_,a,1);
372372
rv__ = rv_;
373-
destroy = 0;
373+
destroyv = 0;
374374
}
375375

376376
THArgCheck(rv__->nDimension == 2, 2, "A should be 2 dimensional");
@@ -398,9 +398,9 @@ void THTensor_(syev)(THTensor *re_, THTensor *rv_, THTensor *a, const char *jobz
398398
THError("Lapack syev : Argument %d : illegal value", -info);
399399
}
400400
/* clean up */
401-
if (destroy)
401+
if (destroyv)
402402
{
403-
if (clonea)
403+
if (clonev)
404404
{
405405
THTensor_(copy)(rv_,rv__);
406406
}
@@ -431,22 +431,22 @@ void THTensor_(gesvd2)(THTensor *ru_, THTensor *rs_, THTensor *rv_, THTensor *ra
431431
THTensor *rs__ = NULL;
432432
THTensor *rv__ = NULL;
433433

434-
int clonea;
435-
int destroy;
434+
int clonea; // set to 1 if ra__ should be copied into ra_ at return
435+
int destroya; // set to 1 if ra__ needs to be destroyed at return
436436

437437
if (a == NULL) /* possibly destroy the inputs */
438438
{
439439
THArgCheck(ra_->nDimension == 2, 1, "A should be 2 dimensional");
440440
ra__ = THTensor_(new)();
441441
clonea = THTensor_(lapackClone)(ra__,ra_,0);
442-
destroy = 1;
442+
destroya = 1;
443443
}
444444
else /*we want to definitely clone */
445445
{
446446
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
447447
clonea = THTensor_(lapackClone)(ra_,a,1);
448448
ra__ = ra_;
449-
destroy = 0;
449+
destroya = 0;
450450
}
451451

452452
THArgCheck(ra__->nDimension == 2, 2, "A should be 2 dimensional");
@@ -510,7 +510,7 @@ void THTensor_(gesvd2)(THTensor *ru_, THTensor *rs_, THTensor *rv_, THTensor *ra
510510
THTensor_(copy)(rv_, rv__);
511511

512512
/* clean up */
513-
if (destroy)
513+
if (destroya)
514514
{
515515
if (clonea)
516516
{
@@ -532,22 +532,22 @@ void THTensor_(getri)(THTensor *ra_, THTensor *a)
532532
THTensor *work;
533533
THTensor *ra__;
534534

535-
int clonea;
536-
int destroy;
535+
int clonea; // set to 1 if ra__ should be copied into ra_ at return
536+
int destroya; // set to 1 if ra__ needs to be destroyed at return
537537

538538
if (a == NULL) /* possibly destroy the inputs */
539539
{
540540
THArgCheck(ra_->nDimension == 2, 1, "A should be 2 dimensional");
541541
ra__ = THTensor_(new)();
542542
clonea = THTensor_(lapackClone)(ra__,ra_,0);
543-
destroy = 1;
543+
destroya = 1;
544544
}
545545
else /*we want to definitely clone */
546546
{
547547
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
548548
clonea = THTensor_(lapackClone)(ra_,a,1);
549549
ra__ = ra_;
550-
destroy = 0;
550+
destroya = 0;
551551
}
552552

553553
THArgCheck(ra__->nDimension == 2, 2, "A should be 2 dimensional");
@@ -583,7 +583,7 @@ void THTensor_(getri)(THTensor *ra_, THTensor *a)
583583
}
584584

585585
/* clean up */
586-
if (destroy)
586+
if (destroya)
587587
{
588588
if (clonea)
589589
{
@@ -601,22 +601,22 @@ void THTensor_(potrf)(THTensor *ra_, THTensor *a)
601601
char uplo = 'U';
602602
THTensor *ra__;
603603

604-
int clonea;
605-
int destroy;
604+
int clonea; // set to 1 if ra__ should be copied into ra_ at return
605+
int destroya; // set to 1 if ra__ needs to be destroyed at return
606606

607607
if (a == NULL) /* possibly destroy the inputs */
608608
{
609609
THArgCheck(ra_->nDimension == 2, 1, "A should be 2 dimensional");
610610
ra__ = THTensor_(new)();
611611
clonea = THTensor_(lapackClone)(ra__,ra_,0);
612-
destroy = 1;
612+
destroya = 1;
613613
}
614614
else /*we want to definitely clone */
615615
{
616616
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
617617
clonea = THTensor_(lapackClone)(ra_,a,1);
618618
ra__ = ra_;
619-
destroy = 0;
619+
destroya = 0;
620620
}
621621

622622
THArgCheck(ra__->nDimension == 2, 2, "A should be 2 dimensional");
@@ -647,7 +647,7 @@ void THTensor_(potrf)(THTensor *ra_, THTensor *a)
647647
}
648648

649649
/* clean up */
650-
if (destroy)
650+
if (destroya)
651651
{
652652
if (clonea)
653653
{
@@ -663,22 +663,22 @@ void THTensor_(potri)(THTensor *ra_, THTensor *a)
663663
char uplo = 'U';
664664
THTensor *ra__;
665665

666-
int clonea;
667-
int destroy;
666+
int clonea; // set to 1 if ra__ should be copied into ra_ at return
667+
int destroya; // set to 1 if ra__ needs to be destroyed at return
668668

669669
if (a == NULL) /* possibly destroy the inputs */
670670
{
671671
THArgCheck(ra_->nDimension == 2, 1, "A should be 2 dimensional");
672672
ra__ = THTensor_(new)();
673673
clonea = THTensor_(lapackClone)(ra__,ra_,0);
674-
destroy = 1;
674+
destroya = 1;
675675
}
676676
else /*we want to definitely clone */
677677
{
678678
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
679679
clonea = THTensor_(lapackClone)(ra_,a,1);
680680
ra__ = ra_;
681-
destroy = 0;
681+
destroya = 0;
682682
}
683683

684684
THArgCheck(ra__->nDimension == 2, 2, "A should be 2 dimensional");
@@ -701,11 +701,11 @@ void THTensor_(potri)(THTensor *ra_, THTensor *a)
701701
THLapack_(potri)(uplo, n, THTensor_(data)(ra__), lda, &info);
702702
if (info > 0)
703703
{
704-
THError("Lapack potrf : A(%d,%d) is 0, A cannot be factorized", info, info);
704+
THError("Lapack potri : A(%d,%d) is 0, A cannot be factorized", info, info);
705705
}
706706
else if (info < 0)
707707
{
708-
THError("Lapack potrf : Argument %d : illegal value", -info);
708+
THError("Lapack potri : Argument %d : illegal value", -info);
709709
}
710710

711711
/* Build full matrix */
@@ -720,7 +720,7 @@ void THTensor_(potri)(THTensor *ra_, THTensor *a)
720720
}
721721

722722
/* clean up */
723-
if (destroy)
723+
if (destroya)
724724
{
725725
if (clonea)
726726
{
@@ -786,20 +786,23 @@ void THTensor_(geqrf)(THTensor *ra_, THTensor *rtau_, THTensor *a)
786786
{
787787
/* Prepare the input for LAPACK, making a copy if necessary. */
788788
THTensor *ra__;
789-
int clonea, destroy;
789+
790+
int clonea; // set to 1 if ra__ should be copied into ra_ at return
791+
int destroya; // set to 1 if ra__ needs to be destroyed at return
792+
790793
if (a == NULL)
791794
{
792795
THArgCheck(ra_->nDimension == 2, 1, "A should be 2 dimensional");
793796
ra__ = THTensor_(new)();
794797
clonea = THTensor_(lapackClone)(ra__, ra_, 0);
795-
destroy = 1;
798+
destroya = 1;
796799
}
797800
else
798801
{
799802
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
800803
clonea = THTensor_(lapackClone)(ra_, a, 1);
801804
ra__ = ra_;
802-
destroy = 0;
805+
destroya = 0;
803806
}
804807

805808
/* Check input sizes, and ensure we have space to store the results. */
@@ -825,7 +828,7 @@ void THTensor_(geqrf)(THTensor *ra_, THTensor *rtau_, THTensor *a)
825828
THTensor_(data)(work), lwork, &info);
826829

827830
/* Clean up. */
828-
if (destroy)
831+
if (destroya)
829832
{
830833
if (clonea)
831834
{
@@ -866,21 +869,23 @@ void THTensor_(orgqr)(THTensor *ra_, THTensor *a, THTensor *tau)
866869
{
867870
/* Prepare the input for LAPACK, making a copy if necessary. */
868871
THTensor *ra__;
869-
int clonea;
870-
int destroy;
872+
873+
int clonea; // set to 1 if ra__ should be copied into ra_ at return
874+
int destroya; // set to 1 if ra__ needs to be destroyed at return
875+
871876
if (a == NULL)
872877
{
873878
THArgCheck(ra_->nDimension == 2, 1, "A should be 2 dimensional");
874879
ra__ = THTensor_(new)();
875880
clonea = THTensor_(lapackClone)(ra__, ra_, 0);
876-
destroy = 1;
881+
destroya = 1;
877882
}
878883
else
879884
{
880885
THArgCheck(a->nDimension == 2, 1, "A should be 2 dimensional");
881886
clonea = THTensor_(lapackClone)(ra_, a, 1);
882887
ra__ = ra_;
883-
destroy = 0;
888+
destroya = 0;
884889
}
885890

886891
/* Check input sizes. */
@@ -905,7 +910,7 @@ void THTensor_(orgqr)(THTensor *ra_, THTensor *a, THTensor *tau)
905910
THTensor_(data)(work), lwork, &info);
906911

907912
/* Clean up. */
908-
if (destroy)
913+
if (destroya)
909914
{
910915
if (clonea)
911916
{

0 commit comments

Comments
 (0)