CN113836134A - Compression method and decompression method and device of sparse matrix - Google Patents

Compression method and decompression method and device of sparse matrix Download PDF

Info

Publication number
CN113836134A
CN113836134A CN202010580734.7A CN202010580734A CN113836134A CN 113836134 A CN113836134 A CN 113836134A CN 202010580734 A CN202010580734 A CN 202010580734A CN 113836134 A CN113836134 A CN 113836134A
Authority
CN
China
Prior art keywords
matrix
sparse matrix
bitmap
sparse
bit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010580734.7A
Other languages
Chinese (zh)
Inventor
不公告发明人
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Simm Computing Technology Co ltd
Original Assignee
Beijing Simm Computing Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Simm Computing Technology Co ltd filed Critical Beijing Simm Computing Technology Co ltd
Priority to CN202010580734.7A priority Critical patent/CN113836134A/en
Publication of CN113836134A publication Critical patent/CN113836134A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2237Vectors, bitmaps or matrices

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Complex Calculations (AREA)

Abstract

The invention provides a compression method, a decompression method and a decompression device of a sparse matrix. The compression method comprises the following steps: establishing a bitmap matrix corresponding to a sparse matrix, wherein the bitmap matrix and the sparse matrix have the same dimensionality, and a preset numerical value corresponding relation exists between each bit element in the bitmap matrix and an element corresponding to the sparse matrix; sequentially compressing and storing non-0 elements in the sparse matrix one by one; and sequentially compressing and storing all bit elements in the bitmap matrix one by one, wherein each bit element in the compressed bitmap matrix and each element in the sparse matrix before compression have a preset position corresponding relation. The compression method of the invention does not need to record the coordinate and other information of each non-0 element in the sparse matrix, only needs to use a bitmap matrix with equal height and equal width as the index for recovering the original sparse matrix, has simple compression method and can effectively save the storage space of the sparse matrix.

Description

Compression method and decompression method and device of sparse matrix
Technical Field
The invention belongs to the technical field of sparse matrices, and particularly relates to a compression method, a decompression method and a decompression device of a sparse matrix.
Background
Conventionally, when compressing the sparse matrix, the element of 0 in the sparse matrix is not stored, and each element other than 0 not only stores the value of the element, but also stores its position coordinate in the matrix. Generally, the ordinate X is the serial number of the row element of the matrix, the abscissa Y is the serial number of the column element of the matrix, and the numerical value and the coordinate are stored as a data structure.
Obviously, in the above compression process of the sparse matrix, a complex storage manner needs to be adopted after compression, and each element also needs to store its coordinate. In addition, the compression and decompression procedures are complicated.
Disclosure of Invention
The present invention is directed to at least one of the technical problems in the prior art, and provides a compression method and a decompression method and apparatus for a sparse matrix.
In one aspect of the present invention, a method for compressing a sparse matrix is provided, including:
establishing a bitmap matrix corresponding to a sparse matrix, wherein the bitmap matrix and the sparse matrix have the same dimensionality, and a preset numerical value corresponding relation exists between each bit element in the bitmap matrix and the corresponding element in the sparse matrix;
sequentially compressing and storing non-0 elements in the sparse matrix one by one;
and sequentially compressing and storing all bit elements in the bitmap matrix one by one, wherein each bit element in the compressed bitmap matrix and each element in the sparse matrix before compression have a preset position corresponding relation.
In some optional embodiments, the numerical correspondence includes:
if the element value of the sparse matrix is 0, the bit element value of the corresponding position in the bitmap matrix is 0;
and if the element value of the sparse matrix is not 0, the bit element value at the corresponding position in the bitmap matrix is 1.
In some optional embodiments, the position correspondence includes:
and each bit element in the bitmap matrix after compression corresponds to each element in the sparse matrix before compression one by one in position.
In some optional embodiments, the sequentially compressing and storing non-0 elements of the sparse matrix one by one includes:
compressing and storing non-0 elements in the sparse matrix into a one-dimensional array line by line; or the like, or, alternatively,
and compressing and storing non-0 elements in the sparse matrix into a one-dimensional array column by column.
In some optional embodiments, the sequentially compressing and storing all bitcells in the bitmap matrix one by one includes:
compressing and storing all bit elements in the bitmap matrix row by row; or the like, or, alternatively,
and compressing and storing all bit elements in the bitmap matrix column by column.
In another aspect of the present invention, a method for decompressing a sparse matrix is provided, including:
acquiring a bitmap matrix corresponding to a sparse matrix, wherein the bitmap matrix and the sparse matrix have the same dimension;
searching each target bit element in the bitmap matrix according to the numerical value corresponding relation between the bit element in the bitmap matrix and the corresponding element in the sparse matrix, wherein the target bit element is the bit element in the bitmap matrix corresponding to each non-0 element in the sparse matrix;
and according to the position of each searched target bit element in the bitmap matrix, determining the position of each non-0 element in the sparse matrix before compression, and decompressing the sparse matrix.
In another aspect of the present invention, an apparatus for compressing a sparse matrix is provided, including:
the device comprises an establishing module, a calculating module and a processing module, wherein the establishing module is used for establishing a bitmap matrix corresponding to a sparse matrix, the bitmap matrix and the sparse matrix have the same dimensionality, and a preset numerical value corresponding relation exists between each bit element in the bitmap matrix and a corresponding element in the sparse matrix;
and the compression module is used for sequentially compressing and storing non-0 elements in the sparse matrix one by one, and sequentially compressing and storing all bit elements in the bitmap matrix one by one, wherein each bit element in the compressed bitmap matrix and each element in the sparse matrix before compression have a preset position corresponding relation.
In some optional embodiments, the numerical correspondence includes:
if the element value of the sparse matrix is 0, the bit element value of the corresponding position in the bitmap matrix is 0;
and if the element value of the sparse matrix is not 0, the bit element value at the corresponding position in the bitmap matrix is 1.
In some optional embodiments, the position correspondence includes:
and each bit element in the bitmap matrix after compression corresponds to each element in the sparse matrix before compression one by one in position.
In some optional embodiments, the sequentially compressing and storing non-0 elements of the sparse matrix one by one includes:
the compression module is specifically used for compressing and storing non-0 elements in the sparse matrix into a one-dimensional array line by line; or the like, or, alternatively,
and compressing and storing non-0 elements in the sparse matrix into a one-dimensional array column by column.
In some optional embodiments, the sequentially compressing and storing all bitcells in the bitmap matrix one by one includes:
the compression module is specifically configured to:
compressing and storing all bit elements in the bitmap matrix row by row; or the like, or, alternatively,
and compressing and storing all bit elements in the bitmap matrix column by column.
In another aspect of the present invention, a sparse matrix decompression apparatus is provided, including:
the device comprises an acquisition module, a calculation module and a display module, wherein the acquisition module is used for acquiring a bitmap matrix corresponding to a sparse matrix, and the bitmap matrix and the sparse matrix have the same dimensionality;
a retrieval module, configured to retrieve each target bit element in the bitmap matrix according to a numerical correspondence between a bit element in the bitmap matrix and a corresponding element in the sparse matrix, where the target bit element is a bit element in the bitmap matrix corresponding to each non-0 element in the sparse matrix;
and the decompression module is used for determining the position of each element which is not 0 in the sparse matrix before compression according to the position of each target bit element in the bitmap matrix, and decompressing the sparse matrix.
In another aspect of the present invention, an electronic device is provided, including:
one or more processors;
a storage unit for storing one or more programs which, when executed by the one or more processors, enable the one or more processors to implement the method according to the preceding description.
In another aspect of the invention, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, is adapted to carry out the method according to the above description.
In another aspect of the invention, a computer program is provided, which, when being executed by a processor, is capable of carrying out the method according to the above description.
The compression method and the decompression method and the device of the sparse matrix do not need to record the coordinate and other information of each non-0 element in the sparse matrix, and only need to use a bitmap matrix with the same height and the same width as the index for recovering the original sparse matrix. When the original matrix needs to be recovered, target bit elements which meet the requirements in the bitmap matrix are retrieved,
the target bit element corresponds to a non-0 element in the sparse matrix, and the non-0 elements in the original sparse matrix stored in sequence are matched according to the position of the retrieved target bit element, so that the original sparse matrix is decompressed and recovered.
Drawings
FIG. 1 is a block diagram of an electronic device according to an embodiment of the invention;
FIG. 2 is a flowchart of a sparse matrix compression method according to another embodiment of the present invention;
FIG. 3 is a diagram illustrating a mapping relationship between a sparse matrix and a bitmap matrix according to another embodiment of the present invention;
FIG. 4a is a comparison of sparse matrix compression before and after compression according to another embodiment of the present invention;
FIG. 4b is a comparison of bitmap matrices before and after compression according to another embodiment of the present invention;
FIG. 5a is a comparison of sparse matrix compression before and after compression according to another embodiment of the present invention;
FIG. 5b is a comparison of bitmap matrices before and after compression according to another embodiment of the present invention;
FIG. 6 is a flowchart illustrating a method for decompressing a sparse matrix according to another embodiment of the present invention;
FIG. 7 is a schematic structural diagram of a sparse matrix compression apparatus according to another embodiment of the present invention;
fig. 8 is a schematic structural diagram of a decompression apparatus of a sparse matrix according to another embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the present invention will be described in further detail with reference to the accompanying drawings and specific embodiments.
First, an example electronic device for implementing the compression method and decompression method and apparatus of a sparse matrix according to an embodiment of the present invention is described with reference to fig. 1.
As shown in FIG. 1, electronic device 200 includes one or more processors 210, one or more memory devices 220, one or more input devices 230, one or more output devices 240, and the like, interconnected by a bus system 250 and/or other form of connection mechanism. It should be noted that the components and structures of the electronic device shown in fig. 1 are exemplary only, and not limiting, and the electronic device may have other components and structures as desired.
The processor 210 may be a Central Processing Unit (CPU), or may be made up of multiple processing cores, or other forms of processing unit having data processing capabilities and/or instruction execution capabilities, and may control other components in the electronic device 200 to perform desired functions.
Storage 220 may include one or more computer program products that may include various forms of computer-readable storage media, such as volatile memory and/or non-volatile memory. The volatile memory may include, for example, Random Access Memory (RAM), cache memory (cache), and/or the like. The non-volatile memory may include, for example, Read Only Memory (ROM), hard disk, flash memory, etc. On which one or more computer program instructions may be stored that may be executed by a processor to implement client functionality (implemented by the processor) and/or other desired functionality in embodiments of the invention described below. Various applications and various data, such as various data used and/or generated by the applications, may also be stored in the computer-readable storage medium.
The input device 230 may be a device used by a user to input instructions and may include one or more of a keyboard, a mouse, a microphone, a touch screen, and the like.
The output device 240 may output various information (e.g., images or sounds) to an outside (e.g., a user), and may include one or more of a display, a speaker, and the like.
Next, a compression method of a sparse matrix according to another embodiment of the present invention will be described with reference to fig. 2.
As shown in fig. 2, a method S100 for compressing a sparse matrix includes:
s110, establishing a bitmap matrix corresponding to a sparse matrix, wherein the bitmap matrix and the sparse matrix have the same dimensionality, and a preset numerical value corresponding relation exists between each bit element in the bitmap matrix and an element corresponding to the sparse matrix.
For example, and in conjunction with fig. 3, assuming that the sparse matrix M1 is a matrix of M rows and K columns, where M and K are both positive integers greater than 1, the bitmap matrix M1_ map is also a matrix of M rows and K columns. The bitmap matrix M1_ map is the same dimension as the sparse matrix M1, that is: the width and height of the bitmap matrix M1_ map are the same as the width and height, respectively, of the sparse matrix M1. Specific values of M and K are not limited, and those skilled in the art can limit the values according to actual needs, which is not limited in this embodiment.
With continued reference to fig. 3, in the sparse matrix M1, the number of 0 elements is much larger than the number of non-0 elements, that is, in the sparse matrix M1, there are only two kinds of values, so that in the corresponding bitmap matrix M1_ map, we can set the value corresponding to 0 element in the sparse matrix M1 as a first value, for example, 0, and set the value corresponding to non-0 element in the sparse matrix M1 as a second value, for example, 1, for representing two kinds of values, that is, 0 element and non-0 element in the sparse matrix, where the first value and the second value may be any unequal values, which can be determined according to practical needs, and this embodiment is not limited thereto, and the following embodiments are all described with the first value being 0 and the second value being 1.
And S120, sequentially compressing and storing the non-0 elements in the sparse matrix one by one.
Illustratively, referring to fig. 4a together, in the sparse matrix M1, there are four non-0 elements a, b, C and d, and when compressing the sparse matrix M1, only the non-0 elements in the sparse matrix M1 are stored, where the storage by compression in sequence means that, as shown in fig. 4a, the non-0 elements in the sparse matrix M1 can be stored row by row, that is, two elements "a" and "b" in the first row are stored in sequence, then one element "C" in the second row is stored, and finally, the element "d" in the last row is stored, and what is actually stored is a one-dimensional array M1_ C.
S130, sequentially compressing and storing all bit elements in the bitmap matrix one by one, wherein each bit element in the compressed bitmap matrix and each element in the sparse matrix before compression have a preset position corresponding relation.
Referring to fig. 4b together, in the bitmap matrix M1_ map corresponding to the sparse matrix M1, all bit elements are sequentially compressed and stored one by one, where the sequential compressed storage refers to that, as shown in fig. 4b, all bit elements may be compressed and stored row by row, or all bit elements may be compressed and stored column by column, forming M1_ map _ C. Moreover, in the compressed M1_ map _ C, each bit element has a preset corresponding relationship with each element in the sparse matrix M1 before compression, for example, in the compressed M1_ map _ C, the position of each bit element may correspond to the position of each element in the sparse matrix M1 one to one, or some other corresponding manner, which is not limited in this embodiment.
In practice, all elements are stored in bytes (Byte). For the bitmap matrix M1_ map, its element is bit (bit), so 1Byte can store 8 bits, that is, one Byte can store 8 elements of M1_ map, at this time, the bitmap matrix M1_ map is also a compressed storage, and the compressed bitmap matrix is M1_ map _ C.
The compression method of the sparse matrix in the embodiment does not need to record information such as coordinates of each non-0 element in the sparse matrix, and only needs to use a bitmap matrix with the same height and the same width as an index for recovering the original sparse matrix. When the original matrix needs to be recovered, target bit elements which meet the requirements in the bitmap matrix are retrieved, the target bit elements correspond to non-0 elements in the sparse matrix, the non-0 elements in the original sparse matrix which is stored in sequence are matched according to the positions of the retrieved target bit elements, and then the sparse matrix is decompressed.
In some optional embodiments, the numerical correspondence includes:
and if the element value of the sparse matrix is 0, the bit element value at the corresponding position in the bitmap matrix is 0. And if the bit element value of the sparse matrix is not 0, the bit element value at the corresponding position in the bitmap matrix is 1.
Illustratively, in fig. 4a, there are two non-0 elements "a" and "b" in the first and second columns of the first row in the sparse matrix M1, respectively, and the remaining columns of the first row are all 0 elements. As shown in fig. 4b, in the corresponding bitmap matrix M1_ map, the first and second column values of the first row corresponding to the non-0 elements "a" and "b" in the sparse matrix M1 are set to "1" and "1", respectively, and the remaining bit element values in the first row corresponding to the 0 elements of the sparse matrix M1 are set to "0". By analogy, if the element value in the sparse matrix M1 is 0, the corresponding bit element value in the bitmap matrix M1_ map is 0, whereas if the element value in the sparse matrix M1 is not 0, the corresponding bit element value in the bitmap matrix M1_ map is 1.
It should be noted that, in addition to the above manner, the numerical correspondence between the sparse matrix and the bitmap matrix may also adopt some other corresponding manners, preferably, in this embodiment, "1" and "0" are used to respectively correspond to a non-0 element and a 0 element in the sparse matrix, so that machine reading and analysis operations may be facilitated, and thus, the compression and decompression efficiency of the sparse matrix may be improved, and each bit element in the bitmap matrix only needs to occupy a storage space of bit, which may greatly reduce the storage space after compression of the sparse matrix.
In some optional embodiments, the position correspondence includes:
and each bit element in the bitmap matrix after compression corresponds to each element in the sparse matrix before compression one by one in position.
In the compression method of the sparse matrix in this embodiment, each bit element in the bitmap matrix after compression corresponds to each element in the sparse matrix before compression in position one to one, so that when the sparse matrix is decompressed, the decompression efficiency can be greatly improved, and any other conversion is not needed, and only the sparse matrix needs to be decompressed quickly according to the position of the bit element.
In some optional embodiments, the sequentially compressing and storing non-0 elements of the sparse matrix one by one includes:
and compressing and storing non-0 elements in the sparse matrix into a one-dimensional array line by line.
Illustratively, as shown in fig. 4a, two non-0 elements "a" and "b" are present in the first row, one non-0 element "C" is present in the second row, and one non-0 element "d" is present in the last row of the sparse matrix M1, and the non-0 elements in the sparse matrix are compressed and stored row by row into a one-dimensional array M1_ C [ a b C d ]. Of course, in addition to this, the non-0 elements in the sparse matrix M1 may be compressed column by column and stored as a one-dimensional array M1_ C [ a C b d ], and so on.
In some optional embodiments, the sequentially compressing and storing all bitcells in the bitmap matrix one by one includes:
and compressing and storing all bit elements in the bitmap matrix row by row.
Illustratively, as shown in FIG. 3, the bitmap matrix M1_ map is compressed and stored row by row, e.g., the first row M of the bitmap is stored11,m12…m1KThen store the second row m21,m22…m2K. And the analogy is that the compressed storage of the bitmap matrix M1_ map is completed.
Of course, other compression storage manners may be adopted, such as column-by-column compression storage of all bit elements in the bitmap matrix. For example, the first column m is first stored11,m21…mM1Then store the second column m12,m22…mM2And the analogy is repeated to finish the compression storage of the bitmap matrix M1_ map.
A specific example will be explained below.
Taking the 4 × 4 sparse matrix M1 with fp32 format as an example, the sparse matrix M1 and storage shown in fig. 5a only need to store four elements other than 0 in sequence, and the size of the storage space occupied by the sparse matrix M is 4 × 16B (32/8).
As shown in fig. 5b, each bit element in the bitmap matrix M1_ map only needs to occupy 1bit of storage space, and one byte can store two rows of bit elements of the M1_ map, so that the total occupied storage size is: 4 × 4/8 ═ 2B, obviously, in this kind of compression storage mode, can greatly reduce the storage space that occupies in the sparse matrix compression process, the effective storage space who saves the sparse matrix.
Through the analysis, the compression method of the sparse matrix in the embodiment does not need to record information such as coordinates of each non-0 element in the sparse matrix at all, only needs to use a bitmap matrix with the same height and the same width as an index for recovering the original sparse matrix, and the compression and the decompression of the sparse matrix are very simple. In addition, the compression method of the sparse matrix of the embodiment can greatly reduce the storage space occupied in the compression process, and effectively save the storage space of the sparse matrix.
In another aspect of the present invention, as shown in fig. 6, a sparse matrix decompression method S200 is provided, where the sparse matrix decompression method is suitable for compressing a sparse matrix by using the sparse matrix compression method described above, and reference may be made to the related description above, which is not repeated herein. The decompression method S200 includes:
s210, acquiring a bitmap matrix corresponding to the sparse matrix, wherein the bitmap matrix and the sparse matrix have the same dimension.
S220, retrieving each target bit element in the bitmap matrix according to the numerical value corresponding relation between the bit element in the bitmap matrix and the corresponding element in the sparse matrix, wherein the target bit element is the bit element in the bitmap matrix corresponding to each non-0 element in the sparse matrix.
S230, according to the position of each searched target bit element in the bitmap matrix, determining the position of each non-0 element in the sparse matrix before compression, and decompressing the sparse matrix.
In the decompression method of the sparse matrix of this embodiment, during decompression, a target bit element that meets requirements in the bitmap matrix is retrieved, the target bit element corresponds to a non-0 element in the sparse matrix, and the non-0 elements in the original sparse matrix that is stored sequentially are matched according to the position of the retrieved target bit element, so as to decompress and restore the original sparse matrix. The decompression process is very simple, and the decompression efficiency of the sparse matrix is improved.
In another aspect of the present invention, as shown in fig. 7, a sparse matrix compression apparatus 100 is provided, and the compression apparatus 100 can be applied to the compression method described above. The compression apparatus 100 includes:
the creating module 110 is configured to create a bitmap matrix corresponding to a sparse matrix, where the bitmap matrix and the sparse matrix have the same dimension, and a preset numerical value correspondence exists between each bit element in the bitmap matrix and a corresponding element in the sparse matrix.
The compression module 120 is configured to sequentially compress and store non-0 elements in the sparse matrix one by one, and sequentially compress and store all bit elements in the bitmap matrix one by one, where a preset position corresponding relationship exists between each bit element in the bitmap matrix after compression and each element in the sparse matrix before compression.
The compression device of the sparse matrix in this embodiment does not need to record information such as coordinates of each non-0 element in the sparse matrix, and only needs to use a bitmap matrix with the same height and the same width as an index for recovering the original sparse matrix. When the original matrix needs to be recovered, target bit elements which meet the requirements in the bitmap matrix are retrieved, the target bit elements correspond to non-0 elements in the sparse matrix, the non-0 elements in the original sparse matrix which is stored in sequence are matched according to the positions of the retrieved target bit elements, and then the original sparse matrix is decompressed and recovered.
In some optional embodiments, the numerical correspondence includes:
if the element value of the sparse matrix is 0, the bit element value of the corresponding position in the bitmap matrix is 0; and the number of the first and second groups,
and if the element value of the sparse matrix is not 0, the bit element value at the corresponding position in the bitmap matrix is 1.
In some optional embodiments, the position correspondence includes:
and each bit element in the bitmap matrix after compression corresponds to each element in the sparse matrix before compression one by one in position.
In some optional embodiments, the sequentially compressing and storing the non-0 elements in the sparse matrix one by one includes:
the compression module 120 is specifically configured to compress and store non-0 elements in the sparse matrix into a one-dimensional array line by line; or the like, or, alternatively,
and compressing and storing non-0 elements in the sparse matrix into a one-dimensional array column by column.
In some optional embodiments, the sequentially compressing and storing all bitcells in the bitmap matrix one by one includes:
the compression module 120 is specifically configured to:
compressing and storing all bit elements in the bitmap matrix row by row; or the like, or, alternatively,
and compressing and storing all bit elements in the bitmap matrix column by column.
In another aspect of the present invention, as shown in fig. 8, a sparse matrix decompression apparatus 300 is provided, where the decompression apparatus 300 is suitable for the decompression method described above, and reference may be made to the related description, which is not repeated herein. The decompression apparatus 300 includes:
an obtaining module 310, configured to obtain a bitmap matrix corresponding to the sparse matrix, where the bitmap matrix and the sparse matrix have the same dimension.
A retrieving module 320, configured to retrieve each target bit element in the bitmap matrix according to a numerical correspondence between a bit element in the bitmap matrix and a corresponding element in the sparse matrix, where the target bit element is a bit element in the bitmap matrix corresponding to each non-0 element in the sparse matrix.
A decompressing module 330, configured to determine, according to the retrieved position of each target bit element in the bitmap matrix, a position of each non-0 element in the sparse matrix before compression, and decompress the sparse matrix.
In the decompression device of the sparse matrix of this embodiment, during decompression, a target bit element that meets requirements in the bitmap matrix is retrieved, the target bit element corresponds to a non-0 element in the sparse matrix, and the non-0 element in the original sparse matrix that is stored in sequence is matched according to the position of the retrieved target bit element, so as to decompress and recover the original sparse matrix. The decompression process is very simple, and the decompression efficiency of the sparse matrix is improved.
In another aspect of the present invention, an electronic device is provided, including:
one or more processors;
a storage unit for storing one or more programs which, when executed by the one or more processors, enable the one or more processors to carry out a method according to the preceding description.
In another aspect of the invention, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, is adapted to carry out the method according to the above description.
The computer readable medium may be included in the apparatus, device, system, or may exist separately.
The computer readable storage medium may be any tangible medium that can contain or store a program, and may be an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, more specific examples of which include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, an optical fiber, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
The computer readable storage medium may also include a propagated data signal with computer readable program code embodied therein, for example, in a non-transitory form, such as in a carrier wave or in a carrier wave, wherein the carrier wave is any suitable carrier wave or carrier wave for carrying the program code.
In another aspect of the invention, a computer program is provided, which when executed by a processor is capable of implementing the method according to the above description.
It will be appreciated that the computer program may be stored on a computer storage medium such as the Random Access Memory (RAM), Read Only Memory (ROM), erasable programmable read only memory (EPROM or flash memory), portable compact disc read only memory (CD-ROM), and the like, described above.
It will be understood that the above embodiments are merely exemplary embodiments taken to illustrate the principles of the present invention, which is not limited thereto. It will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the spirit and substance of the invention, and these modifications and improvements are also considered to be within the scope of the invention.

Claims (10)

1. A method of compressing a sparse matrix, comprising:
establishing a bitmap matrix corresponding to a sparse matrix, wherein the bitmap matrix and the sparse matrix have the same dimensionality, and a preset numerical value corresponding relation exists between each bit element in the bitmap matrix and an element corresponding to the sparse matrix;
sequentially compressing and storing non-0 elements in the sparse matrix one by one;
and sequentially compressing and storing all bit elements in the bitmap matrix one by one, wherein each bit element in the compressed bitmap matrix and each element in the sparse matrix before compression have a preset position corresponding relation.
2. The method of claim 1, wherein the numerical correspondence comprises:
if the element value of the sparse matrix is 0, the bit element value of the corresponding position in the bitmap matrix is 0;
and if the element value of the sparse matrix is not 0, the bit element value at the corresponding position in the bitmap matrix is 1.
3. The method of claim 1, wherein the positional correspondence comprises:
and each bit element in the bitmap matrix after compression corresponds to each element in the sparse matrix before compression one by one in position.
4. The method according to any one of claims 1 to 3, wherein the sequentially compressing and storing the non-0 elements in the sparse matrix one by one comprises:
compressing and storing non-0 elements in the sparse matrix into a one-dimensional array line by line; or the like, or, alternatively,
and compressing and storing non-0 elements in the sparse matrix into a one-dimensional array column by column.
5. The method according to any one of claims 1 to 4, wherein the sequentially compressing and storing all the bitcells in the bitmap matrix one by one comprises:
compressing and storing all bit elements in the bitmap matrix row by row; or the like, or, alternatively,
and compressing and storing all bit elements in the bitmap matrix column by column.
6. A method for decompressing a sparse matrix, comprising:
acquiring a bitmap matrix corresponding to a sparse matrix, wherein the bitmap matrix and the sparse matrix have the same dimension;
searching each target bit element in the bitmap matrix according to the numerical value corresponding relation between the bit element in the bitmap matrix and the corresponding element in the sparse matrix, wherein the target bit element is the bit element in the bitmap matrix corresponding to each non-0 element in the sparse matrix;
and according to the position of each searched target bit element in the bitmap matrix, determining the position of each non-0 element in the sparse matrix before compression, and decompressing the sparse matrix.
7. An apparatus for compressing a sparse matrix, comprising:
the device comprises an establishing module, a calculating module and a processing module, wherein the establishing module is used for establishing a bitmap matrix corresponding to a sparse matrix, the bitmap matrix and the sparse matrix have the same dimensionality, and a preset numerical value corresponding relation exists between each bit element in the bitmap matrix and an element corresponding to the sparse matrix;
and the compression module is used for sequentially compressing and storing non-0 elements in the sparse matrix one by one, and sequentially compressing and storing all bit elements in the bitmap matrix one by one, wherein each bit element in the compressed bitmap matrix and each element in the sparse matrix before compression have a preset position corresponding relation.
8. A sparse matrix decompression apparatus, comprising:
the device comprises an acquisition module, a calculation module and a display module, wherein the acquisition module is used for acquiring a bitmap matrix corresponding to a sparse matrix, and the bitmap matrix and the sparse matrix have the same dimensionality;
a retrieval module, configured to retrieve each target bit element in the bitmap matrix according to a numerical correspondence between a bit element in the bitmap matrix and a corresponding element in the sparse matrix, where the target bit element is a bit element in the bitmap matrix corresponding to each non-0 element in the sparse matrix;
and the decompression module is used for determining the position of each element which is not 0 in the sparse matrix before compression according to the position of each target bit element in the bitmap matrix, and decompressing the sparse matrix.
9. An electronic device, comprising:
one or more processors;
a storage unit to store one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the method of any of claims 1 to 6.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, is able to carry out a method according to any one of claims 1 to 6.
CN202010580734.7A 2020-06-23 2020-06-23 Compression method and decompression method and device of sparse matrix Pending CN113836134A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010580734.7A CN113836134A (en) 2020-06-23 2020-06-23 Compression method and decompression method and device of sparse matrix

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010580734.7A CN113836134A (en) 2020-06-23 2020-06-23 Compression method and decompression method and device of sparse matrix

Publications (1)

Publication Number Publication Date
CN113836134A true CN113836134A (en) 2021-12-24

Family

ID=78964094

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010580734.7A Pending CN113836134A (en) 2020-06-23 2020-06-23 Compression method and decompression method and device of sparse matrix

Country Status (1)

Country Link
CN (1) CN113836134A (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198621A1 (en) * 2006-02-13 2007-08-23 Iu Research & Technology Corporation Compression system and method for accelerating sparse matrix computations
US20170293659A1 (en) * 2016-04-12 2017-10-12 Hsilin Huang Method, System and Program Product for Mask-Based Compression of a Sparse Matrix
CN110489428A (en) * 2019-08-26 2019-11-22 上海燧原智能科技有限公司 Multi-dimensional sparse matrix compression method, decompression method, device, equipment and medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198621A1 (en) * 2006-02-13 2007-08-23 Iu Research & Technology Corporation Compression system and method for accelerating sparse matrix computations
US20170293659A1 (en) * 2016-04-12 2017-10-12 Hsilin Huang Method, System and Program Product for Mask-Based Compression of a Sparse Matrix
CN109416702A (en) * 2016-04-12 2019-03-01 黄锡霖 Method, system and the program product of sparse matrix compression based on mask
CN110489428A (en) * 2019-08-26 2019-11-22 上海燧原智能科技有限公司 Multi-dimensional sparse matrix compression method, decompression method, device, equipment and medium

Similar Documents

Publication Publication Date Title
US7924183B2 (en) Method and system for reducing required storage during decompression of a compressed file
CN111008230B (en) Data storage method, device, computer equipment and storage medium
CN111125033B (en) Space recycling method and system based on full flash memory array
CN110532347B (en) Log data processing method, device, equipment and storage medium
CN107924292A (en) Hardware-accelerated type storage compression
CN110019347B (en) Data processing method and device of block chain and terminal equipment
KR102227912B1 (en) Optimized data condenser and method
CN114327244A (en) Data migration method and device, processor and computing equipment
CN113836134A (en) Compression method and decompression method and device of sparse matrix
CN108234552B (en) Data storage method and device
CN116302670A (en) Encoding and decoding method, encoder and decoder, chip, hard disk and communication system
CN113190549B (en) Multidimensional table data calling method, multidimensional table data calling device, server and storage medium
CN112612427B (en) Vehicle stop data processing method and device, storage medium and terminal
US10037148B2 (en) Facilitating reverse reading of sequentially stored, variable-length data
CN111125425A (en) Method, system and device for reading and writing video data and readable storage medium
CN111049836A (en) Data processing method, electronic device and computer readable storage medium
CN115248664B (en) Data reading and writing method, device, equipment and storage medium
JP3191857B2 (en) Simulation execution device and data compression method thereof
CN114282158A (en) Matrix calculation circuit, matrix calculation method, electronic device, and computer-readable storage medium
JP2595902B2 (en) Disk map creation method
CN116860514A (en) Data processing method, device, computer equipment and computer readable storage medium
CN113297155A (en) Data storage method, device and readable storage medium
CN117076533A (en) Transaction data serialization method and device, electronic equipment and storage medium
CN112988685A (en) Data compression and decompression method and device
CN115221132A (en) Configuration method and device of flash memory word stock and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination