Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SciViews
svbox-renku
Commits
814342f8
Commit
814342f8
authored
Aug 23, 2021
by
Philippe Grosjean
Browse files
First version of the Renku svbox
parent
44e520bd
Pipeline
#243913
failed with stage
in 8 minutes and 52 seconds
Changes
18
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
.Rprofile
0 → 100644
View file @
814342f8
setHook
(
"rstudio.sessionInit"
,
function
(
newSession
)
{
if
(
newSession
)
{
#message("Welcome to RStudio ", rstudioapi::getVersion())
source
(
"R/github_init.R"
)
source
(
"R/github_restore.R"
)
# TODO: create a notes project in ~/github and switch to it
# (Re)create files
# rstudioapi::openProject("~/github/notes)
# TODO: may be renku save?
}
},
action
=
"append"
)
.renku/renku.ini
View file @
814342f8
[renku "interactive"]
default_url
=
/rstudio
\ No newline at end of file
default_url
=
/rstudio
cpu_request
=
0.5
mem_request
=
2G
[renku]
autocommit_lfs
=
false
lfs_threshold
=
100kb
Dockerfile
View file @
814342f8
# For finding latest versions of the base image see
# https://github.com/SwissDataScienceCenter/renkulab-docker
ARG
RENKU_BASE_IMAGE=renku/renkulab-r:4.0.5-0.8.0
FROM
${RENKU_BASE_IMAGE}
# For finding rocker images see
# https://github.com/rocker-org/rocker-versioned2
# define build arguments
ARG
RENKU_BASE=renku/renkulab-py:3.8-0.8.0
ARG
BASE_IMAGE=rocker/geospatial:4.0.5
# define base images
FROM
$RENKU_BASE as renku_base
FROM
$BASE_IMAGE
LABEL
maintainer="Philippe Grosjean <phgrosjean@sciviews.org>"
USER
root
ENV
NB_USER rstudio
ENV
NB_UID 1000
ENV
NB_GID 1000
ENV
VENV_DIR /srv/venv
ENV
HOME /home/${NB_USER}
ENV
SHELL bash
ENV
CONDA_PATH /opt/conda
# prepend conda and local/bin to PATH
ENV
PATH ${HOME}/.local/bin:${CONDA_PATH}/bin:$PATH
# The `rsession` binary that is called by nbrsessionproxy to start R
# doesn't seem to start without this being explicitly set
ENV
LD_LIBRARY_PATH /usr/local/lib/R/lib
# pin the version of RStudio
ENV
RSTUDIO_VERSION 1.3.959
#ENV RSESSION_PROXY_RSTUDIO_1_4 yes # Required if RStudio version is >= 1.4
# Set PATH for R! It doesn't read from the environment...
# and install pinned RStudio version
RUN
echo
"PATH=
${
PATH
}
"
>>
/usr/local/lib/R/etc/Renviron
&&
\
echo
"PATH=
${
PATH
}
"
>>
/etc/profile.d/set_path.sh
&&
\
/rocker_scripts/install_rstudio.sh
# Add Tini
ENV
TINI_VERSION v0.18.0
ADD
https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN
chmod
+x /tini
&&
ln
-s
/tini /usr/bin/
# install dependencies
RUN
apt-get update
--fix-missing
&&
\
apt-get
install
-yq
--no-install-recommends
\
bzip2
\
ca-certificates
\
curl
\
gpg-agent
&&
\
curl
-sL
https://deb.nodesource.com/setup_10.x | bash -
&&
\
curl
-s
https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
&&
\
apt-get update
&&
\
apt-get
install
-yq
--no-install-recommends
\
git-lfs
\
gnupg
\
jq
\
nodejs
\
libglib2.0-0
\
libsm6
\
libxext6
\
libxrender1
\
libzmq3-dev
\
wget
\
vim
\
# added for SciViews Box/BioDataScience
hunspell-en-us \
hunspell-en-gb \
hunspell-fr-modern \
nano && \
apt-get purge && \
apt-get clean && \
apt autoremove --yes && \
rm -rf /var/lib/apt/lists/*
# inject the renku-jupyter stack
COPY
--from=renku_base /opt/conda /opt/conda
COPY
--from=renku_base --chown=rstudio:rstudio /usr/local/bin/ /usr/local/bin/
COPY
--from=renku_base --chown=rstudio:rstudio /home/jovyan/ /home/rstudio/
COPY
--from=renku_base /entrypoint.sh /entrypoint.sh
# set permissions of the R library directory to be editable by NB_USER
# This is done in the original image, but we don't want this: we want users to
# install packages in the ~/R folder instead
#ADD fix-permissions.sh /usr/local/bin
#RUN fix-permissions.sh /usr/local/lib/R
RUN
chown
1000:1000 /opt/conda
&&
\
usermod
-a
-G
users
rstudio
&&
\
# this hack lets some of the setup from the base renku image work here
ln -s /home/${NB_USER} /home/jovyan
# customize RStudio
COPY
config/snippets/r.snippets /etc/rstudio/snippets
COPY
config/rstudio-prefs.json /etc/rstudio
COPY
config/dictionaries/* /usr/share/hunspell/
RUN
mkdir
-p
/home/rstudio/.config/rstudio/dictionaries
&&
\
chown
1000:1000 /home/rstudio/.config/rstudio/dictionaries
&&
\
mkdir
-p
/home/rstudio/.config/rstudio/dictionaries/languages-system
&&
\
chown
1000:1000 /home/rstudio/.config/rstudio/dictionaries/languages-system
&&
\
cp
/usr/share/hunspell/en_US.aff /home/rstudio/.config/rstudio/dictionaries/languages-system/en_US.aff
&&
\
cp
/usr/share/hunspell/en_US.dic /home/rstudio/.config/rstudio/dictionaries/languages-system/en_US.dic
&&
\
cp
/usr/share/hunspell/en_US.dic_delta /home/rstudio/.config/rstudio/dictionaries/languages-system/en_US.dic_delta
&&
\
cp
/usr/share/hunspell/en_GB.aff /home/rstudio/.config/rstudio/dictionaries/languages-system/en_GB.aff
&&
\
cp
/usr/share/hunspell/en_GB.dic /home/rstudio/.config/rstudio/dictionaries/languages-system/en_GB.dic
&&
\
cp
/usr/share/hunspell//en_GB.dic_delta /home/rstudio/.config/rstudio/dictionaries/languages-system/en_GB.dic_delta
&&
\
cp
/usr/share/hunspell/fr.aff /home/rstudio/.config/rstudio/dictionaries/languages-system/fr_FR.aff
&&
\
cp
/usr/share/hunspell/fr.dic /home/rstudio/.config/rstudio/dictionaries/languages-system/fr_FR.dic
&&
\
cp
/usr/share/hunspell//fr_FR.dic_delta /home/rstudio/.config/rstudio/dictionaries/languages-system/fr_FR.dic_delta
&&
\
chown
1000:1000 /home/rstudio/.config/rstudio/dictionaries/languages-system/
*
&&
\
chown
1000:1000 /home/rstudio/.config/rstudio
&&
\
mkdir
-p
/etc/rstudio/snippets
# Uncomment and adapt if code is to be included in the image
# COPY src /code/src
# Uncomment and adapt if your R or python packages require extra linux (ubuntu) software
# e.g. the following installs apt-utils and vim; each pkg on its own line, all lines
# except for the last end with backslash '\' to continue the RUN line
#
# USER root
# RUN apt-get update && \
# apt-get install -y --no-install-recommends \
# apt-utils \
# vim
# USER ${NB_USER}
# install the R dependencies
COPY
install.R /tmp/
RUN
R
-f
/tmp/install.R
USER
${NB_USER}
# install the python dependencies
# set up conda in the NB_USER environment
RUN
echo
".
${
CONDA_PATH
}
/etc/profile.d/conda.sh"
>>
~/.bashrc
&&
\
echo
"conda activate base"
>>
~/.bashrc
&&
\
pip
install
"jupyter-rsession-proxy==1.1"
&&
\
# install IRKernel
R --quiet -e "install.packages('IRkernel')" && \
R --quiet -e "IRkernel::installspec(prefix='${CONDA_PATH}')" && \
echo "source ~/.bashrc" >> ~/.bash_profile
# install R and python dependencies
COPY
install.R /tmp/
COPY
requirements.txt /tmp/
RUN
pip3
install
-r
/tmp/requirements.txt
# RENKU_VERSION determines the version of the renku CLI
# that will be used in this image. To find the latest version,
# visit https://pypi.org/project/renku/#history.
ARG
RENKU_VERSION=0.16.0
########################################################
# Do not edit this section and do not add anything below
# Install renku from pypi or from github if it's a dev version
RUN if
[
-n
"
$RENKU_VERSION
"
]
;
then
\
currentversion
=
$(
pipx list |
sed
-n
"s/^
\s
*package
\s
renku
\s\(
[^,]
\+\)
,.*
$/
\1
/p"
)
;
\
if
[
"
$RENKU_VERSION
"
!=
"
$currentversion
"
]
;
then
\
pipx uninstall renku
;
\
gitversion
=
$(
echo
"
$RENKU_VERSION
"
|
sed
-n
"s/^[[:digit:]]
\+\.
[[:digit:]]
\+\.
[[:digit:]]
\+\(\.
dev[[:digit:]]
\+\)
*
\(
+g
\(
[a-f0-9]
\+\)\)
*
\(
+dirty
\)
*
$/
\3
/p"
)
;
\
if
[
-n
"
$gitversion
"
]
;
then
\
pipx
install
--force
"git+https://github.com/SwissDataScienceCenter/renku-python.git@
$gitversion
"
;
\
else
\
pipx
install
--force
renku
==
${
RENKU_VERSION
}
;
\
fi
\
fi
\
fi
########################################################
\ No newline at end of file
RUN
R
-f
/tmp/install.R
&&
\
pip3
install
-r
/tmp/requirements.txt
&&
\
mkdir
-p
~/github
COPY
post-init.sh /post-init.sh
ENTRYPOINT
[ "/tini", "--", "/entrypoint.sh" ]
CMD
[ "jupyterhub-singleuser" ]
WORKDIR
${HOME}
LICENSE-fix-permissions
0 → 100644
View file @
814342f8
# Licensing terms
`fix-permissions.sh` is licensed under the terms of the Modified BSD License
(also known as New or Revised or 3-Clause BSD), as follows:
- Copyright (c) 2001-2015, IPython Development Team
- Copyright (c) 2015-, Jupyter Development Team
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the Jupyter Development Team nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## About the Jupyter Development Team
The Jupyter Development Team is the set of all contributors to the Jupyter project.
This includes all of the Jupyter subprojects.
The core team that coordinates development on GitHub can be found here:
https://github.com/jupyter/.
## Our Copyright Policy
Jupyter uses a shared copyright model. Each contributor maintains copyright
over their contributions to Jupyter. But, it is important to note that these
contributions are typically only changes to the repositories. Thus, the Jupyter
source code, in its entirety is not the copyright of any single person or
institution. Instead, it is the collective copyright of the entire Jupyter
Development Team. If individual contributors want to maintain a record of what
changes/contributions they have specific copyright on, they should indicate
their copyright in the commit message of the change, when they commit the
change to one of the Jupyter repositories.
With this in mind, the following banner should be used in any source code file
to indicate the copyright and license terms:
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
\ No newline at end of file
R/R-benchmark-25.R
0 → 100644
View file @
814342f8
# R Benchmark 2.5 (06/2008) [Simon Urbanek]
# version 2.5: scaled to get roughly 1s per test, R 2.7.0 @ 2.6GHz Mac Pro
# R Benchmark 2.4 (06/2008) [Simon Urbanek]
# version 2.4 adapted to more recent Matrix package
# R Benchmark 2.3 (21 April 2004)
# Warning: changes are not carefully checked yet!
# version 2.3 adapted to R 1.9.0
# Many thanks to Douglas Bates (bates@stat.wisc.edu) for improvements!
# version 2.2 adapted to R 1.8.0
# version 2.1 adapted to R 1.7.0
# version 2, scaled to get 1 +/- 0.1 sec with R 1.6.2
# using the standard ATLAS library (Rblas.dll)
# on a Pentium IV 1.6 Ghz with 1 Gb Ram on Win XP pro
# revised and optimized for R v. 1.5.x, 8 June 2002
# Requires additionnal libraries: Matrix, SuppDists
# Author : Philippe Grosjean
# eMail : phgrosjean@sciviews.org
# Web : http://www.sciviews.org
# License: GPL 2 or above at your convenience (see: http://www.gnu.org)
#
# Several tests are adapted from the Splus Benchmark Test V. 2
# by Stephan Steinhaus (stst@informatik.uni-frankfurt.de)
# Reference for Escoufier's equivalents vectors (test III.5):
# Escoufier Y., 1970. Echantillonnage dans une population de variables
# aleatoires réelles. Publ. Inst. Statis. Univ. Paris 19 Fasc 4, 1-47.
#
# type source("c:/<dir>/R2.R") to start the test
runs
<-
3
# Number of times the tests are executed
times
<-
rep
(
0
,
15
);
dim
(
times
)
<-
c
(
5
,
3
)
require
(
Matrix
)
# Optimized matrix operations
require
(
SuppDists
)
# Optimized random number generators
#Runif <- rMWC1019 # The fast uniform number generator
Runif
<-
runif
# If you don't have SuppDists, you can use: Runif <- runif
#a <- rMWC1019(10, new.start=TRUE, seed=492166) # Init. the generator
#Rnorm <- rziggurat # The fast normal number generator
# If you don't have SuppDists, you can use: Rnorm <- rnorm
#b <- rziggurat(10, new.start=TRUE) # Init. the generator
Rnorm
<-
rnorm
remove
(
"a"
,
"b"
)
options
(
object.size
=
100000000
)
cat
(
"\n\n R Benchmark 2.5\n"
)
cat
(
" ===============\n"
)
cat
(
c
(
"Number of times each test is run__________________________: "
,
runs
))
cat
(
"\n\n"
)
cat
(
" I. Matrix calculation\n"
)
cat
(
" ---------------------\n"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (1)
cumulate
<-
0
;
a
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
invisible
(
gc
())
timing
<-
system.time
({
a
<-
matrix
(
Rnorm
(
2500
*
2500
)
/
10
,
ncol
=
2500
,
nrow
=
2500
);
b
<-
t
(
a
);
dim
(
b
)
<-
c
(
1250
,
5000
);
a
<-
t
(
b
)
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
1
,
1
]
<-
timing
cat
(
c
(
"Creation, transp., deformation of a 2500x2500 matrix (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (2)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
abs
(
matrix
(
Rnorm
(
2500
*
2500
)
/
2
,
ncol
=
2500
,
nrow
=
2500
));
invisible
(
gc
())
timing
<-
system.time
({
b
<-
a
^
1000
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
2
,
1
]
<-
timing
cat
(
c
(
"2400x2400 normal distributed random matrix ^1000____ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (3)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
Rnorm
(
7000000
)
invisible
(
gc
())
timing
<-
system.time
({
b
<-
sort
(
a
,
method
=
"quick"
)
# Sort is modified in v. 1.5.x
# And there is now a quick method that better competes with other packages!!!
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
3
,
1
]
<-
timing
cat
(
c
(
"Sorting of 7,000,000 random values__________________ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (4)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
Rnorm
(
2800
*
2800
);
dim
(
a
)
<-
c
(
2800
,
2800
)
invisible
(
gc
())
timing
<-
system.time
({
b
<-
crossprod
(
a
)
# equivalent to: b <- t(a) %*% a
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
4
,
1
]
<-
timing
cat
(
c
(
"2800x2800 cross-product matrix (b = a' * a)_________ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (5)
cumulate
<-
0
;
c
<-
0
;
qra
<
-0
for
(
i
in
1
:
runs
)
{
a
<-
new
(
"dgeMatrix"
,
x
=
Rnorm
(
2000
*
2000
),
Dim
=
as.integer
(
c
(
2000
,
2000
)))
b
<-
as.double
(
1
:
2000
)
invisible
(
gc
())
timing
<-
system.time
({
c
<-
solve
(
crossprod
(
a
),
crossprod
(
a
,
b
))
})[
3
]
cumulate
<-
cumulate
+
timing
# This is the old method
#a <- Rnorm(600*600); dim(a) <- c(600,600)
#b <- 1:600
#invisible(gc())
#timing <- system.time({
# qra <- qr(a, tol = 1e-7);
# c <- qr.coef(qra, b)
# #Rem: a little faster than c <- lsfit(a, b, inter=F)$coefficients
#})[3]
#cumulate <- cumulate + timing
}
timing
<-
cumulate
/
runs
times
[
5
,
1
]
<-
timing
cat
(
c
(
"Linear regr. over a 3000x3000 matrix (c = a \\ b')___ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
,
"c"
,
"qra"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
times
[
,
1
]
<-
sort
(
times
[
,
1
])
cat
(
" --------------------------------------------\n"
)
cat
(
c
(
" Trimmed geom. mean (2 extremes eliminated): "
,
exp
(
mean
(
log
(
times
[
2
:
4
,
1
]))),
"\n\n"
))
cat
(
" II. Matrix functions\n"
)
cat
(
" --------------------\n"
)
if
(
R.Version
()
$
os
==
"Win32"
)
flush.console
()
# (1)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
Rnorm
(
2400000
)
invisible
(
gc
())
timing
<-
system.time
({
b
<-
fft
(
a
)
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
1
,
2
]
<-
timing
cat
(
c
(
"FFT over 2,400,000 random values____________________ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (2)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
array
(
Rnorm
(
600
*
600
),
dim
=
c
(
600
,
600
))
# Only needed if using eigen.Matrix(): Matrix.class(a)
invisible
(
gc
())
timing
<-
system.time
({
b
<-
eigen
(
a
,
symmetric
=
FALSE
,
only.values
=
TRUE
)
$
Value
# Rem: on my machine, it is faster than:
# b <- La.eigen(a, symmetric=F, only.values=T, method="dsyevr")$Value
# b <- La.eigen(a, symmetric=F, only.values=T, method="dsyev")$Value
# b <- eigen.Matrix(a, vectors = F)$Value
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
2
,
2
]
<-
timing
cat
(
c
(
"Eigenvalues of a 640x640 random matrix______________ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (3)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
Rnorm
(
2500
*
2500
);
dim
(
a
)
<-
c
(
2500
,
2500
)
#Matrix.class(a)
invisible
(
gc
())
timing
<-
system.time
({
#b <- determinant(a, logarithm=F)
# Rem: the following is slower on my computer!
# b <- det.default(a)
b
<-
det
(
a
)
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
3
,
2
]
<-
timing
cat
(
c
(
"Determinant of a 2500x2500 random matrix____________ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (4)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
crossprod
(
new
(
"dgeMatrix"
,
x
=
Rnorm
(
3000
*
3000
),
Dim
=
as.integer
(
c
(
3000
,
3000
))))
invisible
(
gc
())
#a <- Rnorm(900*900); dim(a) <- c(900, 900)
#a <- crossprod(a, a)
timing
<-
system.time
({
b
<-
chol
(
a
)
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
4
,
2
]
<-
timing
cat
(
c
(
"Cholesky decomposition of a 3000x3000 matrix________ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (5)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
a
<-
new
(
"dgeMatrix"
,
x
=
Rnorm
(
1600
*
1600
),
Dim
=
as.integer
(
c
(
1600
,
1600
)))
invisible
(
gc
())
#a <- Rnorm(400*400); dim(a) <- c(400, 400)
timing
<-
system.time
({
# b <- qr.solve(a)
# Rem: a little faster than
b
<-
solve
(
a
)
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
5
,
2
]
<-
timing
cat
(
c
(
"Inverse of a 1600x1600 random matrix________________ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
times
[
,
2
]
<-
sort
(
times
[
,
2
])
cat
(
" --------------------------------------------\n"
)
cat
(
c
(
" Trimmed geom. mean (2 extremes eliminated): "
,
exp
(
mean
(
log
(
times
[
2
:
4
,
2
]))),
"\n\n"
))
cat
(
" III. Programmation\n"
)
cat
(
" ------------------\n"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (1)
cumulate
<-
0
;
a
<-
0
;
b
<-
0
;
phi
<-
1.6180339887498949
for
(
i
in
1
:
runs
)
{
a
<-
floor
(
Runif
(
3500000
)
*
1000
)
invisible
(
gc
())
timing
<-
system.time
({
b
<-
(
phi
^
a
-
(
-
phi
)
^
(
-
a
))
/
sqrt
(
5
)
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
1
,
3
]
<-
timing
cat
(
c
(
"3,500,000 Fibonacci numbers calculation (vector calc)(sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
,
"phi"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (2)
cumulate
<-
0
;
a
<-
3000
;
b
<-
0
for
(
i
in
1
:
runs
)
{
invisible
(
gc
())
timing
<-
system.time
({
b
<-
rep
(
1
:
a
,
a
);
dim
(
b
)
<-
c
(
a
,
a
);
b
<-
1
/
(
t
(
b
)
+
0
:
(
a
-1
))
# Rem: this is twice as fast as the following code proposed by R programmers
# a <- 1:a; b <- 1 / outer(a - 1, a, "+")
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
2
,
3
]
<-
timing
cat
(
c
(
"Creation of a 3000x3000 Hilbert matrix (matrix calc) (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (3)
cumulate
<-
0
;
c
<-
0
gcd2
<-
function
(
x
,
y
)
{
if
(
sum
(
y
>
1.0E-4
)
==
0
)
x
else
{
y
[
y
==
0
]
<-
x
[
y
==
0
];
Recall
(
y
,
x
%%
y
)}}
for
(
i
in
1
:
runs
)
{
a
<-
ceiling
(
Runif
(
400000
)
*
1000
)
b
<-
ceiling
(
Runif
(
400000
)
*
1000
)
invisible
(
gc
())
timing
<-
system.time
({
c
<-
gcd2
(
a
,
b
)
# gcd2 is a recursive function
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
3
,
3
]
<-
timing
cat
(
c
(
"Grand common divisors of 400,000 pairs (recursion)__ (sec): "
,
timing
,
"\n"
))
remove
(
"a"
,
"b"
,
"c"
,
"gcd2"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"
)
flush.console
()
# (4)
cumulate
<-
0
;
b
<-
0
for
(
i
in
1
:
runs
)
{
b
<-
rep
(
0
,
500
*
500
);
dim
(
b
)
<-
c
(
500
,
500
)
invisible
(
gc
())
timing
<-
system.time
({
# Rem: there are faster ways to do this
# but here we want to time loops (220*220 'for' loops)!
for
(
j
in
1
:
500
)
{
for
(
k
in
1
:
500
)
{
b
[
k
,
j
]
<-
abs
(
j
-
k
)
+
1
}
}
})[
3
]
cumulate
<-
cumulate
+
timing
}
timing
<-
cumulate
/
runs
times
[
4
,
3
]
<-
timing
cat
(
c
(
"Creation of a 500x500 Toeplitz matrix (loops)_______ (sec): "
,
timing
,
"\n"
))
remove
(
"b"
,
"j"
,
"k"
)
if
(
R.Version
()
$
os
==
"Win32"
||
R.Version
()
$
os
==
"mingw32"