L2 norm, Do not use Nrm2 (name conflict).
| 831 | |
| 832 | /// L2 norm, Do not use Nrm2 (name conflict). |
| 833 | float Tensor::l2() const { |
| 834 | float nrm = 0.0f; |
| 835 | TYPE_LANG_SWITCH(data_type_, DType, device_->lang(), Lang, { |
| 836 | device_->Exec( |
| 837 | [&nrm, this](Context *ctx) { |
| 838 | Nrm2<DType, Lang>(*this, &nrm, ctx); |
| 839 | }, |
| 840 | {this->block()}, {}, "L1"); |
| 841 | }); |
| 842 | return nrm / Size(); |
| 843 | } |
| 844 | |
| 845 | // DEPRECATED use l2() |
| 846 | float Tensor::L2() const { return l2(); } |