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
pub mod indices;
pub mod merge;
use std::fmt::Write;
pub const GR:&str = "\x1B[01;92m";
pub const UNGR:&str = "\x1B[0m";
#[macro_export]
macro_rules! here {
() => {{
fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
let name = type_name_of(f);
format!("\n{}:{} {}", file!(), line!(), &name[..name.len()-3])
}}
}
#[derive(Default)]
pub struct MinMax<T> {
pub min: T,
pub minindex: usize,
pub max: T,
pub maxindex: usize
}
impl <T>std::fmt::Display for MinMax<T> where T:Copy+std::fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f,"min: {}, minindex {}, max: {}, maxindex: {}",
self.min.gr(),self.minindex.gr(),self.max.gr(),self.maxindex.gr() )
}
}
pub fn tof64<T>(s: &[T]) -> Vec<f64> where T: Copy, f64: From<T> {
s.iter().map(| &x | f64::from(x)).collect()
}
pub trait Printing<T> {
fn gr(self) -> String where Self:Sized {
format!("{GR}{}{UNGR}",self.to_str())
}
fn to_str(self) -> String;
}
impl<T> Printing<T> for T where T:std::fmt::Display {
fn to_str(self) -> String { self.to_string() }
}
impl<T> Printing<T> for &[T] where T:std::fmt::Display {
fn to_str(self) -> String {
self.iter().fold(
String::from("["),
|mut s,item| { write!(s," {}",item).ok(); s } )
+" ]"
}
}
impl<T> Printing<T> for &[&[T]] where T:std::fmt::Display {
fn to_str(self) -> String {
self.iter().fold(
String::from("["),
|mut s,&item| { writeln!(s," {}",item.to_str()).ok(); s } )
+"]"
}
}
impl<T> Printing<T> for &[Vec<T>] where T:std::fmt::Display {
fn to_str(self) -> String {
self.iter().fold(
String::from("[\n"),
|mut s,item| { writeln!(s," {}",item.to_str()).ok(); s } )
+"]"
}
}
pub fn printvv<T>(s: &[Vec<T>]) where T:Copy+std::fmt::Display {
println!("{GR}[");
for v in s { println!(" {}",v.to_str()) };
println!("]{UNGR}");
}
pub trait Indices {
fn revindex(self) -> Vec<usize>;
fn invindex(self) -> Vec<usize>;
fn complindex(self) -> Vec<usize>;
fn unindex<T: Copy>(self, v:&[T], ascending:bool) -> Vec<T>;
fn unindexf64<T: Copy>(self, v:&[T], ascending: bool) -> Vec<f64> where f64:From<T>;
fn ucorrelation(self, v: &[usize]) -> f64;
fn indx_to_f64 (self) -> Vec<f64>;
}