在 N 维矩阵中计算、存储和检索值
这个问题可能与您在这里阅读的问题有很大不同 - 我希望它可以提供一个有趣的挑战。
本质上,我有一个算法,它使用 5 个(或更多)变量来计算单个值,称为结果
。现在我必须在没有内存限制但有非常严格的处理限制的嵌入式设备上实现这个算法。
因此,我想运行一个计算引擎,计算每个变量的 20 个不同值的结果,并将这些信息存储在文件中。您可以将其视为 5(或更多)维矩阵或 5(或更多)维数组,每个维度有 20 个条目长。
在任何现代语言中,填充此数组就像使用 5 个(或更多)嵌套 for
循环一样简单。棘手的部分是我需要将这些值转储到一个文件中,然后将该文件放置到嵌入式设备上,以便设备可以将其用作查找表。
现在的问题是:
- 什么格式可以接受 用于存储数据?
- 什么程序(MATLAB、C# 等) 可能最适合计算 数据?
- 必须使用C#来导入数据 在设备上 - 这可能吗 给出了#1 的答案吗?
编辑: 是否可以从我的查找表文件中读取数据而不将整个文件读入内存?您能解释一下在 C# 中如何实现这一点吗?
This question is probably quite different from what you are used to reading here - I hope it can provide a fun challenge.
Essentially I have an algorithm that uses 5(or more) variables to compute a single value, called outcome
. Now I have to implement this algorithm on an embedded device which has no memory limitations, but has very harsh processing constraints.
Because of this, I would like to run a calculation engine which computes outcome
for, say, 20 different values of each variable and stores this information in a file. You may think of this as a 5(or more)-dimensional matrix or 5(or more)-dimensional array, each dimension being 20 entries long.
In any modern language, filling this array is as simple as having 5(or more) nested for
loops. The tricky part is that I need to dump these values into a file that can then be placed onto the embedded device so that the device can use it as a lookup table.
The questions now, are:
- What format(s) might be acceptable
for storing the data? - What programs (MATLAB, C#, etc)
might be best suited to compute the
data? - C# must be used to import the data
on the device - is this possible
given your answer to #1?
Edit:
Is it possible to read from my lookup table file without reading the entire file into memory? Can you explain how that might be done in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也会评论1和3。最好使用固定宽度的输出文件而不是 CSV。这可能比 CSV 占用更多或更少的空间,具体取决于输出数字。然而,它对于查找表来说往往效果很好,因为可以在不读取整个文件的情况下确定在固定宽度数据文件中查找的位置。这对于查找表通常很重要。
与 CSV 一样,固定宽度数据的读写很简单。一些面向数学的语言可能提供较差的字符串和二进制操作功能,但无论如何,在导入步骤中将数据转换为固定宽度应该非常容易。
第二个问题更难回答,尤其是在不知道您正在计算哪种算法的情况下。 Matlab 和类似的程序往往非常适合某些类型的计算,并且通常内置有很多东西以使其更容易。也就是说,此类语言中内置的许多数学内容可以以库的形式用于其他语言。
I'll comment on 1 and 3 as well. It may be preferable to use a fixed width output file rather than a CSV. This may take up more or less space than a CSV, depending on the output numbers. However, it tends to work well for lookup tables, as figuring out where to look in a fixed width data file can be done without reading the entire file. This is usually important for a lookup table.
Fixed width data, as with CSV, is trivial to read and write. Some math-oriented languages might offer poor string and binary manipulation functionality, but it should be really easy to convert the data to fixed width during the import step regardless.
Number 2 is harder to answer, particularly without knowing what kind of algorithm you are computing. Matlab and similar programs tend to be great about certain types of computations and often have a lot of stuff built in to make it easier. That said, a lot of the math stuff that is built into such languages is available for other languages in the form of libraries.
我将对(1)和(3)进行评论。您所需要做的就是将数据转储到切片中。选择一个遍历并按该顺序转储数据。将其写为逗号分隔的数字。
I'll comment on (1) and (3). All you need to do is dump the data in slices. Pick a traversal and dump data out in that order. Write it out as comma-delimited numbers.