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
//use custos::{Buffer, ClearBuf, CPU, WithConst};
/*
#[test]
fn test_device_return() {
let x = {
let device = CPU::new();
let buf = Buffer::with(&device, [1., 2., 3.,]);
buf.device()
};
}
*/
/*
// won't compile
#[test]
fn test_return_buf() {
let mut buf = {
let device = CPU::new();
Buffer::from((&device, [1, 2, 4, 6, -4]))
};
assert_eq!(buf.as_slice(), vec![1, 2, 4, 6, -4]);
let device = CPU::new();
device.clear(&mut buf);
assert_eq!(buf.as_slice(), &[0; 5])
}*/
/*
// won't compile
#[test]
fn test_return_cache_buf() {
let mut buf = {
let device = CPU::new();
custos::cpu::cpu_cached::<i32>(&device, 100)
};
assert_eq!(buf.as_slice(), vec![1, 2, 4, 6, -4]);
let device = CPU::new();
device.clear(&mut buf);
assert_eq!(buf.as_slice(), &[0; 5])
}
*/
/*
// won't compile
#[test]
fn test_return_cache_dev() {
let mut buf = {
let device = CPU::new();
let dev = custos::AsDev::dev(&device);
custos::cached::<i32>(&dev, 10)
};
assert_eq!(buf.as_slice(), vec![1, 2, 4, 6, -4]);
let device = CPU::new();
device.clear(&mut buf);
assert_eq!(buf.as_slice(), &[0; 5])
}
*/
/*
// won't compile
#[test]
fn test_return_cache_dev() {
let mut buf = {
let device = CPU::new();
let a = Buffer::<f32>::new(&device, 10);
let dev = a.device;
custos::cached::<i32>(&dev, 10)
};
assert_eq!(buf.as_slice(), vec![1, 2, 4, 6, -4]);
let device = CPU::new();
device.clear(&mut buf);
assert_eq!(buf.as_slice(), &[0; 5])
}
*/
/*
// won't compile
#[test]
fn test_clone_buf_invalid_return() {
{
let device = CPU::new();
let buf = Buffer::<f32>::new(&device, 10);
buf.clone()
};
}*/
// should not compile, but it does (unsafe block)
/*
use custos::{CPU, Buffer};
#[test]
fn test_shallow_ub() {
let device = CPU::new();
let _x = {
let buf: Buffer = Buffer::from((&device, vec![1f32, 2., 3., 4., 5.]));
let x: Buffer = unsafe {buf.shallow()};
x
};
//drop(device);
//println!("x: {x:?}");
}
*/
/*
use custos::{CPU, Buffer};
#[test]
fn test_as_dims_transform() {
let device = CPU::new();
let _x = {
let buf: Buffer = Buffer::from((&device, vec![1f32, 2., 3., 4., 5.]));
buf.as_dims::<()>()
};
//drop(device);
//println!("x: {x:?}");
}*/