Skip to main content

# Questions tagged [matrix]

In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries.

690 questions
Filter by
Sorted by
Tagged with
3 votes
3 answers
98 views

### Determinant of matrix Python

This is an addition of my previous question Python matrix class. I've added a determinant function using Laplace expansion to my Matrix class. What I am looking for specifically is how 3x3 matrices ...
• 10.3k
8 votes
5 answers
1k views

### Python matrix class

To prepare for my studies in linear algebra, I've decided to write a simple matrix class. This is the initial program, with functions to find the determinant and decomposition(s) to follow. I wanted ...
• 10.3k
3 votes
1 answer
172 views

### Snail matrix in Java - version III (generalizing)

Once again, in the previous version, Alexander Ivanchenko helped me with his awesome answer. Now, I have improved the toString() and, also, generalized the class ...
• 28.9k
4 votes
1 answer
327 views

### Snail matrix in Java - version II

(This post is the continuation of Snail matrix in Java. Also, this post has an continuation.) As previously, a snail matrix is any square matrix $M_n = \mathbb{N}^{n \times n}$ with cell elements ...
• 28.9k
6 votes
2 answers
873 views

### Snail matrix in Java

(This post has an continuation: Snail matrix in Java - version II.) Inspired by this post, I decided to solve that problem in Java. The idea is to decide on an $n \in \mathbb{N}$, create a square ...
• 28.9k
14 votes
4 answers
2k views

### Create a snail matrix

Statement: Create a script that, given an integer $n$, create a square matrix of dimensions $n \times n$ with the numbers from $1$ to $n^2$, arranged in a snail pattern. Example: ...
• 521
2 votes
0 answers
64 views

### Optimizing even more a C++ matrix class with expression templates using variadic templates

I looked at Bowie Owens' cppcon 2019 talk (the slides can be found here) where he shows how to implement a tridiagonal matrix classes using expression templates but without resorting to the CRTP. (It ...
• 21
4 votes
2 answers
171 views

### Matrix Factorisation class packaging methods for factorisation of explicit & implicit data matrices using Gradient Descent, SGD and ALS

Attached below, and also as this GitHub gist, is code for a Python class I wrote as part of a personal learning/portfolio project on collaborative-filtering recommender systems via matrix ...
8 votes
2 answers
455 views

### Image Rotation and Transpose Functions Implementation in C++

This is a follow-up question for Gaussian Fisheye Image Generator Implementation in C++ and An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. I am trying to ...
• 5,392
5 votes
1 answer
461 views

### High Performance Matrix Multiplication is not very high speed, why?

I would appreciate a review of the following Rust implementation of high performance matrix multiplication. After reviewing available literature, including Anatomy of High Performance Matrix ...
• 119
6 votes
1 answer
304 views

### AVX2 8x8 Float Matrix Multiply in Rust

I'm interested in a fast 8x8 32-bit float matrix multiply in Rust, assuming availability of AVX2. After learning about the AVX2 intrinsics, here is what I came up with: ...
• 119
2 votes
1 answer
77 views

### Transpose matrix in ANSI C

Is there a way to transpose a matrix in ANSI C way much better than this ANSI C code? Can I do transpose in a different and ...
• 183
7 votes
4 answers
1k views

### Matrix Class Implementation

I have written a minimal matrix class. I would like to utilize the latest C++ features, follow best practices, and utilize multi-threading in some of the operations. I have also setup a GoogleTest ...
0 votes
0 answers
14 views

### Creating a matrix or matrices for positioning squares on screen

The following implements a mix of hard-code (manual pick and choose) and abstracted solution for creating and placing some squares on screen using different matrix patterns for positioning. Each ...
• 499
0 votes
0 answers
22 views

### Efficiently computing a batch of results given a batch assignment vector and series of corresponding matrices

I have a 1D tensor of tokens that belong to different batches. The batch sizes here are uneven. Each batch needs to be multiplied with a corresponding weight matrix. My current approach is using a ...
5 votes
2 answers
513 views

### Generic matrix library in Java

I have this repository. The most important source files follow. com.github.coderodde.math.linear.matrix.AbstractMatrix.java: ...
• 28.9k
1 vote
0 answers
191 views

### A CUDA kernel for a matrix product as outer product vectors

To multiply the matrices A and B using the outer product of vectors, we can express each row of matrix A as a row vector and each column of matrix B as a column vector. Then, we can take the outer ...
• 647
6 votes
3 answers
813 views

### C++ Bitwise adjacency matrix implementation

I have tried to implement a bitwise adjacency matrix to represent a graph with a fixed number of vertices. Instead of wastefully representing each connection with an integer, 64 connections are ...
• 163
1 vote
1 answer
106 views

### Binary search of 2D matrix

I have written code as below: ...
• 149
4 votes
2 answers
208 views

### Create classes for matrices, including inheritance

I've been learning C++ on and off, and recently learnt about overloading and templates. I wanted to used these concepts to create classes about matrices using ...
2 votes
1 answer
682 views

### Fast BLAS-like matrix multiplication in Rust

I have some matrix multiplication code I am writing for a linear algebra library I'm working on. The goal is to emulate BLAS (and achieve BLAS-like performance) without using a BLAS library, as my use-...
• 205
6 votes
1 answer
250 views

### C++ Eigen/Mex function to perform two pagewise convolutions on a 3D matrix with a simple kernel

I am trying to accelerate an algorithm where I am computing a 2D variance of many complex matrices stored as pages of a 3D array in Matlab. My implementation uses a Mex function with the C++ Matlab ...
• 357
3 votes
0 answers
90 views

### Speed up a JavaScript function for inverting matrices using Gauss elimination

I wrote this function and I'm interested if it can be sped up by improving the code. The function accepts either column major 1D array or 2D row major array. Maybe there are some obvious JS tricks ...
2 votes
1 answer
114 views

### An implementation of Givens method for diagonalising symmetric matrices

So I tried to create a code which aims to diagonalise symmetric matrices via Givens algorithm. The program only works for symmetric matrices, for we know a symmetric matrix is always diagonalisable, ...
• 121
2 votes
1 answer
526 views

### Matrix-vector multiplication with block-column distribution and MPI_Reduce_scatter

I'm studying MPI and I'm trying to solve the exercise (number 3.5) taken from Pacheco's book Introduction to parallel programming. Essentially the exercise is: Write an MPI program that computes the ...
• 217
4 votes
2 answers
522 views

### Calculate determinant of a matrix using cofactor expansion

I'm using the following two functions to calculate the determinant of A. Would this code be considered to have an asymptotic time complexity of O(n³)? The recursion is throwing me off, but I think ...
3 votes
2 answers
524 views

### 2D Matrix in C++

I wanted to play with a two-dimensional generic data container in C++ and explore different methods of traversals: using closures and iterators. I'd like a review of it. ...
• 1,099
3 votes
1 answer
346 views

### How can I optimize double for loop in matrix

I am trying to optimize a function called place_block. It is meant to give the best row, col coordinate in the matrix to place a given block of row and column size. ...
2 votes
1 answer
96 views

### Multidimensional array in Java

I have this multidimensional array that generalizes vectors and matrices: com.github.coderodde.util.MultidimensionalArray.java: ...
• 28.9k
2 votes
1 answer
121 views

### Matrix led 7x10 with arduino

Good afternoon, a few days ago I finished a personal project of a 7x10 led matrix programmed with the ATMEGA328p microcontroller. To control the matrix I use 2 74HC595 shift registers in cascade in ...
1 vote
1 answer
51 views

### Sparse String Matrix Storage Class C++

Introduction I implemented a class to store a matrix with entries at positions (i,j) that are strings. The matrices I would like to efficiently store in this class have strings as entries and it ...
• 113
6 votes
2 answers
164 views

### N dimensional array index utility

I created the below class to help working with ND Arrays, mapping based on this question. This will help in implementing the code for handling convolutions. How can I improve upon this? Is there ...
• 405
4 votes
3 answers
687 views

### Immutable matrix class with mathematical methods

This was a homework assignment for a data structures course. The goal was to implement a given interface and the assignment was auto-graded by a system that ran some validation tests. Sadly I did not ...
• 197
4 votes
1 answer
421 views

### Need for matrix multiplication speed

I need help to make matrix multiplication in C run as fast as possible. On my AMD Phenom(tm) II X6 1090T, my program multiplies two square singe precision 4096x4096 matrices in about 6.9 seconds. ...
2 votes
3 answers
308 views

### A constexpr, const correct matrix class with compile-time checks

I've expanded, and enhanced my matrix class which uses, aside from dynamic memory for the elements, only 3, const literals. These are rows, cols, and a ptr. The methods are all constexpr and the ...
• 173
2 votes
0 answers
64 views

### S_n covariance calculation function

I am trying to understand the estimator proposed in ["Multidimensional outlier detection and robust estimation using Sn covariance"][1]. I wrote the code in a basic line-by-line form which ...
5 votes
2 answers
374 views

### A matrix class using const members

I've long used a simple matrix class with a vector and rows/cols for the shape. But I've always disliked getters even when necessary to prevent exposing invariants. Then came c++20 which provided the ...
• 173
3 votes
1 answer
409 views

### Cosine similarity calculation in Rust, which is slower than NumPy

I'm running this in release mode. Currently, the following function takes around 6.7 seconds to run on my computer vs 3.7 seconds on Python. I know that Numpy is just calling to C, but I'm trying to ...
0 votes
1 answer
307 views

### Approximation of the multiplicative matrix inverse (linalg.inv ())

I am trying to compute the multiplicative inverse of a large matrix (~ >40,000x40,000). This can be done with e.g. numpy.linalg.inv or ...
• 103
2 votes
1 answer
125 views

### Returning all divisors of a number as a matrix with N X 2 dimensions

I have developed a class structure with methods to return a matrix from a single input array. The objective is to insert the middle value of the array so 2n remains ...
• 23
1 vote
2 answers
69 views

### Validator for 0/1 entries in a matrix

I build a function(A kind of puzzle) that counts from a matrix the number of valid count (Explanation below). The matrix is ​​made up of 0,1. Input- a matrix- list of lists row number column number ...
• 13
5 votes
1 answer
185 views

### С++: Find max element from section in matrix

I'm a newbie in programming. Could you please check my code and give any refactoring ideas, tips, etc... how it can be improved. I wrote a code to perform the following task: Find in randomly filled ...
3 votes
0 answers
63 views

### Accelerating this stacked matrix-matrix product in OpenCL

I am trying to compute a matrix-matrix product of N stacked complex double N x N matrices. For simplicity, I assume N = 512. I have written code in C++ parallelized with OMP and using OpenBLAS for the ...
• 31
3 votes
0 answers
1k views

### Return a 2D matrix from a C++ function in Python: ctypes versus pybind11

I found two ways in which I can use a custom C++ function (returning a 2D matrix) in Python. One approach that uses the Python module ctypes and another that uses the Python module pybind11. Approach ...
• 321
1 vote
1 answer
117 views

### multiply matrices

I wrote a program that calculates the multiplication of two matrices (of compatible dimensions) where each element of the resulting matrix is ​​calculated by a separate thread. Each thread calculates ...
• 449
3 votes
0 answers
114 views

### Two-dimensional arrays in C

I have a bit of trouble with two-dimensional arrays in C. I want to pass such an array to a function accepting a pointer to pointers. I figured no way of really passing the array itself. Furthermore, ...
• 31
0 votes
0 answers
98 views

### Load license plate data from Excel

The code below gets data from an Excel spreadsheet and returns some values; this can take up to 15 minutes because the Excel has more than 15 columns and an average of 20,000 rows. ...
• 11
0 votes
1 answer
49 views

### Function for inserting values in a nxn matrix by changing directions inside of it

I am relatively new to C++ and I had this task to solve, where you are given a number and you have to create an nxn array of integers, where you would have to continually switch directions (right, ...
• 1
0 votes
1 answer
122 views

### Given a matrix return true if it contains the Identity matrix (by recursion)

I need to write recursive static method with given 3 parameters the method will return true if the sub matrix with the size of (int size) which the left corner is mat[x][x] is the identity matrix ...
12 votes
3 answers
2k views

### Matrix implementation

I am trying to implement an optimal and fast running matrix in C++. I need some review of the code and ideas on how to improve the code quality if it shall be. ...