| 67 | } |
| 68 | |
| 69 | std::shared_ptr<Tensor> Tensor::CreateFromReqs(const nvcv::Tensor::Requirements &reqs) |
| 70 | { |
| 71 | std::vector<std::shared_ptr<CacheItem>> vcont = Cache::Instance().fetch(Key{reqs}); |
| 72 | |
| 73 | // None found? |
| 74 | if (vcont.empty()) |
| 75 | { |
| 76 | std::shared_ptr<Tensor> tensor(new Tensor(reqs)); |
| 77 | Cache::Instance().add(*tensor); |
| 78 | return tensor; |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | // Get the first one |
| 83 | auto tensor = std::static_pointer_cast<Tensor>(vcont[0]); |
| 84 | NVCV_ASSERT(tensor->dtype() == reqs.dtype); |
| 85 | return tensor; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | namespace { |
| 90 | |