Deploying Symfony2 app with Capifony - APC loader still uses previous release

Question: I've recently upgraded my Symfony2 application to 2.1 and migrated it to a new server, so I figured I'd configure Capifony to make deploying simpler. Everything has gone great except for the fact that it now doesn't make use of the APCLoader, so I've had to comment this out temporarily until it's sorted.
Here's the relevant code from app.php:
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.

$loader = new ApcClassLoader('my_prefix', $loader);
$loader->register(true);

The problem is that 'my_prefix' isn't unique per release so it'll end up trying to look for cached files that belong to previous releases, which may or may not still be there. This is obviously a very big problem!
What would be the best solution for this? Should I somehow write a task that capifony will run before deploying that changes the prefix to something unique, such as the #{latest_release} variable? Or should I somehow reset the entire contents of the APC cache after each deploy?
I'm not too sure of the best way to do either of these things, so if you'd recommend one of them could you please point me in the right direction to be able to implement it? Or is there an alternative solution that I haven't thought of?
Answer: You could use the ApcBundle, which provides a command that will create new file in the web/ directory, execute it through HTTP, then remove it. Then, you could use your run "/path/to/app/console apc:clear" command in your deployment script.
Comment: If you do this, be sure to also clear (or disable) php's realpath cache, as described in my answer below.  Otherwise the APC classmap will simply be repopulated again with the wrong values.
Answer: You could try clearing the APC cache.
The easiest way to do this is to restart Apache.
You could also write a PHP script to do so:
<?php
apc_clear_cache();

See:
Does a graceful Apache restart clear APC?
http://php.net/manual/en/function.apc-clear-cache.php
Comment: Thanks, but do you know how this would be called from the capifony deploy script? I was thinking I could create a Symfony2 command such as `my_namespace:apc:clear` containing the function call and execute this from capifony using `run "/path/to/app/console my_namespace:apc:clear"` in a post deploy hook, but I'm not sure if it matters that this will be using the CLI php instead of apache. Do you know if this makes any difference?
Comment: Yes, I think the CLI PHP has a separate cache. - http://stackoverflow.com/questions/911158/how-to-clear-apc-cache-entries
Comment: Thanks for the heads up. That question definitely looks useful, I'm sure I'll be able to get it sorted now. I'll accept your answer but will also post an answer showing what I did to get it working...
Comment: Thanks, but I think theunraveler has the more helpful answer.
Comment: You're not wrong. Sorry - I don't think it was there when I accepted yours.
Answer: Another, potentially simpler solution to this would be to simply build a classmap file as part of your release process, instead of using APC for the class map.  I haven't been able to track down the cause (yet, anyway), but I've found that even when I clear the apc user cache after deploying a new release, the old release can still pollute the cache.  (I'm not sure how, since I use a method like that suggested by theunraveler to clear, and I do so after updating the symlink to the new release, so the old files should no longer be accessed, but it still does happen.  Edit: Figured out why this happens.  See https://stackoverflow.com/a/22680064/160565)
Anyway, I ended up just switching to using composer to dump an autoloader file as desribed in the "Use Composer's Class Map Functionality" section here: http://symfony.com/doc/current/book/performance.html
Basically you need to remove the ApcClassLoader stuff from app.php, then add this line to your deployment:
php composer.phar dump-autoload --optimize

I'm not sure what the efficiency is of using a classmap file vs using APC to cache the class locations directly, but it doesn't seem to have a noticeable effect on performance.  Either one is obviously a significant boost over manually scanning the filesystem for each lookup.
Edit: Also, if you do take the approach of clearing the APC cache after deploying a new release, make sure you also clear php's realpath cache (or disable it), as described here.  Otherwise php will continue accessing files from your old release after the cache has been cleared, which will cause it to be repopulated with the wrong paths.
In fact, it's a good idea to clear php's realpath cache on release anyway (or disable it), because otherwise any non-php files in your project will be out of sync with the php files until the cache expires.


Differentiable function and limit

Question: $f(x)$ is a differentiable function such that both $T=lim_{x\to\infty} f(x)$ and $L=lim_{x\to\infty} f'(x)$ exist and are finite. Then must it be true that $L=0$? Seems true for many functions. But I am having hard time actually formally proving this. Thanks for any help.
Answer: $f(x+1)-f(x) = \int_x^{x+1}f'(x)$. Since $lim_{+\infty}f(x) <+\infty$, for every $c>0$, there exists $n$ such that $x,y\geq n$ implies that $\mid f(y)-f(x)\mid <c$,
in particular $\mid f(n+1)-f(n)\mid = \mid \int_n^{n+1}f'(x)\mid =\mid f'(c_n)\mid<c$ where $c_n\in [n,n+1]$ by the mean value theorem. This implies $lim f'(c_n) =lim_{+\infty} f'(x)= 0$.

Differentiable function and limit


Can I mix brands of chainsaw chains?

Question: I have a Stihl 260 chainsaw, with a 3/8" chain and a 20" bar. What criteria do I need to apply when picking a second chainsaw chain?
Comment: I bought an Oregon chain for my Stihl MS 290 20 inch, and it gets very hot and smokes at the end of the bar. It doesn't seem to work right, so I'm going back to Stihl before I damage my saw.
Answer: I'll defer to the experts but personally, I wouldn't mix brands of chainsaw chains.
I seem to recall that Stihl chain designs help reduce/prevent kick-back and binding (which presumably explains why they're more expensive). Plus, they use a green and yellow color-coding system to help you select a powerhead, bar and chain combination that complies with kickback requirements of various safety standards (e.g. ANSI Standard B175.1).
But again, I'm no expert -- just paranoid about safety. =)
-M
Comment: paranoia and chainsaws sounds like great bedfellows.
Comment: @Steve, never a truer word said. Chainsaws are completely unforgiving and don't discriminate between wood and flesh.
Answer: Mixing brands of chains is no problem, provided you use compatible chains. I'm no longer able to buy "original" chains for my old Homelite so I buy it off the roll at the local mower/chainsaw dealer, who also joins it up for me. It's worth noting that this particular dealer won't sell you a chain unless you know exactly what to ask for or bring in an old one for comparison.
The wrong type of chain can be inefficient or even downright dangerous, so get some expert advise before buying a non-genuine chain. If you have an doubts err on the safe side - always.
Answer: Oregon (http://www.oregonchain.com/) makes chainsaw accessories, including chains that would fit my chainsaw.

Stihl chains are pre-stretched, so you won't get as much initial stretch on the saw.
I heard that Stihl chains are built to closer tolerances, but nothing authoritative.
It looks like the Oregon chain needs a slightly different sized sharpening file. I don't want to have to sort out which file goes with which chain.
As @Mike B pointed out, there color-codings on Stihl saws, which is convenient.
I compared the price of a Stihl chain at my Stihl dealer to the price of an Oregon chain at my local hardware store, and the difference wasn't very big.

I decided to stick with Stihl chains.
Answer: You have to pay attention to pitch (distance between drive links) to match the sprocket (and bar tip sprocket if you're using a roller nose) and thickness of the drive tang on the drive link must match to the groove on the bar with proper established clearances.
If you pay attention to those dimensions, you can use other brands.
The loggers I grew up with used Oregon Chain by the spool. Time is money and time spent in the field sharpening anything was a waste, so you made up multiple chains, often for several saws with different bar lengths, changed them out and when you had enough, fired up your sharpening grinder (files? psh!) and processed all your dull chains for angle, depth of cut per species of tree you were felling.
Answer: stihl chains have oil groves that keep you bar and chain oiled as well as having 2 diff types of chains for kick back the green label is for less kick back for less experienced wood cutters and the yellow for pro wood cutters with bigger hp saws. my advice is stick with the stihl chains they are desighned for your saw
Answer: Agreed. Buy the Stihl. My husband just bought a different brand of 14"chain and it won't fit our Stihl chainsaw.  Going back for a Stihl brand chain with the box from the last Stihl chain we had that fit.  I'd say don't waste your time, get the right one to begin with.
Not worth the hassle (unless you go through dozens of chains per year, in which case do the research on pitch, spacing, grove, etc as mentioned above.)

Can I mix brands of chainsaw chains?


Json object converted into a Datatable

Question: Using a server call the user of my web application is creating a json object d. This object contains numerous keys (think of "Mean", "Stdev", etc.). The user is changing the underlying timeseries on a webpage.

An jquery $.POST is executed and if successful returns the json object and calls the method above.
The above scheme works already. This updates

some value

However, I would really like to update a complete datatable (datatable as in http://datatables.net/examples/advanced_init/).
At runtime I don't know what key are in d. Is datatables.js the right tool for dynamic data in a table?
Answer: Yep, that is what dataTables.js was made for.
Although it is unclear what you mean exactly with datatable, table and dataTable.
dataTable.js is responsible for the display (rendering) of a table like structure on your page with lots of functionality (like sorting, searching, filtering, pagination, editing etc.) that would otherwise be very difficult to achieve. It is not a tool that helps you to maintain the field in a table (or datatable) of your DB. (But it can be)
dataTable.js uses server sided code with some cleverly helper functions to help you to use a mySql database via PHP. But it does not rely on this examples. You can use any serversided code and any database as long as it understands the query that is sent from dataTables.js and resturns the json-data that dataTables.js expects.
For complex (DB)-table manipulation you need to write your own server sided code.
Regarding your question I guess you should have a look at the serversided examples that come with dataTables.js.
For getting individual values of cell or row values on the actual page the user sees you should look at the column rendering examples.
Don't regard this as an Answer, it is just to lengthy for a comment. Be prepared that using dataTables.js is way different from the working code of your question.
Comment: Needless to say that I have spent quite a while on studying the examples. However, I am still too weak in JavaScript to make sense of all of them. It's not clear to me how to proceed. Shall I have a global variable in JavaScript pointing to the Datatable. And clear the content of the dataTable everytime before I refill it? It's all a bit too magic still
Comment: It is helpful to have the dataTables object in a global variable in case you want to acess its functionality after the initialisation. But if you want to use the serverside example you just need to init it with serversided:true and an url to your datasource. Reloading and refreshing of the content will be done by internal callbacks automatically. You only need to overwrite these callbacks if you want to do something that differs from default functionality.
Comment: Have a further look around to grasp the concept, try to create a simple example and come back with more specified questions and some example code of what you have tried and where you are stuck. I'm glad to help you further! Good Luck and don't give up to soon. It's worth it.
Comment: I have managed to come up with a semi-working solution. Based on total clearing and refilling whenever a function is fired off. This is still a bit unreliable though and it lacks any elegance.
Answer: Here's a fragment of the code. It works actually now. However, I find the concept (removing content and adding row-wise) super dodgy:

                            Value

Please note that I have not included the code for the computation of d (done on the server with a $.ajax POST call.

Json object converted into a Datatable


what is the supercritical state?

Question: is the supercritical state of matter a separate state of matter or is it a combination of a liquid and a gas? could someone give me an overview of this state and its properties. i have seen some videos in which the meniscus of a liquid vanishes and reappears as the liquid turns to its supercritical state and back. i find this hard to comprehend as i am used to seeing the meniscus of a liquid go down the container as it vaporises. could someone explain this spontaneous change in state?
Answer: In the supercritical state the difference between liquid and gas vanishes.
The sharp distinction between liquid and gas only exists up to a critical pressure and temperature at which the energy needed to vaporize the liquid vanishes and the densities of the liquid and the gas get equal, above this points no different liquid and gas phases exist.
In other words, it is possible to transform a liquid into a gas without encountering a change of state (but rather some a cross-over). But when you are below the critical temperature and the critical pressure, there is a sharp distinction due to the first order phase transition line.
The Van der Waals gas gives a good qualitative explanation for this.
In a way the properties of the supercritical state are a combination of the ones of the liquid and the gas, its viscosity is low (as for a gas) but usually it is a good solvent (supercritical $\text{CO}_2$ is used to extract caffeine from coffee beans in decaffeination).
Around the critical point (when the pressure is the critical pressure and the temperature is the critical temperature) additional phenomena can be observed, such as long range fluctuations leading to clouding in the fluid (as small temperature fluctuations drive the system between liquid and gaseous state, thus causing the light to be scattered), this phenomenon is called critical opalescence. For more on this read more about the critical point.
Answer: At pressures and temperatures above the critical point, the boundary between fluid and gas disappears.  A supercritical fluid has no surface tension, as there is no liquid-gas boundary.  That's why the meniscus of the fluid state disappears.
In liquid water, for example, the polar molecules of water tend to stick to one another because the positive and negative poles of the molecules attract.  Glass also is composed of polar molecules, and when water is placed in a glass tube, positive and negative ends of the glass molecules attract opposite polarities of the water molecules, resulting in a meniscus because polar attraction causes the water molecules to creep up the sides of the glass slightly.
Kinetic energy of the gaseous phase breaks the bonds between molecules of water, and likewise breaks the bonds between water and glass molecules, so there is no meniscus.  Likewise, the molecules of a supercritical fluid are too energetic for a meniscus to form.
Above the critical point, the attributes of a supercritical fluid can be "fine-tuned" to be more gas-like or more fluid-like by varying the pressure and temperature.  A supercritical fluid may be considered a mixture of two phases, rather than a separate phase.
Here is a temperature/pressure phase diagram of carbon dioxide that shows where the supercritical fluid exists:
http://en.wikipedia.org/wiki/Supercritical_fluid#/media/File:Carbon_dioxide_pressure-temperature_phase_diagram.svg

what is the supercritical state?


Do I own a watchdog?

Question: Quite often times when I do a reboot, I get the following error message:
kernel: watchdog watchdog0: watchdog did not stop!

I tried to find out more about watchdog by doing man watchdog, but it says no manual entry. I tried yum list watchdog and found that it was not installed. However, when I look at the /dev directory, I actually found two watchdogs:
watchdog and watchdog0
I am curious. Do I actually own any watchdogs? Why does the kernel complain that it did not stop when I do a reboot?
Answer: Most modern PC hardware includes watchdog timer facilities. You can read more about them here via wikipedia: Watchdog Timers. Also from the Linux kernel docs:
excerpt - https://www.kernel.org/doc/Documentation/watchdog/watchdog-api.txt

A Watchdog Timer (WDT) is a hardware circuit that can reset the
  computer system in case of a software fault.  You probably knew that
  already.
Usually a userspace daemon will notify the kernel watchdog driver via
  the /dev/watchdog special device file that userspace is still alive,
  at regular intervals.  When such a notification occurs, the driver
  will usually tell the hardware watchdog that everything is in order,
  and that the watchdog should wait for yet another little while to
  reset the system.  If userspace fails (RAM error, kernel bug,
  whatever), the notifications cease to occur, and the hardware watchdog
  will reset the system (causing a reboot) after the timeout occurs.
The Linux watchdog API is a rather ad-hoc construction and different
  drivers implement different, and sometimes incompatible, parts of it.
  This file is an attempt to document the existing usage and allow
  future driver writers to use it as a reference.

This SO Q&A titled, Who is refreshing hardware watchdog in Linux?, covers the linkage between the Linux kernel and the hardware watchdog timer.
What about the watchdog package?
The description in the RPM makes this pretty clear, IMO. The watchdog daemon can either act as a software watchdog or can interact with the hardware implementation.
excerpt from RPM description

The watchdog program can be used as a powerful software watchdog
  daemon or may be alternately used with a hardware watchdog device such
  as the IPMI hardware watchdog driver interface to a resident Baseboard
  Management Controller (BMC).  watchdog periodically writes to
  /dev/watchdog; the interval between writes to /dev/watchdog is
  configurable through settings in the watchdog sysconfig file.
This configuration file is also used to set the watchdog to be used as
  a hardware watchdog instead of its default software watchdog
  operation.  In either case, if the device is open but not written to
  within the configured time period, the watchdog timer expiration will
  trigger a machine reboot. When operating as a software watchdog, the
  ability to reboot will depend on the state of the machine and
  interrupts.
When operating as a hardware watchdog, the machine will experience a
  hard reset (or whatever action was configured to be taken upon
  watchdog timer expiration) initiated by the BMC.
Comment: @QuestionOverflow - as I understand it the system provides the watchdog facility (it's essentially hardware). The kernel therefore owns it and manages this hardware just as it would any other piece of hardware within the system. You the user interact with it through the kernel, but do not own it in any official capacity. You're simply a consumer of it. WDT's are used as a built-in protection, in case running software ties up the hardware in unforeseen ways. They're a safety mechanism that allow the system the ability to recover.
Comment: Thanks, the kernel doc is useful. To clarify, does this mean that the kernel owns a watchdog and the user, me, do not own one since I have not installed any?
Comment: I see.. But it seems I am able to interact with it directly if I install watchdog. There seems to be a config file `/etc/watchdog.conf` to alter its behaviour directly.
Comment: @QuestionOverflow - Take a look at the watchdog description in the RPM. It explains it all. I'll add it to my A.
Answer: As a side note, to search your manuals, you can do:
man -k watchdog

and any manual which uses the word at least in the name or title/description will show up in your console. If you expect many options, you may want to use it with less as in:
man -k watchdog | less

In our case here, though, you probably won't get much more than 2 or 3 entries.
That shows a utility which is named wdctl, allowing you to see the current status/setup of the watchdog. Here is an example on one of the Jetson boards I'm working with:
$ wdctl
Device:        /dev/watchdog
Identity:      Tegra WDT [version 1]
Timeout:       120 seconds
Pre-timeout:    0 seconds
FLAG           DESCRIPTION               STATUS BOOT-STATUS
KEEPALIVEPING  Keep alive ping reply          0           0
MAGICCLOSE     Supports magic close char      0           0
SETTIMEOUT     Set timeout (in seconds)       0           0

We can see the Timeout entry which tells you how long the watchdog will wait before forcing an auto-reboot.
In newer versions of Linux, this is controlled through systemd. Look at /etc/systemd/system.conf where you can find a couple of parameters (usually commented out by default):
[Manager]
...
#RuntimeWatchdogSec=0
#ShutdownWatchdogSec=10min
...

Note: If easier for you, you could also use the apropos command line tool instead of man -k. It does the same thing, although the -k is not required in this case.
apropos watchdog

Also the keyword (watchdog in this example) can be a regular expression by default.

Do I own a watchdog?


Why mass of nucleus decreases after binding of it's components (protons and neutrons)?

Question: Nucleus mass should be equal to sum of mass of protons and neutrons, but after binding of these particles, its mass is reduced. Why? Due to reduced mass of protons or neurons? Then what's the purpose of calculated mass?
Comment: Possible duplicate of [Mass defect- From where mass is being lost?](https://physics.stackexchange.com/questions/60802/mass-defect-from-where-mass-is-being-lost) also see https://physics.stackexchange.com/questions/193969/binding-energy-and-mass?rq=1
Comment: The same thing happens with atoms, just on a smaller scale.
Comment: The same happens with planets and asteroids as well.
Answer: The strong force is the one that keeps quarks and gluons in confinement in a proton or neutron, and the residual strong force or nuclear force is the force that keeps the protons and neutrons in a nucleus.
Now the nucleus has a lesser mass then the sum of its constituents. The reason is that you need to add energy to get the constituents back (separate them).
That energy that you need to add to the bound system to make it unbound again (to separate the nucleus's protons and neutrons) is exactly the same energy (or mass defect) that is missing from the bound system when you measure it compared to the sum of the separate constituents.
This is the reason why it is called mass defect and that is why we use E=m*c^2, because that missing mass that you ask about is exactly the same as the energy that is binding the nucleus together (protons and neutrons). And it is exactly the same energy that you need to add to the system to separate the neutrons and protons again, so the
Energy (binding)= Energy (that you need to separate again)=(mass defect)*c^2
So you can convert the energy into mass.
Answer: let's consider the simplest case: if a proton comes close to a neutron they start interacting through strong force, and in such system there is an excess of energy, which can be radiated or carried away by other particle, and if it happens then these proton and neutron would stay together, now they weigh less since some energy escaped, and to break them apart we now have to apply some energy to the system
combining protons and neutrons make nuclear of atoms, some combinations are stable and we have stable elements, other combinations are not and tend to change into a state with lower energy, and the process we observe we call radioactivity
deep inside of stars lighter elements get converted into heavier ones, and released energy lets stars shine for many millions and billions of years, however, this process stops at iron, which has the combination of neutrons and protons with the lowest energy
Answer: One has to keep clear that there are two general frameworks where the term "mass" is used. One is the classical framework where $m$ is the inertial mass for $F=ma$, and Newton's laws dominate and one can use Archimedes principle to calculate the mass of alloys. In this system mass is an additive conserved quantity. This is also the low velocity frames, i.e. velocities very small compared with the velocity of light. The classical physics system.
For velocities near the velocity of light one cannot have Galilean transformations (necessary for Newton's mechanics) to go from one frame to another, but Lorenz transformations. One has to use four vectors, $(E,p_x,p_y,p_z)$ and the "length" of this four vector is called the invariant mass characterizing the system. Particles are characterized by this mass  $m$ when measured individually, but when in a system, one has to add the four vectors and the sum can  be different than the sum of the individual masses comprising the system.
The second frame is the frame of atoms molecules particles, a micro frame because distances are small, governed by quantum mechanics and special relativity.
Protons and neutrons within a nucleus are in a quantum mechanically bound state, i.e a state in a potential well. Their free particle four vectors when falling in the potential  well, during the creation of the nucleus,  lost energy and momentum  by radiation $( α, β, γ )$ and the addition of the four vectors of the nuclei that make up the nucleus has a total mass less than the sum of the masses of the free nuclei.
With the above in mind lets see the question:

Nucleus mass should be equal to sum of mass of protons and neutrons,

Only in the classical physics frame, which is not the frame of protons and neutrons.

but after binding of these particles, its mass is reduced. Why?

Because of special relativity which induces a relationship  between masses of systems that have constituents, through the four vectors of each constituent and the law of addition of four vectors.

Due to reduced mass of protons or neurons?

The protons and neutrons in the potential of the nucleus are described by virtual four vectors, and yes, those four vectors have instantaneously different masses , less than the free particle rest mass.

Then what's the purpose of calculated mass?

The measured rest( or invariant) mass of individual protons and neutrons is invariant when the particles are free. The measured rest mass of the composed nucleus is also invariant . The difference of the sum of individual masses to the mass of the nucleus tells how much energy will be needed to get the protons and neutrons  free, outside their built up potential well. The potential well of a system of nucleons  is built up by the strong force, a spill over of the quantum chormodynamic force between quarks which compose the neutrons and protons.
Answer: The law of conservation of energy is one of the "building blocks" on which Classical Physics is fabricated so imagine the "surprise" when in 1932 a experiment was done by Cockcroft and Walton which showed that energy could be created.
Cockcroft and Walton used their accelerator to give protons (Hydrogen ions) sufficient kinetic energy so that when a proton hit a lithium nucleus two alpha particles (Helium nuclei) were produced.
$\rm ^1_1H+^7_3Li \rightarrow ^4_2He+ ^4_2He$
Knowing the kinetic energies of the protons and measuring the kinetic energy of the alpha particles showed that kinetic energy had been "created" in this reaction.
In 1905 Einstein had postulated the idea of the equivalence of energy and mass $E=mc^2$ and using the known masses of Hydrogen, Lithium and Helium atom/nuclei Cockcroft and Walton showed that in the reaction they were investigating the total mass of the products was less than the total mass of the reactants by exactly the same amount predicted from the Einstein formula.
You might now ask why it was that the law of conservation of mass was, and still is, used by chemists and other scientists in other fields.
The answer lies in the fact that in chemical reactions the energies involved are very much smaller (~eV, ~$1.6\times 10^{-19}\rm J$) than in nuclear reactions (~MeV) with corresponding much smaller (and non-measurable) reductions in mass.
This reduction in mass even occurs when you stretch a spring!
Answer: The binding energy of protons and neutrons in the nucleus is large enough that a fraction of the mass of the bound nucleus (expressed simply as the sum of the individual nucleon masses) is converted into binding energy (by E = mc^2) and hence is "missing" in that sum.


What are the disadvantages of using SSA form?

Question: SSA form is common intermediate representation used in compilers where all variables are assigned to exactly once. It greatly helps with a myriad of optimizations, such as constant folding, dead code elimination, and redundancy elimination. With these advantages, there must be some disadvantages to using it. What are they?
Answer: Things that are not disadvantages
We'll start with some things that are sometimes considered to be disadvantages, but actually aren't. They may not be advantages, but they just aren't problems, or are problems that have convenient solutions.
Transforming to SSA form
Dominance frontier algorithms (e.g. Cytron et al) do produce minimal SSA form efficiently, at the cost of algorithmic complexity and a surprising amount of subtlety.
However, modern algorithms exist that are much simpler, and also have the advantage that SSA form can be constructed during IR building rather than as a post-pass. See, for example, Braun et al.
Transforming from SSA form
SSA form was originally considered to be an intermediate form that would then be "undone" for backend passes such as code generation, register allocation, and code scheduling.
Modern superscalar CPUs have made code scheduling even more important than it was in the 1990s, and so since it has to be done anyway, flattening SSA form and instruction scheduling can be the same thing, and spilling and register allocation can be done after scheduling.
This is such a powerful approach that many modern compilers don't have or need a general peephole optimisation pass; it can all be handled by adding more tiles to instruction selection.
Things that are disadvantages
Phi nodes are special
For all the advantages of SSA form, phi nodes can be a pain to handle correctly.
Phi nodes are sometimes like other nodes, and sometimes not like other nodes. Any optimisation pass which transforms SSA into SSA must, in general, treat phi nodes as a special case.
That they always appear at the start of a basic block is just one of many issues.
Maintaining SSA form after performing certain kinds of transformation can also be a pain, although algorithms have been developed over the last couple of decades that make this a little less painful.
State and memory models
Even 30 years later, we still don't have a single "right idea" about how to represent state modification in SSA form. The general idea is to pass some kind of token around, and possibly split state tokens if needed, but this can quickly get unwieldy.
Modern programmers are very interested in multithreading, and often rely on adherence to a documented memory model. Memory models dictate that certain operations must "happen before" other operations, especially in the presence of atomic operations, so that some results are visible in a known order when observed from a different thread on a different CPU.
None of this is impossible, but it's not always easy to represent "happens before" relationships in SSA form.
Multiple results
One of the basic assumptions of SSA form is that an expression produces one result, but in general this is not the case.
This is sometimes known as the "div/rem problem", because some CPUs (e.g. x86 and x64) have a division instruction that produces the quotient and the remainder. Asking for both is a scenario found in a large number of real programs:
int q = x / y;
int r = x % y;

Compilers such as GCC and LLVM go to some trouble to fuse quotient/remainder into a single operation if they can, but the resulting operation has two outputs. Again, it's possible to represent such things in SSA form, but it's not easy.
(Just as an aside, another example is x87's fsincos instruction, which does exactly what you think it does. Even on CPUs or GPUs without a combined sin/cos instruction, it often pays to fuse sin and cos when it can be done, so that domain checks and range reduction can be done once rather than twice. LLVM expends a lot of effort on this very common case.)
This is related to memory models, because many atomic operations such as atomic load (but not atomic store!) and compare/exchange produce both a result and a sequence token.
Having nodes with multiple outputs also complicates tiling-based instruction selection; classic algorithms for code generation on DAGs require more subtle handling if nodes can have multiple results.
And finally, instruction tiles themselves may also have multiple logical results! Apart from div/rem, consider an arithmetic instruction which also affects processor flags which you could then branch on.
/* On a CPU with arithmetic instructions that affect flags,
   it would be nice not to have an explicit test-against-zero
   instruction here, and just use the flags from the subtraction.
*/
x = a - b;
if (x > 0) {
   whatever();
}

The repeated predecessor problem
I don't know if this has an official name, but I'm calling it this.
One very common situation in real programs is if-then-else bodies that only contain variable-to-variable transfers.
int x;
if (condition()) {
    x = y;
}
else {
    x = z;
}

What the programmer would like is for this to be implemented as a conditional move instruction, if it's available on the target CPU.
A straightforward translation to SSA form would produce something like this:
block_1:
    c = condition();
    if (c) then goto block_2 else goto block_3;

block_2:
    x_2 := y;
    goto block_4;

block_3:
    x_3 := z;
    goto block_4;

block_4:
    x_4 := phi(x_2, x_3);
    # etc etc

This hides the real structure of the variable lifetimes, and means the compiler needs to do extra work analysing four different blocks.
You could start by removing one block:
block_1:
    c = condition();
    if (c) then goto block_4 else goto block_3;

block_3:
    x_3 := z;
    goto block_4;

block_4:
    x_4 := phi(y, x_3);
    # etc etc

And that would certainly help, although it's not clear which block to remove. Best of all would be to remove both blocks:
block_1:
    c = condition();
    if (c) then goto block_4 else goto block_4;

block_4:
    x_4 := phi(y, z);
    # etc etc

However, this is not valid SSA form!  And it's hard to capture capture this in a variant of SSA form, because most algorithms that work on SSA form are not designed for the same block to appear more than once in a block's predecessors.
Alternatives to SSA form
So what to do instead?
Def-use chains
Don't forget this old standby! Def-use chains provide almost the same information as SSA form; the only catch is that they don't describe the paths along which definitions reach, which is what makes SSA form attractive in the first place.
This also doesn't give you a graph representation, with all the advantages that this implies. Still, depending on what optimisations you need, it might get you 90% of the way there with much less implementation effort.
Continuation-passing style
Some compiler writers have experimented with CPS, popular with compilers for functional languages, adapted to imperative languages. After all, if lambda is the ultimate goto, why not just represent gotos as lambdas in your IR? State-modification operations can also be implemented in a purely functional style with state tokens.
CPS is appealing because you do get all of the machinery developed for functional languages, but it isn't without its problems. After all, it isn't the graph representation that you might want for instruction selection and scheduling.
Basic block argument form
BBA form is a hybrid of SSA form and CPS, with the idea being that all values used by a basic block and the blocks that it dominates are passed explicitly.
You don't actually pass continuations as you would in CPS, but block invocations have essentially the same semantics as tail calls, so a lot of optimisation approaches that work on CPS work here, too.
The example above might look like this:
block_1:
    c = condition();
    if (c) then goto block_4(y) else goto block_4(z);

block_4(x):
    # use x here

Then within a basic block, you can have a SSA-like graph representation, only without phi nodes.
Basic block arguments may be where mainstream IR design is headed.
Comment: For the multiple results of an operation, it's perfectly possible (and quite efficient) to allow tuple types for the virtual SSA registers.

I worked on a [generalised SSA](https://combinatorylogic.github.io/mbase-docs/ssa-fold.pdf) IR that allows to abstract from any particularities of instructions, types and whatnot, handling only the SSA aspect of the code representation.
Comment: That certainly works. The sea of nodes uses a similar technique of introducing projection nodes. I'm curious how well instruction selection from SSA form works?
Comment: LLVM is using an intermediate DAG representation, and, curiously, they get out of SSA when already in DAG, not before. One reason for doing this is that SSA can make register allocation heuristics a bit easier (though it's up to discussion if the result is closer to optimal than for the more heavy heuristics).

In my ([significantly simpler](https://github.com/combinatorylogic/soc/blob/devel/backends/c2/emit.hl)) backends I just do instruction selection on a flat 3-address code after getting out of an SSA, and then do register allocation separately.
Answer: There's two ways of approaching this question. SSA form could be imposed on the user, like in pure functional languages where all variables are immutable (i.e. assigned only once each); or it could be an implementation detail of the compiler, so that code with mutable variables is transformed into SSA form during compilation.
In the former case, the question devolves into one about the disadvantages of "immutable languages"; this Q&A has plenty of good answers about that, so I'll address the latter, i.e. what are the downsides of using SSA form as an intermediate representation in a compiler?

It is not trivial to actually perform the transformation, particularly for variables which are mutated in a loop, where the number of assignments to the variable is not statically known.
Typically a second transformation back out of SSA form is also needed, where each SSA variable is associated with a register in such a way that the same register isn't used for two variables with overlapping lifetimes. Doing this optimally is not trivial; it's an NP-complete graph colouring problem even for a fixed number of registers (greater than 2).
Some of the optimisations you mention are possible without SSA form; constant folding can be done when constructing an abstract semantic graph (ASG), and dead code elimination can be done by reachability analysis on the control-flow graph (CFG).

All of that said, if you want to achieve advanced low-level optimisations then you are better off compiling to a third-party intermediate representation (IR) such as LLVM IR, and then taking advantage of the optimising compiler which already exists for that IR; the existing optimising compiler can generally do far better than you can, except for domain-specific optimisations which rely on context that the backend doesn't know about.
In that case, the choice of whether to perform an SSA transform yourself is wholly determined by whether it's required by the IR you target. Some backends require you to do the transform yourself, while others will do it for you.
Comment: Yes I meant SSA as in internal IR. I'll clarify in the question.
Comment: @Seggan I don't think there was anything wrong with the question; and the considerations about SSA form (used internally in the compiler) are still different for "immutable languages" because either no transform will be required, or the transform will be much easier to implement.
Answer: Here are some disadvantages:

Increased memory usage: SSA form introduces additional variables, which can lead to increased memory usage. This is because each occurrence of a variable in the original program is represented by a new variable in SSA form, resulting in redundant storage.

Increased compile time: The transformation from the original code to SSA form involves additional analysis and rewriting steps. This can increase the compilation time, especially for larger programs, as the compiler needs to perform more computations and maintain the SSA form throughout the optimisation process.

Difficulty in handling mutable variables: SSA form is designed for immutable variables, where each variable is assigned exactly once. Handling mutable variables, such as those modified within loops or conditional branches, can be challenging in SSA form.
Comment: I'm not sure if I agree with this... I'd say that compilation times are actually a selling point of SSA, because many optimizations are faster to perform in SSA. Mutable variables are also fine, that's what the phi nodes are for.
Comment: SSA is designed specifically to handle mutable variables. You would not need an SSA otherwise, you'd already be in an SSA if everything was immutable.


Can I regenerate the the photo thumbnails that have turned black after restoring my iPhone?

Question: I had to restore my iOS 5.1 iPhone from iCloud after recieving a replacement. Many of the thumbnails for photographs are now black. Is there a way to regenerate them?
Answer: Wait and see. When I looked the following morning, the black thumbnails had all been regenerated automatically.
Answer: I may have experienced something similar the other day when my new iPad (3) arrived, and I restored to it from my original iPad (1) backup.  I happened to be in the Photos app (on the new iPad) when I initiated the syncing of my photos.  When it completed, I noticed that all my albums were now there in the Photos app—that none had thumbnails.
Solution (worked for me):
1. quit Photos (tap-and-hold on any icon, wait for the "jiggles" and then tap on the red "x" for the Photos app).
2. re-launch the Photos app.
Comment: My thumnails came back overnight. BTW I don't see the (x) on the Photos app at all when all apps are jiggling...


Contracting tensors

Question: Given $F^{\mu\nu}$ defined as in QED:
$$
F^{\mu\nu} =
\begin{bmatrix}
0&E_x&E_y&E_z\\
-E_x&0&-B_z&B_y\\
-E_y&B_z&0&-B_x\\
-E_z&-B_y&B_x&0
\end{bmatrix}
$$
when contracting it in the lagrangian as $F^{\mu\nu}F_{\mu\nu}$ how do I compute it? Simply as a product of matrices?
Answer: Your first equation involves a common, but misleading, abuse of notation. The left-hand side shows a generic contravariant component $F^{\mu\nu}$ of the field strength tensor and the right hand side shows all components. It would be better to write something like $[F^{\mu\nu}]$ on the left-hand side (simply writing $F$ would be ambiguous as to whether the components are co- or contravariant).
Now, it should be absolutely clear, how to compute $F^{\mu\nu}F_{\mu\nu}$. The Einstein sum convention tells you to sum over all indices that occur once as upper and once as lower index. In other words one has to compute $\sum_\mu \sum_\nu F^{\mu\nu}F_{\mu\nu}$ (here without implicit summation!), where $F^{\mu\nu}$ and $F_{\mu\nu}$ are simply numbers. Don't forget, that $F^{\mu\nu} \ne F_{\mu\nu}$, but you have to contract with the metric tensor first to lower the indices (again using the sum convention):
$$ F_{\mu\nu} = F^{\alpha\beta}g_{\mu\alpha}g_{\nu\beta}. $$
Comment: I explicitly chose not give the full answer since the question is close to homework like, and we want to encourage people to work such things out for themselves. Now that it's in the comments it probably won't hurt to edit it in.
Comment: Fair enough. I have deleted my comment (OP last seen 8 hours ago).

Contracting tensors


Getting VIN's of North American Vehicles

Question: I'm considering getting a BlueDriver scan tool, but to use it's reports feature either it needs to detect or you need to manually enter a North American VIN.  Since I live outside the USA, I was wondering if there is a reliable way to get North American VIN codes so I could manually enter them?
Comment: Do you mean where to locate the VIN on the car or do you just need a database of some kind?
Comment: @Zshoulders a database of some kind so I could look up equivalent VIN numbers for a non-us vehicle.
Answer: A VIN (Vehicle Identification Number) code is unique to each vehicle - it gives all the information such as which manufacturing plant right down to which radio and speakers were fitted etc.
If the scan tool you are looking at is limited to North American vehicles (which surprises me - most i checked were targeted at the manufacturers VW, Landrover, GM etc) then I suggest you look at other ones. I bought one in the UK for a vehicle used in Switzerland - vehicle made in UK - it works fine.


What is this dot? Not fireflies question

Question: I fat fingered a key, saw it show up; how do I get rid of it?  What is it? It shows like the orange dot that marks the last selected object,  but it's white; orange dot is still doing it's thing on other objects. ty.
Comment: it doesn't become orange when you select it?
Comment: Yeah it does   (Comments have to be 15 characters to post (filler to achieve that lol))  EDIT: No it doesn't lol
Answer: It may be the origin of an object that has no more vertices in it, for example maybe you deleted all the vertices of an object in Edit mode, but didn't delete the object itself in Object mode, so the object itself still exists even if it has no more vertices, and its origin is still displayed. So select it and press X to delete.
Answer: Isolate it - I think it's a vertex or origin of a bounding box sort of. You have a lot of available layers. Move it and check the outliner to see what's active. Then, look at properties and check the dimensions against the size of the bounding box. You could make the Bounding Box visible in the Data Tab (I think) or Object Tab by controlling the maximum draw. See the box and object take the same size.
In Edit Mode, clean up by deleting loose geometry or vertices to see if that does it (assuming the Bounding Box idea isn't yielding any happy). Report back!
EDIT or Ensure the origin is with the geometry. [T] option. The Properties will report Location based on an object's origin; if there's a big disparity between what you see and what's listed, that's probably it. Another tip-off is you select an object most of the time by its origin.
Answer: Got it,  I was able to select it by clicking on it (who knew lol). Wasn't anything visible in my scene though.  Outliner says it was a cylinder.  I couldn't scale it small enough or large enough to actually see it though.  Shrugs  it's gone though; deleted it.  Don't know... :) Thanks though.


Preview in OSX El Capitan defaults to 100% scale

Question: When printing a jpeg, preview now defaults to 100% scale, which is not what I want. I am having to manually select scale to fit and fill entire paper. How can I make it always default to the latter (as it used to in previous versions of OSX)?
Answer: In the Preview Preferences, you can define the 100% scale.  In Preview press Cmd ,, then click on the Images tab.  You will get two options

1 image pixel equals 1 screen pixel
Size on screen equals size on printout

Select the second one.


It's unconventional, but is "T's & C's" technically correct?

Question: It looks a bit weird and isn't the commonly used term, but is it not correct? The apostrophe would be marking the shortening of "terms" to "t" and "conditions" to "c", of course.
Comment: In *speech*, I suspect if they were going to abbreviate at all, most people would probably lump both initials together and say **T and C's** (just as they'd ask for *"Two **G and T's**, please"* in a bar). But there's not really any meaning to the concept of "correct" here.
Comment: This from the [Acronym Finder](http://www.acronymfinder.com/Terms-and-Conditions-(Ts%26Cs).html): 'What does _Ts&Cs_ stand for?
Ts&Cs stands for Terms and Conditions [
This definition appears very rarely and is found in the following Acronym Finder categories:

Slang/chat, popular culture
Business, finance, etc.]
Comment: @FumbleFingers The difference is that you wouldn't pluralize both words when you expanded that abbreviation. You'd ask for _two gin and tonics_, not _two gins and tonics_. (you're essentially treating it like a compound word _gin-and-tonic_) But the expanded version of _Ts and Cs_ is _terms and conditions_.
Comment: Darn it, I thought the question was on the form when I voted to close there, not the abbreviation.
Comment: Yep, "T's and C's" (with various punctuations) is a common term that would be understood by anyone in business in the US and most "average" people as well.
Answer:
It looks a bit weird and isn't the commonly used term

It's certainly a commonly used term, and a search finds plenty using each of the variants "Ts and Cs", "Ts & Cs", "T's and C's" and "T's & C's.
Whether one uses apostrophes with single-letter capital abbreviations is something different style guides differ on. If you aren't writing to a style-guide then I'd note that to not use the apostrophe is generally the more modern style, and being consistent one way or the other is a very good idea.


Calibration curve of an instrument

Question: In the calibration procedure of an instrument (e.g. a pressure transducer), when we want to determine the calibration curve, is it a good choice to force the passage of the calibration curve through the origin?
Comment: What do you mean by forcing the curve through the origin?
Comment: I mean imposing that for an input equal to zero the output of the instrument is set arbitrarily to zero.
Comment: I could see this being done if the variable you want to work with is gauge pressure. You would want the signal at atmospheric pressure to correlate to 0 psig, as an example. You may want to gather the calibration data and see if forcing the curve to go through the origin appreciably affects the accuracy at the higher end of range.
Answer: This depends on the sensor.  In some sensors, an offset it to be expected, and should be included in a calibration curve.  In others, there is a good physics reason that the actual output should be zero when the thing being measured is zero, and you should force it through the origin.
Lets look at two examples:

A half-bridge strain sensor with two active elements.  This type of sensor consists of two strain gauges stuck on a metal beam such that when the beam bends one is compressed and one is tensioned. The two are connected in series, between the supply rail and ground (lets say 5V and ground for arguments sake). The zero position will be when neither is stressed, and the output will be close to 2.5V, but if one strain gauge is slightly different from the other due to manufacturing variations, then it will be slightly off.  In this case, you should not force the fit through the origin.
A current-sensing shunt resistor.  These are low value resistors designed to allow you to measure the current through them without dissipating too much energy.  The voltage measured is directly proportional to the current thanks to ohms law.  If there is no current flowing through, then there cannot possibly be a voltage generated, and any voltage you do measure is probably a fault in the measurement kit not the shunt.  So in this case, you might well choose to force the calibration curve through the origin.

In general, you would need to look at the sensor's datasheet (if you bought it) or think carefully though how it works (if you made it) to decide whether you expect an offset.  If you tell us what type of pressure transducer it is and how it works, then we might be able to tell you which category it falls into. Mechanical pressure sensors based on a movable membrane will usually (but not always) fall into the first category, where ionisation gauges would usually fall into the second.
Either way, after doing the fit, you should check whether the observed offset is what you expect, and that the fit to the data is good.
Comment: In my case, due to the calibration system used I'm not able to have a value of pressure lower than 9 bar. So the feasible options are to either force the curve through the origin or allow for an offset. The sensor are the "GE Sensing PTX 500"
Comment: With that sensor you should not force the fit through the origin. You should do a fit then check the offset - if it is more than 0.05mA then you should check that the sensor is working properly or consider adjusting it.
Answer: If you're developing the calibration curve for a sensor (a device like a pressure transducer), since your measurement system will account for the conversion of the signal from an electrical signal in V or mA to Pressure using the sensor's calibration curve, then there's no reason to do so unless the sensor is really giving a strong bias at zero input. If it is, then I would suspect a defective sensor.
Let's say I have a load cell and I want to develop the calibration curve for it. I will set up my calibrator which applies a precise load in N and reads the electrical output of the transducer in V. I'll do this at 0, the max load I expect and a few points in between. If my sensor has a linear response, I should have a nice straight line graph with an equation like this:
$$F_{Newtons}= m*Volts + b  $$
Where $m$ has units of $ \frac{Newtons}{Volt}$ and $b$ has units of $Newtons$
If $b$ is large, relative to the $m*Volts$ term, I would question the integrity of the load cell.
Comment: Yes, I totally agree. In my case, due to the calibration system used I'm not able to have a value of pressure lower than 9 bar. So the feasible options are to either force the curve through the origin or allow for an offset.

Calibration curve of an instrument


set iPhone Required device capabilities

Question: My application is for "iPhone ONLY", But I have made a mistake in the first place by not setting the application for specific device.
The current setting now is:
Requirement: Compatible for iPhone, iPod touch and iPad.
I would like to set it to:
Requirement: Compatible for iPhone.
I have go to some tutorial and forum. and nothing can solve my problem. I have also contact the apple support and this is what I got:
"You are permitted to expand your device requirements only.  Submitting an update to your binary to restrict your device requirements is not permitted. "
is it mean that I can not set my application for iPhone only?
If i can change it, what would you recommend me to do?
I have change the setting of device capability inside the plist, to one of this. which one is correct, use "UIRequiredDeviceCapabilities" or "Required device capabilities"?
i provide the screenshoot in here:
http://img218.imageshack.us/gal.php?g=screenshot20100604atam1.png
does the way I use it correct?
Thanks.
Answer:
"You are permitted to expand your device requirements only. Submitting an update to your binary to restrict your device requirements is not permitted. "

I think you have posted the answer yourself. As of now, it looks like you cannot change it

set iPhone Required device capabilities


drupal zen theme using sass - sub folder dont get regenerated

Question: i have followed these instructions to install ruby and compass and sass, everything is ok and works. However, do i need to do a 'compass watch' at a lower level for the component and layout folders in my zen theme folders as well? for example, if i change .../sass/layouts/fixed.scss it doesnt automatically regenerate the equivalent ...css/layouts/fixed.css
Answer: compass watch should only need to be run from your subtheme folder.  Files in the components and layout folders should use partials (files beginning with underscore).  Then you have to make sure to use @import "components/fixed"; inside your styles.scss for each partial you want to include.
When compass compiles the styles.scss file, the partials that you have @import's for will be automatically included in style.css
Comment: i checked the styles.scss file and it already has that in there by default. I notice that when I amend the responsive.scss file (change the page width) , in my terminal session it shows "change detected to layouts/_responsive.scss, overwrite css/styles.css" but it is not doing anything with equivalent layouts/_responsive.css file? The change seems to be applied to styles.css, and it works, but not the way I expected.


Will two albums duplicate pictures in Photos.app?

Question: I am trying to put together several albums and some of them have a picture from another album. For example a parties album and a birthday 2015 album or a granddaughters 2015 album.  So how do I put the same photos in these 3 albums, and are they duplicated or just cross referenced?
Answer: Just drag the photo from one album to another. The photo will be added to the second album and not removed from the first. Only one master copy of the photo is kept and is cross-referenced throughout the library regardless of where it is used.
Comment: WOW!!! That was quick . Thanks so much. I am on a deadline for a party and want to have an album to use as a screensaver to surprise my family.
Comment: oops. Another question. How do I have two albums open.Sorry for stupid questions. I am new to all of this. I go to photos and open the album, but then when I open the other album, the first is replaced with this one.  So how do i get them 'side by side' to drag and drop?  Thanks again
Comment: @Orchard I use the sidebar for this kind of thing, accessible from View → Show Sidebar.


What operation is ggml_mul_mat performing? (K×Q in LLaMA)

Question: I'm reading the source code of alpaca.cpp in an attempt to understand how a large language model works. (I have a strong programming background, but almost no math, so it's easier for me to start with code and then go backwards to the papers once I have some idea what's going on.)
Partway down llama_eval, it makes a call to ggml_mul_mat() which caught my attention:
// K * Q
struct ggml_tensor * KQ = ggml_mul_mat(ctx0, K, Q);

At first I thought this was an ordinary matrix multiplication; the "Attention is all you need" paper certainly uses that for K and Q. But in this case K and Q appear to be 3d tensors, and my understanding is that matrix multiplication only works on 2d matrices.
So I dug into the ggml code; ggml_mul_mat itself is just a wrapper function, but the first thing I noticed is that it supports up to 4 dimensions, with an interleaved result:
static inline bool ggml_can_mul_mat(const struct ggml_tensor * t0, const struct ggml_tensor * t1) {
 return (t0->ne[0]  == t1->ne[0])  &&
        (t0->ne[2]  == t1->ne[2])  &&
        (t0->ne[3]  == t1->ne[3]);
}

const int ne[4] = { a->ne[1], b->ne[1], a->ne[2], b->ne[3] };
struct ggml_tensor * result = ggml_new_tensor(ctx, GGML_TYPE_F32, MIN(a->n_dims, b->n_dims), ne);

...which, if I'm reading this right, means that it will take an A×M×C×D tensor, and an A×N×C×D tensor, and return an M×N×C×D tensor, truncating as needed, which definitely doesn't sound like matrix multiplication already.
The actual implementation (in ggml_compute_forward_mul_mat_*()) has a lot of special cases, and even the simplest case I could find I'm having trouble reading without already understanding what it's doing. But the best impression I've got is that it's doing some sort of sideways matrix multiplication, piecewise along the other two dimensions.
Does this operation have a name? Is it some kind of standard operation in CNNs, or is it something that GGML and/or LLaMA have made up? Where can I read more about what's going on here?
Comment: Could this just be batchwise matrix multiplication, the additional dimension being the batch dimension?
Answer: You're right that the operation performed by ggml_mul_mat() is not ordinary matrix multiplication, but a more general version of it. As the commenter to your question notes, the operation you're looking at is called batched matrix multiplication. It is a standard operation in deep learning frameworks and is commonly used in various types of neural networks, including CNNs and transformers.
In batched matrix multiplication, you have two tensors, A and B, with shapes $(A_0, A_1, A_2, ..., A_n)$ and $(B_0, B_1, B_2, ..., B_m)$, respectively. When you perform batched matrix multiplication, you multiply 2D matrices along certain dimensions while keeping the other dimensions fixed. In the specific case of ggml_mul_mat() in the LLaMA implementation, it performs batched matrix multiplication along dimensions 1 and 2, and the result is an output tensor with shape $(A_0, B_1, A_2, B_3)$.
With regards to the specific case you mentioned:

Tensor $X$ with shape $(a, m, c, d)$
Tensor $Y$ with shape $(a, n, c, d)$

The batched matrix multiplication will result in a new tensor, $Z$, with shape $(m, n, c, d)$. The operation is performed as follows:
$Z[i, j, k, l] = \sum(X[:, i, k, l] \times Y[:, j, k, l])$
In this equation, we perform element-wise multiplication and sum over the first dimension $(a)$. The resulting tensor $Z$ will have shape $(m, n, c, d)$.
Batch matrix multiplication is also described in the documentation of the DL libraries:

TensorFlow: tf.linalg.matmul
PyTorch: torch.matmul or torch.bmm


Hard disk failure error on SMART status. how can i fix it?

Question: i am running ubuntu on my pc. i am receiving hard disk failure error on SMART status.
how can i fix it?
thanks.
Comment: Please add the exact error message to your question.
Comment: You fix it by replacing the drive.
Comment: hey Nathan . Avoid answering questions in comment. Make this one sentence into an answer and it will be voted to the top. You get bonus points for guidance how to replace a disk.
Answer: As I answered a while ago, you can check the SMART status of a disk through Disk Utility... But that's really only a tiny portion of the story.
Your disk is failing a test. Some of the SMART tests aren't too important but you need to check which it is. If it's one of the following, back up, buy another disk, and move everything off and bin the current disk.

Read Error Rate
Reallocated Sectors Count
Spin Retry Count
End-to-End error
Command Timeout
Reallocation Event Count
Current Pending Sector Count
Uncorrectable Sector Count
Soft Read Error Rate

It sounds dramatic but if one of those values is beyond its threshold, your drive has a real possibility of suffering some sort of critical failure in the near future. Acting as soon as possible may save you a sudden and rude interruption when you need the drive in the future and it fails.
Comment: I got a lot of End-to-End errors caused by a bad power cord. I changed it and want to reset the end-to-end error count just to disable the warning. The data on the device is not that important and I'm aware of the risk...
Answer: This may be a critical situation, so:

Backup your data (and the system as well if you need)
Run an utility to check the hard disk (see below).

Check the disk:
<code>$ su -
# cd /
# touch /forcefsck
# reboot
</code>
or
<code># shutdown -rF now
</code>
Graphical Interface
Ubuntu Main Menu -> System -> Administration -> Disk Utility
The application has Disk drives in left pane and Status of the drive in right pane. You can find SMART status also there with its status indicating with Green/Red light indication.

Click the SMART Data button below the
status, so that you can see the
details of the problem
Click "Run self-test" button and choose the extended one (in the middle normally).
The take a look on the result and come back here in the case.
Answer: SMART stands for Self-monitoring analysis and reporting tool. It's a system which monitors your drive and Ubuntu is able to read certain values and thresholds, so it can warn you of imminent hard-drive failure.
You can view SMART data in Ubuntu here:
<code>System > Administration > Disk Utility > (select your hard-drive)
</code>
Values which exceed the expected threshold will be shown in red - you could post them back here for more info, but generally you should perform a backup of the whole drive (or at least the files which are relevant to you) to an external drive, a different computer or a cloud-based storage service.
Answer: Hi I have had same problem with one of my laptop's drive running win 7 later intstalled ubuntu to see if it detects the problem or not but it was giving me bad time also. The disk was dying obviously, so that reason why I stopped using my laptop for a while and thought that I will going to replace the HDD later. Running the deep scan showed me the problem at the start sectors.
After a month or so I was visiting a local hardware shop and saw those external cases to convert the laptop hard drive to an external drive. I bought one reconnected to my desktop running win 7.. what do I get? No error, checked the disk again it was reporting the 4 bad sectors on a surface scan starting from 7th to 20th sector of HDD.
Now what i did I repartitioned my HDD in to two partitions the first one having those bad sectors and second one clean. Now i reformatted my second partition and installed the system on to the second partition (yes ubuntu) and it's been over a year I never ever have that issue with that.
So the phrase "your disk will become unusable is not justifiable here" well in my case it doesn't. :) Just needed to mention one more thing here that I am booting my system using converted external HDD. :)
Hope it helps someone out there also.
Cheers!
Comment: If bad sectors are caused by a weakness in the magnetic field, these have a tendency to grow over time. I wouldn't trust that partitioning trick over the long haul but it can indeed buy you some time.


What are the chances that two children of the same couple will have the same genes without being identical twins?

Question: If I randomly select half the chromosomes of the male and female eventually I will select the same exact half for both a second time. How often does this occur? Is this considered a twin if it is born at a different time as in years apart?
Comment: Just because the poster might not have an intuition for why this is obviously very low doesn't make this a bad question. In fact, this is interesting.
Answer: The chances are effectively zero.
Even in the absence of recombination, this calculation involves choosing the correct member of a pair from each of the 23 chromosomes, from both the father and the mother.
223 × 223 = 246 = 70,368,744,177,664
So, less than a 1 in 70-trillion chance. For some context, only about 117 billion humans have ever been born in history.

A more accurate calculation would include recombination, which occurs on all chromosomes (except the XY in males). Incorporating this would require knowledge of the recombination profile and number of genes for each chromosome. It would make the above probability many, many orders of magnitude less likely. (Like, it's very possible there are more potential combinations of two parents' chromosomes than there are atoms in the universe.)

If this were to occur, I personally wouldn't call them twins. That term is consistently used to reference a single pregnancy, regardless of whether the children are genetically identical.
Answer: There is a one in 1/(0.5)^46 = 70 trillion chance of this happening in theory without accounting for recombination. However, there is a 6% chance of this happening when there are 4 chromosomes, which is applicable to real plant and animal species! With real human data, which takes into account recombination, hotspots, etc., there is a one in 4.771 * 10^39 chance of this happening. This is one in a 5 thousand billion billion billion billion chance, and only 100 billion humans have ever lived.
Extra information:
Theoretically, there is a one in 17.59 trillion chance of independent assortment happening so that the exact autosome combination is the same (0.5^44).
There are chromosomes A and B. Uppercase: from mom. Lowercase: from dad
Mother: A1 A2 B1 B2
Father: a1 a2 b1 b2
1st step: assort chromosome A. 4 options. (A1 a1, A2 a1, A1 a2, A2 a2)
2nd step: assort chromosome B. 4 options. (B1 b1, B2 b1, B1 b2, B2 b2)
Now, there are 16 options for the child for 2 chromosomes.
Imagine a pairwise matrix of these options; the top left to bottom right diagonal represents the pairs in which two children have the same chromosome combination. This is 16 children out of a total 16*16, or 0.0625 = ~6% chance of happening. This means this must happen regularly for some animal species! https://en.wikipedia.org/wiki/List_of_organisms_by_chromosome_count
If we increase the chromosome count to 22, there are 4 options for each chromosome, so there is a one in 1/(0.25)^22 or 1/(0.5)^44 or one in 17.59 trillion chance.
Different-sex siblings can never be 100% genetically identical.
For men, the Y-chromosome will always be the same and brothers will have a 1/2 chance of having the same X chromosome. For women, the X chromosome from the father will always be the same and there is a 1/2 chance of getting the same X chromosome from the mother. Since they have to be both the same sex (50% chance) and get the same X chromosome, this increases the odds by 4 to (1/(0.5)^44)*4 = 70 trillion. This is why the sex chromosome acts like an autosome.
For full siblings, there is an observed mean of 0.50146 relatedness with an SD of 0.03761 (from the supplementary table). To get this halfway to twins, we would need 0.25/0.03761 = 6.6471683063 SDs above the mean. This occurs, on average, once in (1 / (1 - norm.cdf(6.6471683063))) = 66,937,665,852 events. To go the rest of the way to full twins, we will need to be (1-0.50146)/0.03761 = 13.2555171497 SDs above the mean, which is one in 4.771 * 10^39 events!
Since about 100 billion humans have ever lived, and a "chance" half-twin half-sibling occurs once every 67 billion humans, this has probably happened before. Interestingly, this 75% genetically related sibling pair, derived from empirical data, has about the same probability of about 75% of the chromosomes happening to assort the same way.
More extra information:
Darlingtonia's answer is good. However, there is recombination, which makes it extremely more unlikely than it already is. The existence of inbreeding helps with this a bit, as sequences might be exactly the same between mother and father already.
Let's look at some data.
This paper used real allele frequencies to generate a relatedness distribution for full siblings.
https://academic.oup.com/beheco/article/20/2/410/219031
Another paper looked at relatedness of full siblings had has standard errors available.
https://academic.oup.com/beheco/article/29/2/468/4819097
But this isn't fine grained enough. Let's make a simulation. Also, let's assume the siblings will both be women or both be men. Since this only happens half the time, the real odds are halved. We will also ignore recombination hotspots, discussed here: http://adamauton.com/adam_auton_thesis.pdf
23*2 chromosomes. 1.6 recombinations per chromosome (we are ignoring variation between different chromosomes): https://book.bionumbers.org/what-is-the-rate-of-recombination/.
Length of the average chromosome: 6.3 Giga-base-pairs divided by 46 = 136,956,522. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6391780/
136,956,522 base pairs make up each of the 46 chromosomes. Recombination happens 1.6 times on each chromosome.
137 base pairs make up each of the 46 chromosomes. Recombination happens 1.6 times on each chromosome. Allow two parents to produce 10 offspring in this way. Then, calculate the average relatedness coefficient between the children.
We could use the infinite allele model but adjusted for the baseline relatedness we'd expect due to chance, which, for four alleles, is 0.25. However, this would incorrectly classify genetic twins as only 75% related.
Therefore, we could use chunks. The length of shared chunks can be used to estimate genetic relatedness. We would also need to use SNPs, not total base pairs, as most base pairs will be the same for all mammals.
At this point, we are making way too many assumptions for this simulation estimate to be realistic.
Instead, let's look at real data:
"IBD sharing between pairs of full siblings in the SAMAFS and Hemani20k data, which have mean IBD proportions of 0.501 and 0.502"
https://journals.plos.org/plosgenetics/article?id=10.1371/journal.pgen.1007979
We want both homologous chromosomes in one individual to be identical by descent to make "twins."
For full siblings, there is an observed mean of 0.50146 relatedness with an SD of 0.03761 (from the supplementary table). To get this halfway to twins, we would need 0.25/0.03761 = 6.6471683063 SDs above the mean. This occurs, on average, once in (1 / (1 - norm.cdf(6.6471683063))) = 66,937,665,852 events. To go the rest of the way to full twins, we will need to be (1-0.50146)/0.03761 = 13.2555171497 SDs above the mean, which is one in 4.771 * 10^39 events!
Since about 100 billion humans have ever lived, and a "chance" half-twin half-sibling occurs once every 67 billion humans, this has probably happened before.


what is the exact meaning and function of "も" in below sentence?

Question: The sentence is "ムダっていわなくても " I know the total meaning is"I wouldn't say that is useless" but I want to know the exact meaning and function of "も" in the sentence.
Answer: It's a part of ても/でも meaning "even if". So the literal translation of ムダっていわなくても is "even if you don't say (it's a) waste...". As usual, the final part of the sentence has been omitted, but it's usually (ムダって言わなくても)いい. Thus the sentence roughly means "You don't have to say (it's a) waste".
Depending on the context, this sentence implies something like this:

I know it's a waste, so you don't have to say that to me! I'm doing this on purpose!
It may be a waste, but saying that without reservation is too harsh!


Necessary and sufficient condition for Bernoulli's theorem

Question: For an ideal fluid, if the vorticity is $\vec{\omega}=\nabla \times \vec{v}$, then Euler's equations can be rewritten as:
$$\rho \dot{v}_i = \rho \epsilon_{ijk} v_j \omega_k - \frac{1}{2}  \rho \partial_i v^2 - \partial_i p $$
Any textbook will then tell you that if you have a steady flow with zero vorticity:
$$ \frac{1}{2} \rho \partial_i v^2 + \partial_i p = 0 $$
which is a differential form of Bernoulli's theorem. However as it is obvious from the previous equation the necessary and sufficient condition for this equation to hold is not a steady flow with $\vec{\omega}=0$ but a steady flow with $\vec{v} \times \vec{\omega}=0$, which is a more general condition. I am wondering if one can give a nice geometric interpretation of this condition. In other worlds, what is the geometric interpretation of a vector field having $\vec{v} \times (\nabla \times \vec{v}) = 0$?
Answer: The actual derivation of the Bernoulli equation comes from the vorticity form of the incompressible Navier-Stokes equation. In terms of vorticity, the Navier-Stokes equation take the form,
$$ \frac{\partial \vec{V}}{\partial t} + \vec{\omega} \times \vec{V} = -\nabla\left(\frac{p}{\rho} + \frac{|\vec{V}|^2}{2} + k\right) + \nu \cdot \left(\nabla \times \vec{\omega}\right)$$
Now if we have steady flow, $\frac{\partial \vec{V}}{\partial t} = 0$, and if we further assume the flow is inviscid, then the equation reduces to,
$$ \vec{\omega} \times \vec{V} = -\nabla\left(\frac{p}{\rho} + \frac{|\vec{V}|^2}{2} + k\right)$$
Obviously, if the flow is irrotational, namely $\vec{\omega} = \nabla \times \vec{V} = 0$, then we are left with,
$$ \nabla\left(\frac{p}{\rho} + \frac{|\vec{V}|^2}{2} + k\right) = 0 $$
or equivalently,
$$ \frac{p}{\rho} + \frac{|\vec{V}|^2}{2} + k = \textrm{constant}$$
This is the most famous form of the Bernoulli equation, which requires steady, incompressible, inviscid, and irrotational flow. Also, an important note on this relation, because the flow is irrotational, the Bernoulli equation can be applied across streamlines. Now for the case you specified, for instance, what if the flow is rotational? Well, you have to consider the direction of the vector quantity $\vec{\omega} \times \vec{V}$. The resulting vector of $\vec{\omega} \times \vec{V}$ is orthogonal to the velocity and vorticity vector. Therefore, along a streamline the quantity $\vec{\omega} \times \vec{V} = 0$. Hence, the resulting equation becomes,
$$ \frac{p}{\rho} + \frac{|\vec{V}|^2}{2} + k = \mathrm{constant\big|_{streamline}}$$
Therefore, the conclusion is that the Bernoulli equation can be applied across streamlines if we have steady, incompressible, inviscid, and irrotational flow ($\vec{\omega} = \nabla \times \vec{V} = 0$). However, if the flow is rotational ($\vec{\omega} = \nabla \times \vec{V} \neq 0$), we can only apply the Bernoulli equation along a streamline.
Comment: What you say is mostly true, but is not what I am interested in at the moment. I am stating that even if we want to apply the Bernoulli theorem across streamlines, across the entrie fluid, one can do that with a condition that is weaker than zero vorticity. However, I have no geometric picture of what a flow with non-zero vorticity, but zero $\vec{v} \times \vec{\omega}$ is.
Comment: Also, generally vorticity is not orthogonal to velocity. The scalar product of the velocity field with the vorticity actually has a name: [https://en.wikipedia.org/wiki/Hydrodynamical_helicity However, this does not change your argument as you never made use of your statement "we must recognize that the vorticity vector is always orthogonal to the the velocity vector". You only need that $\vec{\omega} \times \vec{v}$ is orthogonal to $\vec{v}$ for your result to hold.
Comment: You are correct. The vorticity vector does not always have to be orthogonal to the velocity vector. Only in a 2-Dimensional flow is the vorticity vector always perpendicular to the velocity vector. However, as you mentioned, the above statement wasn't used to reach the same conclusion.
Answer: The quantity $\vec{v}\times(\vec{\nabla}\times\vec{v})$ you are interested in here is known as the Lamb vector in theoretical fluid dynamics. It's gone a bit out of fashion these days, but there's some useful material in the JFM paper by C. W. Hamman, J. C. Klewicki and R. M. Kirby, "On the Lamb vector divergence in Navier–Stokes flows". Perhaps more pertinently, your question is a near-duplicate of a question asked here in February with an answer that has some more detail also. A Google search on "Lamb vector" may turn up more material you find interesting.
P.S.: Perhaps the main reason why people typically invoke the more restrictive condition of irrotationality to justify the use of the Bernoulli equation is that the space of irrotational flows is an invariant subspace of the Navier-Stokes equations (meaning, roughly, there's a large, and practically relevant, set of flows that satisfy this condition), whereas the subspace of flows with zero "vortex force" (Lamb vector) is not invariant, so non-trivial rotational flows with vanishing Lamb vector everywhere will not in general retain this state. I think...
I hasten to add that I'm not an expert on this; I'll readily admit that I don't even know what an interesting rotational flow with vanishing Lamb vector would look like.


Ho to show All Versions of "Append Changes to Existing Text" Data in mail using workflow

Question: How to get plain text from "Append Changes to Existing Text" using workflow in mail content
Answer: Append Changes to Existing Text will always give latest entry in workflow.
There is a work around to have all the entries in the workflow.
For this you need to create another multi line column which will store the entries of all the versions of actual multi line column. Only thing is that, this column should be hidden on New/Edit Forms so that users can not modify its value from UI.
Following are the steps:

Create a column, say HiddenHistoryColumn in the list of type multi line of text.
Create a list workflow on that list on item create and update.
Create three local workflow variables of string type as e.g. PreEntries, LatestEntry, CombinedEntries
Following is the workflow steps. (you may change these as per your need)
If CurrentItem:Column1 is not empty
    set Variable:PreEntries to CurrentItem:HiddenHistoryColumn
    then set Variable:LatestEntry to CurrentItem:Column1
    then set Variable:CombinedEntries to [%Current Item:Modified By%] ([%Current Item:Modified%]): [%Variable:LatestEntry%] <NewLine> [%Variable:PreEntries%]  //Format it as per your need in string builder dialog box
    then set HiddenHistoryColumn to Variable:CombinedEntries
    then Email User1

Use HiddenHistoryColumn in Email Body to get all version of "Append Changes to Existing"

Ho to show All Versions of “Append Changes to Existing Text” Data in mail using workflow


web development in Opera

Question: Do you think that this approach is correct? Opera has less than 3% in the market. Should I develop my project to support Opera? I intend no to. I want to do this using HTML5 and as far as I know not all elements of new version of html are supported by Opera. What is your approach?
Comment: What in particular does Opera not support that you want to use?
Answer: You should develop with interoperability in mind as to develop your Web sites in a way that will work across devices and softwares.
Browser Market Shares
The global market share stats are hiding a lot of juicy details and you would be surprised by the data if you look at it closely. Statcounter is a way to get an idea of stats. Just be careful, because these are just collecting data with counters. But you could for example compared the world market shares for Desktop with the Russian Federation market shares.
Or you could check the world market shares for Mobile with the ones of let say Mexico and USA and you would notice that two neighboring countries have very different market shares.
Web Specifications supported by Opera
To get an understanding of what is supported or not supported yet by Opera, I would recommend you read the Web specifications support in Opera products. It gives a detailed list of the areas of support not only for Opera desktop but all type of Opera browsers (Mobile and Mini included).
If you check the user agent string, you can also get the version of the rendering engine, for example, Presto 2.10, and then head to the specific Web technologies support page for this engine. It would help to assess what are Web technologies supported.
Another good site that will help you assess the support of Web features across the browsers is When Can I use. For example for CSS Animation and CSS transitions.
Answer: 3% means millions of users. Opera is especially used in mobile devices (even old ones) and other devices, like consoles.
Opera is also especially useful for impaired users, which cannot be left behind. You should develop all your projects using the many HTML features to help impaired users in various ways. Accessibility should be one of your main concerns.
As far as HTML 5 concerns, not all new elements are supported by any browser out there. HTML 5 is still a work in progress specification, and all browsers are still incompatible with many features. This is why there are many useful ways to improve compatibility, for example Modernizr.
With these things in mind, I would surely take Opera into consideration.

web development in Opera


How to hide welcome drop down menu from the ribbon in sharepoint 2010?

Question: I am currently working on the masterpage of my sharepoint site and I want to hide the welcome drop down menu that appears on the top right corner of my  sharepoint site and all the tabs. In place of a drop down I only want to display the user's name. How can I do that?
Answer: You can hide or remove the welcome control

< wssuc:Welcome id="IdWelcome" runat="server" EnableViewState="false"
  style="display:none" >

To add user name without the code use this tutorial


Counting overlaps between raster files using ArcPy?

Question: Would it be possible to simply detect and count overlaps between raster files, i.e. not polygons against rasters, using arcpy? By default I don't have the spatial analyst extension for ArcMap 10.1 but if need be I could acquire one temporarily. I need to iterate over small tif files in various directories and test them against large rasters.
Comment: Rasters have an extent property in the describe, you can easily test for extent-overlap-extent but when you are talking about cell-on-cell it's a bit more difficult. Probably best to use GDAL in python to test that.
Comment: Right. I was thinking I might create a mosaic dataset, build footprint polygons and just test that rather than try for a shortcut. Something of the sort.
Comment: That would work no doubt, I would use os.walk to search folders and subfolders then arcpy.describe to get the extent object and then using extent.XMin, extent.YMin... test for numerical intersection with the big raster(s). If you're not comfortable with that you can os.walk to get the folders and then use arcpy.listRasters() to list the rasters in each folder and subfolder.
Comment: Are these single band rasters or multiband?
Comment: They're single-band narrow pathways. As such I don't think the extent trick would work in this specific case, but it's a good tip.
Answer: Try the following workflow:

Reclassify your rasters so that Value = 1.
Calculate Cell Statistics using a "SUM" statistic.

Any value in the resulting raster > 1 is an overlap area.  Additionally, the value of the resulting raster indicates how many overlapping rasters there are.
Comment: I like that approach @aaron. How then would you turn that into a boolean yes/no for overlap? Perhaps calculate statistics and use arcpy.GetRasterProperties_management(raster,"MAXIMUM") to indicate overlap.
Comment: Good ideas, though I'd have to reclassify all my rasters of which there are many. Thanks for the tip.
Comment: @Sleep6 You could automate this very quickly using ModelBuilder.
Comment: True, it's just that the data is all over the place, which is why I thought arcpy would be the better choice to crawl through various subfolders.
Comment: @Sleep6 It would be great to use Python with this approach.  All of your narrow pathways in each raster would then have the value of "1" and background values in the raster extent would have "0" values.  It would also be very easy to use `arcpy.da.walk` to grab all of the rasters in various directories.


Which lines do I play in keyboard music that accompanies singing?

Question: I have this Gershwin songbook for piano and voice. I am not sure whether I am supposed to play the vocal line. The vocal line has its own staff, but the notes are also doubled on the piano's staff as well. In some sections of the songs it is clear that the accompaniment follows the vocal line but the piano plays chords underneath the melody notes as opposed to just the melody notes. However, in other sections of the song, it seems impossible to play all the notes written on the piano's staff. For instance in the music below, at the second line from the top where the lyrics are: "We'd love to take a picture of the happy bride" The vocal line appears identical in the top single staff as well as the treble clef of the piano part. But in some instances the melody notes go too high to be able to play all the notes written. Why do they do that? How am I supposed to approach this? Am I supposed to only play the notes with the stems pointing down, indicating the accompaniment part?
Answer: Do what the singer wants you to.
Some singers may prefer you to double the vocal part, perhaps to help give them confidence. A more experienced singer is likely to prefer that you do not double the vocal part, as this approach allows more prominence to the voice. An inexperienced singer learning the music may prefer you to double the melody during early rehearsals, but not later on. There may even be sections played with the vocal line and sections played without. The music is written in a way that provides for all these options depending on the skill and desires of the singer and accompanist.
Answer: As a piano solo, the piano part — the two lower staves — is intended to be played as written. Were it being used to accompany a singer, then the stem-up notes could be included or omitted as desired.
The one place where the notes span more than an octave is in the middle of the second system on the word "of". In that case, though, the chord on "-ture" is only an eighth note. That can be played, then released to play the D on "of". It is also expected that pedal will be used to assist as needed.
Answer: In my opinion you can just ignore the melodyline performed by the voice.

But why do they do this?

If you play the song without a singer you need to play the melody too:
Be free to adapt the arrangement to your abilties. The biggest span is in the 3rd line groom. The middle E and D can be played with the thumb.
Comment: There's no D there; it's an E. The chord is E-F#-A#
Comment: in the measure of *groom* - 1st bar 3rd line - there's is no F#.  But yes, the 2nd bar  needs a spam of finger 2-5 of a 7th. So we have to drop the higher E.
Comment: Oh, you mean probably the *groom* in line 4 ? There is a decime in the left hand F#-A#, that could be a handycap to: Play first F# and then subito A#
Comment: Ah, yes. You're right. My mistake.
Answer: The middle line is there to cover all. The top line is there to cover solely the vocal part. Tha bottom line covers what the piano left hand will play - or even a bass guitar part.
As far as 'what lines do I play?' is concerned, it's up to you - and the vocalist. They may prefer either - a consummate singer will probably like his own melody line absent from the r.h., whereas a beginner, or one learning the piece, would like it for support. 'Twere it me, I'd be playing verbatim until the singer is confident, then trying without the top notes in the treble clef.
There's also the very top line - the chords, for guitar, uke, et al.And there's no good reason why the piano player can't use that as a guide to accompaniment, making the bottom two lines redundant.
It's interesting that the 2nd and 3rd lines actually desigate vocals, with stems up. But the 1st line does no such thing - and at the end, there are notes which are only payed by piano, not sung.
So, no golden rule, but lots of options!


Why are oceans said to have "low productivity" in terms of photosynthesis?

Question: 80% of the world's photosynthesis takes place in the ocean. Despite this, oceans are also said to have low productivity - they cover 75% of the earth's surface, but out of the annual 170 billion tonnes of dry weight fixed by photosynthesis, they contribute to only 55 billion tonnes. Are not these two facts, which I have come across separately, contradictory? If oceans fix 80% of the total $\ce{CO2}$ fixed by photosynthesis on earth and release 80% of the total $\ce{O2}$ released by photosynthesis on earth, they should have accounted for 80% of the dry weight produced as well. Is there any way to reconcile these facts? In any case, if 80% photosynthesis occurs in oceans, that hardly seems low productivity - then why are oceans said to have low primary productivity (a host of reasons are also given for this - that light is not available at all depths in oceans, etc.)? A large amount of photosynthesis taking place should mean a large productivity!
Comment: It'll help if you can provide where you found those two statistics (80% of the world's productivity takes place in the ocean and 55/170 million tonnes of dry weight is produced by the oceans)
Comment: [BioNumbers](http://bionumbers.hms.harvard.edu/search.aspx?log=y&task=searchbytrmorg&trm=primary+production&org=) suggests that the 170 and 50 Gt values are roughly correct, as measured by the papers cited.
Comment: Actually both were my [high school level] textbooks. But here is a reference for the 170 billion tonnes figure.
Answer: First, we have to know which are the most important criteria for photosynthesis to occur; these are: light, CO2, water, nutrients.
docenti.unicam.it/tmp/2619.ppt
Second, the productivity, you are talking about, it should be called "primary productivity" and it is calculated, dividing the amount of carbon converted per area (m2) by the time.
ww2.unime.it/snchimambiente/PrPriFattMag.doc
So, thanks to the fact that oceans occupy the larger area of the world, the marine microorganisms can convert lots of inorganic carbon into organic (principle of photosynthesis).
A big problem in the oceans is availability of nutrients; these tend to deposit or react with water or other chemical compounds, even though the marine photosynthetic organisms are essentially found on the surface, where, of course, light is present. This reduces as a consequence the  photosynthetic productivity potential of oceans.
Comment: You should provide some references to support your answer.
Answer:
If oceans fix 80% of the total CO2CO2 fixed by photosynthesis on earth
  and release 80% of the total O2O2 released by photosynthesis on earth,
  they should have accounted for 80% of the dry weight produced as well.

First, what is meant by "O2 released"? Does it mean "O2 released from the oceans into the atmosphere, where it contributes to a growing surplus"? That can't be the case since the amount of O2 in the atmosphere is pretty constant, and there is evidence that it is significantly lower than in Jurassic times.  Overall the global O2 sinks must balance the O2 sources, or if anything must slightly exceed them, resulting in the current gradually increasing atmospheric CO2 levels at the expense of O2 levels.
So by "released" we have to just mean "released by the process of photosynthesis, at the point of its operation".
Oceans fix 80% of the total CO2 fixed by photosynthesis, yes, but they also unfix it at a similar rate. For every algal cell that's photosynthesising, there's one that's dead or dying and being consumed by bacteria (which consume O2), or that's consuming oxygen itself in order to keep its metabolic processes operating at night. So the NET amount of O2 released by the oceans is something close to zero.
Now we have to ask what we mean by "productivity" in this context. If a molecule of CO2 gets fixed due to algal activity but then almost immediately gets unfixed again, does that count as "productivity"? But, blink and you'd miss it! Even if you don't blink, it's hardly likely to be measurable. The dry weight of the algae at the end of the of the process is the same as at the beginning. so if we define "productivity" as "increase in dry weight of algae" then the productivity is zero.
For algal photosynthesis to have an enduring effect on global CO2 or O2 levels, the fixed CO2 has to become incorporated into something less fleeting than algae. Something like cod or hake, which as a bonus can be harvested and placed on tables. "Productivity" usually refers to the power of the oceans to replenish the stocks of these things post-harvest, and that is indeed low when compared to the ability of the land to produce repeated harvests.
It would be a different story if we were to regard algae as potentially suitable for mass harvesting, so that their ability to grow like wildfire in the presence of fertilizer runoffs from the land was regarded as "productivity" rather than as a profound nuisance. But this is not the case.
In other words, we tend to define "productivity" in terms of what is useful to us as a species, and algae are generally not useful.


Force nodes created by Feeds module to be published even if nodes are unpublished by default

Question: How can I do this? Force nodes created by Feeds module to be published even if regular nodes are unpublished by default.
Answer: Implement hook_nodeapi() for the 'presave' operation to set the node status to published if there is a new one created by Feeds:
function MODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if ($op === 'presave' && empty($node->nid) && !empty($node->feeds_node_item)) {
    $node->status = 1;
  }
}

Comment: I'm going to try this
Answer: Making nodes published is not a problem, the question is how are we going to tell the nodes created by Feeds. The quickest options are

a separate node type for imported content, or
a hidden field that only gets set via Feeds mapping

Assuming none of the quick solutions would fit your scenario, the only actual way to tell Feed-created nodes is the feeds_node_item. After importing a node, it will contain a record for the node, with nid column set to the node id.
Making use of the Rules module, the whole trick is just a matter of an Execute custom PHP code for condition to check if the record is there for the newly created node:
Add new rule
Event: After saving new content
Add a condition
Select the condition to add: Execute custom PHP code
PHP code
<?php
$a = db_fetch_array(db_query("select count(*) c from {feeds_node_item}
                              where nid = %d", array($node->nid)));
return $a['c'] != 0;
?>

Add an action
Select an action to add: Publish content
Answer: I've done something similar to expose the user status as a mapper; see the patch proposed in Add user status to FeedsUserProcessor, which would be similar.