Rcpp Version 1.0.14
Loading...
Searching...
No Matches
as_vector.h
Go to the documentation of this file.
1
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2
//
3
// as_vector.h: Rcpp R/C++ interface class library -- as_vector( sugar matrix expression )
4
//
5
// Copyright (C) 2010 - 2014 Dirk Eddelbuettel and Romain Francois
6
//
7
// This file is part of Rcpp.
8
//
9
// Rcpp is free software: you can redistribute it and/or modify it
10
// under the terms of the GNU General Public License as published by
11
// the Free Software Foundation, either version 2 of the License, or
12
// (at your option) any later version.
13
//
14
// Rcpp is distributed in the hope that it will be useful, but
15
// WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
18
//
19
// You should have received a copy of the GNU General Public License
20
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22
#ifndef Rcpp__sugar__matrix_as_vector_h
23
#define Rcpp__sugar__matrix_as_vector_h
24
25
namespace
Rcpp
{
26
namespace
internal{
27
28
template
<
int
RTYPE,
bool
NA,
typename
T>
29
inline
Rcpp::Vector<RTYPE>
30
as_vector__impl
(
MatrixBase<RTYPE,NA,T>
& t,
Rcpp::traits::false_type
){
31
T& ref = t.
get_ref
() ;
32
int
nc = ref.ncol(), nr = ref.nrow() ;
33
Vector<RTYPE>
out
(
static_cast<
R_xlen_t
>
(nr) * nc) ;
34
R_xlen_t
k =0;
35
for
(
int
col_index
=0;
col_index
<nc;
col_index
++)
36
for
(
int
row_index
=0;
row_index
<nr;
row_index
++, k++)
37
out
[k] = ref(
row_index
,
col_index
) ;
38
39
return
out
;
40
}
41
42
template
<
int
RTYPE,
bool
NA,
typename
T>
43
inline
Rcpp::Vector<RTYPE>
44
as_vector__impl
(
MatrixBase<RTYPE,NA,T>
& t,
Rcpp::traits::true_type
){
45
Matrix<RTYPE>
& ref = t.
get_ref
() ;
46
R_xlen_t
size =
static_cast<
R_xlen_t
>
(ref.
ncol
())*ref.
nrow
() ;
47
typename
Rcpp::Vector<RTYPE>::const_iterator
first
(
static_cast<
const
Rcpp::Vector<RTYPE>
&
>
(ref).begin()) ;
48
return
Vector<RTYPE>
(
first
,
first
+size );
49
}
50
51
}
// internal
52
53
template
<
int
RTYPE,
bool
NA,
typename
T>
54
inline
Rcpp::Vector<RTYPE>
55
as_vector
(
const
MatrixBase<RTYPE,NA,T>
& t ){
56
return
internal::as_vector__impl
(
const_cast<
MatrixBase<RTYPE,NA,T>
&
>
(t),
typename
Rcpp::traits::same_type
< T ,
Matrix<RTYPE>
>() ) ;
57
}
58
59
}
// Rcpp
60
#endif
61
Rcpp::MatrixBase
Definition
MatrixBase.h:32
Rcpp::MatrixBase::get_ref
MATRIX & get_ref()
Definition
MatrixBase.h:39
Rcpp::Matrix
Definition
Matrix.h:28
Rcpp::Matrix::ncol
int ncol() const
Definition
Matrix.h:94
Rcpp::Matrix::nrow
int nrow() const
Definition
Matrix.h:97
Rcpp::Vector
Definition
Vector.h:35
Rcpp::Vector::const_iterator
traits::r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
Definition
Vector.h:46
Rcpp::internal::as
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
Definition
as.h:43
Rcpp::internal::as_vector__impl
Rcpp::Vector< RTYPE > as_vector__impl(MatrixBase< RTYPE, NA, T > &t, Rcpp::traits::false_type)
Definition
as_vector.h:30
Rcpp
Rcpp API.
Definition
algo.h:28
Rcpp::as_vector
Rcpp::Vector< RTYPE > as_vector(const MatrixBase< RTYPE, NA, T > &t)
Definition
as_vector.h:55
Rcpp::traits::integral_constant
Definition
integral_constant.h:29
Rcpp::traits::same_type
Definition
same_type.h:29
inst
include
Rcpp
sugar
matrix
as_vector.h
Generated on Sun Jan 12 2025 11:21:43 for Rcpp Version 1.0.14 by
1.9.8