Skip to content

Commit

Permalink
revise function names
Browse files Browse the repository at this point in the history
  • Loading branch information
zzjjzzgggg committed Dec 2, 2016
1 parent 7d83ac3 commit 54b49fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
18 changes: 14 additions & 4 deletions eigenutils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __EIGENUTILS_H__
#define __EIGENUTILS_H__

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

Expand All @@ -22,6 +24,10 @@ void write(const std::string &filename, const Matrix &matrix) {
template <class Matrix>
void read(const std::string &filename, Matrix &matrix) {
std::ifstream in(filename, std::ios::in | std::ios::binary);
if (!in) {
std::cout << "Cannot open file " << filename << std::endl;
std::exit(-1);
}
typename Matrix::Index rows = 0, cols = 0;
in.read((char *)(&rows), sizeof(typename Matrix::Index));
in.read((char *)(&cols), sizeof(typename Matrix::Index));
Expand All @@ -32,14 +38,14 @@ void read(const std::string &filename, Matrix &matrix) {
}

template <class Tensor>
void write_tensor(const std::string &filename, const Tensor &tensor) {
void write_tensor(const std::string &filename,
const Tensor &tensor) {
std::ofstream out(filename, std::ios::out | std::ios::binary |
std::ios::trunc);
typename Tensor::Index rank = tensor.rank();
out.write((char *)(&rank), sizeof(typename Tensor::Index));
out.write(
(char *)tensor.dimensions().data(),
rank * sizeof(typename Tensor::Index));
out.write((char *)tensor.dimensions().data(),
rank * sizeof(typename Tensor::Index));
out.write((char *)tensor.data(),
tensor.size() * sizeof(typename Tensor::Scalar));
out.close();
Expand All @@ -48,6 +54,10 @@ void write_tensor(const std::string &filename, const Tensor &tensor) {
template <class Tensor>
void read_tensor(const std::string &filename, Tensor &tensor) {
std::ifstream in(filename, std::ios::in | std::ios::binary);
if (!in) {
std::cout << "Cannot open file " << filename << std::endl;
std::exit(-1);
}
typename Tensor::Index rank;
in.read((char *)(&rank), sizeof(typename Tensor::Index));
typename Tensor::Dimensions dimensions;
Expand Down
12 changes: 6 additions & 6 deletions stringutils.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "stringutils.h"

namespace strutils {
void split_filename(const std::string &fullname,
void splitFilename(const std::string &fullname,
std::string &base,
std::string &filename_wo_ext,
std::string &ext) {
Expand All @@ -28,7 +28,7 @@ void split_filename(const std::string &fullname,
* ../syn/events2_U100_I10_T100.dat -->
* ../syn/events2_U100_I10_T100_test.dat
*/
std::string insert_middle(const std::string &filename,
std::string insertMiddle(const std::string &filename,
const std::string &sufix) {
auto idx = filename.rfind('.');
if (idx != std::string::npos) {
Expand All @@ -39,7 +39,7 @@ std::string insert_middle(const std::string &filename,
return filename + "_" + sufix;
}

std::string get_base_path(const std::string &fullname) {
std::string getBasePath(const std::string &fullname) {
auto idx = fullname.rfind('/');
if (idx != std::string::npos) {
return fullname.substr(0, idx + 1);
Expand All @@ -48,7 +48,7 @@ std::string get_base_path(const std::string &fullname) {
}
}

std::string pretty_number(const int num) {
std::string prettyNumber(const int num) {
if (num < 1e3)
return fmt::format("{}", num);
else if (num < 1e6)
Expand All @@ -59,7 +59,7 @@ std::string pretty_number(const int num) {
return fmt::format("{}G", num / 1000000000);
}

std::string pretty_size(const int size) {
std::string prettySize(const int size) {
if (size < Kilobytes)
return fmt::format("{}B", size);
else if (size < Megabytes)
Expand All @@ -70,7 +70,7 @@ std::string pretty_size(const int size) {
return fmt::format("{:.2f}G", size / Gigabytes);
}

std::string pretty_time(const double secs) {
std::string prettyTime(const double secs) {
if (secs < 60)
return fmt::format("{:.2f}s", secs);
else {
Expand Down
12 changes: 6 additions & 6 deletions stringutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace strutils {

void split_filename(const std::string &fullname,
void splitFilename(const std::string &fullname,
std::string &base,
std::string &filename_wo_ext,
std::string &ext);
Expand All @@ -18,18 +18,18 @@ void split_filename(const std::string &fullname,
* ../syn/events2_U100_I10_T100.dat -->
* ../syn/events2_U100_I10_T100_test.dat
*/
std::string insert_middle(const std::string &filename,
std::string insertMiddle(const std::string &filename,
const std::string &sufix);

std::string get_base_path(const std::string &fullname);
std::string getBasePath(const std::string &fullname);

std::string pretty_number(const int num);
std::string prettyNumber(const int num);

static const double Kilobytes = 1 << 10, Megabytes = 1 << 20,
Gigabytes = 1 << 30;
std::string pretty_size(const int size);
std::string prettySize(const int size);

std::string pretty_time(const double seconds);
std::string prettyTime(const double seconds);

void split(const std::string &s, char delim,
std::vector<std::string> &elems);
Expand Down
2 changes: 1 addition & 1 deletion timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Timer {
double seconds() const { return milliseconds() / 1000; }

const std::string getStr() const {
return strutils::pretty_time(seconds());
return strutils::prettyTime(seconds());
}

static char* curTime() {
Expand Down

0 comments on commit 54b49fc

Please sign in to comment.