# Compiling matrix multiplication using a list of matrices

I'm trying to create compiled function which computes a list of Gamma matrices named GammaM and multiply them within the compiled code.

cf = Compile[{{n, _Integer}}, Module[{M, GammaM}, M = Table[0.0 + 0.0 I, {i, 1, n}, {j, 1, n}]; GammaM = Table[gamma[i, n], {i, 1, n}]; M = GammaM[].GammaM[]; M], CompilationTarget -> "C", RuntimeOptions -> "Speed"]; 


However I am unable to get a compiled function; the error I get is:

Compile::cplist: GammaM[] should be a tensor of type Integer, Real, or Complex; evaluation will use the uncompiled function. >>

Compile::cset: "Variable M of type !({\"_Complex\", 2}) encountered in assignment of type {!(\"_Integer\", 0)}."

The function gamma[i,n] is defined recursively and returns a complex matrix:

s3 = {{1.0, 0}, {0.0, -1.0}}; s2 = {{0.0, -I}, {I, 0.0}}; s1 = {{0.0, 1.0}, {1.0, 0.0}}; gamma[mu_, N_] :=  If[mu <= N - 2,   -KroneckerProduct[gamma[mu, N - 2] , s3],   If[mu == N - 1, KroneckerProduct[IdentityMatrix[2^((N - 2)/2)], s2],     KroneckerProduct[IdentityMatrix[2^((N - 2)/2)], s1]]   ] 


Any idea what I may be doing wrong will be appreciated.

Replay

Category: functions Time: 2016-07-28 Views: 0

## Related post

• Performing matrix multiplications with a list 2013-12-10

I have a question in regards to PseudoInverse. I have $A$, an $n\times 2$ matrix, and when I want to compute $(A^T A)^{-1}A$, by using PseudoInverse, Mathematica is able to give me an answer for this. However If I want to compute $(A^T A)^{-1}$, I am

• Why did matrix multiplication using python's numpy become so slow after upgrading ubuntu from 12.04 to 14.04? 2014-08-15

I used to have Ubuntu 12.04 and recently did a fresh installation of Ubuntu 14.04. The stuff I'm working on involves multiplications of big matrices (~2000 X 2000), for which I'm using numpy. The problem I'm having is that now the calculations are ta

• Sparse matrix multiplication for billion by billion matrices 2014-12-31

I have to do multiplication of two billion by billion sparse matrices (on a CPU), hence any help or hints in optimizing the below given code would be extremely useful. Note: I am only showing the code to compute number of non-zeros in the output matr

• Matrix Multiplication using divide and conquer approach 2016-01-25

I am a beginner in programming and just learned new concepts and started writing code for matrix multiplication but I got confused in pointers and others so I am uploading my code here in seek of guidelines. #include <stdio.h> #include <stdlib.h&

• Optimizing a simple calculus using a list of matrices - Repeated dot product between a vector and a list of matrices 2013-05-10

I want to make the following operation : $$\begin{bmatrix} \dot q_1\\\dot q_2 \end{bmatrix} + \begin{bmatrix} \begin{bmatrix} q_1 & q_2 \end{bmatrix} \mathbf A_1 \begin{bmatrix} q_1\\ q_2 \end{bmatrix} \\ \begin{bmatrix} q_1 & q_2 \end{bmatrix} \ • How to simplify symbolic matrix multiplication using the associativity of scalar multiplication? 2014-10-01 My input is (2A).(3B). Is there a way to get 6A.B? All I could get back from Mathematica was (2A).(3B) itself. I'd like to make use of the associativity of scalar multiplication in symbolic dot products. How can I get there? --------------Solutions-- • Warnings in matrix multiplication using functions 2016-02-03 I'm getting three errors: Assignment makes integer from pointer without a cast Passing argument 1 of read from incompatible pointer type Expected int * (*) but argument is of type int (*) Here is the code: #include <stdio.h> #include < • Sparse matrix matrix multiplication using SUMMA 2016-02-04 I'm a beginner to SpGEMM(General Sparse Matrix-Matrix Multiplication). I want to know how SUMMA(Scalable Universal Matrix Multiplication Algorithm) for sparse matrices works. There are a few papers like this and this that I'm trying to read to unders • Why is MATLAB so fast in matrix multiplication? 2011-05-19 I am making some benchmarks with CUDA, C++, C#, and Java, and using MATLAB for verification and matrix generation. But when I multiply with MATLAB, 2048x2048 and even bigger matrices are almost instantly multiplied. 1024x1024 2048x2048 4096x4096 ---- • how to display result of MRJob Sparse Matrix Multiplication 2016-07-24 I am a beginner in the world Python mrjob, I have started to implement the algorithm of Sparse Matrix Multiplication using mrjob and I did not get compile error when-when I run the code on my windows prompt by this command : python matrix.py < matA.t • Java 8 Stream Matrix Multiplication 10X Slower Than For Loop? 2016-01-27 I have created a module that performs matrix multiplication using streams. It can be found here: https://github.com/firefly-math/firefly-math-linear-real/ I've attempted to write a benchmark in order to compare the stream loop implementation to the c • OpenCL matrix multiplication on Mathematica 2015-01-14 I took a matrix multiplication written using OpenCL from here: src = "__kernel void floatMatrixMult(__global float * MResp, __global float * M1, __global float * M2, __global int * q) { // Vector element index int i = get_global_id(0); int j = get_gl • How to use Compile for accelerating matrix multiplications? 2013-03-11 I am trying to find the inverse of the matrix A m = n = 500; SeedRandom; A = RandomReal[10, {m, n}]; iteratively using the following matrix iterative method$$X_{k+1}=X_k(2I-AX_k) when $X_0=\frac{2}{\sigma_1^2+\sigma_r^2}A^*$, with $\sigm • Which algorithm is performant for matrix multiplication of 4x4 matrices of affine transformations 2015-12-26 I am wondering what is a good, performant algorithm for matrix multiplication of 4x4 matrices. I am implementing some affine transformations and I am aware that there are several algorithms for efficient matrix multiplication, like Strassen. But are • How to form a block-diagonal Matrix from a list of matrices? 2013-02-18 For example, like this: I know join[...] works, but it is a bit troublesome for multiple matrices. I also tried DiagonalMatrix[...], but DiagonalMatrix can only form a matrix from a list of elements. --------------Solutions------------- a = {{1, 2, 3 • Error using Solve on Matrix Multiplication 2013-08-16 I am trying to make a function the will find that value of$x$in the following equation:$x.a=b$all values of$x, a, b$are matrices. The dimensions of$x$are unknown, but$a$and$b$have the same dimensions of$n*8$where$n\$ depends on the matr

• Elementwise dot multiplication for lists of matrices 2016-07-11

I have lists of matrices and want to do element-wise matrix multiplication. Is there an easy way to do this that I've missed? e.g: {A, B, C}.{X, Y, Z} = {A.X, B.Y, C.Z} where A, B, C, X, Y, and Z are all matrices. --------------Solutions-------------

• Multiple bibliographies (reference lists) using embedded bibliography database 2011-09-28

I would like to have multiple bibliographies (reference lists) as described in Airminded · Multiple bibliographies in LaTeX (TeX Frequently Asked Questions -- question label "multbib"). However, I'd like to use with a single .tex file, which wou

• using Mathematica's matrix multiplication in C++ 2012-10-31

Is there any way that I can utilize Mathematica's matrix multiplication in a C++ program? I'm making a 3D graphics engine (for class) in C++ and I would really like to use Mathematica for all of my math. Thank you. I have Mathematica 8, and Visual St