What color format, depth buffer should I use in a RenderTexture for WebGL screen output in Unity? Is NPOT ok? MipMaps?

Today I learned about a technique for forcing uniform resolution in a Unity WebGL build, as described here in the answer by DMGregory. Yay! I’m experimenting with implementing this technique on a large ongoing project and am seeing promising results so far. However, I am a little bit baffled as what color format I should choose for the RenderTexture. It seems to me it would be most efficient to choose something without an Alpha channel, but that’s just a hunch. There are seemingly zillions of formats (not all supported on WebGL): RenderText Inpector

partial list of RenderTexture color formats

With the build-test cycle on WebGL being slow as it is, I’m looking for some insight as to how to choose the most efficient color format. And what about the depth buffer setting?

Finally, does it matter if the RenderTexture is NPOT? Again my hunch is to have it be as few pixels as possible, even if NPOT, but ¯_(ツ)_/¯ Same goes for MipMaps — seems like wasted memory space but I’m guessing here.

Edit: I found this, which does explain the nomenclature at least, but I’m still unsure how I should be thinking about this.

Part specification is longer then depth of objekt

I want to solve the Funkton lns50 all the Values are Part 1 of an List

ri = ri[[1]] rj = rj[[1]] kij = kij[[1]] yi = yi[[1]] phm = phm[[1]] ylm = ylm[[1]] plm = plm[[1]] yhm = yhm[[1]] si = si[[1]] ss = ss[[1]] sf = sf[[1]] mi = mi[[1]] tsi = tsi[[1]] \[Delta]i = \[Delta]i[[1]] dri = dri[[1]] drj = drj[[1]] lij = lij[[1]]\[CapitalDelta] lns50 = Sqrt[(    (Out[12] \[CapitalDelta]ri[[1]])^2 + (Out[13] \[CapitalDelta]rj[[         1]])^2     + (Out[14] \[CapitalDelta]kij[[1]])^2 + (Out[         15] \[CapitalDelta]yi[[1]])^2     + (Out[16] \[CapitalDelta]phm[[1]])^2 + (Out[         17] \[CapitalDelta]ylm[[1]])^2     + (Out[18] \[CapitalDelta]plm[[1]])^2 + (Out[         19] \[CapitalDelta]yhm[[1]])^2     + (Out[20] \[CapitalDelta]si[[1]])^2 + (Out[         21] \[CapitalDelta]mi[[1]])^2     + (Out[22] \[CapitalDelta]tsi[[1]])^2 + (Out[         23] \[CapitalDelta]\[Delta]i[[1]])^2     + (Out[24] \[CapitalDelta]lij[[1]])^2)] 

So i only need to change the "Position" of List by changing [[1]] to [[2]]

ri = ri[[2]] rj = rj[[2]] kij = kij[[2]] yi = yi[[2]] phm = phm[[2]] ylm = ylm[[2]] plm = plm[[2]] yhm = yhm[[2]] si = si[[1]] ss = ss[[1]] sf = sf[[1]] mi = mi[[1]] tsi = tsi[[2]] \[Delta]i = \[Delta]i[[1]] dri = dri[[1]] drj = drj[[1]] lij = lij[[1]] \[CapitalDelta] lns50 = Sqrt[(    (Out[12] \[CapitalDelta]ri[[1]])^2 + (Out[13] \[CapitalDelta]rj[[         1]])^2     + (Out[14] \[CapitalDelta]kij[[1]])^2 + (Out[         15] \[CapitalDelta]yi[[1]])^2     + (Out[16] \[CapitalDelta]phm[[1]])^2 + (Out[         17] \[CapitalDelta]ylm[[1]])^2     + (Out[18] \[CapitalDelta]plm[[1]])^2 + (Out[         19] \[CapitalDelta]yhm[[1]])^2     + (Out[20] \[CapitalDelta]si[[1]])^2 + (Out[         21] \[CapitalDelta]mi[[1]])^2     + (Out[22] \[CapitalDelta]tsi[[1]])^2 + (Out[         23] \[CapitalDelta]\[Delta]i[[1]])^2     + (Out[24] \[CapitalDelta]lij[[1]])^2)] 

my Problem is, that Mathematica gives the Errormessage `Part specification is longer then depth of objekt´

Please tell me if you got any clue what I need to tell Mathematica instead.

I tried ClearAll but it doesnt worked

Left Join with multiple Depth in postgres

I have a schema that looks like this:

                  +------------+ +------------+    + acc_email  | | account    |    +============+ +============+    | id         | | id         |<-+-+ account_id | +------------+  | | email      |                 | +------------+                 |  +------------+                 |  | password   |                 |  |============|                 |  | id         |                 +--+ account_id |                    | password   |                    | iterations |                    | salt       |                    +------------+ 

The users login via email, need to find the account, than find the password. I got this far:

       SELECT *           FROM acc_email     LEFT JOIN account            ON acc_email.account_id = account.id 

How do I join and retrieve the account email, account and latest password in a single query?

FunctionCompile returns Part::partd: Part specification 151345[[1]] is longer than depth of object

Today, I install mathematica 12.3 on my computer(windows), then I run the FunctionCompile code

cf = FunctionCompile[Function[Typed[arg, "MachineInteger"], arg + 1]] 

but it goes wrong, and return the information

Part::partd: Part specification 151345[[1]] is longer than depth of object 

I test on my another computer, FunctionCompile works well, so what’s happening here?

Why does Mathematica crash at a certain recursion depth?

If I enter

Block[{$  RecursionLimit = 70000}, x = x + 1] 

I get

$  RecursionLimit: Recursion depth of 70000 exceeded during evaluation of 1+x. 

But at $ RecursionLimit = 80000, Mathematica crashes (i.e. goes unresponsive for a little while and then clears all variables). Why is this? Is there some limiting factor that I can increase to go even further?

Arbitrary depth nested for-loops without recursion

Suppose I have an array of n values I want to apply nested for-loops over to an arbitrary depth m.

const array = [1, 2, 3];  // 2-depth for-loop for (const i of array) {   for (const j of array) {     // do the thing   } }  // 3-depth for-loop for (const i of array) {   for (const j of array) {     for (const k of array) {       // do the thing     }   } } 

The obvious solution is to use recursion. In JavaScript/TypeScript, a generator lends itself well here. For an example problem, let’s calculate the probability distribution of the sum of rolling m 6-sided dice.

type Reducer<T, TResult> = (current: T, accumulator?: TResult) => TResult;  function* nestForLoopRecursive<T, TResult>(   array: T[],   depth: number,   reduce: Reducer<T, TResult> ): Generator<TResult> {   for (const value of array) {     if (depth === 1) {       yield reduce(value);     } else {       for (const next of nestForLoopRecursive(array, depth - 1, reduce)) {         yield reduce(value, next);       }     }   } }  function reduceSum(current: number, prev = 0): number {   return current + prev; }  const pips = [1, 2, 3, 4, 5, 6];  interface RollDistribution {   [key: number]: number; }  function rollMDice(m: number): RollDistribution {   const results: RollDistribution = {};    for (const result of nestForLoopRecursive(pips, m, reduceSum)) {     results[result] = results[result] !== undefined ? results[result] + 1 : 1;   }    return results; }  for (let m = 1; m <= 3; m++) {   console.log(`Rolling $  {m} $  {m === 1 ? 'die' : 'dice'}`);   console.log(rollMDice(m));   console.log(); } 


Rolling 1 die { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1 }  Rolling 2 dice {   '2': 1,   '3': 2,   '4': 3,   '5': 4,   '6': 5,   '7': 6,   '8': 5,   '9': 4,   '10': 3,   '11': 2,   '12': 1 }  Rolling 3 dice {   '3': 1,   '4': 3,   '5': 6,   '6': 10,   '7': 15,   '8': 21,   '9': 25,   '10': 27,   '11': 27,   '12': 25,   '13': 21,   '14': 15,   '15': 10,   '16': 6,   '17': 3,   '18': 1 } 

My understanding is that any recursive function can be rewritten iteratively, though it usually requires some augmentation. (For example, an in-order traversal of a binary tree can be done iteratively if you augment each node with two bits and a parent pointer.)

How can I rewrite nestForLoopRecursive() without using a stack or any other recursive data structure? In particular, is it possible to do this in at most O(n lg(m)) space?

Here’s a CodeSandbox with everything needed written in TypeScript. The code yet to be written starts at line 16. Feel free to answer using whatever language you choose, though, including pseudocode.

Time Complexity of Recursive Ray Tracing with respect to Depth

How does depth of ray tracing affect the run time (role in the complexity) of the recursive ray tracing algorithm with reflection and refraction?

How I have calculated it is, for each ray after intersection, it is split to 2 rays (one for reflection and one is the refracted ray), so the complexity with respect to depth would be exponential time ~O(2^D) for the ray tracing depth D. And for the image resolution of M*N, the complexity would be O(M.N.2^D).

Would you confirm these results, or am I missing something?

Iterative Depth First Search for cycle detection on directed graphs

I found this pseudocode on Wikipedia, and looks very elegant and intuitive:

L ← Empty list that will contain the sorted nodes while exists nodes without a permanent mark do     select an unmarked node n     visit(n)  function visit(node n)     if n has a permanent mark then         return     if n has a temporary mark then         stop   (not a DAG)      mark n with a temporary mark      for each node m with an edge from n to m do         visit(m)      remove temporary mark from n     mark n with a permanent mark     add n to head of L 

I am trying to write an iterative version for this using 3 marks (UNVISITED, VISITED, PROCESSED), but the lack of tail recursion really bothers me.

How should I approach this?

Cover interval with minimum sum intervals – DP recursion depth problem

I have just found the official solutions online (have been looking for them for a while, but after posting this I quickly found it), and I’m currently trying to understand it. As I can tell, it uses a much simpler DP, which only uses an O(N) array.

This year I attended a programming competition, where we had a few interesting problems. I had trouble with some of them, and since the next round approaches, I want to clear them up.

The problem in a nutshell
We are given N weighted intervals, and a [A,B] interval. We have to cover the [A,B] interval with the given ones, in such a way, that we minimize the overall weight sum (and then the number of required intervals). We need to print the sum, the number of intervals, and then the intervals themselves. If we can not cover [A, B], we need to report that as a special value (-1).

First thoughts
If we sort the intervals by begin time, then we can do simple 0-1 Knapsack-like DP and solve the problem. Also, if the priorities were swapped (minimize count THAN sum), a simple greedy would do it.

The limits
Basically, all interval starts and ends are in the range 1-1 000 000, and N<=100 000. All intervals lie within [A,B].

My approach
I wrote a recursive algorithm like the 0-1 Knapsack one in python, that also stored the last selected interval – thus allowing the recovering of the selection list from the DP array later. It was a (current_interval, last_covered_day) -> (cost, last_selected_interval, last_covered_day')-like function. I used a dict as a DP array, as a regular array that big would have violated memory constraints and filling it fully would also increase runtime (at least that’s what I thought – but a 1000000 * 100000 array would certainly would!). I wrote the function as a recursive one so it would not fill in the entire DP array and be faster & more memory-efficient.

The problem with this
Simply, I got RecursionError: maximum recursion depth exceededs on larger datasets – 100k deep recursion was simply too much. I read since on GeeksForGeeks that it should be possible to increase it, but I am still not confident that it would be safe. My recursive function is also not tail-call optimizatiable, so that would also not work.

So my questions
Is there a way of solving this problem without DP? If no, is filling in a full table an option with those high limits? Maybe we can come up with a different DP approach that does not use such big tables? Is it safe to just increase recursion depth limits with this kinds of problems?

Circuit depth of computing the continued fractions of a rational number

If you want to convert a rational number into its continued fraction, what is the circuit depth of this process, in terms of the total number of bits of input?

I was reading through some notes which mentioned that the work being done while computing the continued fraction is basically the same as the work being done while computing a GCD. Are their circuit depths similar?