当前位置:网站首页>Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
2022-07-02 09:12:00 【Qigui】
Individuality signature : The most important part of the whole building is the foundation , The foundation is unstable , The earth trembled and the mountains swayed . And to learn technology, we should lay a solid foundation , Pay attention to me , Take you to firm the foundation of the neighborhood of each plate .
Blog home page : Qigui's blog
special column : data structure (C Language version )
From the south to the North , Don't miss it , Miss this article ,“ wonderful ” May miss you la
Triple attack( Three strikes in a row ):Attention,Like and Collect.
List of articles
One 、 Compressed storage of matrix
( One )、 Storage structure of array
1、 One dimensional array
(1)、 Definition :
ElemType a[MaxSize]; //ElemType Type one-dimensional array
Each array element has the same size , And physically continuous storage 
int main()
{
int a[10]={
0};
int i=0;
for(i=0;i<10;i++)
a[i]=i;
return 0;
}
Array elements a[i] Storage address = Initial address +i*sizeof(ElemType)
2、 Two dimensional array
(1)、 Definition :
ElemType b[M][N]; //M That's ok N Two dimensional array of columns
(2)、 storage :
Row first storage or column first storage .M That's ok N Two dimensional array of columns b[M][N] in ,
If pressed Line first Storage , be b[i][j] Storage address = Initial address +(iN+j)sizeof(ElemType)
If pressed Column priority Storage , be b[i][j] Storage address = Initial address +(jM+i)sizeof(ElemType)
( Two )、 Special matrix
Some matrices with high order often appear in numerical analysis , At the same time, there are many elements with the same value in the matrix , Or zero element . Sometimes To save storage space , This kind of matrix can be compressed and stored .
Compressed storage : It means that only one storage space is allocated for multiple elements with the same value , Do not allocate storage space to zero elements . The purpose is to save storage space .
If the elements with the same value or zero elements are distributed regularly in the matrix , Then we call this kind of matrix Special matrix
1、 Symmetric matrix
if n Any element of a square matrix of order a i , j a_{i,j} ai,j There are a i , j a_{i,j} ai,j= a j , i a_{j,i} aj,i Then the matrix is Symmetric matrix 
The symmetric matrix A[1…n][1…n] Stored in one-dimensional array B[n(n+1)/2] in ,B The numerical subscript is from 0 Start 
Ordinary storage :n*n Two dimensional array
Compressed storage policy :
(1)、 Lower triangular matrix :
Store only the main diagonal (i=j)+ Lower triangle (i>j)
if i>=j, Lower triangle elements A[i][j] The storage position in the array is (i-1)*i/2+j-1
(2)、 Upper triangular matrix :
Store only the main diagonal (i=j)+ Upper triangle (i<j)
if i<j, Upper triangle element A[i][j] The storage position in the array is (j-1)*j/2+i-1
2、 Trigonometric matrix
Similar to symmetric matrices , The difference is that after storage ( Next ) Elements on the triangle and the main diagonal , Also store the elements on the other side of the diagonal once .
Put this on ( Next ) Trigonometric matrix A[1…n][1…n] Compressed storage in B[n(n+1)/2+1] in .
Compressed storage policy : Line by line priority / The principle of column priority will be ( On ) The triangle elements are stored in a one-dimensional array , And store the constant in the last position c
(1)、 Lower triangular matrix : Except for the main diagonal and the lower triangle , The rest of the elements are the same
The subscript of any element in the lower triangular matrix in an array k And i、j The corresponding relation of is :
1、i>=j:(i-1)i/2+j-1;
2、i<j:n(n+1)/2
(2)、 Upper triangular matrix : Except for the main diagonal and the upper triangle , The rest of the elements are the same
The subscript of any element in the upper triangular matrix in an array k And i、j The corresponding relation of is :
1、i>=j:(i-1)(2n-i+2)/2+(j-i);
2、i<j:n(n+1)/2
3、 Tridiagonal matrix ( Also known as banded matrix )
In a tridiagonal matrix, except for the elements on the main diagonal and the two diagonals most adjacent above and below the main diagonal , All elements are 0.
All in all 3n-2 A non-zero element . When |i-j|>1 when , Yes a i , j a_{i,j} ai,j=0
Compressed storage : Line by line priority ( Or column priority ) principle , Store only the banded portion
4、 sparse matrix
The number of non-zero elements is far less than the number of matrix elements and the distribution is irregular .
Compressed storage policy : Only non-zero elements are stored
(1)、 Sequential storage :
A triple < That's ok , Column , value >
Non zero elements and their rows and columns form a triple ( Line mark 、 Column mark 、 value ). Sparse matrix compressed storage will lose the characteristics of random access
// Definition of triples
struct element
{
int row,col;
ElemType item;
}
(2)、 Chain store :
Cross linked list method
Rightward field right: Point to the next element of the peer
Down field down: Point to the next element in the same column
边栏推荐
- oracle删除表空间及用户
- 【Go实战基础】gin 如何验证请求参数
- C# 高德地图 根据经纬度获取地址
- Actual combat of microservices | discovery and invocation of original ecosystem implementation services
- 深入剖析JVM是如何执行Hello World的
- Gocv boundary fill
- Introduction to the basic concept of queue and typical application examples
- How to realize asynchronous programming in a synchronous way?
- Watermelon book -- Chapter 5 neural network
- 1、 QT's core class QObject
猜你喜欢

From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method

微服务实战|负载均衡组件及源码分析

WSL installation, beautification, network agent and remote development

Oracle modify database character set

Multi version concurrency control mvcc of MySQL

Introduction to the basic concept of queue and typical application examples

Microservice practice | teach you to develop load balancing components hand in hand

How to realize asynchronous programming in a synchronous way?

【Go实战基础】gin 如何获取 GET 和 POST 的请求参数

机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
随机推荐
【Go实战基础】gin 如何获取 GET 和 POST 的请求参数
微服务实战|原生态实现服务的发现与调用
西瓜书--第六章.支持向量机(SVM)
微服务实战|手把手教你开发负载均衡组件
Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method
Move a string of numbers backward in sequence
Watermelon book -- Chapter 5 neural network
查看was发布的应用程序的端口
C# 百度地图,高德地图,Google地图(GPS) 经纬度转换
Win10 uses docker to pull the redis image and reports an error read only file system: unknown
Troubleshooting and handling of an online problem caused by redis zadd
Matplotlib剑客行——容纳百川的艺术家教程
破茧|一文说透什么是真正的云原生
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
使用IBM MQ远程连接时报错AMQ 4043解决思路
C#钉钉开发:取得所有员工通讯录和发送工作通知
Solution of Xiaomi TV's inability to access computer shared files
oracle删除表空间及用户
双非本科生进大厂,而我还在底层默默地爬树(上)
【Go实战基础】gin 如何绑定与使用 url 参数