Skip to content

Commit 9f3f0aa

Browse files
committed
fixes #92
1 parent cb1bb16 commit 9f3f0aa

File tree

10 files changed

+46
-33
lines changed

10 files changed

+46
-33
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ importFrom(disordR,hash)
3131
importFrom(disordR,consistent)
3232
importFrom(disordR,drop)
3333

34+
importFrom("stats", "runif")
35+
3436
S3method("as.function",ktensor)
3537
S3method("as.function",kform)
3638
S3method(Ops,kform)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# stokes 1.2-3
22

3+
- consistentification of rform() and rtensor()
34
- new vignette on phi()
45

56

R/mult.R

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,33 @@
204204
})
205205
}
206206

207-
`rform` <- function(terms=9, k=3, n=7, coeffs, ensure=TRUE){
208-
if(missing(coeffs)){coeffs <- seq_len(terms)}
207+
`rform` <- function(terms=9, k=3, n=7, ensure=TRUE, integer=TRUE){
209208
ind <- t(replicate(terms,sample(seq_len(n),k)))
210209
if(ensure & all(ind)<n){ind[sample(which(ind==max(ind)),1)] <- n}
211-
kform(spray(ind,coeffs,addrepeats=TRUE))
210+
if(integer){
211+
coeffs <- seq_len(terms)
212+
} else {
213+
coeffs <- runif(terms)
214+
}
215+
kform(spray(ind, coeffs, addrepeats=TRUE))
212216
}
213217

214-
`rformm` <- function(terms=30, k=7, n=20, coeffs, ensure=TRUE){
215-
rform(terms=terms, k=k, n=n, coeffs=coeffs, ensure=ensure)
218+
`rformm` <- function(terms=30, k=7, n=20, ensure=TRUE, integer=TRUE){
219+
rform(terms=terms, k=k, n=n, ensure=ensure)
216220
}
217221

218-
`rformmm` <- function(terms=90, k=15, n=30, coeffs, ensure=TRUE){
219-
rform(terms=terms, k=k, n=n, coeffs=coeffs, ensure=ensure)
222+
`rformmm` <- function(terms=90, k=15, n=30, ensure=TRUE, integer=TRUE){
223+
rform(terms=terms, k=k, n=n, ensure=ensure)
220224
}
221225

222-
`rtensor` <- function(terms=9, k=3, n=7, coeffs){
223-
if(missing(coeffs)){coeffs <- seq_len(terms)}
224-
M <- matrix(sample(seq_len(n),terms*k,replace=TRUE),terms,k)
225-
ktensor(spray(M,seq_len(terms),addrepeats=TRUE))
226+
`rtensor` <- function(terms=9, k=3, n=7, integer=TRUE){
227+
M <- matrix(sample(seq_len(n), terms*k, replace=TRUE), terms, k)
228+
if(integer){
229+
coeffs <- seq_len(terms)
230+
} else {
231+
coeffs <- runif(terms)
232+
}
233+
ktensor(spray(M, coeffs, addrepeats=TRUE))
226234
}
227235

228236
`as.1form` <- function(v){

man/rform.Rd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
Random \eqn{k}-form objects and \eqn{k}-tensors,
1111
intended as quick \dQuote{get you going} examples}
1212
\usage{
13-
rform(terms=9, k=3, n=7, coeffs, ensure=TRUE)
14-
rformm(terms=30, k=7, n=20, coeffs, ensure=TRUE)
15-
rformmm(terms=90, k=15, n=30, coeffs, ensure=TRUE)
16-
rtensor(terms=9,k=3,n=7,coeffs)
13+
rform(terms=9, k=3, n=7, ensure=TRUE, integer=TRUE)
14+
rformm(terms=30, k=7, n=20, ensure=TRUE, integer=TRUE)
15+
rformmm(terms=90, k=15, n=30, ensure=TRUE, integer=TRUE)
16+
rtensor(terms=9, k=3, n=7, integer=TRUE)
1717
}
1818
\arguments{
1919
\item{terms}{Number of distinct terms}
2020
\item{k, n}{A \eqn{k}-form maps \eqn{V^k} to
2121
\eqn{\mathbb{R}}{R}, where \eqn{V=\mathbb{R}^n}{V=R^n}}
22-
\item{coeffs}{The coefficients of the form; if missing use
23-
\code{seq_len(terms)}}
2422
\item{ensure}{Boolean with default \code{TRUE} meaning to ensure that
2523
the \code{dovs()} of the returned value is in fact equal to
2624
\code{n}. If \code{FALSE}, sometimes the \code{dovs()} is strictly
2725
less than \code{n} because of random sampling}
26+
\item{integer}{Boolean specifying whether the coefficients are
27+
integers or not}
2828
}
2929
\details{
3030
Random \eqn{k}-form objects and \eqn{k}-tensors.
@@ -55,4 +55,6 @@ a ^ dx ^ dy
5555
(x <- rtensor())
5656
x \%X\% x
5757

58+
59+
5860
}

man/stokes-package.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ U1 \%X\% U2
5454
## A k-form is an alternating k-tensor:
5555
K1 <- as.kform(cbind(1:5,2:6),rnorm(5))
5656
K2 <- kform_general(3:6,2,1:6)
57-
K3 <- rform(9,3,9,runif(9))
57+
K3 <- rform(9,3,9)
5858

5959
## The distributive law is true
6060

tests/testthat/test_alt.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_that("Function Alt() behaves itself", {
2727
terms <- sample(2:4,1)
2828
k <- sample(3:4,1)
2929
n <- sample(2:4,1)
30-
S <- rtensor(terms,k,n,rnorm(terms))
30+
S <- rtensor(terms,k,n,integer=FALSE)
3131
foo(S)
3232
V <- matrix(rnorm(k*n),ncol=k)
3333
bar(S,V)

tests/testthat/test_contract.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test_that("Function contract() behaves itself", {
1818

1919

2020
for(i in 1:2){
21-
o <- rform(2,k=5,n=9,coeffs=runif(2))
21+
o <- rform(2, k=5, n=9, integer=FALSE)
2222
V <- matrix(rnorm(45),ncol=5)
2323
foo(o,V)
2424
}

tests/testthat/test_cross.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ test_that("Tensor product is distributive and associative", {
3939
terms <- rpois(1,20)
4040
k <- sample(3:10,1)
4141
n <- k+sample(3:10,1)
42-
T1 <- rtensor(terms,k,n,rnorm(terms))
43-
T2 <- rtensor(terms+1,k,n,rnorm(terms+1))
44-
T3 <- rtensor(terms+2,k,n,rnorm(terms+2))
42+
T1 <- rtensor(terms,k,n,integer=FALSE)
43+
T2 <- rtensor(terms+1,k,n,integer=FALSE)
44+
T3 <- rtensor(terms+2,k,n,integer=FALSE)
4545
foo3(T1,T2,T3)
4646
}
4747
})
@@ -65,8 +65,8 @@ test_that("tensorprod() is in fact a tensor product", {
6565
terms <- rpois(1,20)
6666
k <- sample(3:10,1)
6767
n <- k+sample(3:10,1)
68-
T1 <- rtensor(terms,k,n,rnorm(terms))
69-
T2 <- rtensor(terms+1,k,n,rnorm(terms+1))
68+
T1 <- rtensor(terms,k,n,integer=FALSE)
69+
T2 <- rtensor(terms+1,k,n,integer=FALSE)
7070
foo2(T1,T2)
7171
}
7272
})
@@ -100,7 +100,7 @@ test_that("ktensors are multilinear", {
100100
terms <- rpois(1,20)
101101
k <- sample(3:10,1)
102102
n <- k+sample(3:10,1)
103-
TT <- rtensor(terms,k,n,rnorm(terms))
103+
TT <- rtensor(terms,k,n,integer=FALSE)
104104
foo1(TT)
105105
}
106106

tests/testthat/test_ops.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ test_that("Cross product Ops behave", {
1818
terms <- rpois(1,20)
1919
k <- sample(3:10,1)
2020
n <- k+sample(3:10,1)
21-
S <- rform(terms,k,n,sample(terms))
21+
S <- rform(terms,k,n)
2222
foo1(S)
2323
}
2424

2525
for(i in 1:10){
2626
terms <- rpois(1,20)
2727
k <- sample(3:10,1)
2828
n <- k+sample(3:10,1)
29-
S1 <- rform(terms,k,n,sample(terms))
30-
S2 <- rform(terms,k,n,sample(terms))
29+
S1 <- rform(terms,k,n)
30+
S2 <- rform(terms,k,n)
3131
foo2(S1,S2)
3232
}
3333

@@ -39,16 +39,16 @@ test_that("Wedge product Ops behave", {
3939
terms <- rpois(1,20)
4040
k <- sample(3:10,1)
4141
n <- k+sample(3:10,1)
42-
K <- rform(terms,k,n,sample(terms))
42+
K <- rform(terms,k,n)
4343
foo1(K)
4444
}
4545

4646
for(i in 1:10){
4747
terms <- rpois(1,20)
4848
k <- sample(3:10,1)
4949
n <- k+sample(3:10,1)
50-
K1 <- rform(terms,k,n,sample(terms))
51-
K2 <- rform(terms,k,n,sample(terms))
50+
K1 <- rform(terms,k,n)
51+
K2 <- rform(terms,k,n)
5252
foo2(K1,K2)
5353
}
5454
})

tests/testthat/test_transform.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test_that("Function pullback() behaves itself", {
2525
} # foo() closes
2626

2727
for(i in 1:3){
28-
o <- rform(terms=3,k=2,n=5,coeffs=rnorm(3))
28+
o <- rform(terms=3, k=2, n=5, integer=FALSE)
2929
randmat <- expression(matrix(rnorm(25),5,5))
3030
isbigdet <- function(x,min_det = 0.01){abs(det(x)) > min_det}
3131
M <- getgood(randmat, isbigdet, default=diag(5), min_det=0.1)

0 commit comments

Comments
 (0)