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.

71 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5 votes
0 answers
103 views

4×4 cofactor in SSE

The cofactor of a 4×4 matrix can be used to convert a "regular geometry" matrix into the matrix that transforms the normals. It's an alternative to the common inverse-transpose pattern. In this post I ...
user555045's user avatar
  • 9,994
5 votes
0 answers
395 views

Creation of matrix with specific attempts at the end

What I want to do is build a Slay-the-Spire-like Map. As you can see in the following image, the map is splitted in ISteps and ...
Maxime Recuerda's user avatar
5 votes
0 answers
509 views

Cache conscious SIMD matrix multiply of unsigned integers

The goal of the code review by order of importance (i.e. What I hope to hear from you): I've verified correctness using a straightforward matrix multiply function though I am open to those who want ...
fpes's user avatar
  • 151
5 votes
0 answers
169 views

Kernel density regression in Julia

Here is a naive implementation of a kernel density regression algorithm in Julia. The code works, but there is quite a bit of room for improvement though. First, there is not an optimal bandwidth ...
Vincent's user avatar
  • 561
4 votes
0 answers
143 views

LeetCode 1632: Rank Transform of a Matrix in Rust

This is a problem-solving code for LeetCode 1632. Given an \$m \times n\$ matrix, return a new matrix answer where ...
prehistoricpenguin's user avatar
4 votes
0 answers
115 views

Naive Solver of Matrix with Periodic Boundary Conditions Feedback

I am creating an \$O(n)\$ solver for an \$Ax = b\$ system where \$A\$ has the form \$ A = \begin{pmatrix} a_1 & b_1 &&&d_{u}\\ c_1 & a_2 & b_2\\& \ddots & \ddots &...
vlovero's user avatar
  • 101
4 votes
0 answers
257 views

How to make a matrix factorization system recommander faster?

I used and modified a matrix factorization function for a system recommender from quuxlabs.com. It works well for small sized input but when we get to large matrix it takes too much time. I was ...
Revolucion for Monica's user avatar
4 votes
0 answers
331 views

Generalized NumPy reshape function to imitate einsum syntax

I often perform a lot of reshape(), transpose() or squeeze() operations on ...
Lukas's user avatar
  • 206
4 votes
0 answers
116 views

Project Euler #2 in Go

I just learned Go (yesterday in fact) and today I made this solution to Project Euler #2. The problem is to sum the even Fibonacci numbers. My program uses the matrix representation of the linear ...
hacatu's user avatar
  • 462
4 votes
0 answers
61 views

Basic declarative style to rotate and crop an image array

I wrote a couple of basic Clojure functions (practicing a declarative style) and I was looking to get some feedback on them. You can see all the code here. Is there anything I could improve on to ...
mmbb's user avatar
  • 193
3 votes
0 answers
89 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
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 ...
sqrt6's user avatar
  • 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 ...
CafféSospeso's user avatar
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
3 votes
0 answers
150 views

Rcpp sparse CSC matrix class

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
zdebruine's user avatar
  • 153
3 votes
0 answers
99 views

Was this an idiomatic and prudent way to extend R's matrix multiplication syntax? Should I have used R's object system?

After reading one too many Lisp books, I decided to try extending R's syntax. My goal was to implement repeated matrix multiplication in a way such that I could write ...
J. Mini's user avatar
  • 127
3 votes
0 answers
349 views

Improving Performance of Numba For-Loop and Matrix Multiplication for Time Integration Solver

I am writing some code that performs a simple time-history integration solver (Newmark method for structural dynamics) and I looking for some suggestions in how I can improve the performance of my ...
Ptrickono's user avatar
3 votes
0 answers
34 views

How would you convert this code to best take advantage of CSS transform for panning/zooming?

I am using react-flow-chart for a job project, but it doesn't implement zoom, and I would like to take the reigns and try applying it myself. I took a linear ...
Mehdi Saffar's user avatar
3 votes
0 answers
1k views

Python program to solve matrix-chain multiplication

An assignment at school required me to write a Python program for this task: In the matrix-chain multiplication problem, we are given a sequence of matrices ...
Justin's user avatar
  • 2,489
3 votes
0 answers
191 views

Lowest cost path through elements in a matrix

I've developed a program in Python that calculates the lowest possible costing path between two points in a matrix, including the values contained in the start and finish cells. The code is below. ...
MrJoe's user avatar
  • 2,053
3 votes
0 answers
416 views

Calculate huge Fibonacci Numbers in C++ using GMP and boost::multiprecision

Problem Statement Calculate the exact value of the n-th Fibonacci number, say the one-billionth. Algorithm The algorithm is based on the idea that Fibonacci numbers can be represented as 2x2 ...
olooney's user avatar
  • 131
3 votes
0 answers
47 views

Deriving incremental feature representations for bit flips

Given a boolean 3D matrix and a set of actions specifying bit flips at certain positions, a set of resulting matrices can be obtained, one matrix for each action, as if executing each bit flip ...
tsorn's user avatar
  • 285
3 votes
0 answers
240 views

Haskell Laplace determinant

I have written a code in Haskell that calculates the determinant of a matrix using the laplace expansion. As I have just started learning Haskell, I would like some opinions on how well (structured) ...
Fabian Schneider's user avatar
3 votes
0 answers
4k views

Matrix multiplication project using multithreading in java

Below is my code of matrix multiplication in Java. It has both implementation of matrix multiplication- one without multi-threading and another one using multi-threading. For multi-threading ...
rani rawat's user avatar
3 votes
0 answers
65 views

Calculating OpenGL view matrices

I'd like a little help here calculating the view matrix for OpenGL based on the lookat type function: ...
user1610950's user avatar
3 votes
0 answers
181 views

Computing pairwise distance covariances for a symmetric matrix

I wrote a non-vectorized, non-parallel wrapper function for computing the pairwise distance covariances (Wikipedia) (original paper) in a data frame: ...
shadowtalker's user avatar
2 votes
0 answers
63 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 ...
11house's user avatar
  • 21
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 ...
user263375's user avatar
2 votes
0 answers
223 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
0 answers
53 views

C++20 Ndim matrix, computing eigenvalues and eigenvectors

My C++20 N-dimensional matrix project now supports basic linear algebra operations: https://github.com/frozenca/Ndim-Matrix Today I want to get some reviews on computing eigenvalues and eigenvectors. ...
frozenca's user avatar
  • 1,703
2 votes
0 answers
52 views

Converting list of sequences into one-hot vectors

I have an array of dim 1000 x 150 where I have 1000 strings each of length 150. And the strings only contain ATCGN (these are ...
user avatar
2 votes
0 answers
110 views

Cosine Similarity Matrix Loss Function

I am currently implementing this paper on generalised end to end loss: https://arxiv.org/pdf/1710.10467.pdf A batch of N speakers and M utterances are fed to the model which outputs an embedding ...
Oliver Holland's user avatar
2 votes
0 answers
145 views

Givens QR decomposition in R or C++: poor performance (or lack thereof) for rectangular matrices

My own Givens-based QR decomposition function in R (pseudocode from Politecnico of Turin's math department) is the following: ...
Antonio Piemontese's user avatar
2 votes
0 answers
127 views

JDS - Cuda implementation

I am trying to implement the Jagged Diagonal Storage code in Cuda for Sparse Matrix - Vector multiplication. The code I wrote is as follows but I'm not sure about it: ...
Perl Del Rey's user avatar
2 votes
0 answers
83 views

Compute angular distances between data points in a matrix

I am having a hard time speeding up a function that I use to compute angular distances between data points in a matrix. More precisely, I want to compute $$\sum_{r=1}^n|\pi - \arccos\left(\frac{(X_{i}-...
user17645's user avatar
2 votes
0 answers
2k views

Fast matrix transpose

I would like to improve the naive matrix transpose algorithm by using a cache friendly algorithm. So far there are 4 variants. Iterate over the source matrix: ...
Catree's user avatar
  • 121
2 votes
0 answers
40 views

Spiral printing elements of a matrix

As I'm learning elixir, I wrote some code for printing elements in the spiral of a matrix(2D array). I was wondering if there is any room for improvements with regards to its performance or ...
Surya's user avatar
  • 121
2 votes
0 answers
34 views

MinMax product for large matrices

I created this program which runs with no error, but I'd like to have some comments if it is possible to optimize it, since I need to run the program with N = 3200. ...
Sigur's user avatar
  • 275
2 votes
0 answers
250 views

C++ matrix operations

Not much formal education in programming. One year in school. We did C++ classes for most user defined objects. I've written a few different class variations for matrices but wonder about how useful ...
Chemistpp's user avatar
  • 227
2 votes
0 answers
125 views

Dijkstra in JavaScript

I am writing the solution of Dijkstra's algorithm in JS. This is what has happened so far. I need to make it so that the choice of nodes is by recursion. Tell me how to do this better. ...
Aletagro's user avatar
2 votes
0 answers
110 views

CUDA kernel to compare matrix entries, weighted with a pattern

I wonder if it's possible to optimize this code in CUDA. Could I get any hints how to? Equivalent algorithm runs faster in Matlab for me, but there I'm doing matrix operations. Compution I'm not ...
yourstruly's user avatar
2 votes
0 answers
3k views

MIPS Assembly Program to access elements in the 4x4 matrix, row or column-major oder

This MIPS Assembly program will make you access the elements in the 4x4 matrix in either row or column-major order i.e. accessing all elements row by row or column by column. Output is posted below ...
Leonard's user avatar
  • 131
2 votes
0 answers
417 views

Matrix inverse by elimination

Because I had trouble in finding a reliable source on the internet for the matrix inverse algorithm using Gaussian elimination, I wrote one myself. Matrix.h ...
I am an Idiot.'s user avatar
2 votes
0 answers
507 views

class for Block Compressed sparse Row storage

Here my Block Compressed sparse Row storage class, I have some doubt about the constructor that use a std::vector<std::vector> for store the initializer list ...
Drudox lebowsky's user avatar
2 votes
0 answers
263 views

Small calibration script for xinput

I've written this as an alternative to xinput_calibrator when it wasn't working for me. It's my first crack at several things: ...
Reinderien's user avatar
  • 62.5k
2 votes
0 answers
2k views

Recursive matrix multiplication in C++

I'm working through CLRS, and I'm hoping to get some pointers (ha!) on my C++ coding style and the way I've implemented recursive matrix multiplication. The code right now seems a bit complex for ...
Matt's user avatar
  • 339
2 votes
0 answers
2k views

HackerRank - Matrix Rotation

Problem statement Given a matrix (up to 300 × 300), rotate each element R steps anti-clockwise along concentric rectangular paths (R up to 109). The algorithm is rated as hard on HackerRank. On ...
Jianmin Chen's user avatar
  • 2,396
2 votes
0 answers
112 views

Online Principal Component Analysis with spectral bounds

I have question regarding online PCA implemented in the paper. I am interested in the Algorithm 2. I am not certain if there is a bug in my code can someone confirm if my code is correct? The ...
Waqas's user avatar
  • 121
2 votes
0 answers
554 views

Find minimum distance in matrix

Challenge URL: http://acm.scu.edu.cn/soj/problem.action?id=3330 Windy has a matrix A with size N*M which only contains 0 or 1. The distance between Axy and Apq is: |x-p| + |y-q| Can you help Windy ...
ljy's user avatar
  • 21
2 votes
0 answers
71 views

Analysis of TV station preferences for various demographic groups

I have a notebook here which details my code and may be more legible. I worked on a project that flattens a table that initially looked like this (this is table1): ...
mburke05's user avatar
  • 641