Commit 15da6cfe authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

Changes to make Klocwork a little happier (#1739)

* address klocwork issue

* move class init

* more klocwork

* more klocwork

* more klocwork

* comment on where the magic number is from

* address review comments

* address review comments
parent 4df5ea8b
......@@ -54,6 +54,7 @@ namespace
{
float inv_2_8 = 1.0f / 256.0f;
}
void MNistLoader::read_scaled(float* loc, size_t n)
{
for (size_t i = 0; i < n; ++i)
......
......@@ -22,7 +22,7 @@
class MNistLoader
{
protected:
MNistLoader(const std::string& filename, std::uint32_t magic);
MNistLoader(const std::string& filename, uint32_t magic);
virtual ~MNistLoader();
virtual void read_header();
......@@ -42,18 +42,18 @@ public:
return fread(loc, sizeof(T), n, m_file);
}
std::uint32_t get_items() { return m_items; }
uint32_t get_items() { return m_items; }
protected:
std::string m_filename;
FILE* m_file{nullptr};
std::uint32_t m_magic;
std::uint32_t m_items;
fpos_t m_data_pos;
uint32_t m_magic;
uint32_t m_items{0};
fpos_t m_data_pos{0};
};
class MNistImageLoader : public MNistLoader
{
static const std::uint32_t magic_value = 0x00000803;
static const uint32_t magic_value = 0x00000803;
virtual void read_header() override;
......@@ -63,16 +63,16 @@ public:
static const char* const TEST;
static const char* const TRAIN;
std::uint32_t get_rows() { return m_rows; }
std::uint32_t get_columns() { return m_columns; }
uint32_t get_rows() { return m_rows; }
uint32_t get_columns() { return m_columns; }
protected:
std::uint32_t m_rows;
std::uint32_t m_columns;
uint32_t m_rows{0};
uint32_t m_columns{0};
};
class MNistLabelLoader : public MNistLoader
{
static const std::uint32_t magic_value = 0x00000801;
static const uint32_t magic_value = 0x00000801;
public:
MNistLabelLoader(const std::string& file);
......@@ -92,8 +92,8 @@ public:
void open();
void close();
std::uint32_t get_rows() { return m_image_loader.get_rows(); }
std::uint32_t get_columns() { return m_image_loader.get_columns(); }
uint32_t get_rows() { return m_image_loader.get_rows(); }
uint32_t get_columns() { return m_image_loader.get_columns(); }
size_t get_batch_size() { return m_batch_size; }
size_t get_items() { return m_items; }
size_t get_epoch() { return m_epoch; }
......@@ -113,10 +113,10 @@ protected:
size_t m_batch_size;
MNistImageLoader m_image_loader;
MNistLabelLoader m_label_loader;
std::int32_t m_items;
int32_t m_items{0};
size_t m_pos{0};
size_t m_epoch{0};
std::unique_ptr<float[]> m_image_floats;
std::unique_ptr<float[]> m_label_floats;
size_t m_image_sample_size;
size_t m_image_sample_size{0};
};
......@@ -76,6 +76,8 @@ cpio::Header cpio::Header::read(istream& stream)
{
throw runtime_error("CPIO magic error");
}
// magic value defined in CPIO spec
rc.magic = 0x71C7;
rc.dev = read_u16(stream, true);
rc.ino = read_u16(stream, true);
rc.mode = read_u16(stream, true);
......@@ -93,6 +95,8 @@ cpio::Header cpio::Header::read(istream& stream)
{
throw runtime_error("CPIO magic error");
}
// magic value defined in CPIO spec
rc.magic = 0x71C7;
rc.dev = read_u16(stream);
rc.ino = read_u16(stream);
rc.mode = read_u16(stream);
......
......@@ -21,6 +21,9 @@
#include <string>
#include <vector>
// The CPIO file format can be found at
// https://www.mkssoftware.com/docs/man4/cpio.4.asp
namespace ngraph
{
namespace cpio
......
......@@ -47,6 +47,8 @@ namespace ngraph
{
}
ResultVector& operator=(const ResultVector&) = default;
ResultVector() {}
};
}
......@@ -97,7 +97,10 @@ pass::MemoryManager::MemoryManager(size_t alignment, bool disable_memory_reuse)
, m_scheme{disable_memory_reuse ? allocation_scheme::NO_REUSE : allocation_scheme::FIRST_FIT}
, m_max_allocated{0}
{
// assert(m_base_offset % m_alignment == 0);
if (m_alignment == 0)
{
throw invalid_argument("Memory alignment must be > 0");
}
m_node_list.emplace_back(numeric_limits<size_t>::max(), block_state::FREE);
}
......
......@@ -148,7 +148,7 @@ void ngraph::pass::ReshapeElimination::construct_dot_transpose_pattern()
NGRAPH_DEBUG << "In callback for construct_dot_transpose_pattern against node = "
<< m.get_match_root()->get_name();
auto mtranspose = std::dynamic_pointer_cast<op::Reshape>(m.get_match_root());
auto mtranspose = std::static_pointer_cast<op::Reshape>(m.get_match_root());
// this also checks the rank
if (mtranspose->get_input_order() != AxisVector{1, 0})
{
......
......@@ -225,6 +225,11 @@ namespace ngraph
}
}
if (n_elements == 0)
{
throw std::runtime_error("AvgPool elements == 0, must be non-zero");
}
out[output_transform.index(out_coord)] = result / n_elements;
}
}
......
......@@ -206,4 +206,5 @@ int main(int argc, char** argv)
cout.imbue(locale(""));
cout << "Total size " << total_size << " in " << total_count << " files\n";
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment