* @require the following code SHOULD work for any bag "b":
* PlainWeightContext<T> ctx;
*
- * ctx.allocate(b);
- * auto span = ctx.weight(b);
+ * auto span = ctx.allocate(b);
* assert(span.data() != nullptr);
* assert(span.size() == bag->size());
*/
- virtual void allocate(const Bag *) = 0;
+ virtual Span<T> allocate(const Bag *) = 0;
// WARN Depercated
virtual void allocate(const KernelObject *) = 0;
PlainWeightContextImpl(PlainWeightContextImpl &&) = delete;
public:
- void allocate(const coco::Bag *bag) override
+ coco::Span<T> allocate(const coco::Bag *bag) override
{
assert(bag != nullptr);
_blob->allocate(bag, sizeof(T));
+ return weight(bag);
}
void allocate(const coco::KernelObject *obj) override
}
// Allocate a weight space
- d->f32()->allocate(bag);
-
- // weight(...) SHOULD return a valid for a valid bag
{
- auto span = d->f32()->weight(bag);
+ auto allocated_span = d->f32()->allocate(bag);
- ASSERT_NE(span.data(), nullptr);
- ASSERT_EQ(span.size(), bag->size());
+ ASSERT_NE(allocated_span.data(), nullptr);
+ ASSERT_EQ(allocated_span.size(), bag->size());
+
+ auto retrieved_span = d->f32()->weight(bag);
+
+ ASSERT_EQ(allocated_span.data(), retrieved_span.data());
+ ASSERT_EQ(allocated_span.size(), retrieved_span.size());
}
}