| 598 | // ---------------------------------------------------------------------------------------- |
| 599 | |
| 600 | class alias_tensor |
| 601 | { |
| 602 | public: |
| 603 | |
| 604 | alias_tensor ( |
| 605 | ) {} |
| 606 | |
| 607 | alias_tensor ( |
| 608 | long long n_, long long k_ = 1, long long nr_ = 1, long long nc_ = 1 |
| 609 | ) |
| 610 | { |
| 611 | DLIB_ASSERT( n_ >= 0 && k_ >= 0 && nr_ >= 0 && nc_ >= 0); |
| 612 | |
| 613 | inst.m_n = n_; |
| 614 | inst.m_k = k_; |
| 615 | inst.m_nr = nr_; |
| 616 | inst.m_nc = nc_; |
| 617 | inst.m_size = n_*k_*nr_*nc_; |
| 618 | } |
| 619 | |
| 620 | long long num_samples( |
| 621 | ) const { return inst.m_n; } |
| 622 | |
| 623 | long long k( |
| 624 | ) const { return inst.m_k; } |
| 625 | |
| 626 | long long nr( |
| 627 | ) const { return inst.m_nr; } |
| 628 | |
| 629 | long long nc( |
| 630 | ) const { return inst.m_nc; } |
| 631 | |
| 632 | size_t size( |
| 633 | ) const { return inst.m_size; } |
| 634 | |
| 635 | alias_tensor_instance operator() ( |
| 636 | tensor& t, |
| 637 | size_t offset = 0 |
| 638 | ) const |
| 639 | { |
| 640 | DLIB_CASSERT(offset+size() <= t.size(), |
| 641 | "offset: "<<offset <<"\n"<< |
| 642 | "size(): "<<size() <<"\n"<< |
| 643 | "t.size(): "<<t.size() <<"\n"); |
| 644 | |
| 645 | #ifdef DLIB_USE_CUDA |
| 646 | if (cuda::use_cuda() && !inst.cudnn_descriptor) |
| 647 | { |
| 648 | inst.cudnn_descriptor = std::make_shared<cuda::tensor_descriptor>(); |
| 649 | inst.cudnn_descriptor->set_size(inst.m_n, inst.m_k, inst.m_nr, inst.m_nc); |
| 650 | } |
| 651 | #endif |
| 652 | inst.data_instance = &t.data(); |
| 653 | inst._annotation = &t.annotation(); |
| 654 | // Note that t might already be an aliasing tensor so we need to take that into |
| 655 | // account. |
| 656 | inst.data_offset = t.get_alias_offset()+offset; |
| 657 | return inst; |
no outgoing calls
no test coverage detected