multiplication

How to avoid multiplication in pointer arithmetic?

我们两清 提交于 2019-12-01 03:01:30
问题 If I write int main(int argc, char *argv[]) { int temp[50][3]; return &temp[argc] - &temp[0]; } and compile it with Visual C++, I get back: 009360D0 55 push ebp 009360D1 8B EC mov ebp,esp 009360D3 8B 45 08 mov eax,dword ptr [argc] 009360D6 8D 0C 40 lea ecx,[eax+eax*2] 009360D9 B8 AB AA AA 2A mov eax,2AAAAAABh 009360DE C1 E1 02 shl ecx,2 009360E1 F7 E9 imul ecx 009360E3 D1 FA sar edx,1 009360E5 8B C2 mov eax,edx 009360E7 C1 E8 1F shr eax,1Fh 009360EA 03 C2 add eax,edx 009360EC 5D pop ebp

Kronecker product between two tensors

删除回忆录丶 提交于 2019-12-01 01:10:43
I have two tensor: x is 2-by-2-by-3, y is also 2-by-2-by-3. Define each frontal slice of tensor is x1 x2 x3,y1,y2,y3. xi or yi are 2-by-2 matrix. How can I do kronecker product between x and y in matlab? What I want to get is kron(x1,y1),kron(x2,y2),kron(x3,y3) in matlab simultaneously without any looping. This could be one approach - %// Pre-processing part [m,n,r] = size(x) %// Get size N = m*n %// number of elements in one 3D slice %// ------------- PART 1: Get indices for each 3D slice %// Get the first mxm block of kron-corresponding indices and then add to %// each such block for the

How to implement multiplication without using multiplication operator in .NET [closed]

。_饼干妹妹 提交于 2019-11-30 23:49:20
I want to implement multiplication of two integer numbers without using multiplication operator, in .NET public uint MultiplyNumbers(uint x, uint y) { } Any idea! I'm assuming this is homework... otherwise there's no sane reason you'd want to do it. Therefore I'll just give hints... If performance isn't terribly important, consider that x * 3 = x + x + x ... think about using a loop. If performance is important but you know that one of the numbers will be small, loop on the smaller number. If performance is important and both numbers could be large, you'll need to think about bit-twiddling.

how to calculate (a times b) divided by c only using 32-bit integer types even if a times b would not fit such a type

安稳与你 提交于 2019-11-30 22:29:49
Consider the following as a reference implementation: /* calculates (a * b) / c */ uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c) { uint64_t x = a; x = x * b; x = x / c; return x; } I am interested in an implementation (in C or pseudocode) that does not require a 64-bit integer type. I started sketching an implementation that outlines like this: /* calculates (a * b) / c */ uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c) { uint32_t d1, d2, d1d2; d1 = (1 << 10); d2 = (1 << 10); d1d2 = (1 << 20); /* d1 * d2 */ return ((a / d1) * (b /d2)) / (c / d1d2); } But the difficulty is to pick

Signed & unsigned integer multiplication

☆樱花仙子☆ 提交于 2019-11-30 22:26:12
In fixed point math I use a lot of 16bit signals and perform multiplication with 32bit intermediate results. For example: int16_t a = 16384; //-1.0q14 or 1.0*2^14 int16_t b = -24576; // -1.4q14 or 1.4*2^14 int16_t c; // result will be q14 c = (int16_t)(((int32_t)a * (int32_t)b)>>14); Lets say a is a q14 number then c with have the same scaling as b. This is fine and works for unsigned as well as signed arithmetic. The question is: What happens if I were to mix types? For example if I know the multiplier "a" is always going to range from 0.0 to 1.0, it is tempting to make it an unsigned int q15

Basic matrix multiplication in OpenCV for Android

╄→гoц情女王★ 提交于 2019-11-30 20:23:29
I'm probably being incredibly stupid here but I'm having trouble doing some basicaly Mat multiplication using OpenCV for Android. I have two Mat's both of the same type, CV_64F mat1 has size: 3 rows, 3 cols mat2 has size: 3 rows, 1 cols I want to multiply them to give the product mat3 of size 3 rows, 1 cols. I've tried using: Mat mat3 = new Mat(3, 1, CvType.CV_64F); Core.multiply(mat1, mat2, mat3); But I get an error: CvException [org.opencv.core.CvException:/home/andreyk/OpenCV2/trunk/opencv_2.3.1.b2/modules/core/src/arithm.cpp:1253: error: (-209) The operation is neither 'array op array'

Kronecker product between two tensors

ぃ、小莉子 提交于 2019-11-30 19:27:36
问题 I have two tensor: x is 2-by-2-by-3, y is also 2-by-2-by-3. Define each frontal slice of tensor is x1 x2 x3,y1,y2,y3. xi or yi are 2-by-2 matrix. How can I do kronecker product between x and y in matlab? What I want to get is kron(x1,y1),kron(x2,y2),kron(x3,y3) in matlab simultaneously without any looping. 回答1: This could be one approach - %// Pre-processing part [m,n,r] = size(x) %// Get size N = m*n %// number of elements in one 3D slice %// ------------- PART 1: Get indices for each 3D

Quickly square a double

夙愿已清 提交于 2019-11-30 16:31:01
问题 I am looking for the fastest way to square a double ( double d ). So far I came up with two approaches: 1. d*d 2. Math.pow(d, 2) To test the performance I set up three test cases, in each I generate random numbers using the same seed for the three cases and just calculate the squared number in a loop 100 000 000 times. In the first test case numbers are generated using random.nextDouble() , in the second case using random.nextDouble()*Double.MAX_VALUE and in the third one using random

Python, numpy, einsum multiply a stack of matrices

回眸只為那壹抹淺笑 提交于 2019-11-30 12:36:08
For performance reasons, I'm curious if there is a way to multiply a stack of a stack of matrices . I have a 4-D array (500, 201, 2, 2). Its basically a 500 length stack of (201,2,2) matrices where for each of the 500, I want to multiply the adjacent matrices using einsum and get another (201,2,2) matrix. I am only doing matrix multiplication on the [2x2] matrices at the end. Since my explanation is already heading off the rails, I'll just show what I'm doing now, and also the 'reduce' equivalent and why its not helpful (because its the same speed computationally). Preferably this would be a

how to do two complement multiplication and division of integers?

放肆的年华 提交于 2019-11-30 12:07:04
问题 I have read this post on binary multiplication using two complement. but it is not very clear to me. Even I have difficulty understanding the wiki article on this. I want to know how to go about calculating multiplications of negative numbers: eg: -1 with -7 should give 7. A 4-bit, 2's complement of -1 is : 1111 A 4-bit, 2's complement of -7 is : 1001 some step-wise way of calculating the multiplication will be helpful. No article I came across talks about division. How to approach this? 回答1: