Skip to content

Commit

Permalink
fix a matrix string parser bug and header path
Browse files Browse the repository at this point in the history
  • Loading branch information
kamarya committed May 23, 2017
1 parent 6278a21 commit 76d8fd7
Show file tree
Hide file tree
Showing 27 changed files with 55 additions and 49 deletions.
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -28,16 +26,16 @@ 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)

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")
6 changes: 6 additions & 0 deletions examples/simple_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ int main(void)
std::cout << std::endl;


susa::matrix <int> 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.");

Expand Down
38 changes: 19 additions & 19 deletions inc/susa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 8 additions & 7 deletions inc/matrix.h → inc/susa/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1126,26 +1126,27 @@ template <class T> void matrix <T>::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);
Expand Down
3 changes: 3 additions & 0 deletions inc/memory.h → inc/susa/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ namespace susa

template <class T> void memory<T>::allocate(size_t sizet_size)
{

if (sizet_objects == sizet_size) return;

sizet_objects = sizet_size;
sizet_bytes = sizet_size * sizeof(T);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/svd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

#include <susa.h>
#include <svd.h>

namespace susa {

Expand Down
9 changes: 2 additions & 7 deletions test/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,10 @@ int main(int argc, char const *argv[])
susa::matrix <float> mat_a = mt_rng.rand(20,10);
std::stringstream ss;
ss << round(mat_a, 2);
std::string str(std::istreambuf_iterator<char>(ss), {});
susa::matrix <double> mat_b(str);
susa::matrix <double> 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);
}
6 changes: 1 addition & 5 deletions test/linalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ int main(int argc, char const *argv[])
experiment = (susa::matrix<int>)(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);
}
6 changes: 6 additions & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions test/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <int> 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 <double> mat_c(
susa::matrix <double> ("[1 2.3 -3.4;8 4.5 1.2;9.1 3 -5]") +
susa::matrix <double> ("[0 0 0;5 -1 1.2;9.1 3 -6]") );
Expand All @@ -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);
}

0 comments on commit 76d8fd7

Please sign in to comment.