* @brief Constructor. Creates an empty Blob object with the specified precision.
* @param tensorDesc Defines the layout and dims of the blob
*/
- explicit Blob(TensorDesc tensorDesc): tensorDesc(tensorDesc) {}
+ explicit Blob(const TensorDesc &tensorDesc): tensorDesc(tensorDesc) {}
/**
* @deprecated Please use TensorDesc for Blob initialization
* @return Total number of elements (a product of all the dimensions)
*/
size_t Resize(const SizeVector &dims, Layout layout = Layout::ANY) noexcept {
- bool bret = deallocate();
-
- if (layout != Layout::ANY) {
- tensorDesc = TensorDesc(tensorDesc.getPrecision(), SizeVector(dims.rbegin(), dims.rend()), layout);
- } else {
- tensorDesc.setDims(SizeVector(dims.rbegin(), dims.rend()));
- }
- if (!bret) {
- allocate();
+ try {
+ bool bret = deallocate();
+
+ if (layout != Layout::ANY) {
+ tensorDesc = TensorDesc(tensorDesc.getPrecision(), SizeVector(dims.rbegin(), dims.rend()), layout);
+ } else {
+ tensorDesc.setDims(SizeVector(dims.rbegin(), dims.rend()));
+ }
+ if (!bret) {
+ allocate();
+ }
+ return product(tensorDesc.getDims());
+ } catch (...) {
+ return 0;
}
- return product(tensorDesc.getDims());
}
/**
* @return The total number of elements (a product of all the dims)
*/
size_t Reshape(const SizeVector &dims, Layout layout = Layout::ANY) noexcept {
- if (product(tensorDesc.getDims()) != product(dims)) {
+ try {
+ if (product(tensorDesc.getDims()) != product(dims)) {
+ return 0;
+ }
+
+ if (layout != Layout::ANY) {
+ tensorDesc = TensorDesc(tensorDesc.getPrecision(), SizeVector(dims.rbegin(), dims.rend()), layout);
+ } else {
+ tensorDesc.setDims(SizeVector(dims.rbegin(), dims.rend()));
+ }
+ return product(tensorDesc.getDims());
+ } catch (...) {
return 0;
}
-
- if (layout != Layout::ANY) {
- tensorDesc = TensorDesc(tensorDesc.getPrecision(), SizeVector(dims.rbegin(), dims.rend()), layout);
- } else {
- tensorDesc.setDims(SizeVector(dims.rbegin(), dims.rend()));
- }
- return product(tensorDesc.getDims());
}
/**