git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/Rdisop@63004 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -1,3 +1,7 @@ |
1 |
+2012-02-23 Steffen Neumann <sneumann@ipb-halle.de> |
|
2 |
+ * Moved from the ancient embedded Rcpp to RcppClassic, |
|
3 |
+ thanks to the work of Dirk Eddelbuettel who did the porting |
|
4 |
+ |
|
1 | 5 |
2010-11-04 Steffen Neumann <sneumann@ipb-halle.de> |
2 | 6 |
* Corrected bug that leads to wrong monoisotopic masses for molecules |
3 | 7 |
containing elements where the most abundant isotope is not the first one, |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
Package: Rdisop |
2 | 2 |
Title: Decomposition of Isotopic Patterns |
3 |
-Version: 1.15.2 |
|
4 |
-Date: 2011-10-05 |
|
3 |
+Version: 1.15.3 |
|
4 |
+Date: 2012-02-23 |
|
5 | 5 |
Author: Anton Pervukhin <apervukh@minet.uni-jena.de>, Steffen Neumann <sneumann@ipb-halle.de> |
6 | 6 |
Maintainer: Steffen Neumann <sneumann@ipb-halle.de> |
7 | 7 |
Description: Identification of metabolites using high precision mass |
... | ... |
@@ -9,9 +9,11 @@ Description: Identification of metabolites using high precision mass |
9 | 9 |
of sum formulae, alternatively for a given sum formula |
10 | 10 |
the theoretical isotope distribution can be calculated |
11 | 11 |
to search in MS peak lists. |
12 |
-Depends: R (>= 2.0.0) |
|
12 |
+Depends: R (>= 2.0.0), RcppClassic, Rcpp |
|
13 |
+LinkingTo: RcppClassic, Rcpp |
|
13 | 14 |
Suggests: RUnit |
14 | 15 |
SystemRequirements: None |
15 | 16 |
License: GPL-2 |
16 | 17 |
URL: http://msbi.ipb-halle.de/ |
17 | 18 |
biocViews: MassSpectrometry |
19 |
+Packaged: 2012-02-16 14:03:45.877398 UTC; edd |
... | ... |
@@ -1,3 +1,3 @@ |
1 | 1 |
# echo "useDynLib(Rdisop)" ; echo -n "export(" ; grep --no-filename "<- function" R/*.R | cut -d" " -f 1 | grep -v First.lib | grep -v getElement | sort | xargs echo -n | tr " " , ; echo ")" |
2 | 2 |
useDynLib(Rdisop) |
3 |
-export(addMolecules,decomposeIsotopes,decomposeMass,getMass,getFormula,getIsotope,getValid,getMolecule,getScore,initializeCHNOPS,initializeCHNOPSMgKCaFe,initializeCHNOPSNaK,initializeElements,initializePSE,initializeCharges,isotopeScore,RcppVersion,subMolecules) |
|
3 |
+export(addMolecules,decomposeIsotopes,decomposeMass,getMass,getFormula,getIsotope,getValid,getMolecule,getScore,initializeCHNOPS,initializeCHNOPSMgKCaFe,initializeCHNOPSNaK,initializeElements,initializePSE,initializeCharges,isotopeScore,subMolecules) |
5 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,18 +0,0 @@ |
1 |
-Built using Rcpp/RcppTemplate Version 5.0 |
|
2 |
- |
|
3 |
-Rcpp/RcppTemplate Copyright (c) 2005-2006 by Dominick Samperi |
|
4 |
- |
|
5 |
-This library is free software; you can redistribute it and/or modify it |
|
6 |
-under the terms of the GNU Lesser General Public License as published by |
|
7 |
-the Free Software Foundation; either version 2.1 of the License, or (at |
|
8 |
-your option) any later version. |
|
9 |
- |
|
10 |
-This library is distributed in the hope that it will be useful, but |
|
11 |
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
12 |
-or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|
13 |
-License for more details. |
|
14 |
- |
|
15 |
-You should have received a copy of the GNU Lesser General Public License |
|
16 |
-along with this library; if not, write to the Free Software Foundation, |
|
17 |
-Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
- |
19 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,16 +0,0 @@ |
1 |
-include ${R_HOME}/etc${R_ARCH}/Makeconf |
|
2 |
-SRC = Rcpp.cpp |
|
3 |
-OBJ = Rcpp.o |
|
4 |
-LIB = libRcpp.a |
|
5 |
- |
|
6 |
-.PHONY: all |
|
7 |
- |
|
8 |
-all: $(LIB) |
|
9 |
- |
|
10 |
-clean: |
|
11 |
- rm -f $(OBJ) $(LIB) |
|
12 |
- |
|
13 |
-$(OBJ): $(SRC) |
|
14 |
- |
|
15 |
-$(LIB): $(OBJ) |
|
16 |
- ar crs $(LIB) $(OBJ) |
17 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,23 +0,0 @@ |
1 |
-include $(R_HOME)/etc/$(R_ARCH)/Makeconf |
|
2 |
- |
|
3 |
-SRC = Rcpp.cpp |
|
4 |
-OBJ = Rcpp.o |
|
5 |
-LINKOBJ = Rcpp.o $(RES) |
|
6 |
-DLLLIBS = -s -L"$(RHOME)/src/gnuwin32" -lR --no-export-all-symbols --add-stdcall-alias |
|
7 |
-LIB = libRcpp.a |
|
8 |
-CXXFLAGS = -I"$(RHOME)/include" -I"$(RHOME)/src/include" $(CPPFLAGS) -Wall -O2 |
|
9 |
-RM = rm -f |
|
10 |
- |
|
11 |
-.PHONY: all all-before all-after clean clean-custom |
|
12 |
- |
|
13 |
-all: all-before libRcpp.a all-after |
|
14 |
- |
|
15 |
-clean: clean-custom |
|
16 |
- $(RM) $(LINKOBJ) $(LIB) |
|
17 |
- |
|
18 |
-$(OBJ): $(SRC) |
|
19 |
- $(CXX) -c $(SRC) -o $(OBJ) $(CXXFLAGS) |
|
20 |
- |
|
21 |
-$(LIB): $(LINKOBJ) |
|
22 |
- $(AR) rs $(LIB) $(OBJ) |
|
23 |
- $(RM) $(OBJ) |
24 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,19 +0,0 @@ |
1 |
- |
|
2 |
-Package build used Rcpp/RcppTemplate Version 4.2 |
|
3 |
- |
|
4 |
-Copyright (c) 2005-2006 by Dominick Samperi |
|
5 |
- |
|
6 |
-This library is free software; you can redistribute it and/or modify it |
|
7 |
-under the terms of the GNU Lesser General Public License as published by |
|
8 |
-the Free Software Foundation; either version 2.1 of the License, or (at |
|
9 |
-your option) any later version. |
|
10 |
- |
|
11 |
-This library is distributed in the hope that it will be useful, but |
|
12 |
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
13 |
-or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|
14 |
-License for more details. |
|
15 |
- |
|
16 |
-You should have received a copy of the GNU Lesser General Public License |
|
17 |
-along with this library; if not, write to the Free Software Foundation, |
|
18 |
-Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
19 |
- |
20 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,892 +0,0 @@ |
1 |
-// Rcpp.cpp: Part of the R/C++ interface class library, Version 5.0 |
|
2 |
-// |
|
3 |
-// Copyright (C) 2005-2006 Dominick Samperi |
|
4 |
-// |
|
5 |
-// This library is free software; you can redistribute it and/or modify it |
|
6 |
-// under the terms of the GNU Lesser General Public License as published by |
|
7 |
-// the Free Software Foundation; either version 2.1 of the License, or (at |
|
8 |
-// your option) any later version. |
|
9 |
-// |
|
10 |
-// This library is distributed in the hope that it will be useful, but |
|
11 |
-// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
12 |
-// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|
13 |
-// License for more details. |
|
14 |
-// |
|
15 |
-// You should have received a copy of the GNU Lesser General Public License |
|
16 |
-// along with this library; if not, write to the Free Software Foundation, |
|
17 |
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
- |
|
19 |
-#include "Rcpp.hpp" |
|
20 |
-#include <cstring> |
|
21 |
- |
|
22 |
-RcppParams::RcppParams(SEXP params) { |
|
23 |
- if(!isNewList(params)) |
|
24 |
- throw std::range_error("RcppParams: non-list passed to constructor"); |
|
25 |
- int len = length(params); |
|
26 |
- SEXP names = getAttrib(params, R_NamesSymbol); |
|
27 |
- if(names == R_NilValue) |
|
28 |
- throw std::range_error("RcppParams: list must have named elements"); |
|
29 |
- for(int i = 0; i < len; i++) { |
|
30 |
- string nm = string(CHAR(STRING_ELT(names,i))); |
|
31 |
- if(nm.size() == 0) |
|
32 |
- throw std::range_error("RcppParams: all list elements must be named"); |
|
33 |
- pmap[nm] = i; |
|
34 |
- } |
|
35 |
- _params = params; |
|
36 |
-} |
|
37 |
- |
|
38 |
-void RcppParams::checkNames(char *inputNames[], int len) { |
|
39 |
- for(int i = 0; i < len; i++) { |
|
40 |
- map<string,int>::iterator iter = pmap.find(inputNames[i]); |
|
41 |
- if(iter == pmap.end()) { |
|
42 |
- string mesg = "checkNames: missing required parameter "; |
|
43 |
- throw range_error(mesg+inputNames[i]); |
|
44 |
- } |
|
45 |
- } |
|
46 |
-} |
|
47 |
- |
|
48 |
-RcppFrame::RcppFrame(SEXP df) { |
|
49 |
- if(!isNewList(df)) |
|
50 |
- throw std::range_error("RcppFrame::RcppFrame: invalid data frame."); |
|
51 |
- int ncol = length(df); |
|
52 |
- SEXP names = getAttrib(df, R_NamesSymbol); |
|
53 |
- colNames.resize(ncol); |
|
54 |
- SEXP colData = VECTOR_ELT(df,0); // First column of data. |
|
55 |
- int nrow = length(colData); |
|
56 |
- if(nrow == 0) |
|
57 |
- throw std::range_error("RcppFrame::RcppFrame: zero lenth column."); |
|
58 |
- |
|
59 |
- // Allocate storage for table. |
|
60 |
- table.resize(nrow); |
|
61 |
- for(int r = 0; r < nrow; r++) |
|
62 |
- table[r].resize(ncol); |
|
63 |
- |
|
64 |
- for(int i=0; i < ncol; i++) { |
|
65 |
- colNames[i] = string(CHAR(STRING_ELT(names,i))); |
|
66 |
- SEXP colData = VECTOR_ELT(df,i); |
|
67 |
- if(!isVector(colData) || length(colData) != nrow) |
|
68 |
- throw std::range_error("RcppFrame::RcppFrame: invalid column."); |
|
69 |
- |
|
70 |
- // Check for Date class. Currently R stores the date ordinal in a |
|
71 |
- // real value. We check for Date under both Real and Integer values |
|
72 |
- // as insurance against future changes. |
|
73 |
- bool isDateClass = false; |
|
74 |
- SEXP classname = getAttrib(colData, R_ClassSymbol); |
|
75 |
- if(classname != R_NilValue) |
|
76 |
- isDateClass = (strcmp(CHAR(STRING_ELT(classname,0)),"Date") == 0); |
|
77 |
- |
|
78 |
- if(isReal(colData)) { |
|
79 |
- if(isDateClass) { |
|
80 |
- for(int j=0; j < nrow; j++) // Column of Date's |
|
81 |
- table[j][i].setDateValue(RcppDate((int)REAL(colData)[j])); |
|
82 |
- } |
|
83 |
- else // Column of REAL's |
|
84 |
- for(int j=0; j < nrow; j++) |
|
85 |
- table[j][i].setDoubleValue(REAL(colData)[j]); |
|
86 |
- } |
|
87 |
- else if(isInteger(colData)) { |
|
88 |
- if(isDateClass) { |
|
89 |
- for(int j=0; j < nrow; j++) // Column of Date's |
|
90 |
- table[j][i].setDateValue(RcppDate(INTEGER(colData)[j])); |
|
91 |
- } |
|
92 |
- else |
|
93 |
- for(int j=0; j < nrow; j++) |
|
94 |
- table[j][i].setIntValue(INTEGER(colData)[j]); |
|
95 |
- } |
|
96 |
- else if(isString(colData)) { // Non-factor string column |
|
97 |
- for(int j=0; j < nrow; j++) |
|
98 |
- table[j][i].setStringValue(string(CHAR(STRING_ELT(colData,j)))); |
|
99 |
- } |
|
100 |
- else if (isFactor(colData)) { // Factor column. |
|
101 |
- SEXP names = getAttrib(colData, R_LevelsSymbol); |
|
102 |
- int numLevels = length(names); |
|
103 |
- string *levelNames = new string[numLevels]; |
|
104 |
- for(int k=0; k < numLevels; k++) |
|
105 |
- levelNames[k] = string(CHAR(STRING_ELT(names,k))); |
|
106 |
- for(int j=0; j < nrow; j++) |
|
107 |
- table[j][i].setFactorValue(levelNames, numLevels, |
|
108 |
- INTEGER(colData)[j]); |
|
109 |
- delete [] levelNames; |
|
110 |
- } |
|
111 |
- else if(isLogical(colData)) { |
|
112 |
- for(int j=0; j < nrow; j++) { |
|
113 |
- table[j][i].setLogicalValue(INTEGER(colData)[j]); |
|
114 |
- } |
|
115 |
- } |
|
116 |
- else |
|
117 |
- throw std::range_error("RcppFrame::RcppFrame: unsupported data frame column type."); |
|
118 |
- } |
|
119 |
-} |
|
120 |
- |
|
121 |
-double RcppParams::getDoubleValue(string name) { |
|
122 |
- map<string,int>::iterator iter = pmap.find(name); |
|
123 |
- if(iter == pmap.end()) { |
|
124 |
- string mesg = "getDoubleValue: no such name: "; |
|
125 |
- throw std::range_error(mesg+name); |
|
126 |
- } |
|
127 |
- int posn = iter->second; |
|
128 |
- SEXP elt = VECTOR_ELT(_params,posn); |
|
129 |
- if(!isNumeric(elt) || length(elt) != 1) { |
|
130 |
- string mesg = "getDoubleValue: must be scalar "; |
|
131 |
- throw std::range_error(mesg+name); |
|
132 |
- } |
|
133 |
- if(isInteger(elt)) |
|
134 |
- return (double)INTEGER(elt)[0]; |
|
135 |
- else if(isReal(elt)) |
|
136 |
- return REAL(elt)[0]; |
|
137 |
- else { |
|
138 |
- string mesg = "getDoubleValue: invalid value for "; |
|
139 |
- throw std::range_error(mesg+name); |
|
140 |
- } |
|
141 |
- return 0; // never get here |
|
142 |
-} |
|
143 |
- |
|
144 |
-int RcppParams::getIntValue(string name) { |
|
145 |
- map<string,int>::iterator iter = pmap.find(name); |
|
146 |
- if(iter == pmap.end()) { |
|
147 |
- string mesg = "getIntValue: no such name: "; |
|
148 |
- throw std::range_error(mesg+name); |
|
149 |
- } |
|
150 |
- int posn = iter->second; |
|
151 |
- SEXP elt = VECTOR_ELT(_params,posn); |
|
152 |
- if(!isNumeric(elt) || length(elt) != 1) { |
|
153 |
- string mesg = "getIntValue: must be scalar: "; |
|
154 |
- throw std::range_error(mesg+name); |
|
155 |
- } |
|
156 |
- if(isInteger(elt)) |
|
157 |
- return INTEGER(elt)[0]; |
|
158 |
- else if(isReal(elt)) |
|
159 |
- return (int)REAL(elt)[0]; |
|
160 |
- else { |
|
161 |
- string mesg = "getIntValue: invalid value for: "; |
|
162 |
- throw std::range_error(mesg+name); |
|
163 |
- } |
|
164 |
- return 0; // never get here |
|
165 |
-} |
|
166 |
- |
|
167 |
-bool RcppParams::getBoolValue(string name) { |
|
168 |
- map<string,int>::iterator iter = pmap.find(name); |
|
169 |
- if(iter == pmap.end()) { |
|
170 |
- string mesg = "getBoolValue: no such name: "; |
|
171 |
- throw std::range_error(mesg+name); |
|
172 |
- } |
|
173 |
- int posn = iter->second; |
|
174 |
- SEXP elt = VECTOR_ELT(_params,posn); |
|
175 |
- if(isLogical(elt)) |
|
176 |
- return INTEGER(elt)[0]; |
|
177 |
- else { |
|
178 |
- string mesg = "getBoolValue: invalid value for: "; |
|
179 |
- throw std::range_error(mesg+name); |
|
180 |
- } |
|
181 |
- return false; // never get here |
|
182 |
-} |
|
183 |
- |
|
184 |
-string RcppParams::getStringValue(string name) { |
|
185 |
- map<string,int>::iterator iter = pmap.find(name); |
|
186 |
- if(iter == pmap.end()) { |
|
187 |
- string mesg = "getStringValue: no such name: "; |
|
188 |
- throw std::range_error(mesg+name); |
|
189 |
- } |
|
190 |
- int posn = iter->second; |
|
191 |
- SEXP elt = VECTOR_ELT(_params,posn); |
|
192 |
- if(isString(elt)) |
|
193 |
- return string(CHAR(STRING_ELT(elt,0))); |
|
194 |
- else { |
|
195 |
- string mesg = "getStringValue: invalid value for: "; |
|
196 |
- throw std::range_error(mesg+name); |
|
197 |
- } |
|
198 |
- return ""; // never get here |
|
199 |
-} |
|
200 |
- |
|
201 |
-RcppDate RcppParams::getDateValue(string name) { |
|
202 |
- map<string,int>::iterator iter = pmap.find(name); |
|
203 |
- if(iter == pmap.end()) { |
|
204 |
- string mesg = "getDateValue: no such name: "; |
|
205 |
- throw std::range_error(mesg+name); |
|
206 |
- } |
|
207 |
- int posn = iter->second; |
|
208 |
- SEXP elt = VECTOR_ELT(_params,posn); |
|
209 |
- if(!isNumeric(elt) || length(elt) != 1) { |
|
210 |
- string mesg = "getDateValue: invalide date: "; |
|
211 |
- throw std::range_error(mesg+name); |
|
212 |
- } |
|
213 |
- |
|
214 |
- int d; |
|
215 |
- if(isReal(elt)) // R stores julian value in a double. |
|
216 |
- d = (int)REAL(elt)[0]; |
|
217 |
- else { |
|
218 |
- string mesg = "getDateValue: invalid value for: "; |
|
219 |
- throw std::range_error(mesg+name); |
|
220 |
- } |
|
221 |
- return RcppDate(d); |
|
222 |
-} |
|
223 |
- |
|
224 |
-RcppDateVector::RcppDateVector(SEXP vec) { |
|
225 |
- int i; |
|
226 |
- if(!isNumeric(vec) || isMatrix(vec) || isLogical(vec)) |
|
227 |
- throw std::range_error("RcppVector: invalid numeric vector in constructor"); |
|
228 |
- int len = length(vec); |
|
229 |
- if(len == 0) |
|
230 |
- throw std::range_error("RcppVector: null vector in constructor"); |
|
231 |
- v = new RcppDate[len]; |
|
232 |
- for(i = 0; i < len; i++) |
|
233 |
- v[i] = RcppDate((int)REAL(vec)[i]); |
|
234 |
- length = len; |
|
235 |
-} |
|
236 |
- |
|
237 |
-RcppStringVector::RcppStringVector(SEXP vec) { |
|
238 |
- int i; |
|
239 |
- if(isMatrix(vec) || isLogical(vec)) |
|
240 |
- throw std::range_error("RcppVector: invalid numeric vector in constructor"); |
|
241 |
- if(!isString(vec)) |
|
242 |
- throw std::range_error("RcppStringVector: invalid string"); |
|
243 |
- int len = length(vec); |
|
244 |
- if(len == 0) |
|
245 |
- throw std::range_error("RcppVector: null vector in constructor"); |
|
246 |
- v = new string[len]; |
|
247 |
- for(i = 0; i < len; i++) |
|
248 |
- v[i] = string(CHAR(STRING_ELT(vec,i))); |
|
249 |
- length = len; |
|
250 |
-} |
|
251 |
- |
|
252 |
-template <typename T> |
|
253 |
-RcppVector<T>::RcppVector(SEXP vec) { |
|
254 |
- int i; |
|
255 |
- |
|
256 |
- // The function isVector returns TRUE for vectors AND |
|
257 |
- // matrices, so it does not distinguish. We could |
|
258 |
- // check the dim attribute here to be sure that it |
|
259 |
- // is not present (i.e., dimAttr == R_NilValue, not 0!). |
|
260 |
- // But it is easier to simply check if it is set via |
|
261 |
- // isMatrix (in which case we don't have a vector). |
|
262 |
- if(!isNumeric(vec) || isMatrix(vec) || isLogical(vec)) |
|
263 |
- throw std::range_error("RcppVector: invalid numeric vector in constructor"); |
|
264 |
- len = length(vec); |
|
265 |
- v = (T *)R_alloc(len, sizeof(T)); |
|
266 |
- if(isInteger(vec)) { |
|
267 |
- for(i = 0; i < len; i++) |
|
268 |
- v[i] = (T)(INTEGER(vec)[i]); |
|
269 |
- } |
|
270 |
- else if(isReal(vec)) { |
|
271 |
- for(i = 0; i < len; i++) |
|
272 |
- v[i] = (T)(REAL(vec)[i]); |
|
273 |
- } |
|
274 |
-} |
|
275 |
- |
|
276 |
-template <typename T> |
|
277 |
-RcppVector<T>::RcppVector(int _len) { |
|
278 |
- len = _len; |
|
279 |
- v = (T *)R_alloc(len, sizeof(T)); |
|
280 |
- for(int i = 0; i < len; i++) |
|
281 |
- v[i] = 0; |
|
282 |
-} |
|
283 |
- |
|
284 |
-template <typename T> |
|
285 |
-T *RcppVector<T>::cVector() { |
|
286 |
- T* tmp = (T *)R_alloc(len, sizeof(T)); |
|
287 |
- for(int i = 0; i < len; i++) |
|
288 |
- tmp[i] = v[i]; |
|
289 |
- return tmp; |
|
290 |
-} |
|
291 |
- |
|
292 |
-template <typename T> |
|
293 |
-vector<T> RcppVector<T>::stlVector() { |
|
294 |
- vector<T> tmp(len); |
|
295 |
- for(int i = 0; i < len; i++) |
|
296 |
- tmp[i] = v[i]; |
|
297 |
- return tmp; |
|
298 |
-} |
|
299 |
- |
|
300 |
-template <typename T> |
|
301 |
-RcppMatrix<T>::RcppMatrix(SEXP mat) { |
|
302 |
- |
|
303 |
- if(!isNumeric(mat) || !isMatrix(mat)) |
|
304 |
- throw std::range_error("RcppMatrix: invalid numeric matrix in constructor"); |
|
305 |
- |
|
306 |
- // Get matrix dimensions |
|
307 |
- SEXP dimAttr = getAttrib(mat, R_DimSymbol); |
|
308 |
- dim1 = INTEGER(dimAttr)[0]; |
|
309 |
- dim2 = INTEGER(dimAttr)[1]; |
|
310 |
- |
|
311 |
- // We guard against the possibility that R might pass an integer matrix. |
|
312 |
- // Can be prevented using R code: temp <- as.double(a), dim(temp) <- dim(a) |
|
313 |
- int i,j; |
|
314 |
- int isInt = isInteger(mat); |
|
315 |
- T *m = (T *)R_alloc(dim1*dim2, sizeof(T)); |
|
316 |
- a = (T **)R_alloc(dim1, sizeof(T *)); |
|
317 |
- for(i = 0; i < dim1; i++) |
|
318 |
- a[i] = m + i*dim2; |
|
319 |
- if(isInt) { |
|
320 |
- for(i=0; i < dim1; i++) |
|
321 |
- for(j=0; j < dim2; j++) |
|
322 |
- a[i][j] = (T)(INTEGER(mat)[i+dim1*j]); |
|
323 |
- } |
|
324 |
- else { |
|
325 |
- for(i=0; i < dim1; i++) |
|
326 |
- for(j=0; j < dim2; j++) |
|
327 |
- a[i][j] = (T)(REAL(mat)[i+dim1*j]); |
|
328 |
- } |
|
329 |
-} |
|
330 |
- |
|
331 |
-template <typename T> |
|
332 |
-RcppMatrix<T>::RcppMatrix(int _dim1, int _dim2) { |
|
333 |
- dim1 = _dim1; |
|
334 |
- dim2 = _dim2; |
|
335 |
- int i,j; |
|
336 |
- T *m = (T *)R_alloc(dim1*dim2, sizeof(T)); |
|
337 |
- a = (T **)R_alloc(dim1, sizeof(T *)); |
|
338 |
- for(i = 0; i < dim1; i++) |
|
339 |
- a[i] = m + i*dim2; |
|
340 |
- for(i=0; i < dim1; i++) |
|
341 |
- for(j=0; j < dim2; j++) |
|
342 |
- a[i][j] = 0; |
|
343 |
-} |
|
344 |
- |
|
345 |
-template <typename T> |
|
346 |
-vector<vector<T> > RcppMatrix<T>::stlMatrix() { |
|
347 |
- int i,j; |
|
348 |
- vector<vector<T> > temp; |
|
349 |
- for(i = 0; i < dim1; i++) { |
|
350 |
- temp.push_back(vector<T>(dim2)); |
|
351 |
- } |
|
352 |
- for(i = 0; i < dim1; i++) |
|
353 |
- for(j = 0; j < dim2; j++) |
|
354 |
- temp[i][j] = a[i][j]; |
|
355 |
- return temp; |
|
356 |
-} |
|
357 |
- |
|
358 |
-template <typename T> |
|
359 |
-T **RcppMatrix<T>::cMatrix() { |
|
360 |
- int i,j; |
|
361 |
- T *m = (T *)R_alloc(dim1*dim2, sizeof(T)); |
|
362 |
- T **tmp = (T **)R_alloc(dim1, sizeof(T *)); |
|
363 |
- for(i = 0; i < dim1; i++) |
|
364 |
- tmp[i] = m + i*dim2; |
|
365 |
- for(i=0; i < dim1; i++) |
|
366 |
- for(j=0; j < dim2; j++) |
|
367 |
- tmp[i][j] = a[i][j]; |
|
368 |
- return tmp; |
|
369 |
-} |
|
370 |
- |
|
371 |
-// Explicit instantiation (required for external linkage) |
|
372 |
-template class RcppVector<int>; |
|
373 |
-template class RcppVector<double>; |
|
374 |
-template class RcppMatrix<int>; |
|
375 |
-template class RcppMatrix<double>; |
|
376 |
- |
|
377 |
-void RcppResultSet::add(string name, RcppDate& date) { |
|
378 |
- SEXP value = PROTECT(allocVector(REALSXP, 1)); |
|
379 |
- numProtected++; |
|
380 |
- REAL(value)[0] = date.getJDN() - RcppDate::Jan1970Offset; |
|
381 |
- SEXP dateclass = PROTECT(allocVector(STRSXP,1)); |
|
382 |
- numProtected++; |
|
383 |
- SET_STRING_ELT(dateclass, 0, mkChar("Date")); |
|
384 |
- setAttrib(value, R_ClassSymbol, dateclass); |
|
385 |
- values.push_back(make_pair(name, value)); |
|
386 |
-} |
|
387 |
- |
|
388 |
-void RcppResultSet::add(string name, double x) { |
|
389 |
- SEXP value = PROTECT(allocVector(REALSXP, 1)); |
|
390 |
- numProtected++; |
|
391 |
- REAL(value)[0] = x; |
|
392 |
- values.push_back(make_pair(name, value)); |
|
393 |
-} |
|
394 |
- |
|
395 |
-void RcppResultSet::add(string name, int i) { |
|
396 |
- SEXP value = PROTECT(allocVector(INTSXP, 1)); |
|
397 |
- numProtected++; |
|
398 |
- INTEGER(value)[0] = i; |
|
399 |
- values.push_back(make_pair(name, value)); |
|
400 |
-} |
|
401 |
- |
|
402 |
-void RcppResultSet::add(string name, string strvalue) { |
|
403 |
- SEXP value = PROTECT(allocVector(STRSXP, 1)); |
|
404 |
- numProtected++; |
|
405 |
- SET_STRING_ELT(value, 0, mkChar(strvalue.c_str())); |
|
406 |
- values.push_back(make_pair(name, value)); |
|
407 |
-} |
|
408 |
- |
|
409 |
-void RcppResultSet::add(string name, double *vec, int len) { |
|
410 |
- if(vec == 0) |
|
411 |
- throw std::range_error("RcppResultSet::add: NULL double vector"); |
|
412 |
- SEXP value = PROTECT(allocVector(REALSXP, len)); |
|
413 |
- numProtected++; |
|
414 |
- for(int i = 0; i < len; i++) |
|
415 |
- REAL(value)[i] = vec[i]; |
|
416 |
- values.push_back(make_pair(name, value)); |
|
417 |
-} |
|
418 |
- |
|
419 |
-void RcppResultSet::add(string name, RcppDateVector& datevec) { |
|
420 |
- SEXP value = PROTECT(allocVector(REALSXP, datevec.size())); |
|
421 |
- numProtected++; |
|
422 |
- for(int i = 0; i < datevec.size(); i++) { |
|
423 |
- REAL(value)[i] = datevec(i).getJDN() - RcppDate::Jan1970Offset; |
|
424 |
- } |
|
425 |
- SEXP dateclass = PROTECT(allocVector(STRSXP,1)); |
|
426 |
- numProtected++; |
|
427 |
- SET_STRING_ELT(dateclass, 0, mkChar("Date")); |
|
428 |
- setAttrib(value, R_ClassSymbol, dateclass); |
|
429 |
- values.push_back(make_pair(name, value)); |
|
430 |
-} |
|
431 |
- |
|
432 |
-void RcppResultSet::add(string name, RcppStringVector& stringvec) { |
|
433 |
- int len = (int)stringvec.size(); |
|
434 |
- SEXP value = PROTECT(allocVector(STRSXP, len)); |
|
435 |
- numProtected++; |
|
436 |
- for(int i = 0; i < len; i++) |
|
437 |
- SET_STRING_ELT(value, i, mkChar(stringvec(i).c_str())); |
|
438 |
- values.push_back(make_pair(name, value)); |
|
439 |
-} |
|
440 |
- |
|
441 |
-void RcppResultSet::add(string name, int *vec, int len) { |
|
442 |
- if(vec == 0) |
|
443 |
- throw std::range_error("RcppResultSet::add: NULL int vector"); |
|
444 |
- SEXP value = PROTECT(allocVector(INTSXP, len)); |
|
445 |
- numProtected++; |
|
446 |
- for(int i = 0; i < len; i++) |
|
447 |
- INTEGER(value)[i] = vec[i]; |
|
448 |
- values.push_back(make_pair(name, value)); |
|
449 |
-} |
|
450 |
- |
|
451 |
-void RcppResultSet::add(string name, double **mat, int nx, int ny) { |
|
452 |
- if(mat == 0) |
|
453 |
- throw std::range_error("RcppResultSet::add: NULL double matrix"); |
|
454 |
- SEXP value = PROTECT(allocMatrix(REALSXP, nx, ny)); |
|
455 |
- numProtected++; |
|
456 |
- for(int i = 0; i < nx; i++) |
|
457 |
- for(int j = 0; j < ny; j++) |
|
458 |
- REAL(value)[i + nx*j] = mat[i][j]; |
|
459 |
- values.push_back(make_pair(name, value)); |
|
460 |
-} |
|
461 |
- |
|
462 |
-void RcppResultSet::add(string name, int **mat, int nx, int ny) { |
|
463 |
- if(mat == 0) |
|
464 |
- throw std::range_error("RcppResultSet::add: NULL int matrix"); |
|
465 |
- SEXP value = PROTECT(allocMatrix(INTSXP, nx, ny)); |
|
466 |
- numProtected++; |
|
467 |
- for(int i = 0; i < nx; i++) |
|
468 |
- for(int j = 0; j < ny; j++) |
|
469 |
- INTEGER(value)[i + nx*j] = mat[i][j]; |
|
470 |
- values.push_back(make_pair(name, value)); |
|
471 |
-} |
|
472 |
- |
|
473 |
-void RcppResultSet::add(string name, vector<string>& vec) { |
|
474 |
- if(vec.size() == 0) |
|
475 |
- throw std::range_error("RcppResultSet::add; zero length vector<string>"); |
|
476 |
- int len = (int)vec.size(); |
|
477 |
- SEXP value = PROTECT(allocVector(STRSXP, len)); |
|
478 |
- numProtected++; |
|
479 |
- for(int i = 0; i < len; i++) |
|
480 |
- SET_STRING_ELT(value, i, mkChar(vec[i].c_str())); |
|
481 |
- values.push_back(make_pair(name, value)); |
|
482 |
-} |
|
483 |
- |
|
484 |
-void RcppResultSet::add(string name, vector<int>& vec) { |
|
485 |
- if(vec.size() == 0) |
|
486 |
- throw std::range_error("RcppResultSet::add; zero length vector<int>"); |
|
487 |
- int len = (int)vec.size(); |
|
488 |
- SEXP value = PROTECT(allocVector(INTSXP, len)); |
|
489 |
- numProtected++; |
|
490 |
- for(int i = 0; i < len; i++) |
|
491 |
- INTEGER(value)[i] = vec[i]; |
|
492 |
- values.push_back(make_pair(name, value)); |
|
493 |
-} |
|
494 |
- |
|
495 |
-void RcppResultSet::add(string name, vector<double>& vec) { |
|
496 |
- if(vec.size() == 0) |
|
497 |
- throw std::range_error("RcppResultSet::add; zero length vector<double>"); |
|
498 |
- int len = (int)vec.size(); |
|
499 |
- SEXP value = PROTECT(allocVector(REALSXP, len)); |
|
500 |
- numProtected++; |
|
501 |
- for(int i = 0; i < len; i++) |
|
502 |
- REAL(value)[i] = vec[i]; |
|
503 |
- values.push_back(make_pair(name, value)); |
|
504 |
-} |
|
505 |
- |
|
506 |
-void RcppResultSet::add(string name, vector<vector<int> >& mat) { |
|
507 |
- if(mat.size() == 0) |
|
508 |
- throw std::range_error("RcppResultSet::add: zero length vector<vector<int> >"); |
|
509 |
- else if(mat[0].size() == 0) |
|
510 |
- throw std::range_error("RcppResultSet::add: no columns in vector<vector<int> >"); |
|
511 |
- int nx = (int)mat.size(); |
|
512 |
- int ny = (int)mat[0].size(); |
|
513 |
- SEXP value = PROTECT(allocMatrix(INTSXP, nx, ny)); |
|
514 |
- numProtected++; |
|
515 |
- for(int i = 0; i < nx; i++) |
|
516 |
- for(int j = 0; j < ny; j++) |
|
517 |
- INTEGER(value)[i + nx*j] = mat[i][j]; |
|
518 |
- values.push_back(make_pair(name, value)); |
|
519 |
-} |
|
520 |
- |
|
521 |
-void RcppResultSet::add(string name, vector<vector<double> >& mat) { |
|
522 |
- if(mat.size() == 0) |
|
523 |
- throw std::range_error("RcppResultSet::add: zero length vector<vector<double> >"); |
|
524 |
- else if(mat[0].size() == 0) |
|
525 |
- throw std::range_error("RcppResultSet::add: no columns in vector<vector<double> >"); |
|
526 |
- int nx = (int)mat.size(); |
|
527 |
- int ny = (int)mat[0].size(); |
|
528 |
- SEXP value = PROTECT(allocMatrix(REALSXP, nx, ny)); |
|
529 |
- numProtected++; |
|
530 |
- for(int i = 0; i < nx; i++) |
|
531 |
- for(int j = 0; j < ny; j++) |
|
532 |
- REAL(value)[i + nx*j] = mat[i][j]; |
|
533 |
- values.push_back(make_pair(name, value)); |
|
534 |
-} |
|
535 |
- |
|
536 |
-void RcppResultSet::add(string name, RcppVector<int>& vec) { |
|
537 |
- int len = vec.size(); |
|
538 |
- int *a = vec.cVector(); |
|
539 |
- SEXP value = PROTECT(allocVector(INTSXP, len)); |
|
540 |
- numProtected++; |
|
541 |
- for(int i = 0; i < len; i++) |
|
542 |
- INTEGER(value)[i] = a[i]; |
|
543 |
- values.push_back(make_pair(name, value)); |
|
544 |
-} |
|
545 |
- |
|
546 |
-void RcppResultSet::add(string name, RcppVector<double>& vec) { |
|
547 |
- int len = vec.size(); |
|
548 |
- double *a = vec.cVector(); |
|
549 |
- SEXP value = PROTECT(allocVector(REALSXP, len)); |
|
550 |
- numProtected++; |
|
551 |
- for(int i = 0; i < len; i++) |
|
552 |
- REAL(value)[i] = a[i]; |
|
553 |
- values.push_back(make_pair(name, value)); |
|
554 |
-} |
|
555 |
- |
|
556 |
-void RcppResultSet::add(string name, RcppMatrix<int>& mat) { |
|
557 |
- int nx = mat.getDim1(); |
|
558 |
- int ny = mat.getDim2(); |
|
559 |
- int **a = mat.cMatrix(); |
|
560 |
- SEXP value = PROTECT(allocMatrix(INTSXP, nx, ny)); |
|
561 |
- numProtected++; |
|
562 |
- for(int i = 0; i < nx; i++) |
|
563 |
- for(int j = 0; j < ny; j++) |
|
564 |
- INTEGER(value)[i + nx*j] = a[i][j]; |
|
565 |
- values.push_back(make_pair(name, value)); |
|
566 |
-} |
|
567 |
- |
|
568 |
-void RcppResultSet::add(string name, RcppMatrix<double>& mat) { |
|
569 |
- int nx = mat.getDim1(); |
|
570 |
- int ny = mat.getDim2(); |
|
571 |
- double **a = mat.cMatrix(); |
|
572 |
- SEXP value = PROTECT(allocMatrix(REALSXP, nx, ny)); |
|
573 |
- numProtected++; |
|
574 |
- for(int i = 0; i < nx; i++) |
|
575 |
- for(int j = 0; j < ny; j++) |
|
576 |
- REAL(value)[i + nx*j] = a[i][j]; |
|
577 |
- values.push_back(make_pair(name, value)); |
|
578 |
-} |
|
579 |
- |
|
580 |
-void RcppResultSet::add(string name, RcppFrame& frame) { |
|
581 |
- vector<string> colNames = frame.getColNames(); |
|
582 |
- vector<vector<ColDatum> > table = frame.getTableData(); |
|
583 |
- int ncol = colNames.size(); |
|
584 |
- int nrow = table.size(); |
|
585 |
- SEXP rl = PROTECT(allocVector(VECSXP,ncol)); |
|
586 |
- SEXP nm = PROTECT(allocVector(STRSXP,ncol)); |
|
587 |
- numProtected += 2; |
|
588 |
- for(int i=0; i < ncol; i++) { |
|
589 |
- SEXP value, names; |
|
590 |
- if(table[0][i].getType() == COLTYPE_DOUBLE) { |
|
591 |
- value = PROTECT(allocVector(REALSXP,nrow)); |
|
592 |
- numProtected++; |
|
593 |
- for(int j=0; j < nrow; j++) |
|
594 |
- REAL(value)[j] = table[j][i].getDoubleValue(); |
|
595 |
- } |
|
596 |
- else if(table[0][i].getType() == COLTYPE_INT) { |
|
597 |
- value = PROTECT(allocVector(INTSXP,nrow)); |
|
598 |
- numProtected++; |
|
599 |
- for(int j=0; j < nrow; j++) |
|
600 |
- INTEGER(value)[j] = table[j][i].getIntValue(); |
|
601 |
- } |
|
602 |
- else if(table[0][i].getType() == COLTYPE_FACTOR) { |
|
603 |
- value = PROTECT(allocVector(INTSXP,nrow)); |
|
604 |
- numProtected++; |
|
605 |
- int levels = table[0][i].getFactorNumLevels(); |
|
606 |
- names = PROTECT(allocVector(STRSXP,levels)); |
|
607 |
- numProtected++; |
|
608 |
- string *levelNames = table[0][i].getFactorLevelNames(); |
|
609 |
- for(int k=0; k < levels; k++) |
|
610 |
- SET_STRING_ELT(names, k, mkChar(levelNames[k].c_str())); |
|
611 |
- for(int j=0; j < nrow; j++) { |
|
612 |
- int level = table[j][i].getFactorLevel(); |
|
613 |
- INTEGER(value)[j] = level; |
|
614 |
- } |
|
615 |
- setAttrib(value, R_LevelsSymbol, names); |
|
616 |
- SEXP factorclass = PROTECT(allocVector(STRSXP,1)); |
|
617 |
- numProtected++; |
|
618 |
- SET_STRING_ELT(factorclass, 0, mkChar("factor")); |
|
619 |
- setAttrib(value, R_ClassSymbol, factorclass); |
|
620 |
- } |
|
621 |
- else if(table[0][i].getType() == COLTYPE_STRING) { |
|
622 |
- value = PROTECT(allocVector(STRSXP,nrow)); |
|
623 |
- numProtected++; |
|
624 |
- for(int j=0; j < nrow; j++) { |
|
625 |
- SET_STRING_ELT(value, j, mkChar(table[j][i].getStringValue().c_str())); |
|
626 |
- } |
|
627 |
- |
|
628 |
- } |
|
629 |
- else if(table[0][i].getType() == COLTYPE_LOGICAL) { |
|
630 |
- value = PROTECT(allocVector(LGLSXP,nrow)); |
|
631 |
- numProtected++; |
|
632 |
- for(int j=0; j < nrow; j++) { |
|
633 |
- LOGICAL(value)[j] = table[j][i].getLogicalValue(); |
|
634 |
- } |
|
635 |
- } |
|
636 |
- else if(table[0][i].getType() == COLTYPE_DATE) { |
|
637 |
- value = PROTECT(allocVector(REALSXP,nrow)); |
|
638 |
- numProtected++; |
|
639 |
- for(int j=0; j < nrow; j++) |
|
640 |
- REAL(value)[j] = table[j][i].getDateRCode(); |
|
641 |
- SEXP dateclass = PROTECT(allocVector(STRSXP,1)); |
|
642 |
- numProtected++; |
|
643 |
- SET_STRING_ELT(dateclass, 0, mkChar("Date")); |
|
644 |
- setAttrib(value, R_ClassSymbol, dateclass); |
|
645 |
- } |
|
646 |
- else { |
|
647 |
- throw std::range_error("RcppResultSet::add invalid column type"); |
|
648 |
- } |
|
649 |
- SET_VECTOR_ELT(rl, i, value); |
|
650 |
- SET_STRING_ELT(nm, i, mkChar(colNames[i].c_str())); |
|
651 |
- } |
|
652 |
- setAttrib(rl, R_NamesSymbol, nm); |
|
653 |
- values.push_back(make_pair(name, rl)); |
|
654 |
-} |
|
655 |
- |
|
656 |
-void RcppResultSet::add(string name, SEXP sexp, bool isProtected) { |
|
657 |
- values.push_back(make_pair(name, sexp)); |
|
658 |
- if(isProtected) |
|
659 |
- numProtected++; |
|
660 |
-} |
|
661 |
- |
|
662 |
-SEXP RcppResultSet::getReturnList() { |
|
663 |
- int nret = (int)values.size(); |
|
664 |
- SEXP rl = PROTECT(allocVector(VECSXP,nret)); |
|
665 |
- SEXP nm = PROTECT(allocVector(STRSXP,nret)); |
|
666 |
- list<pair<string,SEXP> >::iterator iter = values.begin(); |
|
667 |
- for(int i = 0; iter != values.end(); iter++, i++) { |
|
668 |
- SET_VECTOR_ELT(rl, i, iter->second); |
|
669 |
- SET_STRING_ELT(nm, i, mkChar(iter->first.c_str())); |
|
670 |
- } |
|
671 |
- setAttrib(rl, R_NamesSymbol, nm); |
|
672 |
- UNPROTECT(numProtected+2); |
|
673 |
- return rl; |
|
674 |
-} |
|
675 |
- |
|
676 |
-#ifdef USING_QUANTLIB |
|
677 |
- |
|
678 |
-// Conversion from QuantLib Date to RcppDate. |
|
679 |
-RcppDate::RcppDate(Date dateQL) { |
|
680 |
- day = (int)dateQL.dayOfMonth(); |
|
681 |
- month = (int)dateQL.month(); |
|
682 |
- year = (int)dateQL.year(); |
|
683 |
- mdy2jdn(); |
|
684 |
-} |
|
685 |
- |
|
686 |
-// Conversion from RcppDate to QuantLib Date. |
|
687 |
-RcppDate::operator Date() const { |
|
688 |
- Date d(day, (Month)month, year); |
|
689 |
- return d; |
|
690 |
-} |
|
691 |
- |
|
692 |
-// Print a QuantLib Date. |
|
693 |
-ostringstream& operator<<(ostringstream& os, const Date& d) { |
|
694 |
- os << d.month() << " " << d.weekday() << ", " << d.year(); |
|
695 |
- return os; |
|
696 |
-} |
|
697 |
- |
|
698 |
-#endif |
|
699 |
- |
|
700 |
-// Print an RcppDate. |
|
701 |
-ostream& operator<<(ostream& os, const RcppDate& date) { |
|
702 |
- os << date.getYear() << "-" << date.getMonth() << "-" << date.getDay(); |
|
703 |
- return os; |
|
704 |
-} |
|
705 |
- |
|
706 |
-#ifdef RCPP_DATE_OPS |
|
707 |
- |
|
708 |
-// A few basic date operations. |
|
709 |
-RcppDate operator+(const RcppDate& date, int offset) { |
|
710 |
- RcppDate temp(date.month, date.day, date.year); |
|
711 |
- temp.jdn += offset; |
|
712 |
- temp.jdn2mdy(); |
|
713 |
- return temp; |
|
714 |
-} |
|
715 |
- |
|
716 |
-int operator-(const RcppDate& date2, const RcppDate& date1) { |
|
717 |
- return date2.jdn - date1.jdn; |
|
718 |
-} |
|
719 |
- |
|
720 |
-bool operator<(const RcppDate &date1, const RcppDate& date2) { |
|
721 |
- return date1.jdn < date2.jdn; |
|
722 |
-} |
|
723 |
- |
|
724 |
-bool operator>(const RcppDate &date1, const RcppDate& date2) { |
|
725 |
- return date1.jdn > date2.jdn; |
|
726 |
-} |
|
727 |
- |
|
728 |
-bool operator>=(const RcppDate &date1, const RcppDate& date2) { |
|
729 |
- return date1.jdn >= date2.jdn; |
|
730 |
-} |
|
731 |
- |
|
732 |
-bool operator<=(const RcppDate &date1, const RcppDate& date2) { |
|
733 |
- return date1.jdn <= date2.jdn; |
|
734 |
-} |
|
735 |
- |
|
736 |
-bool operator==(const RcppDate &date1, const RcppDate& date2) { |
|
737 |
- return date1.jdn == date2.jdn; |
|
738 |
-} |
|
739 |
- |
|
740 |
-#endif |
|
741 |
- |
|
742 |
-// Offset used to convert from R date representation to Julian day number. |
|
743 |
-const int RcppDate::Jan1970Offset = 2440588; |
|
744 |
- |
|
745 |
-// The Julian day number (jdn) is the number of days since Monday, |
|
746 |
-// Jan 1, 4713BC (year = -4712). Here 1BC is year 0, 2BC is year -1, etc. |
|
747 |
-// On the other hand, R measures days since Jan 1, 1970, and these dates are |
|
748 |
-// converted to jdn's by adding Jan1970Offset. |
|
749 |
-// |
|
750 |
-// mdy2jdn and jdn2mdy are inverse functions for dates back to |
|
751 |
-// year = -4799 (4800BC). |
|
752 |
-// |
|
753 |
-// See the Wikipedia entry on Julian day number for more information |
|
754 |
-// on these algorithms. |
|
755 |
-// |
|
756 |
- |
|
757 |
-// Transform month/day/year to Julian day number. |
|
758 |
-void RcppDate::mdy2jdn() { |
|
759 |
- int m = month, d = day, y = year; |
|
760 |
- int a = (14 - m)/12; |
|
761 |
- y += 4800 - a; |
|
762 |
- m += 12*a - 3; |
|
763 |
- jdn = (d + (153*m + 2)/5 + 365*y |
|
764 |
- + y/4 - y/100 + y/400 - 32045); |
|
765 |
-} |
|
766 |
- |
|
767 |
-// Transform from Julian day number to month/day/year. |
|
768 |
-void RcppDate::jdn2mdy() { |
|
769 |
- int jul = jdn + 32044; |
|
770 |
- int g = jul/146097; |
|
771 |
- int dg = jul % 146097; |
|
772 |
- int c = (dg/36524 + 1)*3/4; |
|
773 |
- int dc = dg - c*36524; |
|
774 |
- int b = dc/1461; |
|
775 |
- int db = dc % 1461; |
|
776 |
- int a = (db/365 + 1)*3/4; |
|
777 |
- int da = db - a*365; |
|
778 |
- int y = g*400 + c*100 + b*4 + a; |
|
779 |
- int m = (da*5 + 308)/153 - 2; |
|
780 |
- int d = da - (m + 4)*153 /5 + 122; |
|
781 |
- y = y - 4800 + (m + 2)/12; |
|
782 |
- m = (m + 2) % 12 + 1; |
|
783 |
- d = d + 1; |
|
784 |
- month = m; |
|
785 |
- day = d; |
|
786 |
- year = y; |
|
787 |
-} |
|
788 |
- |
|
789 |
-SEXP RcppFunction::listCall() { |
|
790 |
- if(names.size() != (unsigned)listSize) |
|
791 |
- throw std::range_error("listCall: no. of names != no. of items"); |
|
792 |
- if(currListPosn != listSize) |
|
793 |
- throw std::range_error("listCall: list has incorrect size"); |
|
794 |
- SEXP nm = PROTECT(allocVector(STRSXP,listSize)); |
|
795 |
- numProtected++; |
|
796 |
- for(int i=0; i < listSize; i++) |
|
797 |
- SET_STRING_ELT(nm, i, mkChar(names[i].c_str())); |
|
798 |
- setAttrib(listArg, R_NamesSymbol, nm); |
|
799 |
- SEXP R_fcall; |
|
800 |
- PROTECT(R_fcall = lang2(fn, R_NilValue)); |
|
801 |
- numProtected++; |
|
802 |
- SETCADR(R_fcall, listArg); |
|
803 |
- SEXP result = eval(R_fcall, R_NilValue); |
|
804 |
- names.clear(); |
|
805 |
- listSize = currListPosn = 0; // Ready for next call. |
|
806 |
- return result; |
|
807 |
-} |
|
808 |
- |
|
809 |
-SEXP RcppFunction::vectorCall() { |
|
810 |
- if(vectorArg == R_NilValue) |
|
811 |
- throw std::range_error("vectorCall: vector has not been set"); |
|
812 |
- SEXP R_fcall; |
|
813 |
- PROTECT(R_fcall = lang2(fn, R_NilValue)); |
|
814 |
- numProtected++; |
|
815 |
- SETCADR(R_fcall, vectorArg); |
|
816 |
- SEXP result = eval(R_fcall, R_NilValue); |
|
817 |
- vectorArg = R_NilValue; // Ready for next call. |
|
818 |
- return result; |
|
819 |
-} |
|
820 |
- |
|
821 |
-void RcppFunction::setRVector(vector<double>& v) { |
|
822 |
- vectorArg = PROTECT(allocVector(REALSXP,v.size())); |
|
823 |
- numProtected++; |
|
824 |
- for(int i=0; i < (int)v.size(); i++) |
|
825 |
- REAL(vectorArg)[i] = v[i]; |
|
826 |
-} |
|
827 |
- |
|
828 |
-void RcppFunction::setRListSize(int n) { |
|
829 |
- listSize = n; |
|
830 |
- listArg = PROTECT(allocVector(VECSXP, n)); |
|
831 |
- numProtected++; |
|
832 |
-} |
|
833 |
- |
|
834 |
-void RcppFunction::appendToRList(string name, double value) { |
|
835 |
- if(currListPosn < 0 || currListPosn >= listSize) |
|
836 |
- throw std::range_error("appendToRList(double): list posn out of range"); |
|
837 |
- SEXP valsxp = PROTECT(allocVector(REALSXP,1)); |
|
838 |
- numProtected++; |
|
839 |
- REAL(valsxp)[0] = value; |
|
840 |
- SET_VECTOR_ELT(listArg, currListPosn++, valsxp); |
|
841 |
- names.push_back(name); |
|
842 |
-} |
|
843 |
- |
|
844 |
-void RcppFunction::appendToRList(string name, int value) { |
|
845 |
- if(currListPosn < 0 || currListPosn >= listSize) |
|
846 |
- throw std::range_error("appendToRlist(int): posn out of range"); |
|
847 |
- SEXP valsxp = PROTECT(allocVector(INTSXP,1)); |
|
848 |
- numProtected++; |
|
849 |
- INTEGER(valsxp)[0] = value; |
|
850 |
- SET_VECTOR_ELT(listArg, currListPosn++, valsxp); |
|
851 |
- names.push_back(name); |
|
852 |
-} |
|
853 |
- |
|
854 |
-void RcppFunction::appendToRList(string name, string value) { |
|
855 |
- if(currListPosn < 0 || currListPosn >= listSize) |
|
856 |
- throw std::range_error("appendToRlist(string): posn out of range"); |
|
857 |
- SEXP valsxp = PROTECT(allocVector(STRSXP,1)); |
|
858 |
- numProtected++; |
|
859 |
- SET_STRING_ELT(valsxp, 0, mkChar(value.c_str())); |
|
860 |
- SET_VECTOR_ELT(listArg, currListPosn++, valsxp); |
|
861 |
- names.push_back(name); |
|
862 |
-} |
|
863 |
- |
|
864 |
-void RcppFunction::appendToRList(string name, RcppDate& date) { |
|
865 |
- if(currListPosn < 0 || currListPosn >= listSize) |
|
866 |
- throw std::range_error("appendToRlist(RcppDate): list posn out of range"); |
|
867 |
- SEXP valsxp = PROTECT(allocVector(REALSXP,1)); |
|
868 |
- numProtected++; |
|
869 |
- REAL(valsxp)[0] = date.getJDN() - RcppDate::Jan1970Offset; |
|
870 |
- SEXP dateclass = PROTECT(allocVector(STRSXP, 1)); |
|
871 |
- numProtected++; |
|
872 |
- SET_STRING_ELT(dateclass, 0, mkChar("Date")); |
|
873 |
- setAttrib(valsxp, R_ClassSymbol, dateclass); |
|
874 |
- SET_VECTOR_ELT(listArg, currListPosn++, valsxp); |
|
875 |
- names.push_back(name); |
|
876 |
-} |
|
877 |
- |
|
878 |
-#include <string.h> |
|
879 |
- |
|
880 |
-// Paul Roebuck has observed that the memory used by an exception message |
|
881 |
-// is not reclaimed if error() is called inside of a catch block (due to |
|
882 |
-// a setjmp() call), and he suggested the following work-around. |
|
883 |
-char *copyMessageToR(const char* const mesg) { |
|
884 |
- char* Rmesg; |
|
885 |
- const char* prefix = "Exception: "; |
|
886 |
- void* Rheap = R_alloc(std::strlen(prefix)+std::strlen(mesg)+1,sizeof(char)); |
|
887 |
- Rmesg = static_cast<char*>(Rheap); |
|
888 |
- std::strcpy(Rmesg, prefix); |
|
889 |
- std::strcat(Rmesg, mesg); |
|
890 |
- return Rmesg; |
|
891 |
-} |
|
892 |
- |
893 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,438 +0,0 @@ |
1 |
-// Rcpp.hpp: Part of the R/C++ interface class library, Version 5.0 |
|
2 |
-// |
|
3 |
-// Copyright (C) 2005-2006 Dominick Samperi |
|
4 |
-// |
|
5 |
-// This library is free software; you can redistribute it and/or modify it |
|
6 |
-// under the terms of the GNU Lesser General Public License as published by |
|
7 |
-// the Free Software Foundation; either version 2.1 of the License, or (at |
|
8 |
-// your option) any later version. |
|
9 |
-// |
|
10 |
-// This library is distributed in the hope that it will be useful, but |
|
11 |
-// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
12 |
-// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|
13 |
-// License for more details. |
|
14 |
-// |
|
15 |
-// You should have received a copy of the GNU Lesser General Public License |
|
16 |
-// along with this library; if not, write to the Free Software Foundation, |
|
17 |
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
- |
|
19 |
-#ifndef Rcpp_hpp |
|
20 |
-#define Rcpp_hpp |
|
21 |
- |
|
22 |
-#include <iostream> |
|
23 |
- |
|
24 |
-#ifdef USING_QUANTLIB |
|
25 |
-#include <ql/quantlib.hpp> |
|
26 |
-using namespace QuantLib; |
|
27 |
-#else |
|
28 |
-#include <sstream> |
|
29 |
-#include <string> |
|
30 |
-#include <list> |
|
31 |
-#include <map> |
|
32 |
-#endif |
|
33 |
- |
|
34 |
-#include <stdexcept> |
|
35 |
-#include <vector> |
|
36 |
- |
|
37 |
-using namespace std; |
|
38 |
- |
|
39 |
-#include <R.h> |
|
40 |
-#include <Rinternals.h> |
|
41 |
- |
|
42 |
-#ifdef BUILDING_DLL |
|
43 |
-#define RcppExport extern "C" __declspec(dllexport) |
|
44 |
-#else |
|
45 |
-#define RcppExport extern "C" |
|
46 |
-#endif |
|
47 |
- |
|
48 |
-#ifndef USING_QUANTLIB |
|
49 |
-#define RCPP_DATE_OPS |
|
50 |
-#endif |
|
51 |
- |
|
52 |
-char *copyMessageToR(const char* const mesg); |
|
53 |
- |
|
54 |
-class RcppDate { |
|
55 |
-private: |
|
56 |
- void mdy2jdn(); // month/day/year to Julian day number. |
|
57 |
- void jdn2mdy(); // Julian day number to month/day/year. |
|
58 |
- int month, day, year; |
|
59 |
- int jdn; // Julian day number |
|
60 |
- |
|
61 |
-public: |
|
62 |
- static const int Jan1970Offset; |
|
63 |
- RcppDate() { month=1, day=1, year=1970; mdy2jdn(); } |
|
64 |
- RcppDate(int Rjdn) { jdn = Rjdn+Jan1970Offset; jdn2mdy(); } |
|
65 |
- RcppDate(int month_, int day_, int year_) : month(month_), |
|
66 |
- day(day_), |
|
67 |
- year(year_) { |
|
68 |
- if(month < 1 || month > 12 || day < 1 || day > 31) |
|
69 |
- throw std::range_error("RcppDate: invalid date"); |
|
70 |
- mdy2jdn(); |
|
71 |
- } |
|
72 |
- int getMonth() const { return month; } |
|
73 |
- int getDay() const { return day; } |
|
74 |
- int getYear() const { return year; } |
|
75 |
- int getJDN() const { return jdn; } |
|
76 |
- |
|
77 |
- // Minimal set of date operations. |
|
78 |
- |
|
79 |
-#ifdef RCPP_DATE_OPS |
|
80 |
- // These operators tend to conflict with QuantLib's |
|
81 |
- friend RcppDate operator+(const RcppDate &date, int offset); |
|
82 |
- friend int operator-(const RcppDate& date1, const RcppDate& date2); |
|
83 |
- friend bool operator<(const RcppDate &date1, const RcppDate& date2); |
|
84 |
- friend bool operator>(const RcppDate &date1, const RcppDate& date2); |
|
85 |
- friend bool operator==(const RcppDate &date1, const RcppDate& date2); |
|
86 |
- friend bool operator>=(const RcppDate &date1, const RcppDate& date2); |
|
87 |
- friend bool operator<=(const RcppDate &date1, const RcppDate& date2); |
|
88 |
-#endif |
|
89 |
- |
|
90 |
- friend std::ostream& operator<<(std::ostream& os, const RcppDate& date); |
|
91 |
-#ifdef USING_QUANTLIB |
|
92 |
- // Conversions from/to a QuantLib Date. |
|
93 |
- RcppDate(Date dateQL); |
|
94 |
- operator Date() const; |
|
95 |
-#endif |
|
96 |
-}; |
|
97 |
- |
|
98 |
-class RcppParams { |
|
99 |
-public: |
|
100 |
- RcppParams(SEXP params); |
|
101 |
- void checkNames(char *inputNames[], int len); |
|
102 |
- double getDoubleValue(string name); |
|
103 |
- int getIntValue(string name); |
|
104 |
- string getStringValue(string name); |
|
105 |
- bool getBoolValue(string name); |
|
106 |
- RcppDate getDateValue(string name); |
|
107 |
-private: |
|
108 |
- map<string, int> pmap; |
|
109 |
- SEXP _params; |
|
110 |
-}; |
|
111 |
- |
|
112 |
-// Supported data frame column types. |
|
113 |
-enum ColType { COLTYPE_DOUBLE, COLTYPE_INT, COLTYPE_STRING, |
|
114 |
- COLTYPE_FACTOR, COLTYPE_LOGICAL, COLTYPE_DATE }; |
|
115 |
- |
|
116 |
-class ColDatum { |
|
117 |
-public: |
|
118 |
- ColDatum() { |
|
119 |
- level = 0; |
|
120 |
- } |
|
121 |
- ~ColDatum() { |
|
122 |
- if(type == COLTYPE_FACTOR) { |
|
123 |
- // For this to work we need a deep copy when type == COLTYPE_FACTOR. |
|
124 |
- // See the copy constructor below. It is wasteful to have |
|
125 |
- // evey factor cell own a separate copy of levelNames, but we leave |
|
126 |
- // the task of factoring it out (using reference counts) for |
|
127 |
- // later. |
|
128 |
- delete [] levelNames; |
|
129 |
- } |
|
130 |
- } |
|
131 |
- ColDatum(const ColDatum& datum) { |
|
132 |
- |
|
133 |
- // Need deep copy so contruction/destruction is synchronized. |
|
134 |
- s = datum.s; |
|
135 |
- x = datum.x; |
|
136 |
- i = datum.i; |
|
137 |
- type = datum.type; |
|
138 |
- level = datum.level; |
|
139 |
- numLevels = datum.numLevels; |
|
140 |
- d = datum.d; |
|
141 |
- if(type == COLTYPE_FACTOR) { |
|
142 |
- levelNames = new string[numLevels]; |
|
143 |
- for(int i = 0; i < numLevels; i++) |
|
144 |
- levelNames[i] = datum.levelNames[i]; |
|
145 |
- } |
|
146 |
- } |
|
147 |
- |
|
148 |
- ColType getType() const { return type; } |
|
149 |
- |
|
150 |
- void setDoubleValue(double val) { x = val; type = COLTYPE_DOUBLE; } |
|
151 |
- void setIntValue(int val) { i = val; type = COLTYPE_INT; } |
|
152 |
- void setLogicalValue(int val) { |
|
153 |
- if(val != 0 && val != 1) |
|
154 |
- throw std::range_error("ColDatum: logical values must be 0/1."); |
|
155 |
- i = val; type = COLTYPE_LOGICAL; |
|
156 |
- } |
|
157 |
- void setStringValue(string val) { s = val; type = COLTYPE_STRING; } |
|
158 |
- void setDateValue(RcppDate date) { |
|
159 |
- d = date; |
|
160 |
- type = COLTYPE_DATE; |
|
161 |
- } |
|
162 |
- void setFactorValue(string *names, int numNames, int factorLevel) { |
|
163 |
- if(factorLevel < 1 || factorLevel > numNames) |
|
164 |
- throw range_error("setFactorValue: factor level out of range"); |
|
165 |
- level = factorLevel; |
|
166 |
- numLevels = numNames; |
|
167 |
- levelNames = new string[numLevels]; |
|
168 |
- for(int i = 0; i < numLevels; i++) |
|
169 |
- levelNames[i] = names[i]; |
|
170 |
- type = COLTYPE_FACTOR; |
|
171 |
- } |
|
172 |
- |
|
173 |
- double getDoubleValue() { |
|
174 |
- if(type != COLTYPE_DOUBLE) |
|
175 |
- throw std::range_error("RcppFrame: wrong data type in getDoubleValue"); |
|
176 |
- return x; |
|
177 |
- } |
|
178 |
- int getIntValue() { |
|
179 |
- if(type != COLTYPE_INT) |
|
180 |
- throw std::range_error("RcppFrame: wrong data type in getIntValue"); |
|
181 |
- return i; |
|
182 |
- } |
|
183 |
- int getLogicalValue() { |
|
184 |
- if(type != COLTYPE_LOGICAL) |
|
185 |
- throw std::range_error("RcppFrame: wrong data type in getLogicalValue"); |
|
186 |
- return i; |
|
187 |
- } |
|
188 |
- string getStringValue() { |
|
189 |
- if(type != COLTYPE_STRING) |
|
190 |
- throw std::range_error("RcppFrame: wrong data type in getStringValue"); |
|
191 |
- return s; |
|
192 |
- } |
|
193 |
- RcppDate getDateValue() { |
|
194 |
- if(type != COLTYPE_DATE) |
|
195 |
- throw std::range_error("RcppFrame: wrong data type in getDateValue"); |
|
196 |
- return d; |
|
197 |
- } |
|
198 |
- double getDateRCode() { |
|
199 |
- return (double)(d.getJDN() - RcppDate::Jan1970Offset); |
|
200 |
- } |
|
201 |
- |
|
202 |
- void checkFactorType() { |
|
203 |
- if(type != COLTYPE_FACTOR) |
|
204 |
- throw std::range_error("RcppFrame: wrong data type in getFactor..."); |
|
205 |
- } |
|
206 |
- int getFactorNumLevels() { checkFactorType(); return numLevels; } |
|
207 |
- int getFactorLevel() { checkFactorType(); return level; } |
|
208 |
- string *getFactorLevelNames() { checkFactorType(); return levelNames; } |
|
209 |
- string getFactorLevelName() { checkFactorType(); return levelNames[level-1];} |
|
210 |
- |
|
211 |
-private: |
|
212 |
- ColType type; |
|
213 |
- string s; |
|
214 |
- double x; |
|
215 |
- int i; // used for int and logical |
|
216 |
- int level; // factor level |
|
217 |
- int numLevels; // number of levels for this factor |
|
218 |
- string *levelNames; // level name = levelNames[level-1] |
|
219 |
- RcppDate d; |
|
220 |
-}; |
|
221 |
- |
|
222 |
-class RcppFrame { |
|
223 |
- vector<string> colNames; |
|
224 |
- vector<vector<ColDatum> > table; // table[row][col] |
|
225 |
-public: |
|
226 |
- RcppFrame(SEXP df); // Construct from R data frame. |
|
227 |
- RcppFrame(vector<string> colNames) : colNames(colNames) { |
|
228 |
- if(colNames.size() == 0) |
|
229 |
- throw std::range_error("RcppFrame::RcppFrame: zero length colNames"); |
|
230 |
- } |
|
231 |
- vector<string>& getColNames() { return colNames; } |
|
232 |
- vector<vector<ColDatum> >& getTableData() { return table; } |
|
233 |
- void addRow(vector<ColDatum> rowData) { |
|
234 |
- if(rowData.size() != colNames.size()) |
|
235 |
- throw std::range_error("RcppFrame::addRow: incorrect row length."); |
|
236 |
- if(table.size() > 0) { |
|
237 |
- |
|
238 |
- // First row added determines column types. Check for consistency |
|
239 |
- // for rows after the first... |
|
240 |
- for(int i = 0; i < (int)colNames.size(); i++) { |
|
241 |
- if(rowData[i].getType() != table[0][i].getType()) { |
|
242 |
- ostringstream oss; |
|
243 |
- oss << "RcppFrame::addRow: incorrect data type at posn " |
|
244 |
- << i; |
|
245 |
- throw std::range_error(oss.str()); |
|
246 |
- } |
|
247 |
- } |
|
248 |
- } |
|
249 |
- table.push_back(rowData); |
|
250 |
- } |
|
251 |
-}; |
|
252 |
- |
|
253 |
-class RcppNumList { |
|
254 |
-public: |
|
255 |
- RcppNumList(SEXP theList) { |
|
256 |
- if(!isNewList(theList)) |
|
257 |
- throw std::range_error("RcppNumList: non-list passed to constructor"); |
|
258 |
- len = length(theList); |
|
259 |
- names = getAttrib(theList, R_NamesSymbol); |
|
260 |
- namedList = theList; |
|
261 |
- } |
|
262 |
- string getName(int i) { |
|
263 |
- if(i < 0 || i >= len) { |
|
264 |
- std::ostringstream oss; |
|
265 |
- oss << "RcppNumList::getName: index out of bounds: " << i; |
|
266 |
- throw std::range_error(oss.str()); |
|
267 |
- } |
|
268 |
- return string(CHAR(STRING_ELT(names,i))); |
|
269 |
- } |
|
270 |
- double getValue(int i) { |
|
271 |
- if(i < 0 || i >= len) { |
|
272 |
- std::ostringstream oss; |
|
273 |
- oss << "RcppNumList::getValue: index out of bounds: " << i; |
|
274 |
- throw std::range_error(oss.str()); |
|
275 |
- } |
|
276 |
- SEXP elt = VECTOR_ELT(namedList, i); |
|
277 |
- if(isReal(elt)) |
|
278 |
- return REAL(elt)[0]; |
|
279 |
- else if(isInteger(elt)) |
|
280 |
- return (double)INTEGER(elt)[0]; |
|
281 |
- else |
|
282 |
- throw std::range_error("RcppNumList: contains non-numeric value"); |
|
283 |
- return 0; // never get here |
|
284 |
- } |
|
285 |
- int size() { return len; } |
|
286 |
-private: |
|
287 |
- int len; |
|
288 |
- SEXP namedList; |
|
289 |
- SEXP names; |
|
290 |
-}; |
|
291 |
- |
|
292 |
-template <typename T> |
|
293 |
-class RcppVector { |
|
294 |
-public: |
|
295 |
- RcppVector(SEXP vec); |
|
296 |
- RcppVector(int len); |
|
297 |
- int size() { return len; } |
|
298 |
- inline T& operator()(int i) { |
|
299 |
- if(i < 0 || i >= len) { |
|
300 |
- std::ostringstream oss; |
|
301 |
- oss << "RcppVector: subscript out of range: " << i; |
|
302 |
- throw std::range_error(oss.str()); |
|
303 |
- } |
|
304 |
- return v[i]; |
|
305 |
- } |
|
306 |
- T *cVector(); |
|
307 |
- vector<T> stlVector(); |
|
308 |
-private: |
|
309 |
- int len; |
|
310 |
- T *v; |
|
311 |
-}; |
|
312 |
- |
|
313 |
-class RcppStringVector { |
|
314 |
-public: |
|
315 |
- RcppStringVector(SEXP vec); |
|
316 |
- ~RcppStringVector() { |
|
317 |
- delete [] v; |
|
318 |
- } |
|
319 |
- inline string& operator()(int i) { |
|
320 |
- if(i < 0 || i >= length) { |
|
321 |
- std::ostringstream oss; |
|
322 |
- oss << "RcppStringVector: subscript out of range: " << i; |
|
323 |
- throw std::range_error(oss.str()); |
|
324 |
- } |
|
325 |
- return v[i]; |
|
326 |
- } |
|
327 |
- int size() { return length; } |
|
328 |
-private: |
|
329 |
- string *v; |
|
330 |
- int length; |
|
331 |
-}; |
|
332 |
- |
|
333 |
-class RcppDateVector { |
|
334 |
-public: |
|
335 |
- RcppDateVector(SEXP vec); |
|
336 |
- ~RcppDateVector() { |
|
337 |
- delete [] v; |
|
338 |
- } |
|
339 |
- inline RcppDate& operator()(int i) { |
|
340 |
- if(i < 0 || i >= length) { |
|
341 |
- std::ostringstream oss; |
|
342 |
- oss << "RcppDateVector: subscript out of range: " << i; |
|
343 |
- throw std::range_error(oss.str()); |
|
344 |
- } |
|
345 |
- return v[i]; |
|
346 |
- } |
|
347 |
- int size() { return length; } |
|
348 |
-private: |
|
349 |
- RcppDate *v; |
|
350 |
- int length; |
|
351 |
-}; |
|
352 |
- |
|
353 |
-template <typename T> |
|
354 |
-class RcppMatrix { |
|
355 |
-public: |
|
356 |
- RcppMatrix(SEXP mat); |
|
357 |
- RcppMatrix(int nx, int ny); |
|
358 |
- int getDim1() { return dim1; } |
|
359 |
- int getDim2() { return dim2; } |
|
360 |
- inline T& operator()(int i, int j) { |
|
361 |
- if(i < 0 || i >= dim1 || j < 0 || j >= dim2) { |
|
362 |
- std::ostringstream oss; |
|
363 |
- oss << "RcppMatrix: subscripts out of range: " << i << ", " << j; |
|
364 |
- throw std::range_ |