Floodfilling a texture in HLSL Compute shader

I have a very large texture which I want to fill with values representing "distance in units from a river tile". The texture is already seeded with these origin river points (meaning distance/value = 0 in them).

From these points I want to floodfill outwards, incrementing the value with each step from these origin points.

Doing this on the CPU is no problem using a stack or similiar structure but ideally I want to do this in the middle of a Compute shader execution which runs over the entire texture.

I have read this which sound similiar to what I want to do but it mentions there might be a smarter way to do this with Compute shaders – which is what I am using.

Any ideas on how to solve this on compute shaders?

Evaluate the limit of a subsequence: Compute the limit $ \lim_{n\to\infty} \cos\left( \pi \sqrt{4n^2 + 5n + 1} \right) $ Integer $n$ on Mathematica

I want to compute the limit $ $ \lim \limits_{n\to\infty} \cos\left( \pi \sqrt{4n^2 + 5n + 1} \right) $ $ for integer $ n$ . By completing the square, we can determine that this limit is equal to $ – \tfrac1{\sqrt2} \approx -0.7071 $ .

But if we don’t restrict $ n$ to an integer, then the limit is indeterminate / does not exist. And can be easily found by typing it on WolframAlpha. Or in Mathematica:

However, I do not know how to compute the limit (on Mathematica) with the original constraint that $ n$ must be an integer.

I know that we can plot a graph on Mathematica:

But what is the exact value of the limit?

The graph suggests that the limit is equal to $ -\tfrac1{\sqrt2} $ . However, this doesn’t look like a convincing result because we can’t know that the limit is exactly equal to $ -\tfrac1{\sqrt2} $ .

Question: Is there a way to compute this limit in Mathematica where it spits out a single numerical value (of $ -1/{\sqrt2}$ )?

How to compute a vector V when N points are given and V satisfies given properties

We are given N points P1,P2,…,PN in a 2D plane(All points are distinct and N is as large as 10^5). For each valid i, the coordinates of the point Pi are (xi,yi). Help me to find a vector V = (a, b) ( where |a|, |b| <= 1e9) such that the following holds:

For each i (1 ≤ i ≤ N), let Si= dot(V, G(Pi, Pi+1)). lets assume PN+1=P1. where G(v1, v2) = ((v2(x) – v1(x)), (v2(y) – v1(y)) and dot(V1, V2) denotes dot product of two vectors

How to choose V such that It is possible to find two integers l and r (1 ≤ l ≤ r ≤ N) such that:

Si < 0 if(i <= r and i >= l) and Si > 0 otherwise

(or)

Si > 0 if(i <= r and i >= l) and Si < 0 otherwise

I need to know if there is a way of choosing vector (a, b) to satisfy the above conditions(If the solution is possible)

Compute duration of an event based on consecutive values in another column

I need to compute the sum of durations of multiple events based on consecutive values in another column.

             ts             | w ----------------------------+---  2020-07-27 15:40:04.045+00 | t  2020-07-27 15:41:04.045+00 | t  2020-07-27 15:41:14.045+00 | f  2020-07-27 15:42:14.045+00 | t  2020-07-27 15:43:14.045+00 | t 

The event is considered being active as long as the column w has a consecutive value of true.

The duration of the first event would be 60 seconds. '2020-07-27 15:41:04.045+00' - 2020-07-27 15:40:04.045+00. The second event has the same duration. The sum of both would be 120 seconds.

What would be the best/most performant approach to computing these values? The longest time range we’ll be looking at will probably be half a year involving about 30 million rows.

I wrote a custom aggregate function that computes the duration but it takes about 16 seconds for only 1.5 million rows.

 Aggregate  (cost=444090.03..444090.04 rows=1 width=4) (actual time=16290.826..16290.828 rows=1 loops=1)    ->  Seq Scan on discriminator0  (cost=0.00..57289.03 rows=1547203 width=9) (actual time=0.016..1723.178 rows=1547229 loops=1)  Planning Time: 0.196 ms  JIT:    Functions: 3    Options: Inlining false, Optimization false, Expressions true, Deforming true    Timing: Generation 0.889 ms, Inlining 0.000 ms, Optimization 0.508 ms, Emission 6.472 ms, Total 7.870 ms  Execution Time: 16291.836 ms 

I’m new to SQL and basically just got this working through trial and error, so I’m sure there is room for improvement. Maybe even a whole different approach. Here’s a fiddle with the aggregate function.

I’m not sure if i should include the code because it’s quite long

Given $n$ unique items and an $m^{th}$ normalised value, compute $m^{th}$ permutation without factorial expansion

We know that the number of permutations possible for $ n$ unique items is $ n!$ . We can uniquely label each permutation with a number from $ 0$ to $ (n!-1)$ .

Suppose if $ n=4$ , the possible permutations with their labels are,

0:  1234 1:  1243 2:  1324 3:  1342 4:  1432 5:  1423 6:  2134 7:  2143 8:  2314 9:  2341 10: 2431 11: 2413 12: 3214 13: 3241 14: 3124 15: 3142 16: 3412 17: 3421 18: 4231 19: 4213 20: 4321 21: 4312 22: 4132 23: 4123 

With any well defined labelling scheme, given a number $ m, 0 \leq m < n!$ , we can get back the permutation sequence. Further, these labels can be normalised to be between $ 0$ and $ 1$ . The above labels can be transformed into,

0:       1234 0.0434:  1243 0.0869:  1324 0.1304:  1342 0.1739:  1432 0.2173:  1423 0.2608:  2134 0.3043:  2143 0.3478:  2314 0.3913:  2341 0.4347:  2431 0.4782:  2413 0.5217:  3214 0.5652:  3241 0.6086:  3124 0.6521:  3142 0.6956:  3412 0.7391:  3421 0.7826:  4231 0.8260:  4213 0.8695:  4321 0.9130:  4312 0.9565:  4132 1:       4123 

Now, given $ n$ and $ m^{th}$ normalised label, can we get the $ m^{th}$ permutation while avoiding the expansion of $ n!$ ? For example, in the above set of permutations, if we were given the $ m^{th}$ normalised label to be $ 0.9$ , is it possible to get the closest sequence 4312 as the answer without computing $ 4!$ ?

How to compute the number of occurrences of a cron schedule over a time span?

For example, given a cron schedule such as: 0 * 1 7 6 and a time span, like the next year, can you directly compute the number of times the schedule will fire? It can be brute forced pretty trivially but I’d like to use this to sort a list so I’d rather not just brute force it. It’s pretty easy to compute the trivial cron patterns:

fn('* * * * *', 1 day) -> 60 * 24 fn('0,30 * * * *', 1 day) -> 2 * 24 

It’s easy up until the calendar gets involved with different length months and then you have to worry about days or the week coinciding with days of the month.

Point Subdomain in Google Domains to Google Compute Instance running WordPress

I have installed wordpress (the bitnami multi-site version) to a compute instance from the marketplace. I’ve also recently moved my domain registration to domains.google.com. Everything is working fine with the top-level domain. I also set up a subdomain, wp.mydomain.com in the domains interface pointed to the static external IP I configured for the compute instance running wordpress. When I go to wp.mydomain.com it redirects me to http://.xip.io/.

How do I get this set up so that I stay on wp.mydomain.com instead of going to my ip address as the url?

Write a program that accepts the radius of a circle in the client side of a program and compute the area and perimeter in the server side program

Write a program that accepts the radius of a circle in the client side of a program and compute the area and perimeter in the server side program and return the values to the client program.

// Client   import java.io.*; import java.net.*;  public class Client {             public static void main(String[] args) throws IOException{                 Socket s = new Socket("localhost",1234);                 BufferedReader br;                 PrintStream ps;   String str;                System.out.println("Enter Radius  :");                 br=new BufferedReader(new InputStreamReader(System.in));    ps=new PrintStream(s.getOutputStream());                ps.println(br.readLine());    br=new BufferedReader(new InputStreamReader(s.getInputStream()));                str=br.readLine();                System.out.println("Area of the circle is : "+str);                 br.close();                 ps.close();            } } 
// Server  import java.io.*; import java.net.*;  class Server {       public static void main(String[] args){           try {           ServerSocket ss = new ServerSocket(1234);                  System.out.println("Waiting for Client Request");                   Socket s=ss.accept();                   BufferedReader br;                   PrintStream ps;                   String str;                   br=new BufferedReader(new InputStreamReader(s.getInputStream()));                   str=br.readLine();                   double r=Double.parseDouble(str);                   double area=3.14*r*r;                   ps=new PrintStream(s.getOutputStream());                   ps.println(String.valueOf(area));                   br.close();                   ps.close();                   s.close();                   ss.close();        }           catch(Exception e)           {                       System.out.println(e);           }  } }  

how to add perimeter of a circle

Compute Structure Tensor

As i know, Structure Tensor is:

enter image description here

How i compute $ I_x^2, I_y^2, I_xI_y$ . I used Hadamard product for compute $ I_x^2, I_y^2, I_xI_y$ . But if i use Hadamard product i will get $ det(M) = 0$ . I’m stuck in here for too long. Can anyone explain for me?. Thank you.