3 #include <matrix-types.h>
4 #include <snowboy-debug.h>
14 float* m_data{
nullptr};
17 float* begin()
const noexcept {
return m_data; }
18 float* end()
const noexcept {
return m_data + m_size; }
19 size_t size()
const noexcept {
return m_size; }
20 float* data()
const noexcept {
return m_data; }
21 float& operator[](
size_t index)
const noexcept {
22 SNOWBOY_ASSERT(index < m_size);
25 float& operator()(
size_t index)
const noexcept {
26 SNOWBOY_ASSERT(index < m_size);
29 bool empty()
const noexcept {
return size() == 0; }
31 void Add(
float x) noexcept;
32 void AddDiagMat2(
float,
const MatrixBase&, MatrixTransposeType,
float) noexcept;
33 void AddMatVec(
float alpha,
const MatrixBase& a, MatrixTransposeType trans,
const VectorBase& x,
float beta) noexcept;
34 void AddVec(
float,
const VectorBase&) noexcept;
35 void AddVec2(
float,
const VectorBase&) noexcept;
36 void ApplyFloor(
float) noexcept;
37 void ApplyLog() noexcept;
38 void ApplyPow(
float) noexcept;
39 float ApplySoftmax() noexcept;
40 void CopyColsFromMat(
const MatrixBase&) noexcept;
42 void CopyRowsFromMat(
const MatrixBase&) noexcept;
45 float EuclideanDistance(
const VectorBase&)
const;
46 bool IsZero(
float cutoff)
const noexcept;
47 float Max()
const noexcept;
48 float Max(
int* e)
const noexcept;
49 float Min()
const noexcept;
50 float Min(
int* e)
const noexcept;
52 float Norm(
float)
const noexcept;
53 SubVector Range(
size_t offset,
size_t size)
const noexcept;
54 void Scale(
float) noexcept;
55 void Set(
float) noexcept;
56 void SetRandomGaussian();
57 void SetRandomUniform();
58 float Sum()
const noexcept;
59 void Write(
bool, std::ostream*)
const;
61 bool HasNan()
const noexcept;
62 bool HasInfinity()
const noexcept;
71 Resize(other.size(), MatrixResizeType::kUndefined);
75 Resize(other.m_size, MatrixResizeType::kUndefined);
79 m_size = other.m_size;
81 m_data = other.m_data;
82 other.m_data =
nullptr;
87 size_t capacity()
const noexcept {
return m_cap; }
88 void Resize(
size_t size, MatrixResizeType resize = MatrixResizeType::kSetZero);
98 void Read(
bool,
bool, std::istream*);
99 void Read(
bool, std::istream*);
100 void Swap(
Vector* other) noexcept;
101 void RemoveElement(
size_t index) noexcept;
103 static void PrintAllocStats(std::ostream&);
104 static void ResetAllocStats();
111 m_data = other.m_data;
112 m_size = other.m_size;
125 Resize(other.size(), MatrixResizeType::kUndefined);
130 Resize(other.m_size, MatrixResizeType::kUndefined);
133 FixedVector(
size_t size, MatrixResizeType resize = MatrixResizeType::kSetZero) {
135 Resize(size, resize);
138 constexpr
size_t capacity()
const noexcept {
return N; }
139 void Resize(
size_t size, MatrixResizeType resize = MatrixResizeType::kSetZero) {
140 if (size > N)
throw std::invalid_argument(
"new size exceeds fixed capacity");
142 if (resize == MatrixResizeType::kSetZero) Set(0.0f);
146 Resize(other.m_size, MatrixResizeType::kUndefined);
151 Resize(other.size(), MatrixResizeType::kUndefined);
Definition: vector-wrapper.h:116
Definition: vector-wrapper.h:106
Definition: vector-wrapper.h:11
Definition: vector-wrapper.h:64
Definition: matrix-wrapper.h:11