refactor(tulip): move cenet/math/ to tulip/
This commit is contained in:
+24
-24
@@ -1,33 +1,33 @@
|
||||
// TODO: write actual tests
|
||||
|
||||
#include <algorithm>
|
||||
#include <cenet/math/expr.hpp>
|
||||
#include <cenet/math/tensor.hpp>
|
||||
#include <cenet/math/tensor_fwd.hpp>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include <tulip/expr.hpp>
|
||||
#include <tulip/tensor.hpp>
|
||||
#include <tulip/tensor_fwd.hpp>
|
||||
|
||||
using cenet::math::dynamic_extent;
|
||||
using tulip::dynamic_extent;
|
||||
|
||||
// Whatever
|
||||
TEST(Tensor, View) {
|
||||
cenet::math::tensor<float, 3, 2, 2> tensor;
|
||||
tulip::tensor<float, 3, 2, 2> tensor;
|
||||
|
||||
auto view = tensor.view()[1][1];
|
||||
}
|
||||
|
||||
TEST(Tensor, Ops) {
|
||||
constexpr float lhsArray[2 * 3] = { 1, 2, 3, 4, 5, 6 };
|
||||
cenet::math::tensor<float, dynamic_extent, 3> lhs;
|
||||
constexpr float lhsArray[2 * 3] = { 1, 2, 3, 4, 5, 6 };
|
||||
tulip::tensor<float, dynamic_extent, 3> lhs;
|
||||
lhs.set_dimensions(2, 3);
|
||||
lhs.view().fill(lhsArray);
|
||||
|
||||
constexpr float rhsArray[2 * 3] = { 6, 5, 4, 3, 2, 1 };
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 3> rhs;
|
||||
constexpr float rhsArray[2 * 3] = { 6, 5, 4, 3, 2, 1 };
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 3> rhs;
|
||||
rhs.view().fill(rhsArray);
|
||||
|
||||
constexpr float resultArray[2 * 3] = { 6 * 1, 6 * 2, 6 * 3, 6 * 4, 6 * 5, 6 * 6 };
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 3> result = lhs + rhs - 1;
|
||||
constexpr float resultArray[2 * 3] = { 6 * 1, 6 * 2, 6 * 3, 6 * 4, 6 * 5, 6 * 6 };
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 3> result = lhs + rhs - 1;
|
||||
result *= lhs;
|
||||
|
||||
for (std::size_t i = 0; i < result.size(); ++i) {
|
||||
@@ -39,15 +39,15 @@ TEST(Tensor, MatMul) {
|
||||
constexpr float lhsArray[2 * 2] = { 1, 2, 3, 4 };
|
||||
constexpr float rhsArray[2 * 2] = { 5, 6, 7, 8 };
|
||||
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 2> lhs;
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 2> rhs;
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 2> lhs;
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 2> rhs;
|
||||
|
||||
lhs.view().fill(lhsArray);
|
||||
rhs.view().fill(rhsArray);
|
||||
|
||||
constexpr float expArray[2 * 2] = { (1 * 5) + (2 * 7), (1 * 6) + (2 * 8), (3 * 5) + (4 * 7), (3 * 6) + (4 * 8) };
|
||||
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 2> result = lhs.matmul(rhs);
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 2> result = lhs.matmul(rhs);
|
||||
for (std::size_t i = 0; i < result.size(); ++i) {
|
||||
EXPECT_EQ(result.coeff(i), expArray[i]);
|
||||
}
|
||||
@@ -58,23 +58,23 @@ TEST(Tensor, MatMul2) {
|
||||
constexpr float lhsArray[3 * 2] = { 1, 2, 5, 6, 7, 8 };
|
||||
constexpr float rhsArray[2 * 1] = { 3, 4 };
|
||||
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 3, 2> lhs;
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 1> rhs;
|
||||
tulip::tensor<tulip::inline_storage<float>, 3, 2> lhs;
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 1> rhs;
|
||||
|
||||
lhs.view().fill(lhsArray);
|
||||
rhs.view().fill(rhsArray);
|
||||
|
||||
constexpr float expArray[3 * 1] = { 11, 39, 53 };
|
||||
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 3, 1> result = lhs.matmul(rhs);
|
||||
tulip::tensor<tulip::inline_storage<float>, 3, 1> result = lhs.matmul(rhs);
|
||||
for (std::size_t i = 0; i < result.size(); ++i) {
|
||||
EXPECT_EQ(result.coeff(i), expArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Tensor, Apply) {
|
||||
constexpr float values[2 * 2] = { 1, 2, 3, 4 };
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 2> tensor;
|
||||
constexpr float values[2 * 2] = { 1, 2, 3, 4 };
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 2> tensor;
|
||||
tensor.view().fill(values);
|
||||
|
||||
constexpr float expected[2 * 2] = { 1, 4, 9, 16 };
|
||||
@@ -89,15 +89,15 @@ TEST(Tensor, Apply2) {
|
||||
constexpr float lhsArray[2 * 2] = { 1, 2, 3, 4 };
|
||||
constexpr float rhsArray[2 * 2] = { 4, 3, 2, 1 };
|
||||
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 2> lhs;
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 2> rhs;
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 2> lhs;
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 2> rhs;
|
||||
|
||||
lhs.view().fill(lhsArray);
|
||||
rhs.view().fill(rhsArray);
|
||||
|
||||
constexpr float expArray[2 * 2] = { 4, 3, 3, 4 };
|
||||
|
||||
cenet::math::tensor<cenet::math::inline_storage<float>, 2, 2> result =
|
||||
tulip::tensor<tulip::inline_storage<float>, 2, 2> result =
|
||||
lhs.apply(rhs, [](auto x1, auto x2) { return std::max(x1, x2); });
|
||||
for (std::size_t i = 0; i < result.size(); ++i) {
|
||||
EXPECT_EQ(result.coeff(i), expArray[i]);
|
||||
@@ -105,7 +105,7 @@ TEST(Tensor, Apply2) {
|
||||
}
|
||||
|
||||
TEST(Tensor, Offsets) {
|
||||
cenet::math::tensor<float, 2, 3, 4> tensor;
|
||||
tulip::tensor<float, 2, 3, 4> tensor;
|
||||
|
||||
for (std::size_t i = 0; i < tensor.size(); ++i)
|
||||
tensor.coeff(i) = static_cast<float>(i);
|
||||
@@ -116,7 +116,7 @@ TEST(Tensor, Offsets) {
|
||||
}
|
||||
|
||||
TEST(Tensor, Offsets2) {
|
||||
using shape_type = cenet::math::static_shape<2, 3, 4>;
|
||||
using shape_type = tulip::static_shape<2, 3, 4>;
|
||||
|
||||
shape_type shape;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user