Related-utility-functions.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <html lang="en">
  2. <head>
  3. <title>Related utility functions - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Type-Conversions.html#Type-Conversions" title="Type Conversions">
  9. <link rel="prev" href="Two-dimensional-arrays.html#Two-dimensional-arrays" title="Two dimensional arrays">
  10. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  11. <meta http-equiv="Content-Style-Type" content="text/css">
  12. <style type="text/css"><!--
  13. pre.display { font-family:inherit }
  14. pre.format { font-family:inherit }
  15. pre.smalldisplay { font-family:inherit; font-size:smaller }
  16. pre.smallformat { font-family:inherit; font-size:smaller }
  17. pre.smallexample { font-size:smaller }
  18. pre.smalllisp { font-size:smaller }
  19. span.sc { font-variant:small-caps }
  20. span.roman { font-family:serif; font-weight:normal; }
  21. span.sansserif { font-family:sans-serif; font-weight:normal; }
  22. --></style>
  23. </head>
  24. <body>
  25. <div class="node">
  26. <a name="Related-utility-functions"></a>
  27. <p>
  28. Previous:&nbsp;<a rel="previous" accesskey="p" href="Two-dimensional-arrays.html#Two-dimensional-arrays">Two dimensional arrays</a>,
  29. Up:&nbsp;<a rel="up" accesskey="u" href="Type-Conversions.html#Type-Conversions">Type Conversions</a>
  30. <hr>
  31. </div>
  32. <h5 class="subsubsection">3.1.4.4 Related utility functions</h5>
  33. <p>A small selection of additional functions that are likely to be of use
  34. to developers concerned with matrix operations has been incorporated
  35. into the API to save the trouble of reinventing them, although doing
  36. so would be straightforward. They are described in this section
  37. without further motivation.
  38. <div class="defun">
  39. &mdash; Function: void <b>*avm_matrix_transposition</b> (<var>void *matrix, int rows, int cols, size_t item_size</var>)<var><a name="index-g_t_002aavm_005fmatrix_005ftransposition-465"></a></var><br>
  40. <blockquote><p>This function takes the address of an arbitrary rectangular
  41. <var>matrix</var> represented as a contiguous array (not a list) and
  42. transposes it in place. That is, this function transforms
  43. an <var>m</var> by <var>n</var> matrix to an <var>n</var> by <var>m</var> matrix
  44. by exchanging the <var>i</var>,<var>j</var>th element with the
  45. <var>j</var>,<var>i</var>th element for all values of <var>i</var> and <var>j</var>.
  46. <p>The numbers of rows and columns in the <var>matrix</var> are given by the
  47. parameters <var>rows</var> and <var>cols</var>, respectively, and the size of
  48. the entries in bytes is given by <var>item_size</var>.
  49. <p>The <var>matrix</var> is assumed to be in row major order, but this
  50. function is applicable to matrices in column major order if the caller
  51. <a name="index-column-major-order-466"></a>passes the number of columns in <var>rows</var> and the number of rows in
  52. <var>cols</var>.
  53. <p>Alternatively, this function can be seen as a conversion between the
  54. row major and the column major representation of a matrix. An <var>m</var>
  55. by <var>n</var> matrix in row major order will be transformed to the same
  56. <var>m</var> by <var>n</var> matrix in column order, or from column order to row
  57. order.
  58. <p>A notable feature of this function is that it allocates no memory so
  59. there is no possibility of a memory overflow even for very large
  60. matrices, unlike a naive implementation which would involve making a
  61. temporary copy of the matrix. There is a possibility of a segmentation
  62. <a name="index-segmentation-fault-467"></a>fault if invalid pointers or dimensions are given.
  63. </p></blockquote></div>
  64. <div class="defun">
  65. &mdash; Function: void <b>*avm_matrix_reflection</b> (<var>int upper_triangular, void *matrix, int n, size_t item_size</var>)<var><a name="index-g_t_002aavm_005fmatrix_005freflection-468"></a></var><br>
  66. <blockquote><p>This function takes a symmetric square <var>matrix</var> of dimension
  67. <var>n</var> containing entries of <var>item_size</var> bytes each and fills in
  68. the redundant entries.
  69. <p>If <var>upper_triangular</var> is non-zero, the
  70. upper triangle of the <var>matrix</var> is copied to the lower triangle. If
  71. <var>upper_triangular</var> is zero, the lower triangular entries are
  72. copied to the upper triangle.
  73. <p>These conventions assume row major order. If the <var>matrix</var> is in
  74. <a name="index-row-major-order-469"></a>column major order, then the caller can either transpose it in place
  75. <a name="index-column-major-order-470"></a>before and after this function by <code>avm_matrix_transposition</code>, or
  76. can complement the value of <var>upper_triangular</var>.
  77. <p>Note that this function may be unnecessary for <code>LAPACK</code> library
  78. functions that ignore the redundant entries in a symmetric matrix,
  79. because they can be left uninitialized, but it is included for the
  80. sake of completeness.
  81. </p></blockquote></div>
  82. <div class="defun">
  83. &mdash; Function: list <b>*avm_row_number_array</b> (<var>counter m, int *fault</var>)<var><a name="index-g_t_002aavm_005frow_005fnumber_005farray-471"></a></var><br>
  84. <blockquote><p>A fast, memory efficient finite map from natural numbers to their list
  85. representations can be obtained by using this function as an
  86. alternative to <code>avm_natural</code> or <code>avm_recoverable_natural</code>
  87. when repeated evaluations of numbers within a known range are
  88. required (<a href="Simple-Operations.html#Simple-Operations">Simple Operations</a> and <a href="Recoverable-Operations.html#Recoverable-Operations">Recoverable Operations</a>).
  89. <p>Given a positive integer <var>m</var>, this function allocates and returns
  90. an array of <var>m</var> lists whose <var>i</var>th entry is the list
  91. representation of the number <var>i</var> as explained in
  92. <a href="Representation-of-Numeric-and-Textual-Data.html#Representation-of-Numeric-and-Textual-Data">Representation of Numeric and Textual Data</a>.
  93. <p>An amount of memory proportional to <var>m</var> is used for the array and
  94. its contents. If there is insufficient memory, a <code>NULL</code> value is
  95. returned and the integer referenced by <var>fault</var> is set to a
  96. non-zero value.
  97. </p></blockquote></div>
  98. <div class="defun">
  99. &mdash; Function: void <b>avm_dispose_rows</b> (<var>counter m, list *row_number</var>)<var><a name="index-avm_005fdispose_005frows-472"></a></var><br>
  100. <blockquote><p>This function reclaims an array <var>row_number</var> of size <var>m</var>
  101. returned by <code>avm_row_number_array</code>, and its contents if any. A
  102. <code>NULL</code> pointer is allowed as the <var>row_number</var> parameter and
  103. will have no effect, but an uninitialized pointer will cause a
  104. <a name="index-segmentation-fault-473"></a>segmentation fault.
  105. </p></blockquote></div>
  106. <div class="defun">
  107. &mdash; Function: void <b>avm_initialize_matcon</b> ()<var>;<a name="index-avm_005finitialize_005fmatcon-474"></a></var><br>
  108. <blockquote><p>This function initializes some static variables used by the functions
  109. declared in <samp><span class="file">matcon.h</span></samp> and should be called before any of them is
  110. called or they might not perform according to specifications.
  111. </p></blockquote></div>
  112. <div class="defun">
  113. &mdash; Function: void <b>avm_count_matcon</b> ()<var>;<a name="index-avm_005fcount_005fmatcon-475"></a></var><br>
  114. <blockquote><p>This function frees the static variables allocated by
  115. <code>avm_initialize_matcon</code> and is used to verify the absence of
  116. memory leaks. It should be called after the last call to any functions
  117. in <samp><span class="file">matcon.h</span></samp> but before <code>avm_count_lists</code> if the latter
  118. is being used (<a href="Simple-Operations.html#Simple-Operations">Simple Operations</a>).
  119. </p></blockquote></div>
  120. </body></html>