mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
delete check.hh
This commit is contained in:
parent
eb5112f09e
commit
1431cc5688
@ -17,9 +17,9 @@
|
|||||||
#ifndef INC_RANDLM_FILTER_H
|
#ifndef INC_RANDLM_FILTER_H
|
||||||
#define INC_RANDLM_FILTER_H
|
#define INC_RANDLM_FILTER_H
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "FileHandler.h"
|
#include "FileHandler.h"
|
||||||
#include "util/check.hh"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define log2(X) (log((double)X)/log((double)2))
|
#define log2(X) (log((double)X)/log((double)2))
|
||||||
@ -45,15 +45,15 @@ public:
|
|||||||
// number of bits in T
|
// number of bits in T
|
||||||
cell_width_ = sizeof(T) << 3;
|
cell_width_ = sizeof(T) << 3;
|
||||||
// current implementation has following constraints
|
// current implementation has following constraints
|
||||||
CHECK(cell_width_ > 0 && cell_width_ <= 64 && cell_width_ >= width);
|
assert(cell_width_ > 0 && cell_width_ <= 64 && cell_width_ >= width);
|
||||||
// used for >> division
|
// used for >> division
|
||||||
log_cell_width_ = static_cast<int>(floor(log((double)cell_width_)/log((double)2) + 0.000001));
|
log_cell_width_ = static_cast<int>(floor(log((double)cell_width_)/log((double)2) + 0.000001));
|
||||||
// size of underlying data in Ts
|
// size of underlying data in Ts
|
||||||
cells_ = ((addresses * width) + cell_width_ - 1) >> log_cell_width_;
|
cells_ = ((addresses * width) + cell_width_ - 1) >> log_cell_width_;
|
||||||
// instantiate underlying data
|
// instantiate underlying data
|
||||||
data_ = new T[cells_];
|
data_ = new T[cells_];
|
||||||
CHECK(data_ != NULL);
|
assert(data_ != NULL);
|
||||||
CHECK(reset());
|
assert(reset());
|
||||||
// 'first_bit' marks the first bit used by 'address' (left padded with zeros).
|
// 'first_bit' marks the first bit used by 'address' (left padded with zeros).
|
||||||
first_bit_ = (width % cell_width_ == 0) ? 0 : cell_width_ - (width % cell_width_);
|
first_bit_ = (width % cell_width_ == 0) ? 0 : cell_width_ - (width % cell_width_);
|
||||||
// mask for full cell
|
// mask for full cell
|
||||||
@ -62,9 +62,9 @@ public:
|
|||||||
address_mask_ = full_mask_ >> first_bit_;
|
address_mask_ = full_mask_ >> first_bit_;
|
||||||
}
|
}
|
||||||
Filter(FileHandler* fin, bool loaddata = true) : data_(NULL) {
|
Filter(FileHandler* fin, bool loaddata = true) : data_(NULL) {
|
||||||
CHECK(loadHeader(fin));
|
assert(loadHeader(fin));
|
||||||
if (loaddata)
|
if (loaddata)
|
||||||
CHECK(loadData(fin));
|
assert(loadData(fin));
|
||||||
}
|
}
|
||||||
virtual ~Filter() {
|
virtual ~Filter() {
|
||||||
delete[] data_;
|
delete[] data_;
|
||||||
@ -80,7 +80,7 @@ public:
|
|||||||
}
|
}
|
||||||
// read / write functions
|
// read / write functions
|
||||||
inline bool read(uint64_t address, T* value) {
|
inline bool read(uint64_t address, T* value) {
|
||||||
CHECK(address <= addresses_);
|
assert(address <= addresses_);
|
||||||
// copy address to 'value'
|
// copy address to 'value'
|
||||||
uint64_t data_bit = address * width_;
|
uint64_t data_bit = address * width_;
|
||||||
uint32_t data_cell = (data_bit >> log_cell_width_); // % cells_;
|
uint32_t data_cell = (data_bit >> log_cell_width_); // % cells_;
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline T read(uint64_t address) {
|
inline T read(uint64_t address) {
|
||||||
CHECK(address <= addresses_);
|
assert(address <= addresses_);
|
||||||
// return value at address
|
// return value at address
|
||||||
T value = 0;
|
T value = 0;
|
||||||
uint64_t data_bit = address * width_;
|
uint64_t data_bit = address * width_;
|
||||||
@ -124,8 +124,8 @@ public:
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
inline bool write(uint64_t address, T value) {
|
inline bool write(uint64_t address, T value) {
|
||||||
CHECK(address <= addresses_);
|
assert(address <= addresses_);
|
||||||
CHECK(log2(value) <= width_);
|
assert(log2(value) <= width_);
|
||||||
// write 'value' to address
|
// write 'value' to address
|
||||||
uint64_t data_bit = address * width_;
|
uint64_t data_bit = address * width_;
|
||||||
uint32_t data_cell = (data_bit >> log_cell_width_); // % cells_;
|
uint32_t data_cell = (data_bit >> log_cell_width_); // % cells_;
|
||||||
@ -223,50 +223,50 @@ public:
|
|||||||
return cells_;
|
return cells_;
|
||||||
}
|
}
|
||||||
virtual bool save(FileHandler* out) {
|
virtual bool save(FileHandler* out) {
|
||||||
CHECK(out != NULL);
|
assert(out != NULL);
|
||||||
CHECK(out->write((char*)&cells_, sizeof(cells_)));
|
assert(out->write((char*)&cells_, sizeof(cells_)));
|
||||||
CHECK(out->write((char*)&cell_width_, sizeof(cell_width_)));
|
assert(out->write((char*)&cell_width_, sizeof(cell_width_)));
|
||||||
CHECK(out->write((char*)&log_cell_width_, sizeof(log_cell_width_)));
|
assert(out->write((char*)&log_cell_width_, sizeof(log_cell_width_)));
|
||||||
CHECK(out->write((char*)&addresses_, sizeof(addresses_)));
|
assert(out->write((char*)&addresses_, sizeof(addresses_)));
|
||||||
CHECK(out->write((char*)&width_, sizeof(width_)));
|
assert(out->write((char*)&width_, sizeof(width_)));
|
||||||
CHECK(out->write((char*)&first_bit_, sizeof(first_bit_)));
|
assert(out->write((char*)&first_bit_, sizeof(first_bit_)));
|
||||||
CHECK(out->write((char*)&full_mask_, sizeof(full_mask_)));
|
assert(out->write((char*)&full_mask_, sizeof(full_mask_)));
|
||||||
CHECK(out->write((char*)&address_mask_, sizeof(address_mask_)));
|
assert(out->write((char*)&address_mask_, sizeof(address_mask_)));
|
||||||
//CHECK(out->write((char*)data_, cells_ * sizeof(T)));
|
//assert(out->write((char*)data_, cells_ * sizeof(T)));
|
||||||
const uint64_t jump = 524288032ul; //(uint64_t)pow(2, 29);
|
const uint64_t jump = 524288032ul; //(uint64_t)pow(2, 29);
|
||||||
if((width_ == 1) || cells_ < jump)
|
if((width_ == 1) || cells_ < jump)
|
||||||
CHECK(out->write((char*)data_, cells_ * sizeof(T)));
|
assert(out->write((char*)data_, cells_ * sizeof(T)));
|
||||||
else {
|
else {
|
||||||
uint64_t idx(0);
|
uint64_t idx(0);
|
||||||
while(idx + jump < cells_) {
|
while(idx + jump < cells_) {
|
||||||
CHECK(out->write((char*)&data_[idx], jump * sizeof(T)));
|
assert(out->write((char*)&data_[idx], jump * sizeof(T)));
|
||||||
idx += jump;
|
idx += jump;
|
||||||
}
|
}
|
||||||
CHECK(out->write((char*)&data_[idx], (cells_ - idx) * sizeof(T)));
|
assert(out->write((char*)&data_[idx], (cells_ - idx) * sizeof(T)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
bool loadHeader(FileHandler* fin) {
|
bool loadHeader(FileHandler* fin) {
|
||||||
CHECK(fin != NULL);
|
assert(fin != NULL);
|
||||||
CHECK(fin->read((char*)&cells_, sizeof(cells_)));
|
assert(fin->read((char*)&cells_, sizeof(cells_)));
|
||||||
CHECK(fin->read((char*)&cell_width_, sizeof(cell_width_)));
|
assert(fin->read((char*)&cell_width_, sizeof(cell_width_)));
|
||||||
CHECK(cell_width_ == sizeof(T) << 3); // make sure correct underlying data type
|
assert(cell_width_ == sizeof(T) << 3); // make sure correct underlying data type
|
||||||
CHECK(fin->read((char*)&log_cell_width_, sizeof(log_cell_width_)));
|
assert(fin->read((char*)&log_cell_width_, sizeof(log_cell_width_)));
|
||||||
CHECK(fin->read((char*)&addresses_, sizeof(addresses_)));
|
assert(fin->read((char*)&addresses_, sizeof(addresses_)));
|
||||||
CHECK(fin->read((char*)&width_, sizeof(width_)));
|
assert(fin->read((char*)&width_, sizeof(width_)));
|
||||||
CHECK(fin->read((char*)&first_bit_, sizeof(first_bit_)));
|
assert(fin->read((char*)&first_bit_, sizeof(first_bit_)));
|
||||||
CHECK(fin->read((char*)&full_mask_, sizeof(full_mask_)));
|
assert(fin->read((char*)&full_mask_, sizeof(full_mask_)));
|
||||||
CHECK(fin->read((char*)&address_mask_, sizeof(address_mask_)));
|
assert(fin->read((char*)&address_mask_, sizeof(address_mask_)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool loadData(FileHandler* fin) {
|
bool loadData(FileHandler* fin) {
|
||||||
// instantiate underlying array
|
// instantiate underlying array
|
||||||
data_ = new T[cells_];
|
data_ = new T[cells_];
|
||||||
CHECK(data_ != NULL);
|
assert(data_ != NULL);
|
||||||
CHECK(fin->read((char*)data_, cells_ * sizeof(T)));
|
assert(fin->read((char*)data_, cells_ * sizeof(T)));
|
||||||
//CHECK(fin->read((char*)&data_[0], ceil(float(cells_) / 2.0) * sizeof(T)));
|
//assert(fin->read((char*)&data_[0], ceil(float(cells_) / 2.0) * sizeof(T)));
|
||||||
//CHECK(fin->read((char*)&data_[cells_ / 2], (cells_ / 2) * sizeof(T)));
|
//assert(fin->read((char*)&data_[cells_ / 2], (cells_ / 2) * sizeof(T)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
uint64_t cells_; // number T making up 'data_'
|
uint64_t cells_; // number T making up 'data_'
|
||||||
@ -288,7 +288,7 @@ public:
|
|||||||
BitFilter(FileHandler* fin, bool loaddata = true)
|
BitFilter(FileHandler* fin, bool loaddata = true)
|
||||||
: Filter<uint8_t>(fin, loaddata) {
|
: Filter<uint8_t>(fin, loaddata) {
|
||||||
if (loaddata)
|
if (loaddata)
|
||||||
CHECK(load(fin));
|
assert(load(fin));
|
||||||
}
|
}
|
||||||
// TODO: overload operator[]
|
// TODO: overload operator[]
|
||||||
virtual bool testBit(uint64_t location) {
|
virtual bool testBit(uint64_t location) {
|
||||||
@ -306,7 +306,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool save(FileHandler* fout) {
|
bool save(FileHandler* fout) {
|
||||||
CHECK(Filter<uint8_t>::save(fout));
|
assert(Filter<uint8_t>::save(fout));
|
||||||
std::cerr << "Saved BitFilter. Rho = " << rho() << "." << std::endl;;
|
std::cerr << "Saved BitFilter. Rho = " << rho() << "." << std::endl;;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -333,10 +333,10 @@ protected:
|
|||||||
class ResizedBitFilter : public BitFilter {
|
class ResizedBitFilter : public BitFilter {
|
||||||
public:
|
public:
|
||||||
ResizedBitFilter(FileHandler* fin) : BitFilter(fin) {
|
ResizedBitFilter(FileHandler* fin) : BitFilter(fin) {
|
||||||
CHECK(load(fin));
|
assert(load(fin));
|
||||||
}
|
}
|
||||||
ResizedBitFilter(FileHandler* fin, uint64_t newsize) : BitFilter(newsize) {
|
ResizedBitFilter(FileHandler* fin, uint64_t newsize) : BitFilter(newsize) {
|
||||||
CHECK(resizeFromFile(fin, newsize));
|
assert(resizeFromFile(fin, newsize));
|
||||||
}
|
}
|
||||||
bool resizeFromFile(FileHandler* oldin, uint64_t newsize);
|
bool resizeFromFile(FileHandler* oldin, uint64_t newsize);
|
||||||
virtual bool testBit(uint64_t location) {
|
virtual bool testBit(uint64_t location) {
|
||||||
@ -349,10 +349,10 @@ protected:
|
|||||||
}
|
}
|
||||||
bool save(FileHandler* fout) {
|
bool save(FileHandler* fout) {
|
||||||
// re-hashing parameters
|
// re-hashing parameters
|
||||||
CHECK(BitFilter::save(fout));
|
assert(BitFilter::save(fout));
|
||||||
std::cerr << "Saved ResizedBitFilter. Rho = " << rho() << "." << std::endl;
|
std::cerr << "Saved ResizedBitFilter. Rho = " << rho() << "." << std::endl;
|
||||||
CHECK(fout->write((char*)&old_addresses_, sizeof(old_addresses_)));
|
assert(fout->write((char*)&old_addresses_, sizeof(old_addresses_)));
|
||||||
CHECK(fout->write((char*)&a_, sizeof(a_)));
|
assert(fout->write((char*)&a_, sizeof(a_)));
|
||||||
return fout->write((char*)&b_, sizeof(b_));
|
return fout->write((char*)&b_, sizeof(b_));
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
/* People have been abusing assert by assuming it will always execute. To
|
|
||||||
* rememdy the situation, asserts were replaced with CHECK. These should then
|
|
||||||
* be manually replaced with assert (when used correctly) or UTIL_THROW (for
|
|
||||||
* runtime checks).
|
|
||||||
*/
|
|
||||||
#ifndef UTIL_CHECK__
|
|
||||||
#define UTIL_CHECK__
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#define CHECK(Condition) do { \
|
|
||||||
if (!(Condition)) { \
|
|
||||||
std::cerr << "Check " << #Condition << " failed in " << __FILE__ << ":" << __LINE__ << std::endl; \
|
|
||||||
abort(); \
|
|
||||||
} \
|
|
||||||
} while (0) // swallow ;
|
|
||||||
|
|
||||||
#endif // UTIL_CHECK__
|
|
Loading…
Reference in New Issue
Block a user