From eddc4f57c0c2464f7e80321e2bb80ff4301e29a2 Mon Sep 17 00:00:00 2001 From: sunwen Date: Wed, 24 May 2023 16:34:51 +0800 Subject: [PATCH] Add deleteColumn function. --- src/Function1D.cpp | 28 ++++++++++++++++++++++++++++ src/Function1D.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/Function1D.cpp b/src/Function1D.cpp index 9458452..041b01a 100644 --- a/src/Function1D.cpp +++ b/src/Function1D.cpp @@ -790,6 +790,34 @@ Matrix Aurora::xcorr(const Matrix& aMatrix1, const Matrix& aMatrix2) return Matrix::New(resultData,resultSize); } +Matrix Aurora::deleteColumn(const Matrix& aMatrix, int aColumnIndex) +{ + int rows = aMatrix.getDimSize(0); + int columns = aMatrix.getDimSize(1); + if (aColumnIndex < 0 || aColumnIndex >= columns) + { + return aMatrix; + } + + double* resultData = Aurora::malloc(rows* (columns-1)); + if(aColumnIndex == 0) + { + cblas_dcopy(rows* (columns-1), aMatrix.getData() + rows, 1, resultData, 1); + } + + else if(aColumnIndex == (columns - 1)) + { + cblas_dcopy(rows* (columns-1), aMatrix.getData(), 1, resultData, 1); + } + else + { + cblas_dcopy(rows * aColumnIndex, aMatrix.getData(), 1, resultData, 1); + cblas_dcopy(rows * (columns - aColumnIndex - 1), aMatrix.getData() + rows * (aColumnIndex + 1), 1, resultData + rows * aColumnIndex, 1); + } + + return Matrix::New(resultData, rows, columns-1); +} + Matrix Aurora::reshape(const Matrix& aMatrix, int aRows, int aColumns, int aSlices) { if(aMatrix.isNull() || (aMatrix.getDataSize() != aRows * aColumns * aSlices)) diff --git a/src/Function1D.h b/src/Function1D.h index 75345e4..64042ea 100644 --- a/src/Function1D.h +++ b/src/Function1D.h @@ -86,6 +86,8 @@ namespace Aurora { Matrix reshape(const Matrix& aMatrix, int aRows, int aColumns, int aSlices); Matrix xcorr(const Matrix& aMatrix1, const Matrix& aMatrix2); + + Matrix deleteColumn(const Matrix& aMatrix, int aColumnIndex); /** * 并集 * @param aIa, [C,ia,~] = intersect(A,B)用法中ia的返回值