Difference between revisions of "NL/Documentation/How Tos/Calc: functie INVERSEMAT"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 1: Line 1:
__NOTOC__
 
  
== INVERSEMAT ==
 
Geeft de inverse van een matrix terug.
 
  
=== Syntaxis: ===
 
<tt>'''INVERSEMAT(matrix)'''</tt>
 
: geeft de inverse terug van de vierkante matrix <tt>'''matrix'''</tt>, welke een matrix als regel of een bereik mag zijn, die alle getallen bevat.
 
  
: <tt>'''INVERSEMAT'''</tt> geeft een matrix terug en moet worden ingevoerd als een matrixformule (bijvoorbeeld door '''Ctrl-Shift-Enter''' te gebruiken in plaats van alleen '''Enter''').
 
  
: Een matrix heeft alleen een inverse als de determinant er van niet nul is.
+
# Copyright 2006 Google Inc.
 +
#
 +
# Licensed under the Apache License, Version 2.0 (the "License");
 +
# you may not use this file except in compliance with the License.
 +
# You may obtain a copy of the License at
 +
#
 +
#    http://www.apache.org/licenses/LICENSE-2.0
 +
#
 +
# Unless required by applicable law or agreed to in writing, software
 +
# distributed under the License is distributed on an "AS IS" BASIS,
 +
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 +
# See the License for the specific language governing permissions and
 +
# limitations under the License.
  
=== Voorbeeld: ===
+
# OO.o build profile analyzer. To get the required patches look at:
<tt>'''=INVERSEMAT({4;2|3;2})'''</tt>
+
# http://wiki.services.openoffice.org/wiki/BuildSpeedup
: indien ingevoerd als een matrixformule in cel B3, geeft <tt>'''{1;-1|-1,5;2}'''</tt> terug, zodat de cellen B3, C3, B4, C4 respectievelijk weergeven <tt>'''1'''</tt>, <tt>'''-1'''</tt>, <tt>'''-1,5'''</tt>, <tt>'''2'''</tt>.
+
# Author: Kai Backman, kaib@google.com
  
<tt>'''=INVERSEMAT(A1:B2)'''</tt>
+
import os
: indien ingevoerd als een matrixformule in cel B3, waarbij de cellen A1, B1, A2, B2 respectievelijk bevatten <tt>'''4'''</tt>, <tt>'''2'''</tt>, <tt>'''3'''</tt>, <tt>'''2'''</tt>, geeft respectievelijk <tt>'''1'''</tt>, <tt>'''-1'''</tt>, <tt>'''-1,5'''</tt>, <tt>'''2'''</tt> terug in de cellen B3, C3, B4 en C4.
+
import re
 +
import sys
  
=== Zie ook: ===
+
def SortProfileTimes(lhs, rhs):
 +
  if lhs[1] < rhs[1]<>: return 1
 +
  elif rhs[1] < lhs[1]<>: return -1
 +
  else<>: return 0
  
[[Documentation/nl/How_Tos/Calc: functie DETERMINANT.MAT|'''DETERMINANT.MAT''']],
+
def ProcessLogFile(file_name, target_durations):
[[Documentation/nl/How_Tos/Calc: functie PRODUCTMAT|'''PRODUCTMAT''']],
+
#  print "Processing file: " + file_name
[[Documentation/nl/How_Tos/Calc: functie EENHEIDSMAT|'''EENHEIDSMAT''']]
+
  file = open(file_name)
 +
  start_time = 0
 +
  end_time = 0
  
[[Documentation/nl/How_Tos/Matrices gebruiken|'''Hoe matrices te gebruiken in Calc''']]
+
  target_start = 0
 +
  target_name = ""
 +
  line = file.readline()
 +
  while line<>!= ""<>:
 +
    tokens = line[:-1].split(" ")
 +
    line = file.readline()
  
[[Documentation/nl/How_Tos/Calc: Matrixfuncties|'''Matrixfuncties''']]
+
    if len(tokens) < 2<>: continue
 +
    if tokens[1] == "build"<>:
 +
      if tokens[0] == "s"<>:
 +
        start_time = int(tokens[2]) * 1000
 +
      elif tokens[0] == "e"<>:
 +
        end_time = int(tokens[2]) * 1000
 +
    elif tokens[1] == "target"<>:
 +
      if tokens[0] == "s":
 +
        target_start = int(tokens[2])
 +
        target_name = tokens[3]
 +
      elif tokens[0] == "e" and target_name == tokens[3]:
 +
        target_duration = int(tokens[2]) - target_start
 +
        target_tokens = tokens[3].split(".")
 +
        target_class = target_tokens[-1]
 +
        if target_class in target_durations<>:
 +
          target_durations[target_class] += target_duration
 +
        else<>:
 +
          target_durations[target_class] = target_duration
 +
  file.close()
 +
  return end_time - start_time
 +
  return
  
[[Documentation/nl/How_Tos/Calc: Functies alfabetisch gesorteerd|'''Functies - alfabetisch gesorteerd''']],
+
 
[[Documentation/nl/How_Tos/Calc: Functies gesorteerd per categorie|'''Functies - gesorteerd per categorie''']]
+
if __name__ == "__main__":
[[Category: NL/Documentation/Reference/Calc]]
+
  target_durations = {}
 +
  total_time = 0
 +
  for file_name in sys.argv[1:]<>:
 +
    total_time += ProcessLogFile(file_name, target_durations)
 +
 
 +
  profile = target_durations.items()
 +
  profile.sort(SortProfileTimes)
 +
  total_target_time = 0
 +
  for target_iter in profile<>:
 +
    target_promille = target_iter[1] * 1000 / total_time
 +
    if target_promille > 0<>:
 +
      print "%6.ds<>%3.d.%1.d%%<>%s"<>% (target_iter[1] / 1000, target_promille/10,
 +
                                      target_promille<>% 10, target_iter[0])
 +
    total_target_time += target_iter[1]
 +
  print "Running time:<>%d s targets:<>%d s<>%d%%"<>% (total_time / 1000, total_target_time / 1000,
 +
                                                  total_target_time * 100 / total_time)

Revision as of 16:06, 28 June 2010



  1. Copyright 2006 Google Inc.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  1. OO.o build profile analyzer. To get the required patches look at:
  2. http://wiki.services.openoffice.org/wiki/BuildSpeedup
  3. Author: Kai Backman, kaib@google.com

import os import re import sys

def SortProfileTimes(lhs, rhs):

 if lhs[1] < rhs[1]<>: return 1
 elif rhs[1] < lhs[1]<>: return -1
 else<>: return 0

def ProcessLogFile(file_name, target_durations):

  1. print "Processing file: " + file_name
 file = open(file_name)
 start_time = 0
 end_time = 0
 target_start = 0
 target_name = ""
 line = file.readline()
 while line<>!= ""<>:
   tokens = line[:-1].split(" ")
   line = file.readline()
   if len(tokens) < 2<>: continue
   if tokens[1] == "build"<>:
     if tokens[0] == "s"<>:
       start_time = int(tokens[2]) * 1000
     elif tokens[0] == "e"<>:
       end_time = int(tokens[2]) * 1000
   elif tokens[1] == "target"<>:
     if tokens[0] == "s":
       target_start = int(tokens[2])
       target_name = tokens[3]
     elif tokens[0] == "e" and target_name == tokens[3]:
       target_duration = int(tokens[2]) - target_start
       target_tokens = tokens[3].split(".")
       target_class = target_tokens[-1]
       if target_class in target_durations<>:
         target_durations[target_class] += target_duration
       else<>:
         target_durations[target_class] = target_duration
 file.close()
 return end_time - start_time
 return 


if __name__ == "__main__":

 target_durations = {}
 total_time = 0
 for file_name in sys.argv[1:]<>:
   total_time += ProcessLogFile(file_name, target_durations)
 profile = target_durations.items()
 profile.sort(SortProfileTimes)
 total_target_time = 0
 for target_iter in profile<>:
   target_promille = target_iter[1] * 1000 / total_time
   if target_promille > 0<>:
     print "%6.ds<>%3.d.%1.d%%<>%s"<>% (target_iter[1] / 1000, target_promille/10,
                                     target_promille<>% 10, target_iter[0])
   total_target_time += target_iter[1]
 print "Running time:<>%d s targets:<>%d s<>%d%%"<>% (total_time / 1000, total_target_time / 1000,
                                                  total_target_time * 100 / total_time)
Personal tools