Skip to content

Commit

Permalink
fix style issues (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jan 17, 2023
1 parent 0b75262 commit 31663a5
Show file tree
Hide file tree
Showing 11 changed files with 622 additions and 585 deletions.
22 changes: 13 additions & 9 deletions kaldifst/csrc/basic-filebuf.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT (included
// below)
// This file is copied from kaldi/src/util/basic-filebuf.h
///////////////////////////////////////////////////////////////////////////////
// This is a modified version of the std::basic_filebuf from libc++
Expand All @@ -9,15 +11,17 @@
// Source License licenses. See LICENSE.TXT for details (included at the
// bottom).
///////////////////////////////////////////////////////////////////////////////
#ifndef KALDIFST_CSRC_UTIL_BASIC_FILEBUF_H_
#define KALDIFST_CSRC_UTIL_BASIC_FILEBUF_H_
#ifndef KALDIFST_CSRC_BASIC_FILEBUF_H_
#define KALDIFST_CSRC_BASIC_FILEBUF_H_

///////////////////////////////////////////////////////////////////////////////
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <memory>
#include <string>
#include <algorithm>
#include <utility>

///////////////////////////////////////////////////////////////////////////////
namespace kaldifst {
Expand Down Expand Up @@ -335,7 +339,7 @@ basic_filebuf<CharT, Traits>::
open(const char* s, std::ios_base::openmode mode) {
basic_filebuf<CharT, Traits>* rt = nullptr;
if (_M_file == nullptr) {
const char* md= _M_get_mode(mode);
const char* md = _M_get_mode(mode);
if (md) {
_M_file = fopen(s, md);
if (_M_file) {
Expand Down Expand Up @@ -367,9 +371,9 @@ basic_filebuf<CharT, Traits>::open(const std::string& s,
template <class CharT, class Traits>
basic_filebuf<CharT, Traits>*
basic_filebuf<CharT, Traits>::open(int fd, std::ios_base::openmode mode) {
const char* md= this->_M_get_mode(mode);
const char* md = this->_M_get_mode(mode);
if (md) {
this->_M_file= fdopen(fd, md);
this->_M_file = fdopen(fd, md);
this->_M_om = mode;
return this;
} else {
Expand Down Expand Up @@ -782,10 +786,10 @@ basic_filebuf<CharT, Traits>::_M_write_mode() {
}

///////////////////////////////////////////////////////////////////////////////
}
} // namespace kaldifst

///////////////////////////////////////////////////////////////////////////////
#endif // KALDIFST_CSRC_UTIL_BASIC_FILEBUF_H_
#endif // KALDIFST_CSRC_BASIC_FILEBUF_H_

///////////////////////////////////////////////////////////////////////////////

Expand Down
40 changes: 23 additions & 17 deletions kaldifst/csrc/determinize-star-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
#ifndef KALDIFST_CSRC_DETERMINIZE_STAR_INL_H_
#define KALDIFST_CSRC_DETERMINIZE_STAR_INL_H_

#include <algorithm>
#include <deque>
#include <limits>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "fst/fst.h"
#include "kaldifst/csrc/log.h"
Expand Down Expand Up @@ -79,9 +85,9 @@ class StringRepository {

inline bool IsEmptyString(StringId id) { return id == no_symbol; }
void SeqOfId(StringId id, std::vector<Label> *v) {
if (id == no_symbol)
if (id == no_symbol) {
v->clear();
else if (id >= single_symbol_start) {
} else if (id >= single_symbol_start) {
v->resize(1);
(*v)[0] = id - single_symbol_start;
} else {
Expand All @@ -90,9 +96,9 @@ class StringRepository {
}
}
StringId RemovePrefix(StringId id, size_t prefix_len) {
if (prefix_len == 0)
if (prefix_len == 0) {
return id;
else {
} else {
std::vector<Label> v;
SeqOfId(id, &v);
size_t sz = v.size();
Expand Down Expand Up @@ -198,9 +204,9 @@ class DeterminizerStar {
InputStateId start_id = ifst_->Start();
if (start_id == kNoStateId) {
determinized_ = true;
// Nothing to do.
return;
} // Nothing to do.
else { // Insert start state into hash and queue.
} else { // Insert start state into hash and queue.
Element elem;
elem.state = start_id;
elem.weight = Weight::One();
Expand Down Expand Up @@ -329,7 +335,7 @@ class DeterminizerStar {
return true;
}
float delta_;
SubsetEqual(float delta) : delta_(delta) {}
explicit SubsetEqual(float delta) : delta_(delta) {}
SubsetEqual() : delta_(kDelta) {}
};

Expand Down Expand Up @@ -499,11 +505,11 @@ class DeterminizerStar {
public:
inline bool operator()(const std::pair<Label, Element> &p1,
const std::pair<Label, Element> &p2) {
if (p1.first < p2.first)
if (p1.first < p2.first) {
return true;
else if (p1.first > p2.first)
} else if (p1.first > p2.first) {
return false;
else {
} else {
return p1.second.state < p2.second.state;
}
}
Expand Down Expand Up @@ -538,10 +544,10 @@ class DeterminizerStar {
Element &next_elem(this_pr.second);
next_elem.state = arc.nextstate;
next_elem.weight = Times(elem.weight, arc.weight);
if (arc.olabel == 0) // output epsilon-- this is simple case so
// handle separately for efficiency
if (arc.olabel == 0) { // output epsilon-- this is simple case so
// handle separately for efficiency
next_elem.string = elem.string;
else {
} else {
std::vector<Label> seq;
repository_.SeqOfId(elem.string, &seq);
seq.push_back(arc.olabel);
Expand Down Expand Up @@ -756,9 +762,8 @@ void DeterminizerStar<F>::EpsilonClosure::AddOneElement(
if (index != -1) {
if (index >= ecinfo_.size()) {
index = -1;
}
// since ecinfo_ might store outdated information, we need to check
else if (ecinfo_[index].element.state != elem.state) {
// since ecinfo_ might store outdated information, we need to check
} else if (ecinfo_[index].element.state != elem.state) {
index = -1;
}
}
Expand Down Expand Up @@ -1095,7 +1100,8 @@ void DeterminizerStar<F>::Debug() {
}

template <class F>
bool DeterminizeStar(F &ifst, MutableFst<typename F::Arc> *ofst, float delta,
bool DeterminizeStar(F &ifst, // NOLINT
MutableFst<typename F::Arc> *ofst, float delta,
bool *debug_ptr, int max_states, bool allow_partial) {
ofst->SetOutputSymbols(ifst.OutputSymbols());
ofst->SetInputSymbols(ifst.InputSymbols());
Expand Down
6 changes: 4 additions & 2 deletions kaldifst/csrc/kaldi-fst-io-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#include "fst/fst.h"
#include "fst/script/print.h"
Expand Down Expand Up @@ -78,9 +80,9 @@ void ReadFstKaldi(std::istream &is, bool binary, VectorFst<Arc> *fst) {
// Consume the \r on Windows, the \n that the text-form FST format starts
// with, and any extra spaces that might have got in there somehow.
while (std::isspace(is.peek()) && is.peek() != '\n') is.get();
if (is.peek() == '\n')
if (is.peek() == '\n') {
is.get(); // consume the newline.
else { // saw spaces but no newline.. this is not expected.
} else { // saw spaces but no newline.. this is not expected.
KALDIFST_ERR << "Reading FST: unexpected sequence of spaces "
<< " at file position " << is.tellg();
}
Expand Down
18 changes: 6 additions & 12 deletions kaldifst/csrc/kaldi-io-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.
#ifndef KALDIFST_CSRC_UTIL_KALDI_IO_INL_H_
#define KALDIFST_CSRC_UTIL_KALDI_IO_INL_H_
#ifndef KALDIFST_CSRC_KALDI_IO_INL_H_
#define KALDIFST_CSRC_KALDI_IO_INL_H_

#include<string>
#include <string>

namespace kaldifst {

Expand All @@ -31,16 +31,10 @@ bool Input::OpenTextMode(const std::string &rxfilename) {
return OpenInternal(rxfilename, false, NULL);
}

bool Input::IsOpen() {
return impl_ != NULL;
}

bool Output::IsOpen() {
return impl_ != NULL;
}
bool Input::IsOpen() { return impl_ != NULL; }

bool Output::IsOpen() { return impl_ != NULL; }

} // namespace kaldifst


#endif // KALDIFST_CSRC_UTIL_KALDI_IO_INL_H_
#endif // KALDIFST_CSRC_KALDI_IO_INL_H_
2 changes: 1 addition & 1 deletion kaldifst/csrc/kaldi-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Input {
/// Equivalent to calling the default constructor followed by Open(); then, if
/// binary != NULL, it calls ReadHeader(), putting the output in "binary"; it
/// throws on error.
Input(const std::string &rxfilename, bool *contents_binary = NULL);
explicit Input(const std::string &rxfilename, bool *contents_binary = NULL);

Input() : impl_(NULL) {}

Expand Down
13 changes: 6 additions & 7 deletions kaldifst/csrc/kaldi-semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.


#ifndef KALDIFST_CSRC_KALDI_SEMAPHORE_H_
#define KALDIFST_CSRC_KALDI_SEMAPHORE_H_

#include <condition_variable>
#include <mutex>
#include <condition_variable> // NOLINT
#include <mutex> // NOLINT

#include "kaldifst/csrc/log.h"

namespace kaldifst {

class Semaphore {
public:
Semaphore(int32_t count = 0);
explicit Semaphore(int32_t count = 0);

~Semaphore();

Expand All @@ -40,13 +39,13 @@ class Semaphore {
void Signal(); ///< increase the counter

private:
int32_t count_; ///< the semaphore counter, 0 means block on Wait()
int32_t count_; ///< the semaphore counter, 0 means block on Wait()

std::mutex mutex_;
std::condition_variable condition_variable_;
KALDIFST_DISALLOW_COPY_AND_ASSIGN(Semaphore);
};

} //namespace kaldifst
} // namespace kaldifst

#endif // KALDIFST_CSRC_KALDI_SEMAPHORE_H_
#endif // KALDIFST_CSRC_KALDI_SEMAPHORE_H_
Loading

0 comments on commit 31663a5

Please sign in to comment.