1 #ifndef __SPARSELIST_HPP__ 2 #define __SPARSELIST_HPP__ 5 #include "utils/PVLog.hpp" 24 void fromBuffer(
const Buffer<T> &source, T zeroVal) {
27 for (
int y = 0; y < source.getHeight(); ++y) {
28 for (
int x = 0; x < source.getWidth(); ++x) {
29 for (
int f = 0; f < source.getFeatures(); ++f) {
30 T val = source.at(x, y, f);
32 mList.push_back({index, val});
40 void toBuffer(
Buffer<T> &dest, T zeroVal) {
41 int numElements = dest.getTotalElements();
42 vector<T> newData(numElements, zeroVal);
43 for (
auto entry : mList) {
45 entry.index > numElements,
46 "Buffer is not large enough to hold index %d / %d\n",
49 newData.at(entry.index) = entry.value;
51 dest.set(newData, dest.getWidth(), dest.getHeight(), dest.getFeatures());
54 void addEntry(
Entry entry) { mList.push_back(entry); }
57 for (
auto entry : mList) {
62 void set(
const vector<Entry> &values) { mList = values; }
64 vector<Entry> getContents() {
return mList; }