2026-03-07 12:09:00 +01:00
|
|
|
#include <cassert>
|
2026-02-11 02:52:03 +01:00
|
|
|
import Crafter.Math;
|
|
|
|
|
import std;
|
|
|
|
|
|
|
|
|
|
using namespace Crafter;
|
|
|
|
|
|
|
|
|
|
int main() {
|
2026-03-23 21:42:40 +01:00
|
|
|
// _Float16 test[] {2,1,2, 2,1,2, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
|
// _Float16 test2[] {2,3,3, 2,5,21, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
|
// VectorF16L<3,2> vec(test);
|
|
|
|
|
// VectorF16L<3,2> vec2(test2);
|
|
|
|
|
// VectorF16L<3,2> result = VectorF16L<3,2>::Cross(vec, vec2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Vector<float, 3, 0> test5(2,1,2);
|
|
|
|
|
// Vector<float, 3, 0> test6(2,3,3);
|
|
|
|
|
// Vector<float, 3, 0> test3 = Vector<float, 3, 0>::Cross(test5, test6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//VectorF16L<3,2> result = vec + vec2;
|
|
|
|
|
//std::println("{}\n{}", result, test3);
|
2026-03-18 03:16:29 +01:00
|
|
|
// std::random_device rd;
|
|
|
|
|
// std::mt19937 gen(rd());
|
|
|
|
|
// std::uniform_real_distribution<float> dist(0, 100);
|
|
|
|
|
|
|
|
|
|
// Vector<_Float16, 8, 8> vA;
|
|
|
|
|
// for(std::uint32_t i = 0; i < 8; i++) {
|
|
|
|
|
// vA.v[i] = dist(gen);
|
|
|
|
|
// }
|
|
|
|
|
// VectorF16<4, 2, 1> vfA(&vA);
|
|
|
|
|
|
|
|
|
|
// Vector<_Float16, 16, 16> vB;
|
|
|
|
|
// for(std::uint32_t i = 0; i < 16; i++) {
|
|
|
|
|
// vB.v[i] = dist(gen);
|
|
|
|
|
// }
|
|
|
|
|
// VectorF16<4, 2, 2> vfB(&vB);
|
|
|
|
|
|
|
|
|
|
// VectorF16<4, 2, 1> vfC = vfA + vfB;
|
|
|
|
|
// auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
|
// for(std::uint32_t i = 0; i < 90000000; i++) {
|
|
|
|
|
// vfC = vfC + vfB;
|
|
|
|
|
// }
|
|
|
|
|
// auto end = std::chrono::high_resolution_clock::now();
|
|
|
|
|
// std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end-start) << std::endl;
|
|
|
|
|
// std::println("{}", vfC);
|
|
|
|
|
|
2026-03-22 03:51:09 +01:00
|
|
|
// std::random_device rd;
|
|
|
|
|
// std::mt19937 gen(rd());
|
|
|
|
|
// std::uniform_real_distribution<float> dist(0, 100);
|
2026-03-18 03:16:29 +01:00
|
|
|
|
2026-03-22 03:51:09 +01:00
|
|
|
// Vector<_Float16, 32, 32> vA;
|
|
|
|
|
// for(std::uint32_t i = 0; i < 32; i++) {
|
|
|
|
|
// vA.v[i] = dist(gen);
|
|
|
|
|
// }
|
2026-03-19 05:53:17 +01:00
|
|
|
|
2026-03-22 03:51:09 +01:00
|
|
|
// std::string log;
|
|
|
|
|
// std::chrono::duration<double> totalVector(0);
|
|
|
|
|
// std::tuple<VectorF16<4, 2, 4>, VectorF16<4, 2, 4>, VectorF16<4, 2, 4>, VectorF16<4, 2, 4>> vfA {VectorF16<4, 2, 4>(&vA), VectorF16<4, 2, 4>(&vA), VectorF16<4, 2, 4>(&vA), VectorF16<4, 2, 4>(&vA)};
|
|
|
|
|
// for(std::uint32_t i = 0; i < 1000000; i++) {
|
|
|
|
|
// auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
|
// vfA = VectorF16<4, 2, 4>::Normalize(std::get<0>(vfA), std::get<1>(vfA), std::get<2>(vfA), std::get<3>(vfA));
|
|
|
|
|
// auto end = std::chrono::high_resolution_clock::now();
|
|
|
|
|
// totalVector += end-start;
|
|
|
|
|
// }
|
2026-03-18 03:16:29 +01:00
|
|
|
|
2026-03-22 03:51:09 +01:00
|
|
|
// std::chrono::duration<double> totalScalar(0);
|
|
|
|
|
// Vector<_Float16, 4, 4> vB;
|
|
|
|
|
// for(std::uint32_t i = 0; i < 4; i++) {
|
|
|
|
|
// vB.v[i] = dist(gen);
|
|
|
|
|
// }
|
|
|
|
|
// for(std::uint32_t i = 0; i < 1000000; i++) {
|
|
|
|
|
// auto start2 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
// vB.Normalize();
|
|
|
|
|
// auto end2 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
// totalScalar += end2-start2;
|
|
|
|
|
// }
|
2026-03-19 05:53:17 +01:00
|
|
|
|
2026-03-22 03:51:09 +01:00
|
|
|
// std::println("{} {} {} {}", std::get<0>(vfA), std::get<1>(vfA), std::get<2>(vfA), std::get<3>(vfA));
|
|
|
|
|
// std::println("{}", vB);
|
|
|
|
|
// std::println("Vector: {}, Scalar: {}", std::chrono::duration_cast<std::chrono::milliseconds>(totalVector), std::chrono::duration_cast<std::chrono::milliseconds>(totalScalar*8));
|
2026-02-11 02:52:03 +01:00
|
|
|
}
|