matrix-multiplication

how to use tf operations in keras models

陌路散爱 提交于 2019-12-11 05:25:48
问题 I am trying to us tensorflow operations within a keras model and I am quite confused about the mechanism and what Lambda layers do to tf tensors. So this works: a = keras.layers.Input(shape=[1, 2], dtype='float', name='a') s= keras.layers.Lambda(lambda x: tf.transpose(tf.transpose(x)))(a) model = keras.models.Model(inputs=a, outputs=s) but this does not work: a = keras.layers.Input(shape=[1, 2], dtype='float', name='a') s = tf.transpose(tf.transpose(a)) s = keras.layers.Lambda(lambda x: x)(s)

3D Elementwise Matrix Multiplication in CUDA?

烈酒焚心 提交于 2019-12-11 03:29:01
问题 I have a 2D Matrix Multiplication program using the following kernel: __global__ void multKernel(int *a, int *b, int *c, int N) { int column = threadIdx.x + blockDim.x * blockIdx.x; int row = threadIdx.y + blockDim.y * blockIdx.y; int index = row * N + column; if(column < N && row < N) { c[index] = a[index] * b[index]; } } Now, I'd like to create a 3D matrix multiplication kernel, but I'm having trouble finding examples of how do create one (also, I'm terrible at reading mathematical formulae

Precision loss when solving nonlinear equations with long integer parameters by mpreal.h

这一生的挚爱 提交于 2019-12-11 02:31:32
问题 I have a numerical computation problem which requires solving nonlinear equations (with long integers) in multiple precision. I tried an MPFR C++ wrapper from this link by Pavel: mpfr C++ wrapper by Pavel The wrapper can be downloaded here: mpfrc++-3.5.6.zip However, there is precision loss in the solution when handling very long integers (equations with small integers worked well). I tried three options as in the sample code below: to use the code immediately does not work with "constant

Multiplying two 2D arrays

风格不统一 提交于 2019-12-11 02:09:00
问题 so I am having an issue multiplying two 2d arrays together. I am pretty sure that matrixA and matrixB are being stored properly, they are displayed properly when the program is ran. When I try to multiply the 2 arrays together I am getting a long string of a lot of 1's and 0's. Any idea on what could be the problem? Here is my code: #include <stdio.h> #include<conio.h> #include <stdlib.h> #include <iostream> /* Routines called. */ int loadMatrixFromFile(char *filename, int *data); void

numpy.einsum for Julia?

断了今生、忘了曾经 提交于 2019-12-11 00:03:37
问题 I'm wondering how to get functionality similar to numpy.einsum in Julia. Specifically, I have a 3rd order tensor that I'm looking to multiply by a 2nd tensor (matrix), contracting both of the dimensions to yield a 1st order tensor (vector). Currently, I'm using PyCall so that I can use the numpy.einsum function like so: using PyCall @pyimport numpy as np a = rand(5,4,3) b = rand(5,4) c = np.einsum("ijk,ij", a,b) size(c) == (3,) It feels kind of silly to rely on calling python in order to do

Multiplying a small matrix by a big matrix

↘锁芯ラ 提交于 2019-12-10 20:55:17
问题 I'm trying to multiply every element in a small matrix (let's say 2x2) with every position in a big matrix (let's say 4x4), element by element. So I want: 1 2 3 4 1 0 3 0 1 0 1 2 3 4 0 0 0 0 0 0 'x' 1 2 3 4 = 1 0 3 0 1 2 3 4 0 0 0 0 The small matrix is applied as many times as it fits, and the multiplication is element by element. I've tried a bunch of loops, but that doesn't feel right in MATLAB, there must be prettier ways of doing it? 回答1: One possibility is to use repmat to repeat the

MATLAB: element-wise multiplication of two matrices over one index?

假如想象 提交于 2019-12-10 19:49:37
问题 I'm trying to figure out if there's a native way of obtaining a certain kind of element-wise product of two matrices in Matlab. The product that I'm looking for takes two matrices, A and B say, and returns there product C , whose elements are given by C(i,j,k) = A(i,j)*B(j,k) Naturally, the number of columns of A is assumed be the same as the number of rows of B . Right now, I'm using the following for-loop (assuming size(A,2)==size(B,1) is true). First, I initialize C : C = zeros(size(A,1),

Multithreading--Why one thread is doing all of the work?

五迷三道 提交于 2019-12-10 19:04:02
问题 I am multiplying two matrices using two threads (however, the program is written to scale up as well, so I could possibly use three, four, etc threads instead). Each thread calculates/does the work for one row (or column) of the final matrix. If one thread is doing work on a row, the other one(s) should not work on that row. It/they should move on to the next available row. First of all, I am not certain if the way I implemented the problem is correct. If you can see a better way, please let

using matrices algebra to manipulate strings: is it feasible?

限于喜欢 提交于 2019-12-10 18:38:49
问题 I'm trying to use matrix algebra with the purpose of manipulating strings. This means being able to multiple matrix-like structures using concatenation and pasting of string or of arrays of strings. I previously tried to implement the thing on R, but it was not possible as matrices can have only one dimensional entries. I hope to be enough language-agnostic and abstract, but I'll use R-like code for sake of clarity. I should make explicit that I don't require real matrices, but matrix-like

Handling Symbolic Matrices in R as in Matlab

丶灬走出姿态 提交于 2019-12-10 18:05:23
问题 I am failing to appropriately work with a Symbolic Matrix in R, with both rSymPy and Ryacas. In Matlab this is easy. I am looking for suggestions how to do this in R and get a similar output as in Matlab . To do this in Matlab I need the 'Symbolic Toolbox'. In this example I wish to generate a Symbolic transition probability matrix "P", which is say 5 x 5, and has elements P11, P12,..., P55. I then want to use this matrix for multiplication (with itself and other matrices) and potentially