diff --git a/CMakeLists.txt b/CMakeLists.txt index ab800fe..f3777cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,8 @@ cmake_minimum_required(VERSION 3.2) project(susa) enable_testing() -set(BUILD_SHARED_LIBS ON) if(APPLE) - message (STATUS "Mac OSX detected.") set(CMAKE_MACOSX_RPATH ON) endif(APPLE) @@ -28,7 +26,7 @@ set (SRC_FILES src/rng.cpp src/svd.cpp src/utility.cpp) -add_library (susa ${SRC_FILES}) +add_library (susa SHARED ${SRC_FILES}) add_subdirectory (examples) @@ -36,8 +34,8 @@ add_subdirectory (test) install (TARGETS susa LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib/static) + ARCHIVE DESTINATION lib) install (DIRECTORY inc/ - DESTINATION include/susa + DESTINATION include FILES_MATCHING PATTERN "*.h") diff --git a/examples/simple_matrix.cpp b/examples/simple_matrix.cpp index e1fb033..f9e72b5 100755 --- a/examples/simple_matrix.cpp +++ b/examples/simple_matrix.cpp @@ -47,6 +47,12 @@ int main(void) std::cout << std::endl; + susa::matrix mat_c("[1; 2; 3]"); + + std::cout << "num rows = " << mat_c.no_rows() << std::endl; + std::cout << "num cols = " << mat_c.no_cols() << std::endl; + std::cout << "num elems = " << mat_c.size() << std::endl; + std::cout << std::endl; SUSA_LOG_INFO("Logs can be disabled by defining SUSA_NDEBUG."); diff --git a/inc/susa.h b/inc/susa.h index 14cea45..587bc83 100644 --- a/inc/susa.h +++ b/inc/susa.h @@ -58,24 +58,24 @@ // Constants #define PI 3.1415926535897932384626433 -#include "memory.h" -#include "sets.h" -#include "matrix.h" -#include "array.h" -#include "base.h" -#include "svd.h" -#include "statistics.h" -#include "rng.h" -#include "mt.h" -#include "fft.h" -#include "rrcosine.h" -#include "channel.h" -#include "convolutional.h" -#include "modulation.h" -#include "utility.h" -#include "linalg.h" -#include "search.h" -#include "signal.h" -#include "debug.h" +#include "susa/memory.h" +#include "susa/sets.h" +#include "susa/matrix.h" +#include "susa/array.h" +#include "susa/base.h" +#include "susa/svd.h" +#include "susa/statistics.h" +#include "susa/rng.h" +#include "susa/mt.h" +#include "susa/fft.h" +#include "susa/rrcosine.h" +#include "susa/channel.h" +#include "susa/convolutional.h" +#include "susa/modulation.h" +#include "susa/utility.h" +#include "susa/linalg.h" +#include "susa/search.h" +#include "susa/signal.h" +#include "susa/debug.h" #endif // SUSA_H diff --git a/inc/array.h b/inc/susa/array.h similarity index 100% rename from inc/array.h rename to inc/susa/array.h diff --git a/inc/base.h b/inc/susa/base.h similarity index 100% rename from inc/base.h rename to inc/susa/base.h diff --git a/inc/channel.h b/inc/susa/channel.h similarity index 100% rename from inc/channel.h rename to inc/susa/channel.h diff --git a/inc/convolutional.h b/inc/susa/convolutional.h old mode 100755 new mode 100644 similarity index 100% rename from inc/convolutional.h rename to inc/susa/convolutional.h diff --git a/inc/debug.h b/inc/susa/debug.h similarity index 100% rename from inc/debug.h rename to inc/susa/debug.h diff --git a/inc/fft.h b/inc/susa/fft.h similarity index 100% rename from inc/fft.h rename to inc/susa/fft.h diff --git a/inc/linalg.h b/inc/susa/linalg.h similarity index 100% rename from inc/linalg.h rename to inc/susa/linalg.h diff --git a/inc/matrix.h b/inc/susa/matrix.h similarity index 99% rename from inc/matrix.h rename to inc/susa/matrix.h index 47511e4..559a2c5 100644 --- a/inc/matrix.h +++ b/inc/susa/matrix.h @@ -1126,26 +1126,27 @@ template void matrix ::parser(std::string str_string) sizet_rows_++; sizet_size = sizet_cols_ * sizet_rows_; - SUSA_ASSERT_MESSAGE(sizet_cols_ % sizet_rows_ == 0, - "the number of columns are not equal in each row."); - + SUSA_ASSERT_MESSAGE(sizet_cols_ % sizet_rows_ == 0, "the number of columns are not equal in each row."); + if (sizet_cols_ % sizet_rows_ != 0) { return; } - + if (sizet_size != 0) { + sizet_rows = sizet_rows_; + sizet_cols = sizet_cols_ / sizet_rows_; + + sizet_size = sizet_cols * sizet_rows; + if ((this->sizet_objects) != sizet_size) { this->allocate(sizet_size); } - sizet_rows = sizet_rows_; - sizet_cols = sizet_cols_ / sizet_rows_; - std::stringstream ss_all(str_string); char* char_buff = (char *)std::malloc(4096); diff --git a/inc/memory.h b/inc/susa/memory.h similarity index 98% rename from inc/memory.h rename to inc/susa/memory.h index fc7e2b9..2ff4efa 100644 --- a/inc/memory.h +++ b/inc/susa/memory.h @@ -80,6 +80,9 @@ namespace susa template void memory::allocate(size_t sizet_size) { + + if (sizet_objects == sizet_size) return; + sizet_objects = sizet_size; sizet_bytes = sizet_size * sizeof(T); diff --git a/inc/modulation.h b/inc/susa/modulation.h similarity index 100% rename from inc/modulation.h rename to inc/susa/modulation.h diff --git a/inc/mt.h b/inc/susa/mt.h similarity index 100% rename from inc/mt.h rename to inc/susa/mt.h diff --git a/inc/rng.h b/inc/susa/rng.h similarity index 100% rename from inc/rng.h rename to inc/susa/rng.h diff --git a/inc/rrcosine.h b/inc/susa/rrcosine.h similarity index 100% rename from inc/rrcosine.h rename to inc/susa/rrcosine.h diff --git a/inc/search.h b/inc/susa/search.h similarity index 100% rename from inc/search.h rename to inc/susa/search.h diff --git a/inc/sets.h b/inc/susa/sets.h similarity index 100% rename from inc/sets.h rename to inc/susa/sets.h diff --git a/inc/signal.h b/inc/susa/signal.h similarity index 100% rename from inc/signal.h rename to inc/susa/signal.h diff --git a/inc/statistics.h b/inc/susa/statistics.h similarity index 100% rename from inc/statistics.h rename to inc/susa/statistics.h diff --git a/inc/svd.h b/inc/susa/svd.h similarity index 100% rename from inc/svd.h rename to inc/susa/svd.h diff --git a/inc/utility.h b/inc/susa/utility.h similarity index 100% rename from inc/utility.h rename to inc/susa/utility.h diff --git a/src/svd.cpp b/src/svd.cpp index f8fad6e..f685671 100644 --- a/src/svd.cpp +++ b/src/svd.cpp @@ -23,7 +23,6 @@ */ #include -#include namespace susa { diff --git a/test/base.cpp b/test/base.cpp index da8f69a..6549f66 100644 --- a/test/base.cpp +++ b/test/base.cpp @@ -35,15 +35,10 @@ int main(int argc, char const *argv[]) susa::matrix mat_a = mt_rng.rand(20,10); std::stringstream ss; ss << round(mat_a, 2); - std::string str(std::istreambuf_iterator(ss), {}); - susa::matrix mat_b(str); + susa::matrix mat_b(ss.str()); SUSA_TEST_EQ(mat_b, round(mat_a, 2), "std::string to susa::matrix conversion."); - std::cout << std::endl << " -----------------"; - std::cout << std::endl << " NUMBER OF FAILED TESTS(" << uint_failed <<")"; - std::cout << std::endl << " NUMBER OF PASSED TESTS(" << uint_passed <<")"; - std::cout << std::endl << " TOTAL NUMBER OF TESTS (" << uint_total <<")"; - std::cout << std::endl; + SUSA_TEST_PRINT_STATS(); return (uint_failed); } diff --git a/test/linalg.cpp b/test/linalg.cpp index bc2f16b..2d8ee94 100644 --- a/test/linalg.cpp +++ b/test/linalg.cpp @@ -57,11 +57,7 @@ int main(int argc, char const *argv[]) experiment = (susa::matrix)(mat_s * 10000.0f); SUSA_TEST_EQ (experiment, expected, "Singular Value Decomposition (SVD) for a sample matrix."); - std::cout << std::endl << " -----------------"; - std::cout << std::endl << " NUMBER OF FAILED TESTS(" << uint_failed <<")"; - std::cout << std::endl << " NUMBER OF PASSED TESTS(" << uint_passed <<")"; - std::cout << std::endl << " TOTAL NUMBER OF TESTS (" << uint_total <<")"; - std::cout << std::endl; + SUSA_TEST_PRINT_STATS(); return (uint_failed); } diff --git a/test/test.h b/test/test.h index 8eccbc8..fc691a6 100644 --- a/test/test.h +++ b/test/test.h @@ -55,5 +55,11 @@ inline void susa_test(bool res, const char* arga, const char* argb, const char* #define SUSA_TEST_EQ(ARGA,ARGB,MSG) (susa_test(ARGA == ARGB,#ARGA,#ARGB,#MSG)) #define SUSA_TEST_EQ_DOUBLE(ARGA,ARGB,MSG) (susa_test(std::abs(ARGA - ARGB) < 1e-4,#ARGA,#ARGB,#MSG)) +#define SUSA_TEST_PRINT_STATS() \ + std::cout << std::endl << " -----------------"; \ + std::cout << std::endl << " NUMBER OF FAILED TESTS(" << uint_failed <<")"; \ + std::cout << std::endl << " NUMBER OF PASSED TESTS(" << uint_passed <<")"; \ + std::cout << std::endl << " TOTAL NUMBER OF TESTS (" << uint_total <<")"; \ + std::cout << std::endl #endif // SUSA_TEST_H diff --git a/test/types.cpp b/test/types.cpp index 3fc20c4..94d896c 100644 --- a/test/types.cpp +++ b/test/types.cpp @@ -38,6 +38,12 @@ int main(int argc, char const *argv[]) mat_a(1,1) = 6.6; SUSA_TEST_EQ(mat_a(1,1), 6.6, "matrix parser"); + susa::matrix mat_b("[1; 2; 3]"); + SUSA_TEST_EQ(mat_b.no_rows(), 3, "matrix parser rows"); + SUSA_TEST_EQ(mat_b.no_cols(), 1, "matrix parser cols"); + SUSA_TEST_EQ(mat_b.size(), 3, "matrix parser size"); + + susa::matrix mat_c( susa::matrix ("[1 2.3 -3.4;8 4.5 1.2;9.1 3 -5]") + susa::matrix ("[0 0 0;5 -1 1.2;9.1 3 -6]") ); @@ -46,11 +52,7 @@ int main(int argc, char const *argv[]) SUSA_TEST_EQ(mat_c(4), 3.5, "move semantic."); SUSA_TEST_EQ(mat_c(2,2), -11, "move semantic."); - std::cout << std::endl << " -----------------"; - std::cout << std::endl << " NUMBER OF FAILED TESTS(" << uint_failed <<")"; - std::cout << std::endl << " NUMBER OF PASSED TESTS(" << uint_passed <<")"; - std::cout << std::endl << " TOTAL NUMBER OF TESTS (" << uint_total <<")"; - std::cout << std::endl; + SUSA_TEST_PRINT_STATS(); return (uint_failed); }