From 677d43fa8f55a8aa52e6bd9d1884e2797650fd65 Mon Sep 17 00:00:00 2001 From: Liam Barry Date: Thu, 3 Aug 2023 18:21:58 +0100 Subject: MLECO-4260: Replace raw C++ pointers with smart variants Model: Added std::unique_ptr qualifier to Model.cc member and used make_unique when creating interpreter object Removed custom destructor and un-necessary memory cleanup following failed allocation DataStructures: Refactored array 2d to use a std::vector under the hood. This should preserve desired attributes including contiguous memory while removing the need for custom destructor. Original size function renamed to dimSize to avoid confusion with vector.size() Accompanying changes made to preprocessing and ASR tests. AppContext: Replaced use of raw pointers in AppContext.hpp. Previously a std::map including IAttribute pointers required individual deallocation as they were allocated using new. Signed-off-by: Liam Barry Change-Id: I1a34dce5dea6ecf4883a9ada3a20f827eb6e6d6b --- .../api/use_case/asr/include/Wav2LetterPreprocess.hpp | 6 +++--- .../api/use_case/asr/src/Wav2LetterPreprocess.cc | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source/application/api/use_case') diff --git a/source/application/api/use_case/asr/include/Wav2LetterPreprocess.hpp b/source/application/api/use_case/asr/include/Wav2LetterPreprocess.hpp index c1fec72..2f29fb0 100644 --- a/source/application/api/use_case/asr/include/Wav2LetterPreprocess.hpp +++ b/source/application/api/use_case/asr/include/Wav2LetterPreprocess.hpp @@ -1,6 +1,6 @@ /* - * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates - * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -124,7 +124,7 @@ namespace app { const int quantOffset) { /* Check the output size will fit everything. */ - if (outputBufSz < (this->m_mfccBuf.size(0) * 3 * sizeof(T))) { + if (outputBufSz < (this->m_mfccBuf.dimSize(0) * 3 * sizeof(T))) { printf_err("Tensor size too small for features\n"); return false; } diff --git a/source/application/api/use_case/asr/src/Wav2LetterPreprocess.cc b/source/application/api/use_case/asr/src/Wav2LetterPreprocess.cc index 99e769c..1794894 100644 --- a/source/application/api/use_case/asr/src/Wav2LetterPreprocess.cc +++ b/source/application/api/use_case/asr/src/Wav2LetterPreprocess.cc @@ -1,6 +1,6 @@ /* - * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates - * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ namespace app { mfccWindow, mfccWindow + this->m_mfccWindowLen); auto mfcc = this->m_mfcc.MfccCompute(mfccAudioData); - for (size_t i = 0; i < this->m_mfccBuf.size(0); ++i) { + for (size_t i = 0; i < this->m_mfccBuf.dimSize(0); ++i) { this->m_mfccBuf(i, mfccBufIdx) = mfcc[i]; } ++mfccBufIdx; @@ -126,16 +126,16 @@ namespace app { -0.03679654, -0.04329004, -0.03679654, -0.01731602, 0.01515152, 0.06060606}; - if (delta1.size(0) == 0 || delta2.size(0) != delta1.size(0) || - mfcc.size(0) == 0 || mfcc.size(1) == 0) { + if (delta1.dimSize(0) == 0 || delta2.dimSize(0) != delta1.dimSize(0) || + mfcc.dimSize(0) == 0 || mfcc.dimSize(1) == 0) { return false; } /* Get the middle index; coeff vec len should always be odd. */ const size_t coeffLen = delta1Coeffs.size(); const size_t fMidIdx = (coeffLen - 1)/2; - const size_t numFeatures = mfcc.size(0); - const size_t numFeatVectors = mfcc.size(1); + const size_t numFeatures = mfcc.dimSize(0); + const size_t numFeatVectors = mfcc.dimSize(1); /* Iterate through features in MFCC vector. */ for (size_t i = 0; i < numFeatures; ++i) { @@ -169,7 +169,7 @@ namespace app { void AsrPreProcess::StandardizeVecF32(Array2d& vec) { - auto mean = math::MathUtils::MeanF32(vec.begin(), vec.totalSize()); + auto mean = math::MathUtils::MeanF32(vec.begin(), vec.totalSize()); auto stddev = math::MathUtils::StdDevF32(vec.begin(), vec.totalSize(), mean); debug("Mean: %f, Stddev: %f\n", mean, stddev); -- cgit v1.2.1