Difference between revisions of "CompressMemoryUsedBy"
m (hyperlink) |
|||
Line 2: | Line 2: | ||
[[Category:Array Functions]] | [[Category:Array Functions]] | ||
− | |||
− | = CompressMemoryUsedBy(A) = | + | == CompressMemoryUsedBy(A) == |
In some cases, this function is able to reduce the amount of memory consumed by array «A». The logical contents of «A» is unchanged, so you won't see a difference, other than possibly a drop in memory usage. | In some cases, this function is able to reduce the amount of memory consumed by array «A». The logical contents of «A» is unchanged, so you won't see a difference, other than possibly a drop in memory usage. | ||
Line 10: | Line 9: | ||
In Analytica's internal representation of arrays, it is able to represent certain types of sparseness. There are basically two forms that may occur: Shared subarrays and constant subvectors. | In Analytica's internal representation of arrays, it is able to represent certain types of sparseness. There are basically two forms that may occur: Shared subarrays and constant subvectors. | ||
− | A shared subarray might occur from an expression such as: | + | A ''shared subarray'' might occur from an expression such as: |
− | + | :<code>Array(I, [A, A, A, B, B])</code> | |
− | Under certain conditions (specifically, when | + | Under certain conditions (specifically, when <code>I</code> comes before all indexes of <code>A</code> and <code>B</code> in Analytica's internal canonical index order), the first three slices along <code>I</code> are the same subarray, allowing Analytica to store it only once and not three times. Likewise, the last two slices along <code>I</code> share a subarray. |
If the same array were created through a different sequence of operations, you might end up with a dense array, with every cell explicitly stored. Under normal operations Analytica does not explicitly detect subarrays that could be potentially shared, since this can be a very expensive operation. [[CompressMemoryUsedBy]] detects these and converts the internal representation into one that shares these common subarrays to save memory. | If the same array were created through a different sequence of operations, you might end up with a dense array, with every cell explicitly stored. Under normal operations Analytica does not explicitly detect subarrays that could be potentially shared, since this can be a very expensive operation. [[CompressMemoryUsedBy]] detects these and converts the internal representation into one that shares these common subarrays to save memory. | ||
− | The second type of sparseness, constant subvectors, occurs when all slices along an index contain precisely the same value. For example, in the array: | + | The second type of sparseness, ''constant subvectors'', occurs when all slices along an index contain precisely the same value. For example, in the array: |
− | {| | + | {|class="wikitable" |
− | ! !! colspan=4 | J | + | ! !! colspan=4 | J ▶ |
|- | |- | ||
− | ! rowspan=3 | I | + | ! rowspan=3 | I ▼ |
| 3 || 5 || 7 || 6 | | 3 || 5 || 7 || 6 | ||
|- | |- | ||
Line 31: | Line 30: | ||
|} | |} | ||
− | When the | + | When the <code>I</code> index is before <code>J</code> in Analytica's internal canonical index order, then the last two slices along <code>I</code> are constant along <code>J</code>. Analytica saves memory (and computation time when this is used in a downstream computation) by storing the value 8 only once, and storing the value 4 only once. Hence in this example, only 6 cells of the original 12 consume memory like this: |
− | {| | + | {|class="wikitable" |
− | ! !! colspan=4 | J | + | ! !! colspan=4 | J ▶ |
|- | |- | ||
− | ! rowspan=3 | I | + | ! rowspan=3 | I ▼ |
| 3 || 5 || 7 || 6 | | 3 || 5 || 7 || 6 | ||
|- | |- | ||
Line 43: | Line 42: | ||
| colspan=4 | 4 | | colspan=4 | 4 | ||
|} | |} | ||
− | |||
[[CompressMemoryUsedBy]] recognizes constant-vector sparseness and replaces the original by a sparse vector when this is detected. | [[CompressMemoryUsedBy]] recognizes constant-vector sparseness and replaces the original by a sparse vector when this is detected. | ||
− | |||
− | |||
[[CompressMemoryUsedBy]] also detects identical text strings when they occur in the same innermost vector, and changes these to share the same text. However, it does not detect identical text strings in arbitrary points in the array (this is for space-time efficiency). | [[CompressMemoryUsedBy]] also detects identical text strings when they occur in the same innermost vector, and changes these to share the same text. However, it does not detect identical text strings in arbitrary points in the array (this is for space-time efficiency). | ||
− | = | + | ==History== |
+ | This function was introduced in [[Analytica 4.3]]. | ||
+ | == See Also == | ||
* [[MemoryInUseBy]](A) -- to monitor the amount of memory consumed. | * [[MemoryInUseBy]](A) -- to monitor the amount of memory consumed. | ||
+ | * [[Memory usage and management]] | ||
+ | * [[Memory Usage Dialog]] |
Revision as of 22:33, 25 January 2016
CompressMemoryUsedBy(A)
In some cases, this function is able to reduce the amount of memory consumed by array «A». The logical contents of «A» is unchanged, so you won't see a difference, other than possibly a drop in memory usage.
In Analytica's internal representation of arrays, it is able to represent certain types of sparseness. There are basically two forms that may occur: Shared subarrays and constant subvectors.
A shared subarray might occur from an expression such as:
Array(I, [A, A, A, B, B])
Under certain conditions (specifically, when I
comes before all indexes of A
and B
in Analytica's internal canonical index order), the first three slices along I
are the same subarray, allowing Analytica to store it only once and not three times. Likewise, the last two slices along I
share a subarray.
If the same array were created through a different sequence of operations, you might end up with a dense array, with every cell explicitly stored. Under normal operations Analytica does not explicitly detect subarrays that could be potentially shared, since this can be a very expensive operation. CompressMemoryUsedBy detects these and converts the internal representation into one that shares these common subarrays to save memory.
The second type of sparseness, constant subvectors, occurs when all slices along an index contain precisely the same value. For example, in the array:
J ▶ | ||||
---|---|---|---|---|
I ▼ | 3 | 5 | 7 | 6 |
8 | 8 | 8 | 8 | |
4 | 4 | 4 | 4 |
When the I
index is before J
in Analytica's internal canonical index order, then the last two slices along I
are constant along J
. Analytica saves memory (and computation time when this is used in a downstream computation) by storing the value 8 only once, and storing the value 4 only once. Hence in this example, only 6 cells of the original 12 consume memory like this:
J ▶ | ||||
---|---|---|---|---|
I ▼ | 3 | 5 | 7 | 6 |
8 | ||||
4 |
CompressMemoryUsedBy recognizes constant-vector sparseness and replaces the original by a sparse vector when this is detected.
CompressMemoryUsedBy also detects identical text strings when they occur in the same innermost vector, and changes these to share the same text. However, it does not detect identical text strings in arbitrary points in the array (this is for space-time efficiency).
History
This function was introduced in Analytica 4.3.
See Also
- MemoryInUseBy(A) -- to monitor the amount of memory consumed.
- Memory usage and management
- Memory Usage Dialog
Enable comment auto-refresher