C++ STL for accessing equally spaced non contiguous elements of a vector - c++-standard-library

I have defined a 1D vector for storing matrix values and want to extract all the elements which happen to lie in a column of a matrix. I know we can write a template but is there exists any STL for such task. Thanks

Related

Perform matrix algebra without specifying Matrix elements, but using the matrix objects as elemental

Is there any functionality in Mathematica that let's the user work directly with matrix objects (potentially of non-defined size), eg. solving a matrix equality for the matrix object without necessarily specifying all elements of the matrix. What I want to do is to manipulate matrix equations while using the matrix objects as elemental, so eg solving a matrix equation for a matrix object (and not for all its elements explicitly.
As a simple example of what I mean: say I'd want to check if two matrix inequalities are equivalent eg. and let's say there is a function matrix[A] that declares that A may be of dimension >2.
matrix[A]
matrix[B]
matrix[C]
In principle that would have to be like an element function, like:
element[A, Reals[dim=n]]
Then there should be a function MatrixSolve[] such that
In: Assuming[A is square and det[A]==0, MatrixSolve[A*B==C,B]]
Out:B->A^(-1)*C.
Or for example:
Q:=A*B *so Q must also be a matrix*
In: Assuming[again the necessary stuff like A square..., Q*A^(-1)===B]]
Out: True
I have not found any such functionalities in the documentation (or in the search function on SE) and was wondering if there is a way to implement this and, if not, why such features would not exist.

Most efficient way to pair two sets of objects based on closest distance?

Assuming I have the above two sets of objects (of class A and B)... how can I efficiently pair the objects in set A with the closest unique object from set B where that object is not closer to any other set A object.
The objects in both sets use 2D vectors to represent their positions.
One scheme for arranging 2D lists by proximity involves Peano encoding the entries, which basically amounts to a perfect bit shuffle of each (x,y) coordinate of n-bits into a single interleaved 2n-bit value. (I first learned of this scheme reading about US Census tract mapping and TIGER data ca. 1984.)
Ex: (x,y)=(0x4,0xB)=(0_1_0_0,_1_1_0_1),
then Peano(x,y) is 01110001 = 71.
This bit shuffle results in a list of numbers that, when sorted, represent 2D proximity along a single number line. It is easy to show that for Peano values A,B,C that A < B < C implies B lies in a 2-D rectangle bounded by A and C.
Just a thought, and may not be what you need at all. Good luck.

Armadillo c++: Is there a specific way for creating efficiently triangular or symmetric matrix

I am using armadillo mostly for symmetric and triangular matrices. I wanted to be efficient in terms of memory storage. However, it seems there is no other way than to create a new mat and fill with zeros(for triangular) or with duplicates(for symmetric) the lower/upper part of the matrix.
Is there a more efficient way of using triangular/symmetric matrices using Armadillo?
Thanks,
Antoine
There is no specific support for triangular or banded matrices in Armadillo. However, since version 3.4 support for sparse matrices has gradually been added. Depending on what Armadillo functions you need, and the sparsity of your matrix, you might gain from using SpMat<type> which implements the compressed sparse column (CSC) format. For each nonzero value in your matrix the CSC format stores the row index along with the value so you would likely not save much memory for a triangular matrix. A banded diagonal matrix should however consume significantly less memory.
symmatu()/symmatl() and trimatu()/trimatl()
may be what you are looking for:
http://arma.sourceforge.net/docs.html

Arbitrary size matrices in maxima

I want to do some calculations with matrices of arbitrary size. Simple example - take two matrices NxM and MxK, with arbitrary elements, and see element of product as sum.
But i cant find a way to do such symbolic calculations without specifying matrix size as integer.
matrix() want integer, makelist() want integer.
Is there a way to do things like this in maxima? Or any CAS?
Unfortunately, Maxima does not know about arbitrary-size matrices, and I don't see an easy way to implement it.
The only way that I see is to define a new kind of expression, and provide simplification rules for operations on them. E.g. (and this is just a sketch of a possible solution): use defstruct to define a structure comprising size and a formula for a typical element, and define a simplification rule for "." (noncommutative multiplication) which creates a new expression with a typical element which is a summation.

Why permutation matrices are used to swap rows of an array?

What are the advantages of using a permutation matrix to swap rows? Why one would create a permutation matrix and then apply a matrix multiplication, is it easier and more efficient than just swapping rows with a for loop?
Permutation matrices are a useful mathematical abstraction, because they allow analysis using the normal rules of matrix algebra, without having to introduce another type of operation.
In software, good implementations do not store a permutation matrix as a full matrix, they store a permutation array and they apply it directly (without a full matrix multiplication).
Depending on the sizes of the matrices and the operations and access patterns involved, it may be cheaper not to apply the permutation to the data in memory at all, but just to use it as an extra indirection. So, when you request (P * M)(i,j), where P is a permutation matrix and M is some other matrix that you are permuting, the data need not be re-arranged at all, but rather the element access operation will look up the permuted row when you access the element.
The first thing that comes into my mind is the issue called "spatial locality". Caching technologies assume that if a memory location is accessed, it is probable to access the nearby locations of the memory. In some programming languages, elements in rows are neighbors whereas elements in columns are neighbors in others. It depends on the implementation. I guess permutation matrices are designed to solve this problem, since optimization of matrix multiplication is one of the problems that algorithms academia mostly works on improving. Simple loop structure will not be able to make use of cache technologies to improve performance.

Resources