Linear congruence calculation - modulo

I need to calculate x having the following formula:
222143612600812046617511287447004107467 = (124238402538911150679814605267508298634 * x + 177062111784129036182002943089208846590) % 240282366920938434633746074317682114559.
% : Is the modulus.
How can I do it?
Thanks in advance for your kind help.
Regards.

Related

Need a vectorized solution in pytorch

I'm doing an experiment using face images in PyTorch framework. The input x is the given face image of size 5 * 5 (height * width) and there are 192 channels.
Objective: To obtain patches of x of patch_size(given as argument).
I have obtained the required result with the help of two for loops. But I want a better-vectorized solution so that the computation cost will be very less than using two for loops.
Used: PyTorch 0.4.1, (12 GB) Nvidia TitanX GPU.
The following is my implementation using two for loops
def extractpatches( x, patch_size): # x is bsx192x5x5
patches = x.unfold( 2, patch_size , 1).unfold(3,patch_size,1)
bs,c,pi,pj, _, _ = patches.size() #bs,192,
cnt = 0
p = torch.empty((bs,pi*pj,c,patch_size,patch_size)).to(device)
s = torch.empty((bs,pi*pj, c*patch_size*patch_size)).to(device)
//Want a vectorized method instead of two for loops below
for i in range(pi):
for j in range(pj):
p[:,cnt,:,:,:] = patches[:,:,i,j,:,:]
s[:,cnt,:] = p[:,cnt,:,:,:].view(-1,c*patch_size*patch_size)
cnt = cnt+1
return s
Thanks for your help in advance.
I think you can try this as following. I used some parts of your code for my experiment and it worked for me. Here l and f are the lists of tensor patches
l = [patches[:,:,int(i/pi),i%pi,:,:] for i in range(pi * pi)]
f = [l[i].contiguous().view(-1,c*patch_size*patch_size) for i in range(pi * pi)]
You can verify the above code using toy input values.
Thanks.

Image Enhancement by adding 2 images in Octave

Hello!
I would like to process an image like all steps in this picture in Octave.
I wonder how I can add to images together to get a picture like (c) of (f)?
My code so far is:
I = imread('343a.tif');
subplot(2,2,1);imshow(I);title('Original Image');
I = im2double (I);
H = fspecial('log', 11,1.5);
Laplacian = imfilter(I,H,'replicate');
subplot(2,2,2);imshow(Laplacian, []);title('Laplacian Image');
H = fspecial('sobel');
Edge = imfilter(I,H,'replicate');
subplot(2,2,4);imshow(Edge);title('Sobel Image');
Would be very thankful for help or suggestions! :)
Best regards!
You add images using the + operator and multiply them using the .* operator:
c = a + b;
f = c .* e;
Yes, it's really that simple! :)

Solving a complex recurrence relation

How to solve the below recurrence relation?
T(n) = 2T(root(n)) + logn/loglogn if n > 4
T(n) = 1 if n <= 4
Preferably by master theorem otherwise by any method.
I know Master Theorem fails,But is there any extension for these type of problems?
Can you guide me any stuff for solving complex relation like above?
I think this should work :
if n = 2^m and T(2^m) = s(m) then
logn = m , loglogn = logm ;
s(m) = 2*s(m/2) + m/logm ;
now solving the above equation is our problem
now you can not use the master theorem for solving this , so you have to use other methods like expanding this equation by writing s(m/2) and s(m/4) and then you might solve this problem , and after doing that you change your parameters to n again .
According to me
if n = 2^m and T(2^m) = s(m) then
logn = m , loglogn = logm ;
s(m) = 2*s(m/2) + m/logm ;

Teechart Axis Item Modification of X axis Item

Can anyone let me know how I can modify the X-Axis Point Value Pro-grammatically.
Thanks
Akshay
If you want change the X values in runtime you can do something as next:
For i = 0 To TChart1.Series.Count
For j = 0 To TChart1.Series(i).Count
TChart1.Series(i).XValues(j) = j + 3
Next j
Next i
Could you tell us if previous help you?
I hope will helps.
Thanks,

Why do i need a special case for lanczos(0)?

i have implemented a simple image resampler in OpenCL which uses the Lanczos function.
Lanczos is defined by:
Written in C:
inline
float lanczos(float x, float a) {
if( x > fabs(a) ) return 0.0f;
if( x == 0.0f ) return 1.0f;
float pix = pi * x;
return sinc(pix)*sinc(pix/a);
}
Why is there a special case for 0? When i pass 0 to the formular it returns 1. But if i don't include the check for x == 0 it doesn't work.
Could someone shed some light for me?
Florian
Paul already answered, but in case OP wants to know why 0 is special case =>
1) x->0, sin(x)/x = 0/0 and this is indeterminate form.
2) One way to solve this problem is to expand sin(x)/x into Taylor series about zero point, by doing this we get:
x2 x4 x6 x8
1 - ----- + ----- - ------ + ----------- + ...
6 120 5040 362880
3) By substituting 0 into x we see that series converges to 1.
Oh man ... i have been looking at the lanczos function for hours ... and haven't noticed that sinc actually is:
sinc -> sin(x)/x
so the special case for 0 is to prevent a division by zero ... plain and simple ...

Resources