Repository navigation
Expand file tree
/
Copy patharray_selfhost_simple.candle
More file actions
88 lines (71 loc) · 1.58 KB
/
Copy patharray_selfhost_simple.candle
File metadata and controls
88 lines (71 loc) · 1.58 KB
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
/// Panum Array Self-Hosted Test - Simplified
// Array class with @builtin methods
class ArrayFloat inherit Object {
@builtin
static ArrayFloat _allocate(List<int> shape, int dtype) {
ellipsis;
}
@builtin
double _get_flat(int index) {
ellipsis;
}
@builtin
void _set_flat(int index, double value) {
ellipsis;
}
@builtin
double _raw_sum() {
ellipsis;
}
@builtin
double _raw_max() {
ellipsis;
}
@builtin
double _raw_min() {
ellipsis;
}
// Self-hosted methods (pure Candle!)
double sum() {
return this._raw_sum();
}
double max() {
return this._raw_max();
}
double min() {
return this._raw_min();
}
}
int main() {
print("=== Panum Self-Hosted Test ===\n");
// Create shape
List<int> shape = List<int>();
shape.add(5);
// Allocate array
ArrayFloat arr = ArrayFloat._allocate(shape, 2);
print("Array allocated\n");
// Write data
arr._set_flat(0, 1.0);
arr._set_flat(1, 2.0);
arr._set_flat(2, 3.0);
arr._set_flat(3, 4.0);
arr._set_flat(4, 5.0);
print("Data written\n");
// Read data
double first = arr._get_flat(0);
double last = arr._get_flat(4);
print("First: ");
print(first);
print("\n");
// Use self-hosted methods
double total = arr.sum();
print("Sum: ");
print(total);
print("\n");
double max_val = arr.max();
print("Max: ");
print(max_val);
print("\n");
print("=== Self-Hosted Success! ===\n");
return 0;
}