Compare commits
No commits in common. "6a06c17b10bd6a52f8d4f109347650472c1fda80" and "6543129c80adc0e541f0e22dfed38911ef69e167" have entirely different histories.
6a06c17b10
...
6543129c80
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(COSC-4P80-Assignment-1 VERSION 0.0.16)
|
project(COSC-4P80-Assignment-1 VERSION 14.2.3)
|
||||||
|
|
||||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||||
|
|
4
build.sh
4
build.sh
|
@ -1,4 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
mkdir build
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release -S ./ -B ./build
|
|
||||||
cmake --build ./build -j 32
|
|
2
lib/blt
2
lib/blt
|
@ -1 +1 @@
|
||||||
Subproject commit bfcb35705910851a6a7466406609793bae3eb2be
|
Subproject commit fb3ed3aa5ee9ac4185dc6228e06b07466fc38e91
|
208
src/main.cpp
208
src/main.cpp
|
@ -6,16 +6,14 @@
|
||||||
#include <blt/iterator/iterator.h>
|
#include <blt/iterator/iterator.h>
|
||||||
#include <a1.h>
|
#include <a1.h>
|
||||||
|
|
||||||
constexpr blt::u32 num_values_part_a = 3;
|
constexpr blt::u32 num_values = 4;
|
||||||
constexpr blt::u32 num_values_part_c1 = 4;
|
constexpr blt::u32 input_count = 5;
|
||||||
constexpr blt::u32 num_values_part_c2 = 7;
|
constexpr blt::u32 output_count = 4;
|
||||||
constexpr blt::u32 input_vec_size = 5;
|
|
||||||
constexpr blt::u32 output_vec_size = 4;
|
|
||||||
|
|
||||||
using input_t = blt::generalized_matrix<float, 1, input_vec_size>;
|
using input_t = blt::generalized_matrix<float, 1, input_count>;
|
||||||
using output_t = blt::generalized_matrix<float, 1, output_vec_size>;
|
using output_t = blt::generalized_matrix<float, 1, output_count>;
|
||||||
using weight_t = decltype(std::declval<input_t>().transpose() * std::declval<output_t>());
|
using weight_t = decltype(std::declval<input_t>().transpose() * std::declval<output_t>());
|
||||||
using crosstalk_t = blt::generalized_matrix<float, 1, output_vec_size>;
|
using crosstalk_t = blt::generalized_matrix<float, output_count, num_values>;
|
||||||
|
|
||||||
// part a
|
// part a
|
||||||
input_t input_1{-1, 1, 1, 1, -1};
|
input_t input_1{-1, 1, 1, 1, -1};
|
||||||
|
@ -60,77 +58,137 @@ const auto weight_total_a = weight_1 + weight_2 + weight_3;
|
||||||
const auto weight_total_c = weight_total_a + weight_4;
|
const auto weight_total_c = weight_total_a + weight_4;
|
||||||
const auto weight_total_c_2 = weight_total_c + weight_5 + weight_6 + weight_7;
|
const auto weight_total_c_2 = weight_total_c + weight_5 + weight_6 + weight_7;
|
||||||
|
|
||||||
crosstalk_t crosstalk_values[num_values_part_a];
|
crosstalk_t crosstalk_values{};
|
||||||
|
|
||||||
template<typename Weights, typename Inputs, typename Outputs>
|
//template<typename Weights, typename Inputs, typename Outputs>
|
||||||
void execute_BAM(const Weights& weights, const Inputs& input, const Outputs& output)
|
//void execute_BAM(const Weights& weights, const Inputs& input, const Outputs& output)
|
||||||
{
|
//{
|
||||||
auto current_inputs = input;
|
// auto current_inputs = input;
|
||||||
auto current_outputs = output;
|
// auto current_outputs = output;
|
||||||
auto next_inputs = current_inputs;
|
// auto next_inputs = current_inputs;
|
||||||
auto next_outputs = current_outputs;
|
// auto next_outputs = current_outputs;
|
||||||
blt::size_t iterations = 0;
|
// blt::size_t iterations = 0;
|
||||||
constexpr blt::size_t max_iterations = 5;
|
// constexpr blt::size_t max_iterations = 5;
|
||||||
|
//
|
||||||
do
|
// do
|
||||||
{
|
// {
|
||||||
current_inputs = next_inputs;
|
// current_inputs = next_inputs;
|
||||||
current_outputs = next_outputs;
|
// current_outputs = next_outputs;
|
||||||
++iterations;
|
// ++iterations;
|
||||||
for (const auto& [index, val] : blt::enumerate(current_inputs))
|
// for (const auto& [index, val] : blt::enumerate(current_inputs))
|
||||||
{
|
// {
|
||||||
auto next = a1::run_step(weights, val, current_outputs[index]);
|
// auto next = a1::run_step(weights, val, current_outputs[index]);
|
||||||
next_inputs[index] = next.first;
|
// next_inputs[index] = next.first;
|
||||||
next_outputs[index] = next.second;
|
// next_outputs[index] = next.second;
|
||||||
}
|
// }
|
||||||
// loop until no changes or we hit the iteration limit
|
// // loop until no changes or we hit the iteration limit
|
||||||
} while ((!a1::equal(current_inputs, next_inputs) || !a1::equal(current_outputs, next_outputs)) && iterations < max_iterations);
|
// } while ((!a1::equal(current_inputs, next_inputs) || !a1::equal(current_outputs, next_outputs)) && iterations < max_iterations);
|
||||||
|
//
|
||||||
BLT_DEBUG("Tracked after %ld iterations", iterations);
|
// BLT_DEBUG("Tracked after %ld iterations", iterations);
|
||||||
a1::check_recall(weights, next_inputs, next_outputs);
|
// a1::check_recall(weights, next_inputs, next_outputs);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void part_a()
|
//void part_a()
|
||||||
{
|
//{
|
||||||
blt::log_box_t box(BLT_TRACE_STREAM, "Part A", 8);
|
// blt::log_box_t box(BLT_TRACE_STREAM, "Part A", 8);
|
||||||
|
//
|
||||||
execute_BAM(weight_total_a, part_a_inputs, part_a_outputs);
|
// execute_BAM(weight_total_a, part_a_inputs, part_a_outputs);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void part_b()
|
//void part_b()
|
||||||
{
|
//{
|
||||||
blt::log_box_t box(BLT_TRACE_STREAM, "Part B", 8);
|
// blt::log_box_t box(BLT_TRACE_STREAM, "Part B", 8);
|
||||||
for (blt::u32 i = 0; i < num_values_part_a; i++)
|
// for (blt::u32 i = 0; i < num_values; i++)
|
||||||
{
|
// {
|
||||||
crosstalk_values[i] = {};
|
// blt::generalized_matrix<float, 1, output_count> accum;
|
||||||
for (blt::u32 k = 0; k < num_values_part_a; k++)
|
// for (blt::u32 k = 0; k < num_values; k++)
|
||||||
{
|
// {
|
||||||
if (i == k)
|
// if (i == k)
|
||||||
continue;
|
// continue;
|
||||||
crosstalk_values[i] += (part_a_outputs[i] * a1::crosstalk(part_a_inputs[i].normalize(), part_a_inputs[k].normalize())).abs();
|
// accum += (part_a_outputs[k] * a1::crosstalk(part_a_inputs[k].normalize(), part_a_inputs[i].normalize()));
|
||||||
}
|
// }
|
||||||
}
|
// crosstalk_values.assign_to_column_from_column_rows(accum, i);
|
||||||
for (const auto& crosstalk_value : crosstalk_values)
|
// }
|
||||||
{
|
// for (blt::u32 i = 0; i < num_values; i++)
|
||||||
auto vec = crosstalk_value.vec_from_column_row();
|
// {
|
||||||
BLT_DEBUG_STREAM << vec << " Mag: " << vec.magnitude() << "\n";
|
// BLT_DEBUG_STREAM << crosstalk_values[i] << " Mag: " << crosstalk_values[i].magnitude() << "\n";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void part_c()
|
//void part_c()
|
||||||
{
|
//{
|
||||||
blt::log_box_t box(BLT_TRACE_STREAM, "Part C", 8);
|
// blt::log_box_t box(BLT_TRACE_STREAM, "Part C", 8);
|
||||||
execute_BAM(weight_total_c, part_c_1_inputs, part_c_1_outputs);
|
// execute_BAM(weight_total_c, part_c_1_inputs, part_c_1_outputs);
|
||||||
BLT_TRACE("--- { Part C with 3 extra pairs } ---");
|
// BLT_TRACE("--- { Part C with 3 extra pairs } ---");
|
||||||
execute_BAM(weight_total_c_2, part_c_2_inputs, part_c_2_outputs);
|
// execute_BAM(weight_total_c_2, part_c_2_inputs, part_c_2_outputs);
|
||||||
}
|
//}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
blt::logging::setLogOutputFormat("\033[94m[${{TIME}}]${{RC}} \033[35m(${{FILE}}:${{LINE}})${{RC}} ${{LF}}${{CNR}}${{STR}}${{RC}}\n");
|
blt::logging::setLogOutputFormat("\033[94m[${{TIME}}]${{RC}} \033[35m(${{FILE}}:${{LINE}})${{RC}} ${{LF}}${{CNR}}${{STR}}${{RC}}\n");
|
||||||
a1::test_math();
|
// a1::test_math();
|
||||||
|
|
||||||
part_a();
|
for (const auto& [index, value] : blt::enumerate(part_c_2_inputs))
|
||||||
part_b();
|
BLT_TRACE_STREAM << index << " : " << value.vec_from_column_row() << '\n';
|
||||||
part_c();
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [index, value] : blt::enumerate(part_c_2_inputs).rev())
|
||||||
|
BLT_TRACE_STREAM << index << " : " << value.vec_from_column_row() << '\n';
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [index, value] : blt::enumerate(part_c_2_inputs).skip(3))
|
||||||
|
BLT_TRACE_STREAM << index << " : " << value.vec_from_column_row() << '\n';
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [index, value] : blt::enumerate(part_c_2_inputs).skip(3).rev())
|
||||||
|
BLT_TRACE_STREAM << index << " : " << value.vec_from_column_row() << '\n';
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [index, value] : blt::enumerate(part_c_2_inputs).rev().skip(3).rev())
|
||||||
|
BLT_TRACE_STREAM << index << " : " << value.vec_from_column_row() << '\n';
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [index, value] : blt::enumerate(part_c_2_inputs).skip(2).take(3))
|
||||||
|
BLT_TRACE_STREAM << index << " : " << value.vec_from_column_row() << '\n';
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [a, b] : blt::in_pairs(part_a_inputs, part_a_outputs).enumerate())
|
||||||
|
{
|
||||||
|
auto& [ma, mb] = b;
|
||||||
|
BLT_TRACE_STREAM << a << " : " << ma.vec_from_column_row() << " " << mb.vec_from_column_row() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [a, b] : blt::in_pairs(part_a_inputs, part_a_outputs).rev())
|
||||||
|
{
|
||||||
|
BLT_TRACE_STREAM << a.vec_from_column_row() << " : " << b.vec_from_column_row() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [a, b] : blt::in_pairs(part_a_inputs, part_a_outputs).take(1))
|
||||||
|
{
|
||||||
|
BLT_TRACE_STREAM << a.vec_from_column_row() << " : " << b.vec_from_column_row() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
BLT_TRACE("");
|
||||||
|
|
||||||
|
for (const auto& [a, b] : blt::in_pairs(part_a_inputs, part_a_outputs).skip(1))
|
||||||
|
{
|
||||||
|
BLT_TRACE_STREAM << a.vec_from_column_row() << " : " << b.vec_from_column_row() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// BLT_TRACE("%s", blt::type_string<blt::meta::lowest_iterator_category<std::bidirectional_iterator_tag, std::random_access_iterator_tag, std::input_iterator_tag>::type>().c_str());
|
||||||
|
|
||||||
|
|
||||||
|
// part_a();
|
||||||
|
// part_b();
|
||||||
|
// part_c();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue