Matlab uint8稀疏 [英] Matlab uint8 sparse

查看:89
本文介绍了Matlab uint8稀疏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab中创建稀疏矩阵时,似乎可以创建填充逻辑或双值数字的稀疏矩阵.

When creating a sparse matrix in Matlab it seems that you can create a sparse matrix either filled with logicals or double valued numbers.

在阅读的同时,我了解到Matlab不支持其他类型的稀疏矩阵,即uint8或其他整数.在我的应用程序中,我知道max(values)==16,而内存是至关重要的,因此我想拥有uint8稀疏矩阵.

While reading around I understood that Matlab does not have support for other type of sparse matrices, i.e. uint8 or other integers. In my application I know that max(values)==16, and the memory is a crucial thing, therefore I would like to have uint8 sparse matrices.

  • 是否可以创建unit8稀疏矩阵?

如果不是(最有可能),为什么Matlab没有实现uint8稀疏矩阵?

If not (most likely), is there any apparent reason of why Matlab has not implemented uint8 sparse matrices?

推荐答案

我可以看到使用uint8代替double会有什么改善.

I can see how using uint8 instead of a double would be no or little improvement.

密集矩阵是一个连续的数组,因此不需要额外的索引或结构化,每个元素的位置由其在内存中的物理位置给出.

A dense matrix is a continuous array so no extra indexing or structuring is required, the position of each element is given by its physical location in the memory.

但是稀疏矩阵还需要存储每个元素索引,在2D矩阵的情况下,稀疏矩阵将是大小为32或64位的两个整数,以记住每个元素的行和列号.最重要的是,可能有一些与实现相关的开销,例如树结构或其他东西,可用于使稀疏矩阵运算高效.

But a sparse matrix should additionally require to store each element index, which in case of a 2D matrix would be two integers 32 or 64 bits in size to remember each element row and column number. On top of that there might be some implementation related overhead, such as a tree structure, or something else, used to make sparse matrix operations efficient.

所以它不是8 uint8与64 double相比,少了八倍的内存使用率,而是(8 + 32 + 32 + log(n)+ ..)vs(64 + 32 + 32 + log (n)+ ..),我想这也许最终可以节省10-20%?

So it is not 8 uint8 vs 64 double, eight times more less memory usage, but rather (8+32+32+log(n)+..) vs (64+32+32+log(n)+..), which i guess might end up being 10-20% savings at the best?

此外,如果我没记错的话,每个内存地址现在都存储64位,这是一个double或8 uint8打包在一起的.这意味着每个条目都需要使用一些额外的位,只是为了记住我们需要在该内存地址处打包哪些uint8,并添加一些额外的位屏蔽操作来执行.

Furthermore each memory address now stores 64 bits if I remember correctly, which is one double or 8 uint8 packed together. This means a few extra bits needs to be used per entry just to remember which uint8 packed at that memory address we need, and adds some extra bit masking operations to perform.

因此,Mathworks的工作人员可能做出了类似的估算,并决定只做double稀疏矩阵.

So the guys at Mathworks probably did similar estimate, and decided to just do double sparse matrices.

这篇关于Matlab uint8稀疏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆