Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dotCall64
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reinhard Furrer
dotCall64
Commits
2da4f597
Commit
2da4f597
authored
7 years ago
by
Florian Gerber
Browse files
Options
Downloads
Patches
Plain Diff
help file
parent
bf557238
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
DESCRIPTION
+5
-5
5 additions, 5 deletions
DESCRIPTION
R/dotCall64.R
+13
-15
13 additions, 15 deletions
R/dotCall64.R
R/vector_dc.R
+4
-5
4 additions, 5 deletions
R/vector_dc.R
man/dotCall64.Rd
+13
-15
13 additions, 15 deletions
man/dotCall64.Rd
man/vector_dc.Rd
+4
-5
4 additions, 5 deletions
man/vector_dc.Rd
with
39 additions
and
45 deletions
DESCRIPTION
+
5
−
5
View file @
2da4f597
...
@@ -9,11 +9,11 @@ Authors@R: c(person("Kaspar", "Moesinger", role = c("aut"),
...
@@ -9,11 +9,11 @@ Authors@R: c(person("Kaspar", "Moesinger", role = c("aut"),
email = "florian.gerber@math.uzh.ch"),
email = "florian.gerber@math.uzh.ch"),
person("Reinhard", "Furrer", role = "ctb",
person("Reinhard", "Furrer", role = "ctb",
email = "reinhard.furrer@math.uzh.ch"))
email = "reinhard.furrer@math.uzh.ch"))
Description:
An alternative version of .C() and .Fortran() supporting long
Description:
The package provides .C64(), which is an enhanced version of .C()
vectors and 64-bit integer type arguments. The provided interface .C64()
and .Fortran(). .C64() supports long vectors, arguments of type 64-bit
features
mechanism
s
to avoid unnecessary copies of read-only
or write-only
integer, and provides a
mechanism to avoid unnecessary copies of read-only
arguments. This makes it a convenient and fast interface to
C/C++ and Fortran
and write-only
arguments. This makes it a convenient and fast interface to
code.
C/C++ and Fortran
code.
License: GPL (>= 2)
License: GPL (>= 2)
URL: https://git.math.uzh.ch/reinhard.furrer/dotCall64
URL: https://git.math.uzh.ch/reinhard.furrer/dotCall64
BugReports: https://git.math.uzh.ch/reinhard.furrer/dotCall64/issues
BugReports: https://git.math.uzh.ch/reinhard.furrer/dotCall64/issues
...
...
This diff is collapsed.
Click to expand it.
R/dotCall64.R
+
13
−
15
View file @
2da4f597
...
@@ -3,17 +3,17 @@
...
@@ -3,17 +3,17 @@
#' \code{.C64} can be used to call compiled and loaded C functions and Fortran subroutines.
#' \code{.C64} can be used to call compiled and loaded C functions and Fortran subroutines.
#' \code{.C64} is similar to \code{\link{.C}} and \code{\link{.Fortran}}, but
#' \code{.C64} is similar to \code{\link{.C}} and \code{\link{.Fortran}}, but
#' \enumerate{
#' \enumerate{
#' \item supports long vectors, i.e., vectors with more than \code{2^31-1} elements
,
#' \item supports long vectors, i.e., vectors with more than \code{2^31-1} elements
#' \item does the necessary castings to expose the R representation of "64-bit integers" (numeric vectors)
#' \item does the necessary castings to expose the R representation of "64-bit integers" (numeric vectors)
#' to 64-bit integers arguments of the compiled function
; int64_t types in C
and integer (kind = 8) in Fortran
,
#' to 64-bit integers arguments of the compiled function
. The latter are int64_t in C code
and integer (kind = 8) in Fortran
code
#' \item provides a mechanism the control
the
duplication of the R objects exposed to the compiled code
,
#' \item provides a mechanism the control duplication of the R objects exposed to the compiled code
#' \item checks if the provided R objects are of the expected type and coerces the
R object
if necessary
.
#' \item checks if the provided R objects are of the expected type
s
and coerces the
m
if necessary
#' }
#' }
#' Compared to \code{\link{.C}}, \code{.C64} has the additional arguments \code{SIGNATURE}, \code{INTENT} and \code{VERBOSE}.
#' Compared to \code{\link{.C}}, \code{.C64} has the additional arguments \code{SIGNATURE}, \code{INTENT} and \code{VERBOSE}.
#' \code{SIGNATURE} specifies the types of the arguments of the compiled function.
#' \code{SIGNATURE} specifies the types of the arguments of the compiled function.
#' \code{INTENT} indicates whether the compiled function "reads", "writes",
#' \code{INTENT} indicates whether the compiled function "reads", "writes",
#' or "read and writes" to the R objects passed to the compiled function.
#' or "read and writes" to the R objects passed to the compiled function.
#' This is then used to duplicate R objects if
(
and only if
)
necessary.
#' This is then used to duplicate R objects if and only if necessary.
#'
#'
#' @param .NAME character vector of length 1. Name of the compiled function to be called.
#' @param .NAME character vector of length 1. Name of the compiled function to be called.
#' @param SIGNATURE character vector of the same length as the number of arguments of the compiled function.
#' @param SIGNATURE character vector of the same length as the number of arguments of the compiled function.
...
@@ -30,15 +30,14 @@
...
@@ -30,15 +30,14 @@
#' While this avoids copying and hence is more efficient in terms of speed and memory usage,
#' While this avoids copying and hence is more efficient in terms of speed and memory usage,
#' it is absolutely necessary that the compiled function does not alter the object,
#' it is absolutely necessary that the compiled function does not alter the object,
#' since this corrupts the R object in the current R session.
#' since this corrupts the R object in the current R session.
#' When the
intent
is \code{"w"}, the corresponding input argument can be specified
#' When the
INTENT
is \code{"w"}, the corresponding input argument can be specified
#' with the function \code{\link{vector_dc}} or its shortcuts \code{\link{integer_dc}} and \code{\link{numeric_dc}}.
#' with the function \code{\link{vector_dc}} or its shortcuts \code{\link{integer_dc}} and \code{\link{numeric_dc}}.
#' This avoids copying the passed R objects and hence is more efficient in terms of speed and memory usage.
#' This avoids copying the passed R objects and hence is more efficient in terms of speed and memory usage.
#' By default, all arguments have
intent
\code{"rw"}.
#' By default, all arguments have
INTENT
\code{"rw"}.
#' @param NAOK logical vector of length 1. If \code{FALSE} (default), the presence of \code{NA}
or
\code{NaN}
or
\code{Inf}
#' @param NAOK logical vector of length 1. If \code{FALSE} (default), the presence of \code{NA}
,
\code{NaN}
, and
\code{Inf}
#' in the R objects passed through \code{...} results in an error.
#' in the R objects passed through \code{...} results in an error.
#' If \code{TRUE}, any \code{NA} or \code{NaN} or \code{Inf} values in the
#' If \code{TRUE}, \code{NA}, \code{NaN}, and \code{Inf} values are passed to the compiled function.
#' arguments are passed on to the compiled function.
#' The used time to check arguments (if \code{FALSE}) is considerable for large vectors.
#' The used time to check arguments (if \code{FALSE}) maybe considerable for large vectors.
#' @param PACKAGE character vector of length 1. Specifies where to search for the function given in \code{.NAME}.
#' @param PACKAGE character vector of length 1. Specifies where to search for the function given in \code{.NAME}.
#' This is intended to add safety for packages,
#' This is intended to add safety for packages,
#' which can use this argument to ensure that no other package can override their external symbols,
#' which can use this argument to ensure that no other package can override their external symbols,
...
@@ -80,7 +79,7 @@
...
@@ -80,7 +79,7 @@
#' input = x_long, index = 9, output = double(1))$output
#' input = x_long, index = 9, output = double(1))$output
#'
#'
#' ## Since 'index' is of type 'signed int' (a 32-bit integer),
#' ## Since 'index' is of type 'signed int' (a 32-bit integer),
#' ## it can only address
vector having up to
2^31-1 elements.
#' ## it can only address
the first
2^31-1 elements
of 'input'
.
#' ## To also address elements beyond 2^31-1, we change the
#' ## To also address elements beyond 2^31-1, we change the
#' ## definition of the C function as follows:
#' ## definition of the C function as follows:
#' ## #include <stdint.h> // for int64_t
#' ## #include <stdint.h> // for int64_t
...
@@ -92,11 +91,11 @@
...
@@ -92,11 +91,11 @@
#' .C64("get64_c", SIGNATURE = c("double", "int64", "double"),
#' .C64("get64_c", SIGNATURE = c("double", "int64", "double"),
#' input = x_long, index = 2^31, output = double(1))$output
#' input = x_long, index = 2^31, output = double(1))$output
#'
#'
#' ## Note that 2^31 is of type double and .C64() casts it to a
#' ## Note that 2^31 is of type double and .C64() casts it
in
to a
n
#' ## int64_t type before calling the C function get64_c().
#' ## int64_t type before calling the C function get64_c().
#'
#'
#' ## The performance of the previous call can be improved by
#' ## The performance of the previous call can be improved by
#' ## setting additional argu
e
ments:
#' ## setting additional arguments:
#' .C64("get64_c", SIGNATURE = c("double", "int64", "double"),
#' .C64("get64_c", SIGNATURE = c("double", "int64", "double"),
#' x = x_long, i = 2^31, r = numeric_dc(1), INTENT = c("r", "r", "w"),
#' x = x_long, i = 2^31, r = numeric_dc(1), INTENT = c("r", "r", "w"),
#' NAOK = TRUE, PACKAGE = "dotCall64", VERBOSE = 0)$r
#' NAOK = TRUE, PACKAGE = "dotCall64", VERBOSE = 0)$r
...
@@ -112,7 +111,6 @@
...
@@ -112,7 +111,6 @@
#' ## The function is provided in dotCall64 and can be called with
#' ## The function is provided in dotCall64 and can be called with
#' .C64("get64_f", SIGNATURE = c("double", "int64", "double"),
#' .C64("get64_f", SIGNATURE = c("double", "int64", "double"),
#' input = x_long, index = 2^31, output = double(1))$output
#' input = x_long, index = 2^31, output = double(1))$output
#'
#' }
#' }
#' @useDynLib dotCall64, .registration = TRUE
#' @useDynLib dotCall64, .registration = TRUE
#' @export
#' @export
...
...
This diff is collapsed.
Click to expand it.
R/vector_dc.R
+
4
−
5
View file @
2da4f597
#' Allocate vectors in .C64()
#' Allocate vectors in .C64()
#'
#'
#' Helper functions to be used in calls to \code{\link{.C64}}.
#' \code{vector_dc} and its shortcuts \code{numeric_dc} and
#' The function \code{vector_dc} and its shortcuts \code{numeric_dc} and
#' \code{integer_dc} are helper functions used in calls to \code{\link{.C64}}.
#' \code{integer_dc} return an R object of class \code{c("vector_dc", "list")}
#' They return an R object of class \code{c("vector_dc", "list")},
#' containing the necessary information (type and length) to allocate the
#' which contains information on the type and length of the vector to allocate.
#' vector (initialized with 0) inside the call to \code{\link{.C64}}.
#' Using \code{vector_dc} together with \code{INTENT = "w"} argument of \code{\link{.C64}}
#' Using \code{vector_dc} together with \code{INTENT = "w"} argument of \code{\link{.C64}}
#' leads to performance gains by avoiding unnecessary castings and copies.
#' leads to performance gains by avoiding unnecessary castings and copies.
#'
#'
...
...
This diff is collapsed.
Click to expand it.
man/dotCall64.Rd
+
13
−
15
View file @
2da4f597
...
@@ -27,16 +27,15 @@ function receives a pointer to the R object itself.
...
@@ -27,16 +27,15 @@ function receives a pointer to the R object itself.
While this avoids copying and hence is more efficient in terms of speed and memory usage,
While this avoids copying and hence is more efficient in terms of speed and memory usage,
it is absolutely necessary that the compiled function does not alter the object,
it is absolutely necessary that the compiled function does not alter the object,
since this corrupts the R object in the current R session.
since this corrupts the R object in the current R session.
When the
intent
is \code{"w"}, the corresponding input argument can be specified
When the
INTENT
is \code{"w"}, the corresponding input argument can be specified
with the function \code{\link{vector_dc}} or its shortcuts \code{\link{integer_dc}} and \code{\link{numeric_dc}}.
with the function \code{\link{vector_dc}} or its shortcuts \code{\link{integer_dc}} and \code{\link{numeric_dc}}.
This avoids copying the passed R objects and hence is more efficient in terms of speed and memory usage.
This avoids copying the passed R objects and hence is more efficient in terms of speed and memory usage.
By default, all arguments have
intent
\code{"rw"}.}
By default, all arguments have
INTENT
\code{"rw"}.}
\item{NAOK}{logical vector of length 1. If \code{FALSE} (default), the presence of \code{NA}
or
\code{NaN}
or
\code{Inf}
\item{NAOK}{logical vector of length 1. If \code{FALSE} (default), the presence of \code{NA}
,
\code{NaN}
, and
\code{Inf}
in the R objects passed through \code{...} results in an error.
in the R objects passed through \code{...} results in an error.
If \code{TRUE}, any \code{NA} or \code{NaN} or \code{Inf} values in the
If \code{TRUE}, \code{NA}, \code{NaN}, and \code{Inf} values are passed to the compiled function.
arguments are passed on to the compiled function.
The used time to check arguments (if \code{FALSE}) is considerable for large vectors.}
The used time to check arguments (if \code{FALSE}) maybe considerable for large vectors.}
\item{PACKAGE}{character vector of length 1. Specifies where to search for the function given in \code{.NAME}.
\item{PACKAGE}{character vector of length 1. Specifies where to search for the function given in \code{.NAME}.
This is intended to add safety for packages,
This is intended to add safety for packages,
...
@@ -56,17 +55,17 @@ The objects of the list reflect the changes made by the compiled C or Fortran co
...
@@ -56,17 +55,17 @@ The objects of the list reflect the changes made by the compiled C or Fortran co
\code{.C64} can be used to call compiled and loaded C functions and Fortran subroutines.
\code{.C64} can be used to call compiled and loaded C functions and Fortran subroutines.
\code{.C64} is similar to \code{\link{.C}} and \code{\link{.Fortran}}, but
\code{.C64} is similar to \code{\link{.C}} and \code{\link{.Fortran}}, but
\enumerate{
\enumerate{
\item supports long vectors, i.e., vectors with more than \code{2^31-1} elements
,
\item supports long vectors, i.e., vectors with more than \code{2^31-1} elements
\item does the necessary castings to expose the R representation of "64-bit integers" (numeric vectors)
\item does the necessary castings to expose the R representation of "64-bit integers" (numeric vectors)
to 64-bit integers arguments of the compiled function
; int64_t types in C
and integer (kind = 8) in Fortran
,
to 64-bit integers arguments of the compiled function
. The latter are int64_t in C code
and integer (kind = 8) in Fortran
code
\item provides a mechanism the control
the
duplication of the R objects exposed to the compiled code
,
\item provides a mechanism the control duplication of the R objects exposed to the compiled code
\item checks if the provided R objects are of the expected type and coerces the
R object
if necessary
.
\item checks if the provided R objects are of the expected type
s
and coerces the
m
if necessary
}
}
Compared to \code{\link{.C}}, \code{.C64} has the additional arguments \code{SIGNATURE}, \code{INTENT} and \code{VERBOSE}.
Compared to \code{\link{.C}}, \code{.C64} has the additional arguments \code{SIGNATURE}, \code{INTENT} and \code{VERBOSE}.
\code{SIGNATURE} specifies the types of the arguments of the compiled function.
\code{SIGNATURE} specifies the types of the arguments of the compiled function.
\code{INTENT} indicates whether the compiled function "reads", "writes",
\code{INTENT} indicates whether the compiled function "reads", "writes",
or "read and writes" to the R objects passed to the compiled function.
or "read and writes" to the R objects passed to the compiled function.
This is then used to duplicate R objects if
(
and only if
)
necessary.
This is then used to duplicate R objects if and only if necessary.
}
}
\examples{
\examples{
## Consider the following C function, which is included
## Consider the following C function, which is included
...
@@ -87,7 +86,7 @@ x_long[9] <- 9; x_long[2^31] <- -1
...
@@ -87,7 +86,7 @@ x_long[9] <- 9; x_long[2^31] <- -1
input = x_long, index = 9, output = double(1))$output
input = x_long, index = 9, output = double(1))$output
## Since 'index' is of type 'signed int' (a 32-bit integer),
## Since 'index' is of type 'signed int' (a 32-bit integer),
## it can only address
vector having up to
2^31-1 elements.
## it can only address
the first
2^31-1 elements
of 'input'
.
## To also address elements beyond 2^31-1, we change the
## To also address elements beyond 2^31-1, we change the
## definition of the C function as follows:
## definition of the C function as follows:
## #include <stdint.h> // for int64_t
## #include <stdint.h> // for int64_t
...
@@ -99,11 +98,11 @@ x_long[9] <- 9; x_long[2^31] <- -1
...
@@ -99,11 +98,11 @@ x_long[9] <- 9; x_long[2^31] <- -1
.C64("get64_c", SIGNATURE = c("double", "int64", "double"),
.C64("get64_c", SIGNATURE = c("double", "int64", "double"),
input = x_long, index = 2^31, output = double(1))$output
input = x_long, index = 2^31, output = double(1))$output
## Note that 2^31 is of type double and .C64() casts it to a
## Note that 2^31 is of type double and .C64() casts it
in
to a
n
## int64_t type before calling the C function get64_c().
## int64_t type before calling the C function get64_c().
## The performance of the previous call can be improved by
## The performance of the previous call can be improved by
## setting additional argu
e
ments:
## setting additional arguments:
.C64("get64_c", SIGNATURE = c("double", "int64", "double"),
.C64("get64_c", SIGNATURE = c("double", "int64", "double"),
x = x_long, i = 2^31, r = numeric_dc(1), INTENT = c("r", "r", "w"),
x = x_long, i = 2^31, r = numeric_dc(1), INTENT = c("r", "r", "w"),
NAOK = TRUE, PACKAGE = "dotCall64", VERBOSE = 0)$r
NAOK = TRUE, PACKAGE = "dotCall64", VERBOSE = 0)$r
...
@@ -119,7 +118,6 @@ x_long[9] <- 9; x_long[2^31] <- -1
...
@@ -119,7 +118,6 @@ x_long[9] <- 9; x_long[2^31] <- -1
## The function is provided in dotCall64 and can be called with
## The function is provided in dotCall64 and can be called with
.C64("get64_f", SIGNATURE = c("double", "int64", "double"),
.C64("get64_f", SIGNATURE = c("double", "int64", "double"),
input = x_long, index = 2^31, output = double(1))$output
input = x_long, index = 2^31, output = double(1))$output
}
}
}
}
\references{
\references{
...
...
This diff is collapsed.
Click to expand it.
man/vector_dc.Rd
+
4
−
5
View file @
2da4f597
...
@@ -21,11 +21,10 @@ integer_dc(length = 0)
...
@@ -21,11 +21,10 @@ integer_dc(length = 0)
object of class \code{vector_dc} and \code{list}.
object of class \code{vector_dc} and \code{list}.
}
}
\description{
\description{
Helper functions to be used in calls to \code{\link{.C64}}.
\code{vector_dc} and its shortcuts \code{numeric_dc} and
The function \code{vector_dc} and its shortcuts \code{numeric_dc} and
\code{integer_dc} are helper functions used in calls to \code{\link{.C64}}.
\code{integer_dc} return an R object of class \code{c("vector_dc", "list")}
They return an R object of class \code{c("vector_dc", "list")},
containing the necessary information (type and length) to allocate the
which contains information on the type and length of the vector to allocate.
vector (initialized with 0) inside the call to \code{\link{.C64}}.
Using \code{vector_dc} together with \code{INTENT = "w"} argument of \code{\link{.C64}}
Using \code{vector_dc} together with \code{INTENT = "w"} argument of \code{\link{.C64}}
leads to performance gains by avoiding unnecessary castings and copies.
leads to performance gains by avoiding unnecessary castings and copies.
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment