« first day (2131 days earlier)      last day (2343 days later) » 

6:00 AM
Are you coming from a party and you drank too much? Want to throw up before you go to bed? Mathematica can help. Look at this for a minute.
 
6:55 AM
does compilation offer any improvements over buiilt-in operations on matrices? (simple stuff as calculating the mean or normalizing).
 
@Alucard Maybe. Many linear algebra functions are backed with a fast c library for numerical computations. Something like Mean should be generally fast. If you cannot pinpoint a hotspot, I wouldn't spend too much time on this.
It really depends on the specific algorithm.
 
7:31 AM
i am using :
S1 = Quiet[
N[s1[[All, All]]/
Sqrt[s1[[All, All]]^2 + s2[[All, All]]^2 + s3[[All, All]]^2] //.
Indeterminate -> 0.]] ;
S2 = Quiet[
N[s2[[All, All]]/
Sqrt[s1[[All, All]]^2 + s2[[All, All]]^2 + s3[[All, All]]^2] //.
Indeterminate -> 0.]] ;
S3 = Quiet[
N[s3[[All, All]]/
Sqrt[s1[[All, All]]^2 + s2[[All, All]]^2 + s3[[All, All]]^2] //.
Indeterminate -> 0.]] ;
to normalize the elements of the 3 matrices. right now i was reading about compile on the Wolfram Reference but in all honesty i am failing to get a working compiled function
@halirutan since the operations are indipendent i should be able to use parallelization , so i thought it made sense using it
 
8:03 AM
@Alucard Have you seen this? Compiling in Mathematica does not just mean taking a piece of code that you have previously written and running Compile on it, you have to plan to compile the piece of code beforehand and then write the piece of code using the subset of Mathematica that can be compiled.
Also, you matrices have to be all of the same type. You can't have matrices which mix real values with Indeterminate, the language that you compile to uses static typing and it can't handle things like that. It is part of what makes it faster.
 
8:23 AM
uhm so in theory i should preprocess the data and remove the indeterminate points ( and the Quiet) in order to compile, but that's mean losing any advantage i may obtain with compile. k, got it, thanks
 
 
5 hours later…
1:14 PM
@Alucard Sorry, you caught me when I was almost offline as I needed to repair the car.
C.E. is correct: Think of Compile as a Mathematica-like C. It can be incredibly fast, but all variables need exact types and mixed types inside tensors (aka vectors, lists, matrices..) are not possible.
Symbols, except as variables are not possible either. So replacing Indeterminate wouldn't work. Additionally, only a small set of Mathematica functions is actually compilable.
What happens, when you do stuff that cannot be compiled is that the compiled code calls back to the Math-Kernel for evaluation, gets the result and works with it. You can imagine that this will almost (!!) always be not what you want as it decreases speed.
 
1:30 PM
Let me give a rundown of the usual approach. First, you write your compiled code. In this case, I want have a list of vectors and I want to calculate the norm of each vector. This can be done in parallel in a compiled function. So you write down the code that calculates the norm of one vector and tell Compile that this function should be run in parallel over all vectors when it sees a list of vectors:
fc = Compile[{{vec, _Real, 1}},
  Sqrt[Total[vec^2]],
  Parallelization -> True,
  RuntimeAttributes -> {Listable}
  ]
As you can see, I have specified both the type and the rank of the vec argument.
Next step is to ensure everything got compiled like you wanted it:
<< CompiledFunctionTools`
CompilePrint[fc]
There are no MainEvaluate calls in this and all instructions could be translated to Mathematica virtual machine code.
Now you can compare it with a simple "Map Norm over the list":
vecs = RandomReal[1, {100000, 100}];
Median[Table[First@AbsoluteTiming[Norm /@ vecs;], {100}]]
Gives 0.015 s here
The compiled function does it a bit better:
Median[Table[First@AbsoluteTiming[fc[vecs];], {100}]]
Runs in 0.0071 s here.
These are the 3 steps: Write your algorithm in pure numerical code. Check if everything was compiled like you want it. Test it and see if parallelization makes sense.
 
 
3 hours later…
4:13 PM
so it generates a pseudo C code where all the types must be declared beforehand. the evaluation speed doubled ,
too bad i have those annoying indeterminate cases.
 
4:26 PM
@Alucard If you need the speed increase then ask yourself how you would solve this problem in a language that doesn't have the concept of indeterminate numbers – as many don't – and ask yourself how you would solve the problem in that language. Then solve it in that way.
 

« first day (2131 days earlier)      last day (2343 days later) »