jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4a6b792058ed03e8af210c63c421c7b32208549f
parent 3232fe1fd1bc2e63adc6aed5292def5825ada1b5
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Fri,  3 Jul 2020 22:33:13 -0700

Reorganizing tests.

Diffstat:
Atests/fileread.cpp | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/strassen.cpp | 4++--
Mutils.cpp | 58----------------------------------------------------------
3 files changed, 59 insertions(+), 60 deletions(-)

diff --git a/tests/fileread.cpp b/tests/fileread.cpp @@ -0,0 +1,57 @@ +uintmax_t wc(char const *fname) +{ + static const auto BUFFER_SIZE = 1024; + int fd = open(fname, O_RDONLY); + if(fd == -1) + exit(1); + + /* Advise the kernel of our access pattern. */ + //posix_fadvise(fd, 0, 0, 1); // FDADVICE_SEQUENTIAL + + char buf[BUFFER_SIZE + 1]; + uintmax_t lines = 0; + + while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)) + { + if(bytes_read == (size_t)-1) + exit(1); + if (!bytes_read) + break; + for(char *p = buf; (p = (char*) memchr(p, '\n', (buf + bytes_read) - p)); ++p) { + printf("About to segfault? It's simple - just don't!\n"); + // printf("%s", p) + for (int i = 1; i < BUFFER_SIZE; i++) { + printf("%c", p[i]); + } + printf("\nGlad you heeded my advice.\n"); + printf("\n\nDONE\n\n"); + ++lines; + //printf(" DONE \n"); + } + } + + return lines; +} + +int istreamtest () { + std::filebuf fb; + if (fb.open ("extra.txt",std::ios::in)) + { + std::istream is(&fb); + char fchar = '-'; + + const int MAX_LENGTH = 1024; + char* line = new char[MAX_LENGTH]; + auto get_begin = std::chrono::high_resolution_clock::now(); + int i = 0; + auto get_end = std::chrono::high_resolution_clock::now(); + while (is.getline(line, MAX_LENGTH) && strlen(line) > 0 && i < 10) { + auto get_end = std::chrono::high_resolution_clock::now(); + std::cout << line << "\n"; + i++; + } + std::cout << " GET " << std::chrono::duration_cast<std::chrono::nanoseconds>(get_end - get_begin).count() << "\n"; + fb.close(); + } + return 0; +} diff --git a/tests/strassen.cpp b/tests/strassen.cpp @@ -22,7 +22,7 @@ Eigen::MatrixXd strassen_mul(Eigen::MatrixXd a, Eigen::MatrixXd b) Eigen::MatrixXd m4 = a.block(a.rows()-block_len,a.cols()-block_len, block_len, block_len) * (b.block(b.rows()-block_len,0, block_len, block_len) - b.block(0,0, block_len, block_len)); Eigen::MatrixXd m5 = (a.block(0, 0, block_len, block_len) + a.block(0,a.cols()-block_len, block_len, block_len)) * (b.block(b.rows()-block_len,b.cols()-block_len, block_len, block_len)); Eigen::MatrixXd m6 = (a.block(a.rows()-block_len,0, block_len, block_len) - a.block(0,0, block_len, block_len)) * (b.block(0,0, block_len, block_len) + b.block(0,b.cols()-block_len, block_len, block_len)); - Eigen::MatrixXd m7 = (a.block(0,a.cols()-block_len, block_len, block_len) - a.block(a.rows()-block_len,a.cols()-block_len, block_len, block_len)) * (b.block(a.rows()-block_len,0, block_len, block_len) + b.block(b.rows()-block_len,b.cols()-block_len, block_len, block_len)) + Eigen::MatrixXd m7 = (a.block(0,a.cols()-block_len, block_len, block_len) - a.block(a.rows()-block_len,a.cols()-block_len, block_len, block_len)) * (b.block(a.rows()-block_len,0, block_len, block_len) + b.block(b.rows()-block_len,b.cols()-block_len, block_len, block_len)); result.block(0,0, block_len, block_len) = m1 + m4 - m5 + m7; result.block(0,result.cols()-block_len, block_len, block_len) = m3 + m5; @@ -49,5 +49,5 @@ int main() auto strassen_end = std::chrono::high_resolution_clock::now(); std::cout << "EIGEN: " << std::chrono::duration_cast<std::chrono::nanoseconds>(eigen_end - eigen_begin).count() / pow(10,9) << " STRASSEN: " << std::chrono::duration_cast<std::chrono::nanoseconds>(strassen_end - strassen_begin).count() / pow(10,9) << "\n"; - //std::cout << "A:\n" << a << "\nB:\n" << b << "\nEigen:\n" << product << "\nStrassen:\n" << sproduct << "\n"; + std::cout << "A:\n" << a << "\nB:\n" << b << "\nEigen:\n" << product << "\nStrassen:\n" << sproduct << "\n"; } diff --git a/utils.cpp b/utils.cpp @@ -55,61 +55,3 @@ std::function<double(double)> rectifier(double (*activation)(double)) }; return rectified; } - -uintmax_t wc(char const *fname) -{ - static const auto BUFFER_SIZE = 1024; - int fd = open(fname, O_RDONLY); - if(fd == -1) - exit(1); - - /* Advise the kernel of our access pattern. */ - //posix_fadvise(fd, 0, 0, 1); // FDADVICE_SEQUENTIAL - - char buf[BUFFER_SIZE + 1]; - uintmax_t lines = 0; - - while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)) - { - if(bytes_read == (size_t)-1) - exit(1); - if (!bytes_read) - break; - for(char *p = buf; (p = (char*) memchr(p, '\n', (buf + bytes_read) - p)); ++p) { - printf("About to segfault? It's simple - just don't!\n"); - // printf("%s", p) - for (int i = 1; i < BUFFER_SIZE; i++) { - printf("%c", p[i]); - } - printf("\nGlad you heeded my advice.\n"); - printf("\n\nDONE\n\n"); - ++lines; - //printf(" DONE \n"); - } - } - - return lines; -} - -int istreamtest () { - std::filebuf fb; - if (fb.open ("extra.txt",std::ios::in)) - { - std::istream is(&fb); - char fchar = '-'; - - const int MAX_LENGTH = 1024; - char* line = new char[MAX_LENGTH]; - auto get_begin = std::chrono::high_resolution_clock::now(); - int i = 0; - auto get_end = std::chrono::high_resolution_clock::now(); - while (is.getline(line, MAX_LENGTH) && strlen(line) > 0 && i < 10) { - auto get_end = std::chrono::high_resolution_clock::now(); - std::cout << line << "\n"; - i++; - } - std::cout << " GET " << std::chrono::duration_cast<std::chrono::nanoseconds>(get_end - get_begin).count() << "\n"; - fb.close(); - } - return 0; -}