3v4l.org

run code in 300+ PHP versions simultaneously
<?php function similarity($w1,$w2) { //return cosine similarity of w1 and w2 using formula in the //definition here: http://en.wikipedia.org/wiki/Cosine_similarity //get numerator: $numerator = 0; for($i = 0, $l = count($w1); $i < $l; $i++) $numerator += $w1[$i]*$w2[$i]; //get abs(w1) and abs(w2) $abs_w1 = 0; $abs_w2 = 0; for($i = 0, $l = count($w1); $i < $l; $i++) { $abs_w1 += $w1[$i]*$w1[$i]; $abs_w2 += $w2[$i]*$w2[$i]; } $abs_w1 = sqrt($abs_w1); $abs_w2 = sqrt($abs_w2); //make denominator: $denominator = $abs_w1*$abs_w2; return $numerator/$denominator; } echo similarity([1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,88]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/diNTK
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'similarity'
          1        SEND_VAL                                                 <array>
          2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5      > RETURN                                                   1

Function similarity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 20
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 20
Branch analysis from position: 31
Branch analysis from position: 20
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
Branch analysis from position: 7
filename:       /in/diNTK
function name:  similarity
number of ops:  44
compiled vars:  !0 = $w1, !1 = $w2, !2 = $numerator, !3 = $i, !4 = $l, !5 = $abs_w1, !6 = $abs_w2, !7 = $denominator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ASSIGN                                                   !2, 0
    8     3        ASSIGN                                                   !3, 0
          4        COUNT                                            ~10     !0
          5        ASSIGN                                                   !4, ~10
          6      > JMP                                                      ->12
          7    >   FETCH_DIM_R                                      ~12     !0, !3
          8        FETCH_DIM_R                                      ~13     !1, !3
          9        MUL                                              ~14     ~12, ~13
         10        ASSIGN_OP                                     1          !2, ~14
         11        PRE_INC                                                  !3
         12    >   IS_SMALLER                                               !3, !4
         13      > JMPNZ                                                    ~17, ->7
   11    14    >   ASSIGN                                                   !5, 0
         15        ASSIGN                                                   !6, 0
   12    16        ASSIGN                                                   !3, 0
         17        COUNT                                            ~21     !0
         18        ASSIGN                                                   !4, ~21
         19      > JMP                                                      ->29
   13    20    >   FETCH_DIM_R                                      ~23     !0, !3
         21        FETCH_DIM_R                                      ~24     !0, !3
         22        MUL                                              ~25     ~23, ~24
         23        ASSIGN_OP                                     1          !5, ~25
   14    24        FETCH_DIM_R                                      ~27     !1, !3
         25        FETCH_DIM_R                                      ~28     !1, !3
         26        MUL                                              ~29     ~27, ~28
         27        ASSIGN_OP                                     1          !6, ~29
   12    28        PRE_INC                                                  !3
         29    >   IS_SMALLER                                               !3, !4
         30      > JMPNZ                                                    ~32, ->20
   16    31    >   INIT_FCALL                                               'sqrt'
         32        SEND_VAR                                                 !5
         33        DO_ICALL                                         $33     
         34        ASSIGN                                                   !5, $33
   17    35        INIT_FCALL                                               'sqrt'
         36        SEND_VAR                                                 !6
         37        DO_ICALL                                         $35     
         38        ASSIGN                                                   !6, $35
   20    39        MUL                                              ~37     !5, !6
         40        ASSIGN                                                   !7, ~37
   22    41        DIV                                              ~39     !2, !7
         42      > RETURN                                                   ~39
   23    43*     > RETURN                                                   null

End of function similarity

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.29 ms | 1402 KiB | 16 Q