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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 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 ...
cpicanco's user avatar
  • 499
0 votes
0 answers
18 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 ...
sidnb13's user avatar
4 votes
2 answers
432 views

Generic matrix library in Java

I have this repository. The most important source files follow. com.github.coderodde.math.linear.matrix.AbstractMatrix.java: ...
coderodde's user avatar
  • 27k
1 vote
0 answers
89 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 ...
user366312's user avatar
6 votes
3 answers
740 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 ...
Paradox's user avatar
  • 163
1 vote
1 answer
86 views

Binary search of 2D matrix

I have written code as below: ...
Szyszka947's user avatar
4 votes
2 answers
147 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 ...
eccentricOrange's user avatar
2 votes
1 answer
296 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-...
JS4137's user avatar
  • 123
6 votes
1 answer
166 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 ...
drakon101's user avatar
  • 181
3 votes
0 answers
60 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 ...
user9163823's user avatar
2 votes
1 answer
75 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, ...
Henry's user avatar
  • 121
2 votes
1 answer
269 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 ...
bobinthebox's user avatar
4 votes
2 answers
460 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 ...
user8393252's user avatar
1 vote
0 answers
65 views

Spell checker using levenshtein minimum distance

I implemented a simple spell checker. Basically I have to user input an incorrect sentence or a word, then a number N, and then N correct words each on new line. The program has to output "...
Raluca123's user avatar
0 votes
0 answers
43 views

Build co-occurence matrix for each row - python

I have 1 dataset (text1) plus a list of words (list A) I wish to build a co-occurrence matrix for each row of words in dataset and words in list A in text1, there are around 10000 rows, each row there ...
Cora's user avatar
  • 1
3 votes
2 answers
388 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. ...
nowox's user avatar
  • 1,015
3 votes
1 answer
318 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. ...
Oreofe Solarin's user avatar
2 votes
1 answer
91 views

Multidimensional array in Java

I have this multidimensional array that generalizes vectors and matrices: com.github.coderodde.util.MultidimensionalArray.java: ...
coderodde's user avatar
  • 27k
2 votes
1 answer
110 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 ...
Lucio Mazzini's user avatar
1 vote
1 answer
41 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 ...
jan0155's user avatar
  • 113
6 votes
2 answers
134 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 ...
Dávid Tóth's user avatar
4 votes
3 answers
564 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 ...
Nifim's user avatar
  • 197
0 votes
0 answers
65 views

Three-dimensional DCT implementation for GPU computation in Matlab

This is a follow-up question for Three-dimensional DCT spatial frequency components illustration and Parallel 3D Discrete Cosine Transformation Implementation in Matlab. I am trying to perform three-...
JimmyHu's user avatar
  • 3,974
4 votes
1 answer
307 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. ...
Stand with Gaza's user avatar
2 votes
3 answers
240 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 ...
doug's user avatar
  • 173
2 votes
0 answers
63 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 ...
user263375's user avatar
5 votes
2 answers
307 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 ...
doug's user avatar
  • 173
2 votes
0 answers
295 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 ...
Karl Hernandez's user avatar
0 votes
1 answer
246 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 ...
Stücke's user avatar
  • 103
2 votes
1 answer
119 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 ...
Dollar X's user avatar
1 vote
2 answers
63 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 ...
yaeB's user avatar
  • 13
5 votes
1 answer
167 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 ...
Ruthenian's user avatar
3 votes
0 answers
62 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 ...
sqrt6's user avatar
  • 31
3 votes
0 answers
789 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 ...
CafféSospeso's user avatar
1 vote
1 answer
113 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 ...
Mark's user avatar
  • 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, ...
Luqus's user avatar
  • 31
0 votes
0 answers
86 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. ...
ralphgz's user avatar
  • 11
0 votes
1 answer
48 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, ...
Nik's user avatar
  • 1
0 votes
1 answer
100 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 ...
anton5450's user avatar
12 votes
3 answers
1k 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. ...
Hrant Nurijanyan's user avatar
4 votes
1 answer
182 views

Minimize memory allocations while calculating the matrix representation of a Hamiltonian

I am writing a script using Julia (calling my functions from the REPL) to compute the matrix representation of certain Hamiltonian. After I run my script I see that the memory allocations count is ...
Leo Flores's user avatar
5 votes
2 answers
311 views

Rotating a matrix clockwise by one element without any libraries (Python 3.9)

The question is as follows: Rotate an NxN matrix clockwise by one element and display the new matrix. For example, if ...
st0n3r's user avatar
  • 73
3 votes
1 answer
110 views

Python: Create submatrices from long/narrow table and save in HDF5

Hello dear StackExchange Community, I have written a small program which is doing the following. In short: it reads in a table in narrow format creates submatrices from it saves it in HDF5 format ...
dry-leaf's user avatar
4 votes
3 answers
227 views

Barebones C++ Matrix class

I have implemented a C++ Matrix class using std::vector and a number for rows/cols. The implementation works decently from the QA I've done. I have implemented a Vector class as a derived class but I'...
LOLcat_enjoyer's user avatar
2 votes
0 answers
210 views

2d Grid - Iterating by Rows / Cells - Take #3

Edited with a bit more unit tests. Preface Following my second version: 2d Grid - Iterating by Rows / Cells - Take #2 I believe that I am now satisfied with this new version below. There is still one ...
Shigoto Shoujin's user avatar
2 votes
2 answers
164 views

2d Grid - Iterating by Rows / Cells - Take #2

Preface Following my first POC version: 2d Grid - Iterating by Rows / Cells I have gained much more understanding, and present A new version A new version is ready, with templates and an attempt at ...
Shigoto Shoujin's user avatar
6 votes
2 answers
981 views

Writing a C++ Matrix class

I am refreshing my C++ programming skills, and I'm currently reading the book C++ 17 by Ivor Horton. The idea is to code some naive implementations of numerical algorithms (Root finding, solving a ...
Quasar's user avatar
  • 335
1 vote
1 answer
289 views

Calculate distances between two multi-dimensional arrays in Matlab

In question "Dictionary based non-local mean implementation in Matlab", the Manhattan distance between two three-dimensional structures can be calculated by ...
JimmyHu's user avatar
  • 3,974
1 vote
0 answers
88 views

Dictionary based non-local mean implementation in Matlab

Given a dictionary including multiple X-Y pairs where X, Y are both three dimensional structure. dictionaryBasedNonlocalMean function return a ...
JimmyHu's user avatar
  • 3,974
4 votes
4 answers
903 views

Make surrounding elements zero in a matrix, when you find a zero value

Please can you suggest a better / Optimized logic or code for the question. It has been asked that when you find a zero value in a matrix, make that element the sum of its upper, lower ,left, right ...
Aryaman 's user avatar

1
2 3 4 5
14