From 55e2326e76e7e1ee2ac0d753198b8f47e1c695ef Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Wed, 3 Jun 2015 12:57:43 +0200 Subject: Add {take,drop}Last{Rows,Columns} --- packages/base/src/Data/Packed/Matrix.hs | 17 +++++++++++++++-- packages/base/src/Numeric/LinearAlgebra/Data.hs | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/base/src/Data/Packed/Matrix.hs b/packages/base/src/Data/Packed/Matrix.hs index 70b9232..3690293 100644 --- a/packages/base/src/Data/Packed/Matrix.hs +++ b/packages/base/src/Data/Packed/Matrix.hs @@ -33,8 +33,9 @@ module Data.Packed.Matrix ( fromRows, toRows, fromColumns, toColumns, fromBlocks, diagBlock, toBlocks, toBlocksEvery, repmat, - flipud, fliprl, - subMatrix, takeRows, dropRows, takeColumns, dropColumns, + flipud, fliprl, subMatrix, + takeRows, takeLastRows, dropRows, dropLastRows, + takeColumns, takeLastColumns, dropColumns, dropLastColumns, extractRows, extractColumns, diagRect, takeDiag, mapMatrix, mapMatrixWithIndex, mapMatrixWithIndexM, mapMatrixWithIndexM_, @@ -253,15 +254,27 @@ r >< c = f where -- | Creates a matrix with the first n rows of another matrix takeRows :: Element t => Int -> Matrix t -> Matrix t takeRows n mt = subMatrix (0,0) (n, cols mt) mt +-- | Creates a matrix with the last n rows of another matrix +takeLastRows :: Element t => Int -> Matrix t -> Matrix t +takeLastRows n mt = subMatrix (rows mt - n, 0) (n, cols mt) mt -- | Creates a copy of a matrix without the first n rows dropRows :: Element t => Int -> Matrix t -> Matrix t dropRows n mt = subMatrix (n,0) (rows mt - n, cols mt) mt +-- | Creates a copy of a matrix without the last n rows +dropLastRows :: Element t => Int -> Matrix t -> Matrix t +dropLastRows n mt = subMatrix (0,0) (rows mt - n, cols mt) mt -- |Creates a matrix with the first n columns of another matrix takeColumns :: Element t => Int -> Matrix t -> Matrix t takeColumns n mt = subMatrix (0,0) (rows mt, n) mt +-- |Creates a matrix with the last n columns of another matrix +takeLastColumns :: Element t => Int -> Matrix t -> Matrix t +takeLastColumns n mt = subMatrix (0, cols mt - n) (rows mt, n) mt -- | Creates a copy of a matrix without the first n columns dropColumns :: Element t => Int -> Matrix t -> Matrix t dropColumns n mt = subMatrix (0,n) (rows mt, cols mt - n) mt +-- | Creates a copy of a matrix without the last n columns +dropLastColumns :: Element t => Int -> Matrix t -> Matrix t +dropLastColumns n mt = subMatrix (0,0) (rows mt, cols mt - n) mt ---------------------------------------------------------------- diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index 9935c15..2161e75 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs @@ -53,8 +53,9 @@ module Numeric.LinearAlgebra.Data( -- * Matrix extraction Extractor(..), (??), - takeRows, dropRows, takeColumns, dropColumns, subMatrix, (?), (¿), fliprl, flipud, - remap, + takeRows, takeLastRows, dropRows, dropLastRows, + takeColumns, takeLastColumns, dropColumns, dropLastColumns, + subMatrix, (?), (¿), fliprl, flipud, remap, -- * Block matrix fromBlocks, (|||), (===), diagBlock, repmat, toBlocks, toBlocksEvery, -- cgit v1.2.3