The R Project SVN R

Rev

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

Rev 1026 Rev 1073
Line 23... Line 23...
23
static void CheckDims(SEXP dims)
23
static void CheckDims(SEXP dims)
24
{
24
{
25
	int i;
25
	int i;
26
 
26
 
27
	for (i = 0; i < LENGTH(dims); i++) {
27
	for (i = 0; i < LENGTH(dims); i++) {
28
		if (INTEGER(dims)[i] <= 0)
28
		if (INTEGER(dims)[i] < 0)
29
			error("invalid array extent\n");
29
			error("invalid array extent\n");
30
	}
30
	}
31
}
31
}
32
 
32
 
33
SEXP do_matrix(SEXP call, SEXP op, SEXP args, SEXP rho)
33
SEXP do_matrix(SEXP call, SEXP op, SEXP args, SEXP rho)
Line 40... Line 40...
40
	snr = CADR(args);
40
	snr = CADR(args);
41
	snc = CADDR(args);
41
	snc = CADDR(args);
42
	byrow = asInteger(CADR(CDDR(args)));
42
	byrow = asInteger(CADR(CDDR(args)));
43
 
43
 
44
	if (isVector(vals) || isList(vals)) {
44
	if (isVector(vals) || isList(vals)) {
45
		if(length(vals) <= 0)
45
		if(length(vals) < 0)
46
			errorcall(call, "argument has length zero\n");
46
			errorcall(call, "argument has length zero\n");
47
	} else errorcall(call, "invalid matrix element type\n");
47
	} else errorcall(call, "invalid matrix element type\n");
48
 
48
 
49
	if (!isNumeric(snr) || !isNumeric(snc))
49
	if (!isNumeric(snr) || !isNumeric(snc))
50
		error("non-numeric matrix extent\n");
50
		error("non-numeric matrix extent\n");
Line 76... Line 76...
76
SEXP allocMatrix(SEXPTYPE mode, int nrow, int ncol)
76
SEXP allocMatrix(SEXPTYPE mode, int nrow, int ncol)
77
{
77
{
78
	SEXP s, t;
78
	SEXP s, t;
79
	int n;
79
	int n;
80
 
80
 
81
	if (nrow <= 0 || ncol <= 0)
81
	if (nrow < 0 || ncol < 0)
82
		error("nonpositive extents to matrix\n");
82
		error("negative extents to matrix\n");
83
	n = nrow * ncol;
83
	n = nrow * ncol;
84
	PROTECT(s = allocVector(mode, n));
84
	PROTECT(s = allocVector(mode, n));
85
	PROTECT(t = allocVector(INTSXP, 2));
85
	PROTECT(t = allocVector(INTSXP, 2));
86
	INTEGER(t)[0] = nrow;
86
	INTEGER(t)[0] = nrow;
87
	INTEGER(t)[1] = ncol;
87
	INTEGER(t)[1] = ncol;
Line 216... Line 216...
216
	x = CAR(args);
216
	x = CAR(args);
217
	if((xdims = getAttrib(x, R_DimSymbol)) != R_NilValue) {
217
	if((xdims = getAttrib(x, R_DimSymbol)) != R_NilValue) {
218
		n = LENGTH(xdims);
218
		n = LENGTH(xdims);
219
		shorten = 0;
219
		shorten = 0;
220
		for(i=0 ; i<n ; i++)
220
		for(i=0 ; i<n ; i++)
221
			if(INTEGER(xdims)[i] <= 1) shorten = 1;
221
			if(INTEGER(xdims)[i] == 1) shorten = 1;
222
		if(shorten) {
222
		if(shorten) {
223
			if(NAMED(x)) x = duplicate(x);
223
			if(NAMED(x)) x = duplicate(x);
224
			x = DropDims(x);
224
			x = DropDims(x);
225
		}
225
		}
226
	}
226
	}