MyNixOS website logo
Description

Interpolation From C.

Simple interpolation methods designed to be used from C code. Supports constant, linear and spline interpolation. An R wrapper is included but this package is primarily designed to be used from C code using 'LinkingTo'. The spline calculations are classical cubic interpolation, e.g., Forsythe, Malcolm and Moler (1977) <ISBN: 9780131653320>.

cinterpolate

Project Status: Active - The project has reached a stable, usable state and is being actively developed. R-CMD-check codecov.io

Simple interpolation functions designed to be used from C. There is essentially no R support in this package, save code designed to be used by the package's own testing. cinterpolate is designed to be used in package code only and modification for use outside of a package is not explicitly supported.

Installation

cinterpolate is now on CRAN and can be installed with

install.packages("cinterpolate")

Development version

After that, install with

install.packages(
  "orderly2",
  repos = c("https://mrc-ide.r-universe.dev", "https://cloud.r-project.org"))

If you install from source, this package requires a fortran compiler because it uses LAPACK and BLAS, despite being only C code.

  • macOS Install Xcode, confirm the command line tools are installed and then install gfortran following these instructions
  • windowsRtools includes gfortran
  • linux Something like apt-get install gfortran depending on your platform

Usage

#include <cinterpolate/cinterpolate.h>

Allocate an object to perform interpolation with. nx and x are the size and values of the function to be interpolated, while ny is the number of functions to be simultaneously (but independently) interpolateed and y is the values for these. If ny > 1, then the values of y are as an R matrix with nx rows and ny columns (the first nx values are the first function, the second nx are the second, and so on). The final two are booleans: fail_on_extrapolate throws an error if extrapolation is requested, and auto_free uses R_alloc() rather than Calloc allowing automatic cleanup.

void *obj = cinterpolate_alloc(type, nx, ny, x, y,
                               fail_on_extrapolate, auto_free);

With the interpolation function, an input value of xout and given some storage yout of length ny, determine f(xout) with

cinterpolate_eval(xout, obj, yout);

Once done the object must be freed with

cinterpolate_free(obj);

Further package setup

Somewhere in the package you must include cinterpolate.c as

#include <cinterpolate/cinterpolate.h>

but this must be included only once or linking will fail. If you only use the interpolation in one place, you can use cinterpolate.c rather than cinterpolate.h. If you use interpolation in more than once place, I recommend a file src/cinterpolate.c containing

#include <cinterpolate/cinterpolate.c>

Be sure to include in your DESCRIPTION a line

LinkingTo: cinterpolate

cinterpolate takes advantage of BLAS for matrix multiplication, so you may need a Makevars that includes

PKG_LIBS = ${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS}

Example

See inst/example for a full example of using cinterpolate within a package

License

MIT + file LICENSE © Imperial College of Science, Technology and Medicine

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Metadata

Version

1.0.1

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows