⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page96.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Canonical Matrix Multiplication</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html2313" HREF="page97.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2311" HREF="page89.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2307" HREF="page95.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2315" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION004270000000000000000">Canonical Matrix Multiplication</A></H2><A NAME="secfdsmatmul">&#160;</A><P>Given an  <IMG WIDTH=42 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline60545" SRC="img618.gif"  > matrix <I>A</I>and an  <IMG WIDTH=37 HEIGHT=17 ALIGN=MIDDLE ALT="tex2html_wrap_inline60557" SRC="img620.gif"  > matrix <I>B</I>,the product <I>C</I>=<I>AB</I> is an  <IMG WIDTH=42 HEIGHT=17 ALIGN=MIDDLE ALT="tex2html_wrap_inline60563" SRC="img621.gif"  > matrix.The elements of the result matrix are given by<P><A NAME="eqnmatmul">&#160;</A> <IMG WIDTH=500 HEIGHT=47 ALIGN=BOTTOM ALT="equation3243" SRC="img622.gif"  ><P>Accordingly, in order to compute the produce matrix, C,we need to compute <I>mp</I> summationseach of which is the sum of <I>n</I> product terms.An algorithm to compute the matrix productis given in Program&nbsp;<A HREF="page96.html#progdenseMatrixb"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The algorithm given is a direct implementation of Equation&nbsp;<A HREF="page96.html#eqnmatmul"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="3312">&#160;</A><A NAME="progdenseMatrixb">&#160;</A> <IMG WIDTH=575 HEIGHT=294 ALIGN=BOTTOM ALT="program3253" SRC="img623.gif"  ><BR><STRONG>Program:</STRONG> <tt>DenseMatrix</tt> class <tt>__times__</tt> method.<BR><P><P>The algorithm begins by checking to see that the matricesto be multiplied have compatible dimensions.That is, the number of columns of the first matrix must be equal tothe number of rows of the second one.This check takes <I>O</I>(1) time in the worst case.<P>Next a matrix in which the result will be formed is constructed (line&nbsp;6).The running time for this is <I>O</I>(<I>mp</I>).For each value of <I>i</I> and <I>j</I>,the innermost loop (lines&nbsp;10-11) does <I>n</I> iterations.Each iteration takes a constant amount of time.<P>The body of the middle loop (lines&nbsp;9-12)takes time <I>O</I>(<I>n</I>) for each value of <I>i</I> and <I>j</I>.The middle loop is done for <I>p</I> iterations,giving the running time of <I>O</I>(<I>np</I>) for each value of <I>i</I>.Since, the outer loop (lines&nbsp;7-12) does <I>m</I> iterations,its overall running time is <I>O</I>(<I>mnp</I>).Finally, the result matrix is returned on line&nbsp;13.This takes a constant amount of time.<P>In summary, we have shown that lines&nbsp;4-5 are <I>O</I>(1);line&nbsp;6 is <I>O</I>(<I>mp</I>);lines&nbsp;7-12 are <I>O</I>(<I>mnp</I>); andline&nbsp;13 is <I>O</I>(1).Therefore, the running time of the canonical matrix multiplicationalgorithm is <I>O</I>(<I>mnp</I>).<P><HR><A NAME="tex2html2313" HREF="page97.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2311" HREF="page89.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2307" HREF="page95.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2315" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright &#169; 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.</ADDRESS></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -