@@ -47,43 +47,53 @@ namespace hypercomplex {
47
47
}
48
48
public:
49
49
std::vector<float > e;
50
-
51
- base (std::vector<float > other) {
52
- assert (valid_dim (other.size ()));
53
- e = other;
50
+
51
+ base (int dim) {
52
+ assert (!valid_dim (dim));
53
+ for (int x = 0 ; x < dim; x++) {
54
+ e.push_back (0 );
55
+ }
56
+ }
57
+ base (std::vector<float > data) {
58
+ assert (valid_dim (data.size ()));
59
+ e = data;
60
+ };
61
+ base (std::vector<float > data, int dim) {
62
+ assert (valid_dim (data.size ()) && dim == data.size ());
63
+ e = data;
54
64
};
55
65
56
66
base operator +(base const & other) {
57
- assert (e.size () ! = other.e .size ());
67
+ assert (e.size () = = other.e .size ());
58
68
std::vector<float > E;
59
69
for (int x = 0 ; x < e.size (); x++) {
60
70
E.push_back (e[x] + other.e [x]);
61
71
}
62
72
return base (E);
63
73
}
64
74
base operator -(base const & other) {
65
- assert (e.size () ! = other.e .size ());
75
+ assert (e.size () = = other.e .size ());
66
76
std::vector<float > E;
67
77
for (int x = 0 ; x < e.size (); x++) {
68
78
E.push_back (e[x] - other.e [x]);
69
79
}
70
80
return base (E);
71
81
}
72
82
void operator +=(base const & other) {
73
- assert (e.size () ! = other.e .size ());
83
+ assert (e.size () = = other.e .size ());
74
84
for (int x = 0 ; x < e.size (); x++)
75
85
e[x] += other.e [x];
76
86
}
77
87
void operator -=(base const & other) {
78
- assert (e.size () ! = other.e .size ());
88
+ assert (e.size () = = other.e .size ());
79
89
for (int x = 0 ; x < e.size (); x++)
80
90
e[x] -= other.e [x];
81
91
}
82
92
83
93
base operator *(base y) {
84
- assert (e.size () ! = y.e .size ());
94
+ assert (e.size () = = y.e .size ());
85
95
if (e.size () == 1 )
86
- return base ({e[0 ]*y.e [0 ]});
96
+ return base (std::vector< float >( {e[0 ]*y.e [0 ]}) );
87
97
88
98
Cpair<base, base> p1 = split (self ());
89
99
Cpair<base, base> p2 = split (y);
@@ -112,21 +122,24 @@ namespace hypercomplex {
112
122
}
113
123
114
124
struct complex : hypercomplex::base {
115
- complex (): hypercomplex::base({0 , 0 }) { };
125
+ complex (): hypercomplex::base(2 ) { };
126
+ complex (std::vector<float > data): hypercomplex::base(data, 2 ) { };
116
127
complex (float _a, float _i): hypercomplex::base({_a, _i}) { };
117
128
118
129
complex (const hypercomplex::base &x) : hypercomplex::base(x) {}
119
130
};
120
131
121
132
struct quaternion : hypercomplex::base {
122
- quaternion (): hypercomplex::base({0 , 0 , 0 , 0 }) { };
133
+ quaternion (): hypercomplex::base(4 ) { };
134
+ quaternion (std::vector<float > data): hypercomplex::base(data, 4 ) { };
123
135
quaternion (float _a, float _i, float _j, float _k): hypercomplex::base({_a, _i, _j, _k}) { };
124
136
125
137
quaternion (const hypercomplex::base &x) : hypercomplex::base(x) {}
126
138
};
127
139
128
140
struct octonion : hypercomplex::base {
129
- octonion (): hypercomplex::base({0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }) { };
141
+ octonion (): hypercomplex::base(8 ) { };
142
+ octonion (std::vector<float > data): hypercomplex::base(data, 8 ) { };
130
143
octonion (float _a, float _i, float _j, float _k, float _e5, float _e6, float _e7, float _e8): hypercomplex::base({_a, _i, _j, _k, _e5, _e6, _e7, _e8}) { };
131
144
132
145
octonion (const hypercomplex::base &x) : hypercomplex::base(x) {}
0 commit comments