Skip to content

Commit

Permalink
use .Library for Matrix
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87065 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Aug 28, 2024
1 parent e702217 commit cab94e1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/eval-etc-2.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ srcdir <- file.path(Sys.getenv("SRCDIR"), "eval-fns.R")
source(if(file.exists(srcdir)) srcdir else "./eval-fns.R", echo = TRUE)
rm("srcdir")

require("Matrix")
require("Matrix", .Library)
D5. <- Diagonal(x = 5:1)
D5N <- D5.; D5N[5,5] <- NA
## a subset/version of example(Matrix) : --------------------------------
Expand Down
8 changes: 4 additions & 4 deletions tests/eval-etc-2.Rout.save
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

R Under development (unstable) (2023-10-23 r85391) -- "Unsuffered Consequences"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin22.6.0
R Under development (unstable) (2024-08-27 r87063) -- "Unsuffered Consequences"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Expand Down Expand Up @@ -56,7 +56,7 @@ Type 'q()' to quit R.
+ cat(nm, ": ", sep = .... [TRUNCATED]
> rm("srcdir")
>
> require("Matrix")
> require("Matrix", .Library)
Loading required package: Matrix
> D5. <- Diagonal(x = 5:1)
> D5N <- D5.; D5N[5,5] <- NA
Expand Down
4 changes: 3 additions & 1 deletion tests/reg-examples3.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ contrasts(fff) <- contr.sum(5)[, 1:2]; contrasts(fff)

## using sparse contrasts: % useful, once model.matrix() works with these :
ffs <- fff
if(requireNamespace("Matrix", lib.loc=.Library)) withAutoprint({
contrasts(ffs) <- contr.sum(5, sparse = TRUE)[, 1:2]; contrasts(ffs)
stopifnot(all.equal(ffs, fff))
contrasts(ffs) <- contr.sum(5, sparse = TRUE); contrasts(ffs)
})

# glm.Rd
utils::data(anorexia, package = "MASS")
Expand Down Expand Up @@ -155,7 +157,7 @@ termplot(hills.lm, transform.x = TRUE,
terms = "log(dist)", main = "Transformed")

# xtabs.Rd
if(require("Matrix")) {
if(require("Matrix", .Library)) {
## similar to "nlme"s 'ergoStool' :
d.ergo <- data.frame(Type = paste0("T", rep(1:4, 9*4)),
Subj = gl(9, 4, 36*4))
Expand Down
19 changes: 13 additions & 6 deletions tests/reg-examples3.Rout.save
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

R Under development (unstable) (2022-03-19 r81942) -- "Unsuffered Consequences"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R Under development (unstable) (2024-08-27 r87063) -- "Unsuffered Consequences"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Expand Down Expand Up @@ -256,15 +256,22 @@ t -1 -1 -0.2471257 0.2688164
>
> ## using sparse contrasts: % useful, once model.matrix() works with these :
> ffs <- fff
> contrasts(ffs) <- contr.sum(5, sparse = TRUE)[, 1:2]; contrasts(ffs)
> if(requireNamespace("Matrix", lib.loc=.Library)) withAutoprint({
+ contrasts(ffs) <- contr.sum(5, sparse = TRUE)[, 1:2]; contrasts(ffs)
+ stopifnot(all.equal(ffs, fff))
+ contrasts(ffs) <- contr.sum(5, sparse = TRUE); contrasts(ffs)
+ })
> contrasts(ffs) <- contr.sum(5, sparse = TRUE)[, 1:2]
> contrasts(ffs)
[,1] [,2] [,3] [,4]
a 1 0 -0.2471257 0.2688164
c 0 1 -0.2471257 0.2688164
i 0 0 -0.1498721 -0.8817814
s 0 0 0.8912491 0.0753323
t -1 -1 -0.2471257 0.2688164
> stopifnot(all.equal(ffs, fff))
> contrasts(ffs) <- contr.sum(5, sparse = TRUE); contrasts(ffs)
> contrasts(ffs) <- contr.sum(5, sparse = TRUE)
> contrasts(ffs)
5 x 4 sparse Matrix of class "dgCMatrix"

a 1 . . .
Expand Down Expand Up @@ -446,7 +453,7 @@ Standard deviations:
+ terms = "log(dist)", main = "Transformed")
>
> # xtabs.Rd
> if(require("Matrix")) {
> if(require("Matrix", .Library)) {
+ ## similar to "nlme"s 'ergoStool' :
+ d.ergo <- data.frame(Type = paste0("T", rep(1:4, 9*4)),
+ Subj = gl(9, 4, 36*4))
Expand Down
10 changes: 7 additions & 3 deletions tests/reg-tests-3.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ cbind(npk, foo)
## failed in R < 2.10.0


if(suppressMessages(require("Matrix"))) {
if(suppressMessages(require("Matrix", .Library))) {
print(cS. <- contr.SAS(5, sparse = TRUE))
stopifnot(all(contr.SAS(5) == cS.),
all(contr.helmert(5, sparse = TRUE) == contr.helmert(5)))
Expand All @@ -131,7 +131,7 @@ print(xtabs(~ x1 + x2, exclude = 'c', na.action = na.pass))

## median should work by default for a suitable S4 class.
## adapted from adaptsmoFMRI
if(suppressMessages(require("Matrix"))) {
if(suppressMessages(require("Matrix", .Library))) {
x <- matrix(c(1,2,3,4))
print(m <- median(x))
stopifnot(all.equal(m, median(as(x, "denseMatrix"))))
Expand Down Expand Up @@ -169,7 +169,7 @@ if(require("MASS")) {
}
## the error was in lm.(w)fit

if(require("Matrix")) {
if(require("Matrix", .Library)) {
m1 <- m2 <- m <- matrix(1:12, 3,4)
dimnames(m2) <- list(LETTERS[1:3],
letters[1:4])
Expand Down Expand Up @@ -277,6 +277,10 @@ if(hasME) withAutoprint({
desc$Repository <- NULL
c3 <- citation(auto = desc)
stopifnot(identical(print(c3$url), URL1)) # R <= 4.4.0 gave both URLs

unloadNamespace(pkg)
})



cat('Time elapsed: ', proc.time(),'\n')
13 changes: 9 additions & 4 deletions tests/reg-tests-3.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R Under development (unstable) (2024-06-18 r86779) -- "Unsuffered Consequences"
R Under development (unstable) (2024-08-27 r87063) -- "Unsuffered Consequences"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

Expand Down Expand Up @@ -689,7 +689,7 @@ Loading required package: survival
> ## failed in R < 2.10.0
>
>
> if(suppressMessages(require("Matrix"))) {
> if(suppressMessages(require("Matrix", .Library))) {
+ print(cS. <- contr.SAS(5, sparse = TRUE))
+ stopifnot(all(contr.SAS(5) == cS.),
+ all(contr.helmert(5, sparse = TRUE) == contr.helmert(5)))
Expand Down Expand Up @@ -756,7 +756,7 @@ x1 a b <NA>
>
> ## median should work by default for a suitable S4 class.
> ## adapted from adaptsmoFMRI
> if(suppressMessages(require("Matrix"))) {
> if(suppressMessages(require("Matrix", .Library))) {
+ x <- matrix(c(1,2,3,4))
+ print(m <- median(x))
+ stopifnot(all.equal(m, median(as(x, "denseMatrix"))))
Expand Down Expand Up @@ -814,7 +814,7 @@ X2 0 1 0

> ## the error was in lm.(w)fit
>
> if(require("Matrix")) {
> if(require("Matrix", .Library)) {
+ m1 <- m2 <- m <- matrix(1:12, 3,4)
+ dimnames(m2) <- list(LETTERS[1:3],
+ letters[1:4])
Expand Down Expand Up @@ -995,6 +995,8 @@ packages.
+ desc$Repository <- NULL
+ c3 <- citation(auto = desc)
+ stopifnot(identical(print(c3$url), URL1)) # R <= 4.4.0 gave both URLs
+
+ unloadNamespace(pkg)
+ })
> c2 <- citation(pkg, .Library)
> c2$author[[1]]$given[[1]] <- "J."
Expand Down Expand Up @@ -1078,6 +1080,9 @@ A BibTeX entry for LaTeX users is
> c3 <- citation(auto = desc)
> stopifnot(identical(print(c3$url), URL1))
[1] "https://example.org"
> unloadNamespace(pkg)
>
>
>
> cat('Time elapsed: ', proc.time(),'\n')
Time elapsed: 2.176 0.139 2.315 0.002 0
Expand Down

0 comments on commit cab94e1

Please sign in to comment.