=============Element-wise operations====================================
| 813 | |
| 814 | // =============Element-wise operations==================================== |
| 815 | float Tensor::l1() const { |
| 816 | float nrm = 0.0f; |
| 817 | TYPE_LANG_SWITCH(data_type_, DType, device_->lang(), Lang, { |
| 818 | device_->Exec( |
| 819 | [&nrm, this](Context *ctx) { |
| 820 | DType ret = DType(0); |
| 821 | Asum<DType, Lang>(*this, &ret, ctx); |
| 822 | nrm = TypeCast<DType, float>(ret); |
| 823 | }, |
| 824 | {this->block()}, {}, "l1"); |
| 825 | }); |
| 826 | return nrm / Size(); |
| 827 | } |
| 828 | |
| 829 | // DEPRECATED use l1() |
| 830 | float Tensor::L1() const { return l1(); } |