Apparatus and method for selecting extrema

By combining a buffer and a processor, and utilizing adjustable comparison thresholds and step values, k extreme values ​​in a dataset are selected in batches, solving the problems of high complexity and high power consumption in the bitone logic sorting method and achieving efficient extreme value selection.

CN115202737BActive Publication Date: 2025-12-12MONTAGE TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110400296.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-14
Publication Date
2025-12-12
Estimated Expiration
2041-06-08

Smart Images

  • Figure CN115202737B_ABST
    Figure CN115202737B_ABST
Patent Text Reader

Abstract

An apparatus and method for selecting k most values from N values, comprising: A) controlling a buffer to receive the N values into a data pool thereof until the number of values in the data pool reaches a predetermined storage capacity of the data pool; B) dividing the values in the data pool into a first portion and a second portion according to their sizes relative to an adjustable comparison threshold until the number of values in the first portion falls within a predetermined range; C) discarding the values in the second portion and controlling the buffer to continue receiving values into the data pool until the number of values in the data pool again reaches the predetermined storage capacity or the buffer has received all of the N values; D) repeating steps B through C until the buffer has received all of the N values; E) dividing the values in the data pool into a first portion and a second portion according to their sizes relative to the adjustable comparison threshold until the number of values in the first portion is k; and F) controlling the buffer to output the k values in the first portion as the k most values.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of computer technology, and more particularly, to an apparatus and method for selecting top values from a plurality of values. BACKGROUND

[0002] It is a common problem in the field of computer technology to find top values in a large data set. Bitonic logic is usually used to select multiple top values (maximum or minimum) from a large data set: first, a large data set is sorted by Bitonic Sequence, and then Bitonic Merge is performed, and after multiple loops, the entire large data set is sorted. In order to sort a large data set with a value number k = 2 n , the total number of comparison operations is determined, which requires a total of n(n+1)k / 4 comparison operations.

[0003] As can be seen, although the number of operations of the Bitonic logic sorting is determined, the number of operations is relatively large, and the operation mode is relatively complex. In addition, because the Bitonic logic sorting will sort the entire data set, in order to move the maximum value to the head of the data sequence and move the minimum value to the tail of the data sequence, a large number of data movement operations are required in the entire operation process. At the same time that the data is moved, the identification (ID) corresponding to each data also needs to be moved accordingly. These all mean that the system needs complex pipeline connection, reserves larger data movement space, and consumes higher power consumption.

[0004] Therefore, a new apparatus and method for selecting top values in a data set are needed. SUMMARY

[0005] One purpose of the present application is to provide an apparatus and method for selecting top-k values from N values.

[0006] According to an aspect of the present application, there is provided an apparatus for selecting k top values from N values, the apparatus comprising a buffer comprising a data pool having a predetermined storage capacity, the buffer being configured to receive the N values into the data pool in batches. The apparatus further comprises a processor coupled to the buffer and configured to perform the following processes: A) controlling the buffer to receive values into the data pool until the number of values in the data pool reaches the predetermined storage capacity; B) dividing the values in the data pool into a first part and a second part according to the size relative to an adjustable comparison threshold until the number of values in the first part meets a predetermined number range; C) discarding the values in the second part, controlling the buffer to continue receiving values into the data pool until the number of values in the data pool reaches the predetermined storage capacity again or the buffer has received all the N values; D) repeating the processes B to C until the buffer has received all the N values; E) dividing the values in the data pool into a first part and a second part according to the size relative to an adjustable comparison threshold until the number of values in the first part is k; F) controlling the buffer to output the k values in the first part as the k top values.

[0007] In some embodiments, in performing the process B and performing the process E, the processor is further configured to adjust the adjustable comparison threshold according to an adjustable step value in response to the number of values in the first part not meeting the predetermined number range or in response to the number of values in the first part not being k.

[0008] In some embodiments, before performing the process B and performing the process E, the processor is further configured to perform the following process: determining a maximum value and a minimum value of the values in the data pool; determining an initial comparison threshold according to the maximum value and the minimum value.

[0009] In some embodiments, before performing the process B and performing the process E, the processor is further configured to perform the following process: determining an initial step value according to the maximum value and the minimum value.

[0010] In some embodiments, before performing the process B and performing the process E, the processor is further configured to determine the initial comparison threshold as half of the sum of the maximum value and the minimum value and determine the initial step value as one fourth of the difference between the maximum value and the minimum value.

[0011] In some embodiments, in performing the process B and performing the process E, the processor is further configured to adjust the adjustable step value to half of a current step value in response to the adjustable comparison threshold being adjusted.

[0012] In some embodiments, the predetermined storage capacity is 2k values.

[0013] In some embodiments, the predetermined number range is greater than or equal to k values and less than 1.5k values.

[0014] In some embodiments, the buffer is a first buffer, and the apparatus further comprises a second buffer coupled to the first buffer, the second buffer configured to continue receiving values in the second buffer into the data pool when the number of values in the data pool reaches the predetermined storage capacity.

[0015] In some embodiments, the step C comprises controlling the first buffer to continue receiving values in the second buffer into the data pool until the number of values in the data pool reaches the predetermined storage capacity again.

[0016] In some embodiments, when controlling the buffer to receive values into the data pool, the processor is further configured to decide whether to receive each value to be received according to the adjustable comparison threshold.

[0017] In another aspect of the present application, a method for selecting k extreme values from N values is also provided, the method comprising: A) controlling a buffer to receive the N values into a data pool included therein until the number of values in the data pool reaches a predetermined storage capacity of the data pool; B) dividing values in the data pool into a first part and a second part according to the size relative to an adjustable comparison threshold until the number of values in the first part meets a predetermined number range; C) discarding values in the second part, controlling the buffer to continue receiving values into the data pool until the number of values in the data pool reaches the predetermined storage capacity again or the buffer has received all the N values; D) repeating the steps B to C until the buffer has received all the N values; E) dividing values in the data pool into a first part and a second part according to the size relative to an adjustable comparison threshold until the number of values in the first part is k; F) controlling the buffer to output the k values in the first part as the k extreme values.

[0018] The above is a summary of the present application, which may have simplified, generalized or omitted details, and therefore those skilled in the art should recognize that this section is only illustrative and is not intended to limit the scope of the present application in any way. This summary section is neither intended nor used to identify key or essential features of the claimed subject matter, nor used to build an aid in determining the scope of the claimed subject matter. BRIEF DESCRIPTION OF DRAWINGS

[0019] The above and other features of this application will become more fully clear through the following description and appended claims, in conjunction with the accompanying drawings. It is understood that these drawings depict only a few embodiments of the application and should not be construed as limiting the scope of the application. The application will be described more clearly and in more detail through the use of the drawings.

[0020] Figure 1 An apparatus for selecting an extremum is shown according to one embodiment;

[0021] Figure 2 A method for selecting the maximum or minimum value according to one embodiment is shown;

[0022] Figure 3 A method for processing values ​​in a buffer according to one embodiment is shown;

[0023] Figure 4 An apparatus for selecting an extremum according to another embodiment is shown;

[0024] Figure 5 An implementation of the present application's solution according to one embodiment is shown. Detailed Implementation

[0025] In the following detailed description, reference is made to the accompanying drawings, which form a part thereof. In the drawings, similar symbols generally denote similar components unless the context otherwise requires. The illustrative embodiments described in the detailed description, drawings, and claims are not intended to be limiting. Other embodiments and variations may be employed without departing from the spirit or scope of the subject matter of this application. It will be understood that various different configurations, substitutions, combinations, and designs can be made to the various aspects of the general description and illustrated in the drawings of this application, all of which explicitly form part of the subject matter of this application.

[0026] Figure 1 An apparatus 100 for selecting an extremum value is shown according to one embodiment of this application.

[0027] like Figure 1 As shown, device 100 includes a buffer 101 that can be coupled to input interface 102, thereby receiving a set of values ​​to be selected from input interface 102, for example, receiving values ​​from input interface 102 in batches. Buffer 101 includes a data pool 101a, into which buffer 101 receives values ​​from input interface 102, wherein data pool 101a has a predetermined storage capacity.

[0028] It is to be noted that, in addition to the data pool 101a, the buffer 101 can also have other storage spaces which can be configured not to store the values to be selected as the top values. Of course, the buffer 101 can also use its entire storage space as the data pool 101a, i.e., the predetermined storage capacity of the data pool 101a is the entire storage space of the buffer 101, which is not limited in the present application. The predetermined storage capacity of the data pool 101a can be configured according to the number of values to be selected as the top values, and when the number of values in the data pool 101a reaches the predetermined storage capacity, the batch of values in the data pool 101a will be processed (which will be described in detail below).

[0029] The buffer 101 can be coupled to the output interface 104 to output the finally selected one or more top values. The buffer 101 can also be coupled to the processor 103 to send various data to the processor 103, including but not limited to the values stored therein, the number of values, the running state parameters, etc., so as to facilitate the processor 103 to control the same.

[0030] The apparatus 100 also includes a processor 103 which can be coupled to the buffer 101 to control the running of the buffer 101 and process the data. The processor 103 can be coupled to the input interface 102 or can have an additional input interface (not shown) to receive control instructions from a user or from other programs, controllers, etc. before or during the running. The user can also pre-edit the control instructions of the processor 103 before the running of the apparatus 100. The processor 103 can process according to the received control instructions or the pre-stored control instructions. In some embodiments, the processor 103 can store parameters for controlling the running of the buffer 101, such as the predetermined number range of the data pool 101a, the comparison threshold, the step value (which will be described in detail below), etc. The processor 103 can also be coupled to the output interface 104 or can have an additional output interface (not shown) to output the control instructions and the stored parameters, etc., so as to facilitate the user to monitor the apparatus 100.

[0031] Figure 2 A method 200 for selecting top-k from a set of N values is shown according to an embodiment of the present application, which can be performed by, for example, the apparatus 100 shown. Figure 1 For the purpose of convenient description, the method 200 will be described below in combination with the apparatus 100, but those skilled in the art can understand that the method 200 can also be performed by other apparatuses. In addition, for the purpose of convenient description, in the following, the N values will be described as including a1, a2, a3, … aN, and the top-k will be described as including m1, m2, m3, … mk. N k ​where N is a positive integer and k is a positive integer less than N.

[0032] The method 200 can comprise a step 201 of controlling the buffer to receive the values into the data pool until the number of values in the data pool reaches a predetermined storage capacity.

[0033] In particular, under the control of the processor 103, the buffer 101 can receive the data to be processed (i.e. N values) into the data pool 101a in batches until the number of values in the data pool 101a reaches its predetermined storage capacity. It can be appreciated that N can be much larger than the predetermined storage capacity, and thus requires to be processed in batches. In one embodiment, the predetermined storage capacity of the data pool 101a can be set to 2k. In such an embodiment, for example, upon receiving the first value, the buffer 101 can receive the value a1from the N values a1, a2, a3...aN. 2k ...a N a1, a2, a3...aN. 2k .

[0034] The method 200 can comprise a step 202 of dividing the values in the data pool into a first portion and a second portion according to their magnitude relative to an adjustable comparison threshold until the number of values in the first portion falls within a predetermined range.

[0035] In particular, upon the number of values in the data pool 101a reaching its predetermined storage capacity, the values in the data pool 101a can be processed to classify the values so as to selectively retain some of the values and discard others. The values in the data pool 101a can be classified according to the function for which the apparatus 100 is configured. For example, when the apparatus 100 is configured to select the k largest values from the N values, the apparatus 100 can divide the values greater than an adjustable comparison threshold into the first portion and the values less than the adjustable comparison threshold into the second portion; similarly, when the apparatus 100 is configured to select the k smallest values from the N values, the apparatus 100 can divide the values less than an adjustable comparison threshold into the first portion and the values greater than the adjustable comparison threshold into the second portion. In other words, the apparatus 100 can divide the values that fall within its target trend of extremum values into the first portion and the values that do not fall within its target trend of extremum values into the second portion.

[0036] In one embodiment, the device 100 determines an initial comparison threshold T0before processing the values in the data pool 101a. It is appreciated that, since the specific values of the 2kvalues to be processed are usually unknown, the initial comparison threshold T0may not divide the 2kvalues into a first portion of values and a second portion of values in a predetermined number range. Therefore, the comparison threshold is adjusted when the number of values in the first portion is not in the predetermined number range. If the device 100 is configured to select k largest values from the N values, when the number of values in the first portion is greater than the predetermined number range, the initial threshold T0is adjusted to a larger threshold T1, and the values in the data pool 101a are re-divided according to the threshold T1, and the number of values in the first portion is reduced because there are fewer values greater than the adjusted threshold T1. On the contrary, when the number of values in the first portion is less than the predetermined number range, the initial threshold T0is adjusted to a smaller threshold T1, and the values in the data pool 101a are re-divided according to the threshold T1, and the number of values in the first portion is increased because there are more values greater than the adjusted threshold T1. Similarly, if the device 100 is configured to select k smallest values from the N values, when the number of values in the first portion is greater than the predetermined number range, the initial threshold T0is adjusted to a smaller threshold T1, and the values in the data pool 101a are re-divided according to the threshold T1, and the number of values in the first portion is reduced because there are fewer values less than the adjusted threshold T1. On the contrary, when the number of values in the first portion is less than the predetermined number range, the initial threshold T0is adjusted to a larger threshold T1, and the values in the data pool 101a are re-divided according to the threshold T1, and the number of values in the first portion is increased because there are more values less than the adjusted threshold T1. In this way, the device 100 obtains a threshold Tn n after one or more of the above processes, which makes the number of values in the first portion in the predetermined number range. n

[0037] The device 100 determines the predetermined number range according to the predetermined storage capacity of the data pool 101a. For example, in an embodiment where the predetermined storage capacity of the data pool 101a is configured to be 2k, the predetermined number range can be determined to be greater than or equal to k values and less than 1.5k values.

[0038] Reference is now made to Figure 3 , Figure 3 Fig. 3 shows a method 300 for adjusting a comparison threshold according to an embodiment of the present application, which can be performed by the device 100 shown in Fig. 1, for example, and can be used in the method 200 shown in Fig. 2. Figure 1 Figure 2 ​​A portion of the method 200 for selecting k extreme values from a set of N values is shown. For the purpose of convenient description, the method 300 will be described in conjunction with the apparatus 100 hereinafter, but it is understood by those skilled in the art that the method 300 can also be performed by other apparatuses.

[0039] The method 300 can comprise a step 301 of determining the maximum and minimum values of the values in the data pool.

[0040] In one embodiment, the apparatus 100 can monitor the received values in real time as the values are received by the buffer 101, so as to update the maximum value a max and the minimum value a min in real time. For example, in one such embodiment, upon receiving the first value a1 by the buffer 101, the apparatus 100 determines the value a1 as the maximum value a max and the minimum value a min . Upon receiving the second value a2 by the buffer 101, the apparatus 100 compares the value a2 with the current maximum value a max and the minimum value a min (which are both a1 at this time): if a2 is greater than a1, the maximum value a max is updated to a2, and the minimum value a min remains a1; if a2 is less than a1, the minimum value a min is updated to a2, and the maximum value a max remains a1. In this way, the apparatus 100 compares each newly received value with the maximum value a max and the minimum value a min , so as to update the maximum value a max and the minimum value a min in real time. Upon receiving the last value of the batch, the apparatus 100 can confirm the maximum value a max and the minimum value a min of the batch of received values, as the number of values in the data pool 101a reaches its predetermined storage capacity.

[0041] In another embodiment, the apparatus 100 can also confirm the maximum value a max and the minimum value a min of the batch of received values after receiving the last value of the batch by the buffer 101. For example, the apparatus 100 can sort the values in the data pool 101a (e.g. bubble sort), so as to determine the maximum value a max and the minimum value a min of the set of values.

[0042] The method 300 can comprise a step 302 of determining an initial comparison threshold based on the maximum and minimum values.

[0043] After determining the maximum value a max and the minimum value a min in the data pool 101a, the apparatus 100 can determine an initial comparison threshold T0according to the maximum value a max and the minimum value a min . For example, in one embodiment, the apparatus 100 can determine the initial comparison threshold T0as half of the sum of the maximum value a max and the minimum value a min before processing the values in the data pool 101a according to equation (1):

[0044] T0= (a max + a min ) / 2 equation (1)

[0045] The method 300 can include step 303 of adjusting the adjustable comparison threshold in response to the number of values in the first portion not meeting the predetermined number range.

[0046] The adjustable comparison threshold can be adjusted in response to the number of values in the first portion not meeting the predetermined number range, thereby adjusting the number of values in the first portion.

[0047] In one embodiment, in addition to the adjustable comparison threshold T, the apparatus 100 can be configured with or determine an adjustable step value S, and the adjustable comparison threshold T can be adjusted according to the adjustable step value S. In one embodiment, the apparatus 100 can determine an initial step value S0according to the maximum value a max and the minimum value a min in the data pool 101a before processing the values in the data pool 101a. For example, the apparatus 100 can determine the initial step value S0as one quarter of the difference between the maximum value a max and the minimum value a min when the apparatus 100 determines the initial comparison threshold T0as half of the sum of the maximum value a max and the minimum value a min according to equation (2):

[0048] S0= (a max - a min ) / 4 equation (2)

[0049] As mentioned above, the adjustable comparison threshold can be adjusted when the number of values in the first portion does not meet the predetermined range. In one embodiment, the comparison threshold can be adjusted to the current comparison threshold plus the current step value when the comparison threshold needs to be increased, and the comparison threshold can be adjusted to the current comparison threshold minus the current step value when the comparison threshold needs to be decreased. For example, when the initial comparison threshold T0 is determined according to equation (1) and the initial step value S0 is determined according to equation (2), if the number of values in the first portion does not meet the predetermined range after the first processing of the values in the data pool 101a, the adjusted comparison threshold T1 can be determined according to equation (3) or (4):

[0050] T1 = (a min +a max ) / 2 + (a max -a min ) / 4 = (3a max +a min ) / 4 equation (3)

[0051] or

[0052] T1 = (a min +a max ) / 2 - (a max -a min ) / 4 = (a max +3a min ) / 4 equation (4)

[0053] In one embodiment, the adjustable step value can also be adjusted accordingly in response to the adjustable comparison threshold being adjusted. In one embodiment, the step value can be adjusted to half of the current step value in response to the comparison threshold being adjusted. For example, when the comparison threshold is adjusted according to equation (3) or equation (4), a new step value S1 can be determined according to equation (5) as half of S0:

[0054] S1 = S0 / 2 = (a max -a min ) / 8 equation (5)

[0055] Those skilled in the art can appreciate that the comparison threshold can also be adjusted in other ways. For example, the comparison threshold can be adjusted to twice or half of the current comparison threshold, or plus or minus a fixed constant, in response to the number of values in the first portion not meeting the predetermined range. In addition, in the embodiment where the comparison threshold is adjusted by the step value, the step value can also be adjusted in other ways, for example, the step value can be adjusted to the current step value minus a fixed constant after each adjustment of the comparison threshold.

[0056] By the above steps 301-303, the comparison threshold value will undergo one or more adjustments, and finally a comparison threshold value T n is obtained n , which will make the number of values in the first part conform to the predetermined number range.

[0057] Returning to Fig. 2, Figure 2 the method 200 can comprise a step 203 of discarding the second part of values, and controlling the buffer to continue receiving values into the data pool until the number of values in the data pool again reaches the predetermined storage capacity or the buffer has received all N values.

[0058] After the values in the buffer 101 are processed (by step 202), the device 100 discards the second part of values, because this part of values is not desired. After the values are discarded, the number of values remaining in the data pool 101a is less than its predetermined storage capacity, so that another part of the N values can be received into the data pool 101a. The buffer 101 is controlled to continue receiving values until the number of values in the data pool 101a again reaches its predetermined storage capacity or the buffer 101 has received all N values.

[0059] While the buffer 101 is controlled to continue receiving values, the device 100 can compare each value to be received with the current comparison threshold value (i.e. the comparison threshold value T n determined after the previous batch of values are processed) to decide whether to receive the value. For example, when the device 100 is configured to select k maximum values from the N values, the device 100 compares each value to be received with the current comparison threshold value T n : the buffer 101 does not receive values less than the current comparison threshold value T n and only receives values greater than the current comparison threshold value T n . Similarly, when the device 100 is configured to select k minimum values from the N values, the device 100 compares each value to be received with the current comparison threshold value T n : the buffer 101 does not receive values greater than the current comparison threshold value T n and only receives values less than the current comparison threshold value T n . In this way, values that are unlikely to belong to the k extreme values can be directly excluded without wasting computational resources for subsequent processing.

[0060] After step 203 is performed, the device 100 performs step 204 of determining whether all N values have been received: 1) if all N values have not been received, the method 200 can return to step 202 and perform the step; or 2) if all N values have been received, the method 200 continues to perform step 205.

[0061] In one embodiment, if the device 100 does not know in advance the exact number N of values, the device 100 can determine whether the buffer 101 has received all N values according to the following method: if the number of values in the data pool 101a has reached its predetermined storage capacity while there are still values attempting to push into the data pool 101a, it can be determined that the buffer 101 has not received all N values; if the number of values in the data pool 101a has not reached its predetermined storage capacity while there are no more values attempting to push into the data pool 101a, it can be determined that the buffer 101 has received all N values. In one embodiment, if the device 100 knows in advance the exact number N of values, the device 100 can count the number of values that have been received to determine whether the buffer 101 has received all N values.

[0062] The method 200 can comprise a step 205 of dividing the values in the data pool into a first part and a second part according to the size relative to the adjustable comparison threshold, until the number of values in the first part is k.

[0063] After the buffer 101 has received all N values (regardless of whether the number of values in the data pool 101a has reached its predetermined storage capacity at this time), the buffer 101 also processes the values in the data pool 101a using an adjustable comparison threshold. Similar to step 202, the comparison threshold can be adjusted one or more times to eventually cause the number of values in the first part to satisfy the condition. Unlike step 202, in step 205, the adjustable comparison threshold is finally adjusted to cause the number of values in the first part to be k. Except that the number of values in the first part is explicitly required to be k, the method of processing values and the method of adjusting the comparison threshold in step 205 can be the same as in step 202 and method 300, and will not be described again. Of course, those skilled in the art can understand that step 202 and step 205 can use different methods of processing values and adjusting the comparison threshold.

[0064] The method 200 can comprise a step 206 of controlling the buffer to output the k values in the first part as the k extreme values.

[0065] After steps 201 to 206 are performed, the k values in the first part are the required k extreme values of the N values. The device 100 outputs the k values as the final extreme value result.

[0066] Figure 4A device 400 for selecting an extreme value according to another embodiment is shown. The device 400 is generally similar to the device 100, also having a buffer 401, a data pool 401a, an input interface 402, a processor 403, and an output interface 404, etc., and can also perform methods 200 and 300, which will not be described further here. Unlike the device 100, in the device 400, the buffer 401 is a first buffer, and it also has a second buffer 405.

[0067] like Figure 4 As shown, the second buffer 405 is coupled to the input interface 402 and the first buffer 401. Unlike device 100, the input interface 402 continuously inputs N values ​​to be selected as the maximum or minimum value. When device 400 executes the method for selecting the maximum or minimum value (e.g., method 200), the number of values ​​in the data pool 401a may reach its maximum storage capacity. At this time, the first buffer 401 needs to process the values ​​in the data pool 401a and cannot continue to receive values ​​from the input interface 402. When the number of values ​​in the data pool 401a reaches its maximum storage capacity, the second buffer 405 can replace the first buffer 401 to continue receiving values ​​from the input interface 402. The values ​​received during this period are stored in the second buffer 405. After the first buffer 401 finishes processing the values ​​in the data pool 401a (at this time, the values ​​in the second part of the data pool 401a are discarded, making the number of values ​​in the data pool 401a less than its predetermined storage capacity, so it can continue to receive values), the first buffer 401 will continue to receive the values ​​in the second buffer 405 into the data pool 401a.

[0068] Figure 5 An implementation 500 of the present application according to another embodiment is shown, which is used to select k extreme values ​​(maximum or minimum values) from a set of N numerical values. For ease of description, the N numerical values ​​will be described below as including a1, a2, a3...a N The k extreme values ​​will be described as including m1, m2, m3...m k Where N is a positive integer, and k is a positive integer less than N.

[0069] See Figure 5 First, a set of N values ​​to be selected as the maximum or minimum value is processed by digital signal processor 501 and then buffered in pingpong buffer 502, so that the N values ​​can be received uninterruptedly.

[0070] Each received value is first compared with the current comparison threshold T (box 503, e.g., via a comparator). Only values ​​that meet the comparison threshold T are pushed to buffer 504 and then further pushed to data pool 505. For example, when selecting k maximum values ​​from N values, values ​​less than the current comparison threshold T are not pushed to buffer 504, while values ​​greater than or equal to the current comparison threshold T are pushed to buffer 504. Similarly, when selecting k minimum values ​​from N values, values ​​greater than the current comparison threshold T are not pushed to buffer 504, while values ​​less than or equal to the current comparison threshold T are pushed to buffer 504. In this way, values ​​that cannot belong to the k maximum / minimum values ​​can be directly excluded without wasting computational resources on subsequent processing. It should be noted that when the first batch of values ​​is pushed to buffer 504, the initial comparison threshold T0 can be set to the upper or lower limit that the system can process (set as the upper limit when selecting k minimum values ​​from N values; set as the lower limit when selecting k maximum values ​​from N values). That is to say, all values ​​will be pushed to buffer 504 at this time to wait for processing.

[0071] Buffer 504 provides buffering, and data pool 505 has two operating states: receive state and compare state. In the receive state, it can receive data from buffer 504 until either buffer 504 or data pool 505 reaches its predetermined storage capacity. When buffer 504 is full, it notifies its parent level to pause operation through a backpressure mechanism.

[0072] Data pool 505 has a predetermined storage capacity. In the receiving state, data pool 505 receives data from buffer 504. The predetermined storage capacity of data pool 505 can be set based on the number of maximum and minimum values ​​to be selected, k, for example, 2k. When the number of values ​​in data pool 505 reaches its predetermined storage capacity, data pool 505 enters a comparison state, where the values ​​are processed as described below.

[0073] When a value is pushed into data pool 505, the pushed value is monitored in real time to determine the maximum value 'a' in data pool 505. max and minimum value a min As discussed above, each newly pushed value is compared with the current maximum value (box 506, e.g., by a comparator and storing the maximum value in a register) and with the current minimum value (box 507, e.g., by a comparator and storing the minimum value in a register). Values ​​greater than the current maximum value are determined as the new maximum value, and values ​​less than the current minimum value are determined as the new minimum value. Therefore, when the number of values ​​in data pool 505 reaches its predetermined storage capacity, the maximum value 'a' can be determined.max and the minimum value a min It is noted that when the first batch of values is pushed into the data pool 505, the first value pushed will be determined as both the maximum value and the minimum value, and the subsequent values will be compared accordingly. After the number of values in the data pool 505 reaches its predetermined storage capacity and the maximum value and the minimum value of the values in the data pool 505 are determined, the current comparison threshold can be updated (block 508, e.g., calculated by a calculator and stored by a register), e.g., as described above with reference to equation 1, to be half of the sum of the maximum value and the minimum value.

[0074] After the number of values in the data pool 505 reaches its predetermined storage capacity, the data pool 505 enters the comparison state from the receiving state, in which the data a1~anin the data pool 505 will be compared with the current comparison threshold: n (blocks 509-1~509-n, e.g., each block can represent a storage bit in the data pool 505) will be compared with the current comparison threshold: when the comparison threshold requirement is met (blocks 510-1~510-n, e.g., by a comparator), the value will be marked with 1 (blocks 512-1~512-n, e.g., by a register to save the mark); when the comparison threshold requirement is not met (blocks 511-1~511-n, e.g., by a comparator), the value will be marked with 2 (blocks 513-1~513-n, e.g., by a register to save the mark). That is, the values will be divided into a first portion of values and a second portion of values based on the comparison threshold. As discussed above, when the k maximum values are selected from the N values, the values greater than the current comparison threshold will be considered to meet the comparison threshold requirement and will be marked with 1 and classified as the first portion of values; the values less than the current comparison threshold will be considered to not meet the comparison threshold requirement and will be marked with 2 and classified as the second portion of values. Similarly, when the k minimum values are selected from the N values, the values less than the current comparison threshold will be considered to meet the comparison threshold requirement and will be marked with 1 and classified as the first portion of values; the values greater than the current comparison threshold will be considered to not meet the comparison threshold requirement and will be marked with 2 and classified as the second portion of values. In other words, the values that meet the target maximum / minimum value trend will be marked with 1 and classified as the first portion of values, and the values that do not meet the target maximum / minimum value trend will be marked with 2 and classified as the second portion of values.

[0075] After the data a1~anin the data pool 505 are compared with the current comparison threshold: nAfter the classification, the number status of the current values in each part can be further counted (block 514): if the number of values with label 1 does not meet the predetermined number range, the comparison threshold will be updated again (block 508). For example, as described above with reference to equations 2-5, the comparison threshold can be updated one or more times based on a step value. The values al~an in the data pool 505 will then be labeled based on the new comparison threshold. n The classification is performed until a comparison threshold T n The number of values with label 1 meets the predetermined number range; if the number of values with label 1 meets the predetermined number range, the values with label 2 will be discarded, and the number of values in the data pool 505 is less than its predetermined storage capacity. When the number of values with label 1 in the data pool 505, the data pool 505 enters a receiving state from the comparison state, receiving data from the buffer 504 until the data pool is full again to enter the comparison state for processing. The predetermined number range can be determined based on the number of selected extreme values k, for example, as described above, determined to be greater than or equal to k values and less than 1.5k values.

[0076] The above process can be repeated one or more times until the last batch of values is pushed into the data pool 505. It should be noted that at this time the number of values in the data pool 505 can be less than its predetermined storage capacity. After the last value is pushed into the data pool 505, the maximum and minimum values of these values are also determined to determine the comparison threshold. These values will also be labeled with label 1 or label 2 based on the current comparison threshold. The difference is that at this time the target of the comparison threshold adjustment is to make the number of values with label 1 k, rather than to meet the predetermined number range. When the number of values with label 1 is k, the k values will be pushed into the buffer 515 as the final selected k values.

[0077] It should be noted that although several steps of the method for accessing the storage module and several modules or sub-modules of the memory controller are mentioned in the above detailed description, such division is only exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules described above can be embodied in one module. Conversely, the features and functions of one module described above can be further divided into several modules embodied. In addition, the order of the steps described in the present application is not mandatory, and the order of execution can be adjusted as needed.

[0078] Those skilled in the art can, by studying the specification, disclosure content and drawings and the attached claims, understand and implement other changes to the disclosed embodiments. In the claims, the word "comprising" does not exclude other elements and steps, and the word "a" or "one" does not exclude a plurality. In the practical application of the present application, a part can perform the functions of multiple technical features referred to in the claims. Any reference signs in the claims should not be understood as limiting the scope.

Claims

1. An apparatus for selecting k extreme values from N values, characterized by, The apparatus comprises: a buffer comprising a data pool having a predetermined storage capacity, the buffer being configured to receive the N values into the data pool in batches; a processor coupled to the buffer and configured to perform the following processing: A) controlling the buffer to receive values into the data pool until the number of values in the data pool reaches the predetermined storage capacity; B) dividing the values in the data pool into a first part and a second part according to their size relative to an adjustable comparison threshold until the number of values in the first part falls within a predetermined number range, wherein dividing the values in the data pool into the first part and the second part according to their size relative to the adjustable comparison threshold comprises: when the apparatus is configured to select k maximum values from the N values, dividing values greater than the adjustable comparison threshold into the first part and dividing values less than the adjustable comparison threshold into the second part; or when the apparatus is configured to select k minimum values from the N values, dividing values less than the adjustable comparison threshold into the first part and dividing values greater than the adjustable comparison threshold into the second part; C) discarding the values in the second part, controlling the buffer to continue receiving values into the data pool until the number of values in the data pool again reaches the predetermined storage capacity or the buffer has received all the N values; D) repeating the steps B to C until the buffer has received all the N values; E) dividing the values in the data pool into a first part and a second part according to their size relative to an adjustable comparison threshold until the number of values in the first part is k; F) controlling the buffer to output the k values in the first part as the k extreme values.

2. The apparatus of claim 1, wherein, In performing the step B and performing the step E, the processor is further configured to adjust the adjustable comparison threshold according to an adjustable step value in response to the number of values in the first part not falling within the predetermined number range or in response to the number of values in the first part not being k.

3. The apparatus of claim 2, wherein, Before performing the step B and performing the step E, the processor is further configured to perform the following processing: determining a maximum value and a minimum value of the values in the data pool; determining an initial comparison threshold according to the maximum value and the minimum value.

4. The apparatus of claim 3, wherein, Before performing the step B and performing the step E, the processor is further configured to perform the following processing: determining an initial step value according to the maximum value and the minimum value.

5. The apparatus of claim 4, wherein, Before performing the step B and performing the step E, the processor is further configured to determine the initial comparison threshold as half of the sum of the maximum value and the minimum value and to determine the initial step value as one quarter of the difference between the maximum value and the minimum value.

6. The apparatus of claim 5, wherein, In performing the step B and performing the step E, the processor is further configured to adjust the adjustable step value to half of a current step value in response to the adjustable comparison threshold being adjusted.

7. The apparatus of claim 1, wherein, The predetermined storage capacity is 2k values.

8. The apparatus of claim 7, wherein, The predetermined quantity range is greater than or equal to k values and less than 1.5k values.

9. The apparatus of claim 1, wherein, The buffer is a first buffer, and the apparatus further comprises a second buffer coupled to the first buffer, the second buffer configured to continue receiving the N values when the quantity of values in the data pool reaches the predetermined storage capacity.

10. The apparatus of claim 9, wherein, The step C further comprises controlling the first buffer to continue receiving values in the second buffer to the data pool until the quantity of values in the data pool again reaches the predetermined storage capacity.

11. The apparatus of claim 1, wherein, In controlling the buffer to receive values to the data pool, the processor is further configured to determine whether to receive each of the values to be received according to the adjustable comparison threshold.

12. A method for selecting k extreme values from N values, characterized in that, The method comprises: A) controlling a buffer to receive the N values to a data pool included therein until the quantity of values in the data pool reaches a predetermined storage capacity of the data pool; B) dividing values in the data pool into a first portion and a second portion according to a size relative to an adjustable comparison threshold until the quantity of values in the first portion meets a predetermined quantity range, wherein dividing values in the data pool into the first portion and the second portion according to the size relative to the adjustable comparison threshold comprises: when the apparatus is configured to select k maximum values from the N values, dividing values greater than the adjustable comparison threshold into the first portion and dividing values less than the adjustable comparison threshold into the second portion; or when the apparatus is configured to select k minimum values from the N values, dividing values less than the adjustable comparison threshold into the first portion and dividing values greater than the adjustable comparison threshold into the second portion; C) discarding values in the second portion, controlling the buffer to continue receiving values to the data pool until the quantity of values in the data pool again reaches the predetermined storage capacity or the buffer has received all of the N values; D) repeating the steps B to C until the buffer has received all of the N values; E) dividing values in the data pool into a first portion and a second portion according to a size relative to an adjustable comparison threshold until the quantity of values in the first portion is k; F) controlling the buffer to output the k values in the first portion as the k extreme values.

13. The method of claim 12, wherein, The steps B and E further comprise adjusting the adjustable comparison threshold according to an adjustable step value in response to the quantity of values in the first portion not meeting the predetermined quantity range or in response to the quantity of values in the first portion not being k.

14. The method of claim 13, wherein, Before performing the step B and performing the step E, the method further comprises: determining a maximum value and a minimum value of values in the data pool; determining an initial comparison threshold according to the maximum value and the minimum value.

15. The method of claim 14, wherein, Before performing the step B and performing the step E, the method further comprises: determining an initial step value according to the maximum value and the minimum value.

16. The method of claim 15, wherein, Before performing the step B and performing the step E, the method further comprises determining the initial comparison threshold as half of a sum of the maximum value and the minimum value and determining the initial step value as one fourth of a difference between the maximum value and the minimum value.

17. The method of claim 16, wherein, While performing the step B and performing the step E, the method further comprises adjusting the adjustable step value to half of a current step value in response to the adjustable comparison threshold being adjusted.

18. The method of claim 12, wherein, The predetermined storage capacity is 2k values.

19. The method of claim 18, wherein, The predetermined number range is greater than or equal to k values and less than 1.5k values.

20. The method of claim 12, wherein, The buffer is a first buffer, and the method further comprises continuing to receive the N values to a second buffer when the number of values in the data pool reaches the predetermined storage capacity.

21. The method of claim 20, wherein, The step C comprises controlling the first buffer to continue to receive values in the second buffer to the data pool until the number of values in the data pool reaches the predetermined storage capacity again.

22. The method of claim 12, wherein, While controlling the buffer to receive values to the data pool, the method further comprises deciding whether to receive each value to be received according to the adjustable comparison threshold.

Citation Information

Patent Citations

  • Fixed-point data screening circuit

    CN107340992A

  • Method and device for adjusting threshold in control strategy of data stream, and apparatus

    CN109218211A