The R Project SVN R

Rev

Rev 66289 | Rev 66774 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 66289 Rev 66495
Line 665... Line 665...
665
    ydims = getAttrib(y, R_DimSymbol);
665
    ydims = getAttrib(y, R_DimSymbol);
666
    ldx = length(xdims);
666
    ldx = length(xdims);
667
    ldy = length(ydims);
667
    ldy = length(ydims);
668
 
668
 
669
    if (ldx != 2 && ldy != 2) {		/* x and y non-matrices */
669
    if (ldx != 2 && ldy != 2) {		/* x and y non-matrices */
-
 
670
	// for crossprod, allow two cases: n x n ==> (1,n) x (n,1);  1 x n = (n, 1) x (1, n)
670
	if (PRIMVAL(op) == 0) {
671
	if (PRIMVAL(op) == 1 && LENGTH(x) == 1) {
671
	    nrx = 1;
672
	    nrx = ncx = nry = 1;
672
	    ncx = LENGTH(x);
673
	    ncy = LENGTH(y);
673
	}
674
	}
674
	else {
675
	else {
675
	    nrx = LENGTH(x);
676
	    nry = LENGTH(y);
676
	    ncx = 1;
677
	    ncy = 1;
-
 
678
	    if (PRIMVAL(op) == 0) {
-
 
679
		nrx = 1;
-
 
680
		ncx = LENGTH(x);
-
 
681
		if(ncx == 1) {	        // y as row vector
-
 
682
		    ncy = nry;
-
 
683
		    nry = 1;
-
 
684
		}
-
 
685
	    }
-
 
686
	    else {
-
 
687
		nrx = LENGTH(x);
-
 
688
		ncx = 1;
-
 
689
	    }
677
	}
690
	}
678
	nry = LENGTH(y);
-
 
679
	ncy = 1;
-
 
680
    }
691
    }
681
    else if (ldx != 2) {		/* x not a matrix */
692
    else if (ldx != 2) {		/* x not a matrix */
682
	nry = INTEGER(ydims)[0];
693
	nry = INTEGER(ydims)[0];
683
	ncy = INTEGER(ydims)[1];
694
	ncy = INTEGER(ydims)[1];
684
	nrx = 0;
695
	nrx = 0;
Line 729... Line 740...
729
	}
740
	}
730
	else if (PRIMVAL(op) == 1) { /* crossprod() */
741
	else if (PRIMVAL(op) == 1) { /* crossprod() */
731
	    if (LENGTH(y) == nrx) {	/* y is a col vector */
742
	    if (LENGTH(y) == nrx) {	/* y is a col vector */
732
		nry = nrx;
743
		nry = nrx;
733
		ncy = 1;
744
		ncy = 1;
-
 
745
	    } else if (nrx == 1) {	// y as row vector
-
 
746
		nry = 1;
-
 
747
		ncy = LENGTH(y);
734
	    }
748
	    }
735
	}
749
	}
-
 
750
	else { // tcrossprod
-
 
751
	    if (nrx == 1) {		// y as row vector
-
 
752
		nry = 1;
-
 
753
		ncy = LENGTH(y);
-
 
754
	    }
736
	else { /* tcrossprod --		y is a col vector */
755
	    else {			// y is a col vector
737
	    nry = LENGTH(y);
756
		nry = LENGTH(y);
738
	    ncy = 1;
757
		ncy = 1;
-
 
758
	    }
739
	}
759
	}
740
    }
760
    }
741
    else {				/* x and y matrices */
761
    else {				/* x and y matrices */
742
	nrx = INTEGER(xdims)[0];
762
	nrx = INTEGER(xdims)[0];
743
	ncx = INTEGER(xdims)[1];
763
	ncx = INTEGER(xdims)[1];
Line 1557... Line 1577...
1557
	error(_("invalid 'ncol' value (< 0)"));
1577
	error(_("invalid 'ncol' value (< 0)"));
1558
    int mn = (nr < nc) ? nr : nc;
1578
    int mn = (nr < nc) ? nr : nc;
1559
    if (mn > 0 && LENGTH(x) == 0)
1579
    if (mn > 0 && LENGTH(x) == 0)
1560
	error(_("'x' must have positive length"));
1580
	error(_("'x' must have positive length"));
1561
 
1581
 
1562
 #ifndef LONG_VECTOR_SUPPORT
1582
#ifndef LONG_VECTOR_SUPPORT
1563
   if ((double)nr * (double)nc > INT_MAX)
1583
   if ((double)nr * (double)nc > INT_MAX)
1564
	error(_("too many elements specified"));
1584
	error(_("too many elements specified"));
1565
#endif
1585
#endif
1566
 
1586
 
1567
   if (TYPEOF(x) == CPLXSXP) {
1587
   if (TYPEOF(x) == CPLXSXP) {