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
use super::scalar::{c64, Rcplx};
use super::*;
use std::iter::FromIterator;
#[derive(PartialEq, Clone)]
pub struct Complexes {
pub(crate) robj: Robj,
}
crate::wrapper::macros::gen_vector_wrapper_impl!(
vector_type: Complexes,
scalar_type: Rcplx,
primitive_type: c64,
r_prefix: COMPLEX,
SEXP: CPLXSXP,
doc_name: complex,
altrep_constructor: make_altcomplex_from_iterator,
);
impl Complexes {
pub fn get_region(&self, index: usize, dest: &mut [Rcplx]) -> usize {
unsafe {
let ptr: *mut Rcomplex = dest.as_mut_ptr() as *mut Rcomplex;
COMPLEX_GET_REGION(self.get(), index as R_xlen_t, dest.len() as R_xlen_t, ptr) as usize
}
}
}
impl Deref for Complexes {
type Target = [Rcplx];
fn deref(&self) -> &Self::Target {
unsafe {
let ptr = DATAPTR_RO(self.get()) as *const Rcplx;
std::slice::from_raw_parts(ptr, self.len())
}
}
}
impl DerefMut for Complexes {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe {
let ptr = DATAPTR(self.get()) as *mut Rcplx;
std::slice::from_raw_parts_mut(ptr, self.len())
}
}
}
impl std::fmt::Debug for Complexes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.len() == 1 {
write!(f, "{:?}", self.elt(0))
} else {
f.debug_list().entries(self.iter()).finish()
}
}
}