Skip to content

Commit eb7913a

Browse files
committed
arithmos: vector calculus and matrix algebra infrastructure
1 parent 7150f76 commit eb7913a

41 files changed

Lines changed: 1952 additions & 10 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

electrostatic-sandbox-framework/electrostatic-core/src/include/electrostatic/electronetsoft/algorithm/arithmos/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Arithmos _αριθμός_
22

3-
Arithmos is a set of APIs that target different taxonomies of algorithms to solve problems through providing _algorithm generic utilities_, and several implementations for the common _abstract data types (adt)_ commonly encountered during solving problems while building commericial applications or participating in problem solving contests.
3+
Arithmos is a set of APIs that target different taxonomies of algorithms to solve problems through providing _algorithm generic utilities_, and several implementations for the common _abstract data types (adt)_ commonly encountered during solving problems while building commercial applications or participating in problem solving contests.
44

55
Arithmos is essentially composed of the following:
66
- [x] Vector2d Library (Finished).
7-
- [ ] Vector3d Library.
8-
- [ ] MatrixNd Library.
7+
- [x] Vector3d Library (Partially Finished).
8+
- [x] MatrixNd Library (Partially Finished).
99
- [ ] Discrete Sets Operations (Conjunctive, Disjunctive, Subtraction, Powersets, De'Morgans formulas).
1010
- [ ] Physics Simulation Library (Collision detection - Force Control - Objects interactions).
11-
- [ ] Statistics Algoritms Library (Present in Java - WIP to port).
11+
- [ ] Statistics Algorithms Library (Present in Java - WIP to port).
1212
- [ ] Differential and Integral Calculus Library.
1313
- [ ] Generic Algorithms Utilities Library.
1414
- [ ] Linear Algorithms Library.
@@ -52,7 +52,7 @@ Most of these libraries rely on the _Generic Algorithms Utilities Library_; this
5252
- Hashing Algorithms.
5353
- [ ] Modular Arithmetics.
5454
- Un-hashing Algorithms.
55-
- Switching Algebra ALgorithms.
55+
- Switching Algebra Algorithms.
5656
- [ ] Elementary Bit switching.
5757
- [ ] Elementary Bit shifting.
5858
- [ ] Elementary Byte switching.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include <electrostatic/electronetsoft/algorithm/arithmos/vectorspaces/matrix/matrix.h>
2+
3+
struct mat_add_metadata {
4+
matrix *m1;
5+
matrix *output;
6+
mat_processors *processors;
7+
};
8+
9+
static inline status_code __on_entry_iterated(mat_proc_sig proc_sig) {
10+
// preprocessing automata -- Machine Input
11+
matrix m0 = proc_sig.mat;
12+
uint64_t row = proc_sig.row_index;
13+
uint64_t column = proc_sig.col_index;
14+
struct mat_add_metadata *metadata = proc_sig.proc.metadata;
15+
16+
matrix m1 = *(metadata->m1);
17+
matrix *out = metadata->output;
18+
mat_processors user_proc = *(metadata->processors);
19+
20+
status_code __code;
21+
22+
// preprocessing automata -- Execute preprocessing sub-automata
23+
if (NULL != user_proc.on_binary_op_preprocessor) {
24+
__code = user_proc.on_binary_op_preprocessor((mat_binary_op_sig) {
25+
.m0 = m0,
26+
.m1 = m1,
27+
.row_index = row,
28+
.col_index = column,
29+
.proc = user_proc,
30+
});
31+
if (PASS != __code) {
32+
return __code;
33+
}
34+
}
35+
36+
// processing automata
37+
out->element[row][column] =
38+
m0.element[row][column] +
39+
m1.element[row][column];
40+
41+
// postprocessing chain
42+
if (NULL != user_proc.on_elementary_op_postprocessor) {
43+
__code = user_proc.on_elementary_op_postprocessor(proc_sig);
44+
if (PASS != __code) {
45+
return __code;
46+
}
47+
}
48+
return PASS;
49+
}
50+
51+
status_code mat_add(matrix m0, matrix m1,
52+
matrix *out,
53+
mat_processors processors) {
54+
55+
caller_graph caller = {
56+
.api = "arithmos:matrix#mat_add",
57+
.func = &mat_add,
58+
.root = processors.root,
59+
};
60+
61+
mat_proc_sig proc_sig = {
62+
.proc = processors,
63+
.caller = caller,
64+
.metadata = processors.metadata,
65+
};
66+
67+
if (rvalue(out) == NULL ||
68+
rvalue(out->element) == NULL) {
69+
return EUNDEFINEDBUFFER;
70+
}
71+
72+
proc_sig.mat = *out;
73+
74+
if (m0.m != m1.m ||
75+
m0.n != m1.n ||
76+
m0.m != out->m ||
77+
m0.n != out->n) {
78+
return EBUFFERTURNCATION;
79+
}
80+
81+
struct mat_add_metadata metadata = {
82+
.m1 = &m1,
83+
.output = out,
84+
.processors = &processors, // performed a chained automata processors
85+
};
86+
87+
mat_processors __proc = {
88+
.on_entry_iterated = &__on_entry_iterated,
89+
.metadata = &metadata
90+
};
91+
92+
status_code __code = mat_iterate_elements(m0, ROW_CONVENTION_ITERATOR, __proc);
93+
if (PASS != __code) {
94+
if (NULL != processors.on_op_failure) {
95+
processors.on_op_failure(proc_sig, __code);
96+
}
97+
return __code;
98+
}
99+
100+
if (NULL != processors.on_op_success) {
101+
processors.on_op_success(proc_sig);
102+
}
103+
104+
return PASS;
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <electrostatic/electronetsoft/algorithm/arithmos/vectorspaces/matrix/matrix.h>
2+
3+
status_code mat_create_from_vector2d(vector2d v, matrix *mat, mat_processors processors) {
4+
caller_graph caller = {
5+
.api = "arithmos:matrix#mat_create_from_vector2d",
6+
.func = &mat_create_from_vector2d,
7+
.root = processors.root,
8+
};
9+
10+
mat_proc_sig proc_sig = {
11+
.proc = processors,
12+
.caller = caller,
13+
.metadata = processors.metadata,
14+
};
15+
16+
// preprocessor automata -- Test main matrix memory addresses
17+
if (rvalue(mat) == NULL ||
18+
rvalue(mat->element) == NULL) {
19+
if (NULL != processors.on_op_failure) {
20+
processors.on_op_failure(proc_sig, EUNDEFINEDBUFFER);
21+
}
22+
return EUNDEFINEDBUFFER;
23+
}
24+
25+
// preprocessor automata -- Test elements allocation
26+
if (rvalue(mat->element + 1) == NULL) {
27+
if (NULL != processors.on_op_failure) {
28+
processors.on_op_failure(proc_sig, EBUFFERTURNCATION);
29+
}
30+
return EBUFFERTURNCATION;
31+
}
32+
33+
proc_sig.mat = *mat;
34+
35+
// processing automata -- Adapt elements
36+
*(mat->element[0]) = v.x;
37+
*(mat->element[1]) = v.y;
38+
39+
if (NULL != processors.on_op_success) {
40+
processors.on_op_success(proc_sig);
41+
}
42+
43+
return PASS;
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <electrostatic/electronetsoft/algorithm/arithmos/vectorspaces/matrix/matrix.h>
2+
3+
status_code mat_create_from_vector3d(vector3d v, matrix *mat, mat_processors processors) {
4+
caller_graph caller = {
5+
.api = "arithmos:matrix#mat_create_from_vector3d",
6+
.func = &mat_create_from_vector3d,
7+
.root = processors.root,
8+
};
9+
10+
mat_proc_sig proc_sig = {
11+
.proc = processors,
12+
.caller = caller,
13+
.metadata = processors.metadata,
14+
};
15+
16+
// preprocessor automata -- Test main matrix memory addresses
17+
if (rvalue(mat) == NULL ||
18+
rvalue(mat->element) == NULL) {
19+
if (NULL != processors.on_op_failure) {
20+
processors.on_op_failure(proc_sig, EUNDEFINEDBUFFER);
21+
}
22+
return EUNDEFINEDBUFFER;
23+
}
24+
25+
proc_sig.mat = *mat;
26+
27+
// preprocessor automata -- Test elements allocation
28+
if (rvalue(mat->element + 1) == NULL || rvalue(mat->element + 2) == NULL) {
29+
if (NULL != processors.on_op_failure) {
30+
processors.on_op_failure(proc_sig, EBUFFERTURNCATION);
31+
}
32+
return EBUFFERTURNCATION;
33+
}
34+
35+
// processing automata -- Adapt elements
36+
*(mat->element[0]) = v.x;
37+
*(mat->element[1]) = v.y;
38+
*(mat->element[2]) = v.z;
39+
40+
return PASS;
41+
}

0 commit comments

Comments
 (0)