BackProp Fixes
This commit is contained in:
parent
7e17b32a81
commit
90ce453b60
11 changed files with 189 additions and 106 deletions
|
|
@ -182,10 +182,26 @@ namespace tp {
|
|||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * tMinSize);
|
||||
}
|
||||
|
||||
explicit Buffer(ualni size) :
|
||||
mSize(size),
|
||||
mLoad(0) {
|
||||
Buffer(const InitialierList<tType>& input) {
|
||||
mSize = 0;
|
||||
for (const auto& val : input) {
|
||||
mSize++;
|
||||
}
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * mSize);
|
||||
mLoad = 0;
|
||||
for (const auto& val : input) {
|
||||
mBuff[mLoad] = val;
|
||||
mLoad++;
|
||||
}
|
||||
}
|
||||
|
||||
explicit Buffer(ualni size) {
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * size);
|
||||
mSize = size;
|
||||
mLoad = size;
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
new (mBuff + i) tType();
|
||||
}
|
||||
}
|
||||
|
||||
Buffer(const Buffer& in) :
|
||||
|
|
@ -274,11 +290,25 @@ namespace tp {
|
|||
}
|
||||
|
||||
public:
|
||||
Buffer& operator=(const tp::InitialierList<tType>& init) {
|
||||
Buffer& operator=(const tp::InitialierList<tType>& input) {
|
||||
// TODO : optimize
|
||||
for (auto arg : init) {
|
||||
append(arg);
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
mBuff[i].~tType();
|
||||
}
|
||||
mAllocator.deallocate(mBuff);
|
||||
|
||||
mSize = 0;
|
||||
for (const auto& val : input) {
|
||||
mSize++;
|
||||
}
|
||||
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * mSize);
|
||||
mLoad = 0;
|
||||
for (const auto& val : input) {
|
||||
mBuff[mLoad] = val;
|
||||
mLoad++;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -320,10 +350,10 @@ namespace tp {
|
|||
}
|
||||
|
||||
void reserve(ualni aSize) {
|
||||
if (aSize == mSize) return;
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
mBuff[i].~tType();
|
||||
}
|
||||
mAllocator.deallocate(mBuff);
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * aSize);
|
||||
mSize = aSize;
|
||||
mLoad = aSize;
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ TEST_DEF_STATIC(Simple1) {
|
|||
|
||||
TEST_DEF_STATIC(Simple2) {
|
||||
Buffer<TestClass, HeapAlloc> buff(size);
|
||||
TEST(buff.size() == 0);
|
||||
TEST(buff.size() == size);
|
||||
for (auto i : Range(size * 10))
|
||||
buff.append(TestClass(i));
|
||||
TEST(buff.size() == size * 10);
|
||||
TEST(buff.size() == size + size * 10);
|
||||
while (buff.size())
|
||||
buff.pop();
|
||||
TEST(buff.size() == 0);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ class TestClass {
|
|||
tp::ualni val1;
|
||||
|
||||
public:
|
||||
TestClass() { val1 = 0; }
|
||||
|
||||
explicit TestClass(tp::ualni val) :
|
||||
val1(val) {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue