Skip to content

Commit feaa893

Browse files
Merge pull request #38 from stephenswat/refactor/algebra_array_type
Rework the vector and matrix types used for algebra
2 parents 62ce770 + 543431e commit feaa893

2 files changed

Lines changed: 28 additions & 27 deletions

File tree

core/include/definitions/algebra.hpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,42 @@
1717
namespace traccc
1818
{
1919

20-
inline std::array<scalar, 2> operator*(const std::array<scalar, 2> &a, scalar s)
20+
inline vector2 operator*(const vector2 &a, scalar s)
2121
{
2222
return {a[0] * s, a[1] * s};
2323
}
2424

25-
inline std::array<scalar, 2> operator*(scalar s, const std::array<scalar, 2> &a)
25+
inline vector2 operator*(scalar s, const vector2 &a)
2626
{
2727
return {s * a[0], s * a[1]};
2828
}
2929

30-
inline std::array<scalar, 2> operator-(const std::array<scalar, 2> &a, const std::array<scalar, 2> &b)
30+
inline vector2 operator-(const vector2 &a, const vector2 &b)
3131
{
3232
return {a[0] - b[0], a[1] - b[1]};
3333
}
3434

35-
inline std::array<scalar, 2> operator+(const std::array<scalar, 2> &a, const std::array<scalar, 2> &b)
35+
inline vector2 operator+(const vector2 &a, const vector2 &b)
3636
{
3737
return {a[0] + b[0], a[1] + b[1]};
3838
}
3939

40-
inline std::array<scalar, 3> operator*(const std::array<scalar, 3> &a, scalar s)
40+
inline vector3 operator*(const vector3 &a, scalar s)
4141
{
4242
return {a[0] * s, a[1] * s, a[2] * s};
4343
}
4444

45-
inline std::array<scalar, 3> operator*(scalar s, const std::array<scalar, 3> &a)
45+
inline vector3 operator*(scalar s, const vector3 &a)
4646
{
4747
return {s * a[0], s * a[1], s * a[2]};
4848
}
4949

50-
inline std::array<scalar, 3> operator-(const std::array<scalar, 3> &a, const std::array<scalar, 3> &b)
50+
inline vector3 operator-(const vector3 &a, const vector3 &b)
5151
{
5252
return {a[0] - b[0], a[1] - b[1], a[2] - b[2]};
5353
}
5454

55-
inline std::array<scalar, 3> operator+(const std::array<scalar, 3> &a, const std::array<scalar, 3> &b)
55+
inline vector3 operator+(const vector3 &a, const vector3 &b)
5656
{
5757
return {a[0] + b[0], a[1] + b[1], a[2] + b[2]};
5858
}
@@ -70,7 +70,7 @@ namespace traccc
7070
*
7171
* @return a vector (expression) representing the cross product
7272
**/
73-
inline std::array<scalar, 3> cross(const std::array<scalar, 3> &a, const std::array<scalar, 3> &b)
73+
inline vector3 cross(const vector3 &a, const vector3 &b)
7474
{
7575
return {a[1] * b[2] - b[1] * a[2], a[2] * b[0] - b[2] * a[0], a[0] * b[1] - b[0] * a[1]};
7676
}
@@ -113,7 +113,7 @@ namespace traccc
113113
*
114114
* @param v the input vector
115115
**/
116-
inline auto norm(const std::array<scalar, 2> &v)
116+
inline auto norm(const vector2 &v)
117117
{
118118
return perp(v);
119119
}
@@ -122,7 +122,7 @@ namespace traccc
122122
*
123123
* @param v the input vector
124124
**/
125-
inline auto norm(const std::array<scalar, 3> &v)
125+
inline auto norm(const vector3 &v)
126126
{
127127
return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
128128
}
@@ -144,7 +144,7 @@ namespace traccc
144144
template <unsigned int kROWS, typename matrix_type>
145145
auto vector(const matrix_type &m, unsigned int row, unsigned int col) noexcept
146146
{
147-
std::array<scalar, kROWS> subvector;
147+
array<scalar, kROWS> subvector;
148148
for (unsigned int irow = row; irow < row + kROWS; ++irow)
149149
{
150150
subvector[irow - row] = m[col][irow];
@@ -159,7 +159,7 @@ namespace traccc
159159
template <unsigned int kROWS, unsigned int kCOLS, typename matrix_type>
160160
auto block(const matrix_type &m, unsigned int row, unsigned int col) noexcept
161161
{
162-
std::array<std::array<scalar, kROWS>, kCOLS> submatrix;
162+
array<array<scalar, kROWS>, kCOLS> submatrix;
163163
for (unsigned int icol = col; icol < col + kCOLS; ++icol)
164164
{
165165
for (unsigned int irow = row; irow < row + kROWS; ++irow)
@@ -177,7 +177,7 @@ namespace traccc
177177
struct transform3
178178
{
179179

180-
using matrix44 = std::array<std::array<scalar, 4>, 4>;
180+
using matrix44 = array<array<scalar, 4>, 4>;
181181

182182
matrix44 _data;
183183
matrix44 _data_inv;
@@ -253,7 +253,7 @@ namespace traccc
253253
*
254254
* @param ma is the full 4x4 matrix 16 array
255255
**/
256-
transform3(const std::array<scalar, 16> &ma)
256+
transform3(const array<scalar, 16> &ma)
257257
{
258258
_data[0][0] = ma[0];
259259
_data[0][1] = ma[4];
@@ -436,7 +436,7 @@ namespace traccc
436436
*
437437
* @return the scalar dot product value
438438
**/
439-
inline scalar dot(const std::array<scalar, 2> &a, const std::array<scalar, 2> &b)
439+
inline scalar dot(const vector2 &a, const vector2 &b)
440440
{
441441
return a[0] * b[0] + a[1] * b[1];
442442
}
@@ -445,7 +445,7 @@ namespace traccc
445445
*
446446
* @param v the input vector
447447
**/
448-
inline std::array<scalar, 3> normalize(const std::array<scalar, 2> &v)
448+
inline vector2 normalize(const vector2 &v)
449449
{
450450
scalar oon = 1. / std::sqrt(dot(v, v));
451451
return {v[0] * oon, v[1] * oon};
@@ -458,7 +458,7 @@ namespace traccc
458458
*
459459
* @return the scalar dot product value
460460
**/
461-
inline scalar dot(const std::array<scalar, 3> &a, const std::array<scalar, 3> &b)
461+
inline scalar dot(const vector3 &a, const vector3 &b)
462462
{
463463
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
464464
}
@@ -467,7 +467,7 @@ namespace traccc
467467
*
468468
* @param v the input vector
469469
**/
470-
inline std::array<scalar, 3> normalize(const std::array<scalar, 3> &v)
470+
inline vector3 normalize(const vector3 &v)
471471
{
472472
scalar oon = 1. / std::sqrt(dot(v, v));
473473
return {v[0] * oon, v[1] * oon, v[2] * oon};
@@ -476,4 +476,3 @@ namespace traccc
476476
} // namespace vector
477477

478478
} // end of namespace
479-

core/include/definitions/primitives.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ namespace traccc {
1616
using geometry_id = uint64_t;
1717
using event_id = uint64_t;
1818
using channel_id = unsigned int;
19-
20-
using vector2 = std::array<scalar, 2>;
21-
using point2 = std::array<scalar, 2>;
22-
using variance2 = std::array<scalar, 2>;
23-
using point3 = std::array<scalar, 3>;
24-
using vector3 = std::array<scalar, 3>;
25-
using variance3 = std::array<scalar, 3>;
2619

20+
template<typename T, std::size_t N>
21+
using array = std::array<T, N>;
22+
23+
using vector2 = array<scalar, 2>;
24+
using point2 = array<scalar, 2>;
25+
using variance2 = array<scalar, 2>;
26+
using point3 = array<scalar, 3>;
27+
using vector3 = array<scalar, 3>;
28+
using variance3 = array<scalar, 3>;
2729
}

0 commit comments

Comments
 (0)