Skip to content

Commit

Permalink
minor Rcpp tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Mar 19, 2020
1 parent f1f1de9 commit 108ea4f
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 152 deletions.
13 changes: 12 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
2020-03-18 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll minor version

* DESCRIPTION (Imports): Updated versioned Depends: on RcppCCTZ

* NAMESPACE: Turn on registration

* src/nanotime.cpp: Slightly more idiomatic Rcpp
* R/nanotime.R: Idem

2020-03-15 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll minor version

* src/duration.cpp: Small fix to cast to plain old type
* src/interval.cpp: Idem
* src/nanotime.cpp: Idem

* src/Makevars (PKG_CXXFLAGS): Minor edits

* cleanup: Added minor helper
Expand Down
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
Package: nanotime
Type: Package
Title: Nanosecond-Resolution Time for R
Version: 0.2.4.3.2
Date: 2020-03-15
Version: 0.2.4.3.3
Date: 2020-03-18
Author: Dirk Eddelbuettel and Leonardo Silvestri
Maintainer: Dirk Eddelbuettel <edd@debian.org>
Description: Full 64-bit resolution date and time support with resolution up
to nanosecond granularity is provided, with easy transition to and from the
standard 'POSIXct' type.
Imports: methods, bit64, RcppCCTZ (>= 0.2.6.3), zoo
Imports: methods, bit64, RcppCCTZ (>= 0.2.7), zoo
Suggests: tinytest, data.table, xts
LinkingTo: Rcpp, RcppCCTZ
License: GPL (>= 2)
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
Collate:
'nanotime.R'
'nanoival.R'
'nanoduration.R'
'nanoperiod.R'
'RcppExports.R'
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
useDynLib(nanotime)
useDynLib(nanotime, .registration = TRUE)
import("methods")
import("bit64")
importFrom("RcppCCTZ", "parseDouble", "formatDouble")
Expand Down
23 changes: 23 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

nanotime_wday_impl <- function(tm_v, tz_v) {
.Call(`_nanotime_nanotime_wday_impl`, tm_v, tz_v)
}

nanotime_mday_impl <- function(tm_v, tz_v) {
.Call(`_nanotime_nanotime_mday_impl`, tm_v, tz_v)
}

nanotime_month_impl <- function(tm_v, tz_v) {
.Call(`_nanotime_nanotime_month_impl`, tm_v, tz_v)
}

nanotime_year_impl <- function(tm_v, tz_v) {
.Call(`_nanotime_nanotime_year_impl`, tm_v, tz_v)
}

nanotime_make_impl <- function(nt_v, tz_v) {
.Call(`_nanotime_nanotime_make_impl`, nt_v, tz_v)
}

32 changes: 16 additions & 16 deletions R/nanotime.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ setAs("integer64", "nanotime", function(from) new("nanotime", as.integer64(from,


.nanotime_character <- function(from, format="", tz="") {
tryCatch(.Call("_nanotime_make", from, tz), error=function(e) {
tryCatch(nanotime_make_impl(from, tz), error=function(e) {
if (e$message == "Cannot retrieve timezone" ||
e$message == "timezone is specified twice: in the string and as an argument") {
stop(e$message)
Expand Down Expand Up @@ -251,7 +251,7 @@ format.nanotime <- function(x, format="", tz="", ...)
bigint <- as.integer64(x)
secs <- as.integer64(bigint / as.integer64(1000000000))
nanos <- bigint - secs * as.integer64(1000000000)

## EXS has special meaning for us: print with the least number of nanotime digits
if (isTRUE(as.logical(grep("%EXS", format)))) {
if (all(nanos %% 1000000000 == 0)) {
Expand All @@ -264,7 +264,7 @@ format.nanotime <- function(x, format="", tz="", ...)
format <- gsub("%EXS", "%E9S", format)
}
}

res <- RcppCCTZ::formatDouble(as.double(secs), as.double(nanos), fmt=format, tgttzstr=tz)
res[is.na(x)] <- as.character(NA)
n <- names(x)
Expand Down Expand Up @@ -650,7 +650,7 @@ seq.nanotime <-
.Call("period_seq_from_to", from, to, by, args$tz)
} else {
nanotime(seq(as.integer64(from), as.integer64(to), by=by))
}
}
}
}
else if(!is.finite(length.out) || length.out < 0L)
Expand Down Expand Up @@ -692,16 +692,16 @@ setMethod("seq", c("nanotime"), seq.nanotime)
##' use \code{all.equal} directly in \code{if} expressions---either
##' use \code{isTRUE(all.equal(....))} or \code{\link{identical}} if
##' appropriate.
##'
##'
##' @param target,current \code{nanotime} arguments to be compared
##' @param ... further arguments for different methods
##'
##' @seealso \code{\link{identical}}, \code{\link{isTRUE}},
##' \code{\link{==}}, and \code{\link{all}} for exact equality
##' testing.
##'
##'
##' @method all.equal nanotime
##'
##'
all.equal.nanotime <- function(target, current, ...) all.equal(S3Part(target, strictS3=TRUE),
S3Part(current, strictS3=TRUE), ...)

Expand All @@ -720,7 +720,7 @@ setMethod("all.equal", c(target = "ANY", current = "nanotime"),
NA_nanotime_ <- nanotime(NA)

##' Get a component of a date time
##'
##'
##' Get a component of a date time. \code{nano_wday} returns the
##' numeric position in a week, with Sunday == 0. \code{nano_mday}
##' returns the numeric day (i.e. a value from 1 to
Expand All @@ -743,28 +743,28 @@ NA_nanotime_ <- nanotime(NA)
##' nano_month(as.nanotime("2020-12-31 23:32:00 America/New_York"), "Europe/Paris")
##' nano_year(as.nanotime("2020-12-31 23:32:00-04:00"), "America/New_York")
##' nano_year(as.nanotime("2020-12-31 23:32:00 America/New_York"), "Europe/Paris")
##'
##'
##' @rdname nano_year
##' @aliases nano_wday
##' @aliases nano_wday,nanotime-method nano_mday,nanotime-method
##' @aliases nano_month,nanotime-method nano_year,nanotime-method
##' @aliases nano_month,nanotime-method nano_year,nanotime-method
##'
setGeneric("nano_wday", function(x, tz) standardGeneric("nano_wday"))
setMethod("nano_wday", c("nanotime"), function(x, tz) .Call("_nanotime_wday", x, tz))
setMethod("nano_wday", c("nanotime"), function(x, tz) nanotime_wday_impl(x, tz))

##' @rdname nano_year
##' @aliases nano_mday
##'
##'
setGeneric("nano_mday", function(x, tz) standardGeneric("nano_mday"))
setMethod("nano_mday", c("nanotime"), function(x, tz) .Call("_nanotime_mday", x, tz))
setMethod("nano_mday", c("nanotime"), function(x, tz) nanotime_mday_impl(x, tz))

##' @rdname nano_year
##' @aliases nano_month
##'
setGeneric("nano_month", function(x, tz) standardGeneric("nano_month"))
setMethod("nano_month", c("nanotime"), function(x, tz) .Call("_nanotime_month", x, tz))
setMethod("nano_month", c("nanotime"), function(x, tz) nanotime_month_impl(x, tz))

##' @rdname nano_year
##'
setGeneric("nano_year", function(x, tz) standardGeneric("nano_year"))
setMethod("nano_year", c("nanotime"), function(x, tz) .Call("_nanotime_year", x, tz))
setMethod("nano_year", c("nanotime"), function(x, tz) nanotime_year_impl(x, tz))
192 changes: 192 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <Rcpp.h>

using namespace Rcpp;

// nanotime_wday_impl
Rcpp::IntegerVector nanotime_wday_impl(const Rcpp::NumericVector tm_v, const Rcpp::CharacterVector tz_v);
RcppExport SEXP _nanotime_nanotime_wday_impl(SEXP tm_vSEXP, SEXP tz_vSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::NumericVector >::type tm_v(tm_vSEXP);
Rcpp::traits::input_parameter< const Rcpp::CharacterVector >::type tz_v(tz_vSEXP);
rcpp_result_gen = Rcpp::wrap(nanotime_wday_impl(tm_v, tz_v));
return rcpp_result_gen;
END_RCPP
}
// nanotime_mday_impl
Rcpp::IntegerVector nanotime_mday_impl(const Rcpp::NumericVector tm_v, const Rcpp::CharacterVector tz_v);
RcppExport SEXP _nanotime_nanotime_mday_impl(SEXP tm_vSEXP, SEXP tz_vSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::NumericVector >::type tm_v(tm_vSEXP);
Rcpp::traits::input_parameter< const Rcpp::CharacterVector >::type tz_v(tz_vSEXP);
rcpp_result_gen = Rcpp::wrap(nanotime_mday_impl(tm_v, tz_v));
return rcpp_result_gen;
END_RCPP
}
// nanotime_month_impl
Rcpp::IntegerVector nanotime_month_impl(const Rcpp::NumericVector tm_v, const Rcpp::CharacterVector tz_v);
RcppExport SEXP _nanotime_nanotime_month_impl(SEXP tm_vSEXP, SEXP tz_vSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::NumericVector >::type tm_v(tm_vSEXP);
Rcpp::traits::input_parameter< const Rcpp::CharacterVector >::type tz_v(tz_vSEXP);
rcpp_result_gen = Rcpp::wrap(nanotime_month_impl(tm_v, tz_v));
return rcpp_result_gen;
END_RCPP
}
// nanotime_year_impl
Rcpp::IntegerVector nanotime_year_impl(const Rcpp::NumericVector tm_v, const Rcpp::CharacterVector tz_v);
RcppExport SEXP _nanotime_nanotime_year_impl(SEXP tm_vSEXP, SEXP tz_vSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::NumericVector >::type tm_v(tm_vSEXP);
Rcpp::traits::input_parameter< const Rcpp::CharacterVector >::type tz_v(tz_vSEXP);
rcpp_result_gen = Rcpp::wrap(nanotime_year_impl(tm_v, tz_v));
return rcpp_result_gen;
END_RCPP
}
// nanotime_make_impl
Rcpp::NumericVector nanotime_make_impl(const Rcpp::CharacterVector nt_v, const Rcpp::CharacterVector tz_v);
RcppExport SEXP _nanotime_nanotime_make_impl(SEXP nt_vSEXP, SEXP tz_vSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::CharacterVector >::type nt_v(nt_vSEXP);
Rcpp::traits::input_parameter< const Rcpp::CharacterVector >::type tz_v(tz_vSEXP);
rcpp_result_gen = Rcpp::wrap(nanotime_make_impl(nt_v, tz_v));
return rcpp_result_gen;
END_RCPP
}

RcppExport SEXP _nanoival_eq(SEXP, SEXP);
RcppExport SEXP _nanoival_ge(SEXP, SEXP);
RcppExport SEXP _nanoival_get_end(SEXP);
RcppExport SEXP _nanoival_get_eopen(SEXP);
RcppExport SEXP _nanoival_get_sopen(SEXP);
RcppExport SEXP _nanoival_get_start(SEXP);
RcppExport SEXP _nanoival_gt(SEXP, SEXP);
RcppExport SEXP _nanoival_intersect(SEXP, SEXP);
RcppExport SEXP _nanoival_intersect_idx_time_interval(SEXP, SEXP);
RcppExport SEXP _nanoival_intersect_time_interval(SEXP, SEXP);
RcppExport SEXP _nanoival_is_unsorted(SEXP, SEXP);
RcppExport SEXP _nanoival_isna(SEXP);
RcppExport SEXP _nanoival_le(SEXP, SEXP);
RcppExport SEXP _nanoival_lt(SEXP, SEXP);
RcppExport SEXP _nanoival_make(SEXP, SEXP);
RcppExport SEXP _nanoival_minus(SEXP, SEXP);
RcppExport SEXP _nanoival_ne(SEXP, SEXP);
RcppExport SEXP _nanoival_new(SEXP, SEXP, SEXP, SEXP);
RcppExport SEXP _nanoival_plus(SEXP, SEXP);
RcppExport SEXP _nanoival_setdiff(SEXP, SEXP);
RcppExport SEXP _nanoival_setdiff_idx_time_interval(SEXP, SEXP);
RcppExport SEXP _nanoival_setdiff_time_interval(SEXP, SEXP);
RcppExport SEXP _nanoival_sort(SEXP, SEXP);
RcppExport SEXP _nanoival_union(SEXP, SEXP);
RcppExport SEXP divides_period_double(SEXP, SEXP);
RcppExport SEXP divides_period_integer64(SEXP, SEXP);
RcppExport SEXP duration_from_string(SEXP);
RcppExport SEXP duration_is_na(SEXP);
RcppExport SEXP duration_to_string(SEXP);
RcppExport SEXP eq_period_period(SEXP, SEXP);
RcppExport SEXP make_duration(SEXP, SEXP, SEXP, SEXP);
RcppExport SEXP minus_integer64_period(SEXP, SEXP);
RcppExport SEXP minus_nanoival_period(SEXP, SEXP, SEXP);
RcppExport SEXP minus_nanotime_period(SEXP, SEXP, SEXP);
RcppExport SEXP minus_period(SEXP);
RcppExport SEXP minus_period_integer64(SEXP, SEXP);
RcppExport SEXP minus_period_period(SEXP, SEXP);
RcppExport SEXP multiplies_period_double(SEXP, SEXP);
RcppExport SEXP multiplies_period_integer64(SEXP, SEXP);
RcppExport SEXP ne_period_period(SEXP, SEXP);
RcppExport SEXP period_day(SEXP);
RcppExport SEXP period_duration(SEXP);
RcppExport SEXP period_from_double(SEXP);
RcppExport SEXP period_from_integer(SEXP);
RcppExport SEXP period_from_integer64(SEXP);
RcppExport SEXP period_from_string(SEXP);
RcppExport SEXP period_isna(SEXP);
RcppExport SEXP period_month(SEXP);
RcppExport SEXP period_seq_from_length(SEXP, SEXP, SEXP, SEXP);
RcppExport SEXP period_seq_from_to(SEXP, SEXP, SEXP, SEXP);
RcppExport SEXP period_to_string(SEXP);
RcppExport SEXP plus_nanoival_period(SEXP, SEXP, SEXP);
RcppExport SEXP plus_nanotime_period(SEXP, SEXP, SEXP);
RcppExport SEXP plus_period_integer64(SEXP, SEXP);
RcppExport SEXP plus_period_period(SEXP, SEXP);

static const R_CallMethodDef CallEntries[] = {
{"_nanotime_nanotime_wday_impl", (DL_FUNC) &_nanotime_nanotime_wday_impl, 2},
{"_nanotime_nanotime_mday_impl", (DL_FUNC) &_nanotime_nanotime_mday_impl, 2},
{"_nanotime_nanotime_month_impl", (DL_FUNC) &_nanotime_nanotime_month_impl, 2},
{"_nanotime_nanotime_year_impl", (DL_FUNC) &_nanotime_nanotime_year_impl, 2},
{"_nanotime_nanotime_make_impl", (DL_FUNC) &_nanotime_nanotime_make_impl, 2},
{"_nanoival_eq", (DL_FUNC) &_nanoival_eq, 2},
{"_nanoival_ge", (DL_FUNC) &_nanoival_ge, 2},
{"_nanoival_get_end", (DL_FUNC) &_nanoival_get_end, 1},
{"_nanoival_get_eopen", (DL_FUNC) &_nanoival_get_eopen, 1},
{"_nanoival_get_sopen", (DL_FUNC) &_nanoival_get_sopen, 1},
{"_nanoival_get_start", (DL_FUNC) &_nanoival_get_start, 1},
{"_nanoival_gt", (DL_FUNC) &_nanoival_gt, 2},
{"_nanoival_intersect", (DL_FUNC) &_nanoival_intersect, 2},
{"_nanoival_intersect_idx_time_interval", (DL_FUNC) &_nanoival_intersect_idx_time_interval, 2},
{"_nanoival_intersect_time_interval", (DL_FUNC) &_nanoival_intersect_time_interval, 2},
{"_nanoival_is_unsorted", (DL_FUNC) &_nanoival_is_unsorted, 2},
{"_nanoival_isna", (DL_FUNC) &_nanoival_isna, 1},
{"_nanoival_le", (DL_FUNC) &_nanoival_le, 2},
{"_nanoival_lt", (DL_FUNC) &_nanoival_lt, 2},
{"_nanoival_make", (DL_FUNC) &_nanoival_make, 2},
{"_nanoival_minus", (DL_FUNC) &_nanoival_minus, 2},
{"_nanoival_ne", (DL_FUNC) &_nanoival_ne, 2},
{"_nanoival_new", (DL_FUNC) &_nanoival_new, 4},
{"_nanoival_plus", (DL_FUNC) &_nanoival_plus, 2},
{"_nanoival_setdiff", (DL_FUNC) &_nanoival_setdiff, 2},
{"_nanoival_setdiff_idx_time_interval", (DL_FUNC) &_nanoival_setdiff_idx_time_interval, 2},
{"_nanoival_setdiff_time_interval", (DL_FUNC) &_nanoival_setdiff_time_interval, 2},
{"_nanoival_sort", (DL_FUNC) &_nanoival_sort, 2},
{"_nanoival_union", (DL_FUNC) &_nanoival_union, 2},
{"divides_period_double", (DL_FUNC) &divides_period_double, 2},
{"divides_period_integer64", (DL_FUNC) &divides_period_integer64, 2},
{"duration_from_string", (DL_FUNC) &duration_from_string, 1},
{"duration_is_na", (DL_FUNC) &duration_is_na, 1},
{"duration_to_string", (DL_FUNC) &duration_to_string, 1},
{"eq_period_period", (DL_FUNC) &eq_period_period, 2},
{"make_duration", (DL_FUNC) &make_duration, 4},
{"minus_integer64_period", (DL_FUNC) &minus_integer64_period, 2},
{"minus_nanoival_period", (DL_FUNC) &minus_nanoival_period, 3},
{"minus_nanotime_period", (DL_FUNC) &minus_nanotime_period, 3},
{"minus_period", (DL_FUNC) &minus_period, 1},
{"minus_period_integer64", (DL_FUNC) &minus_period_integer64, 2},
{"minus_period_period", (DL_FUNC) &minus_period_period, 2},
{"multiplies_period_double", (DL_FUNC) &multiplies_period_double, 2},
{"multiplies_period_integer64", (DL_FUNC) &multiplies_period_integer64, 2},
{"ne_period_period", (DL_FUNC) &ne_period_period, 2},
{"period_day", (DL_FUNC) &period_day, 1},
{"period_duration", (DL_FUNC) &period_duration, 1},
{"period_from_double", (DL_FUNC) &period_from_double, 1},
{"period_from_integer", (DL_FUNC) &period_from_integer, 1},
{"period_from_integer64", (DL_FUNC) &period_from_integer64, 1},
{"period_from_string", (DL_FUNC) &period_from_string, 1},
{"period_isna", (DL_FUNC) &period_isna, 1},
{"period_month", (DL_FUNC) &period_month, 1},
{"period_seq_from_length", (DL_FUNC) &period_seq_from_length, 4},
{"period_seq_from_to", (DL_FUNC) &period_seq_from_to, 4},
{"period_to_string", (DL_FUNC) &period_to_string, 1},
{"plus_nanoival_period", (DL_FUNC) &plus_nanoival_period, 3},
{"plus_nanotime_period", (DL_FUNC) &plus_nanotime_period, 3},
{"plus_period_integer64", (DL_FUNC) &plus_period_integer64, 2},
{"plus_period_period", (DL_FUNC) &plus_period_period, 2},
{NULL, NULL, 0}
};

RcppExport void R_init_nanotime(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
Loading

0 comments on commit 108ea4f

Please sign in to comment.