-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRcppExports.R
More file actions
137 lines (126 loc) · 4.86 KB
/
RcppExports.R
File metadata and controls
137 lines (126 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#' Compute summed segment lengths or total cable
#' @description \code{c_seglengths} computes the summed segment length equivalent
#' to \code{nat::seglengths(sumsegment = T)}
#' @param sl A \code{seglist} with 1-indices into vectors x,y,z
#' @param x,y,z Numeric vectors with 3D coordinate data
#' (which could be columns from a data frame)
#' @export
c_seglengths <- function(sl, x, y, z) {
.Call(`_natcpp_c_seglengths`, sl, x, y, z)
}
#' @description \code{c_total_cable} computes the summed total cable for a
#' whole neuron. It's intended use is the \code{nat::summary.neuron} function.
#' @rdname c_seglengths
#' @export
c_total_cable <- function(sl, x, y, z) {
.Call(`_natcpp_c_total_cable`, sl, x, y, z)
}
#' Convert physical coordinates to pixel coordinates
#'
#' @param xyz Nx3 matrix of physical coordinates
#' @param dims Integer dimensions of the 3d image array
#' @param origin Numeric: 3d coordinates of the origin
#' @param voxdims Numeric: 3 numbers describing the voxel dimensions
#' @param clamp Logical: whether or not to clamp values within the pixel
#' boundaries of the image.
#' @return Nx3 integer matrix of pixel coordinates
#' @export
c_ijkpos <- function(xyz, origin, voxdims, dims, clamp = FALSE) {
.Call(`_natcpp_c_ijkpos`, xyz, origin, voxdims, dims, clamp)
}
#' Find 1D index given n-dimensional indices
#' @param dims Integer dimensions of the array (usually 3d)
#' @param indices Nx3 integer matrix of pixel coordinates
#' @return numeric vector of linear indices into the array
#' @export
c_sub2ind <- function(dims, indices) {
.Call(`_natcpp_c_sub2ind`, dims, indices)
}
#' Convert physical coordinates to 1d indices into image array
#'
#' @param xyz Nx3 matrix or data.frame of physical coordinates
#' @param dims Integer dimensions of the 3d image array
#' @param origin Numeric: 3d coordinates of the origin
#' @param voxdims Numeric: 3 numbers describing the voxel dimensions
#' @param clamp Logical: whether or not to clamp values within the pixel
#' boundaries of the image.
#' @return Nx3 integer matrix of pixel coordinates
#' @export
c_coords21dindex <- function(xyz, origin, voxdims, dims, clamp = FALSE) {
.Call(`_natcpp_c_coords21dindex`, xyz, origin, voxdims, dims, clamp)
}
#' Convert a matrix into list of row vectors
#'
#' @details Typically this will be for 3D coordinates but there are no limits
#' on row length.
#' @param object An integer, numeric, character or logical matrix of N rows and
#' M columns
#' @return a list containing N vectors of length M corresponding to the rows of
#' \code{object}.
#' @export
#' @examples
#' \dontrun{
#' library(nat)
#' xyz=xyzmatrix(Cell07PNs)
#' mat2list = function(m) {
#' um=unname(m)
#' lapply(1:nrow(um), function(i) um[i,])
#' }
#' bench::mark(rcpp=c_ListofMatrixRows(xyz), r=mat2list(xyz))
#' }
#' @export
c_ListofMatrixRows <- function(object) {
.Call(`_natcpp_c_ListofMatrixRows`, object)
}
#' A simple function to compute the lengths of the elements of an R list
#'
#' @details This is equivalent to the \code{base::lengths} however it it much
#' faster for long lists (and somewhat slower for short ones).
#' @param L a list
#' @return An integer vector containing the length of each element of \code{L}
#' @export
c_listlengths <- function(L) {
.Call(`_natcpp_c_listlengths`, L)
}
#' Find the first and last elements of all vectors in a list
#'
#' @description \code{c_topntail} returns an 2xN matrix containing the start and end
#' of each of the vectors in the input list. Length 0 vectors are ignored, while
#' length 1 vectors are duplicated
#'
#' @param L a list containing integer vectors, typically a \code{seglist}
#' @return For \code{c_topntail} an integer \code{matrix}. For \code{c_topntail_list}
#' a \code{list}.
#' @export
c_topntail <- function(L) {
.Call(`_natcpp_c_topntail`, L)
}
#' @description For \code{c_topntail_list}, a list of the same length as
#' \code{L} having the same elements when their length is <=2 or
#' the first and last elements when length>2.
#' @export
#' @rdname c_topntail
c_topntail_list <- function(L) {
.Call(`_natcpp_c_topntail_list`, L)
}
#' Turn a segment list into an edgelist suitable for constructing an ngraph
#' @details It is up to the caller to generate the \code{seglist}.
#' Note that isolated points will be dropped since they have no edges.
#' @param L a list containing integer vectors from \code{as.seglist}
#' @return An integer matrix of N rows and 2 columns
#' @export
#' @examples
#'
#' \dontrun{
#' library(nat)
#' # make a neuron with multiple subtrees
#' n=prune_vertices(Cell07PNs[[1]], 48L)
#' # Must use flatten=T if including all subtrees
#' sl=as.seglist(n, all = TRUE, flatten = TRUE)
#' c_EdgeListFromSegList(sl)
#' }
c_EdgeListFromSegList <- function(L) {
.Call(`_natcpp_c_EdgeListFromSegList`, L)
}