有没有办法在 C 的标准库中以矢量化形式表达数组?
Is there a way to express an array in vectorized form in standard library in C?
我正在尝试输入以下数组
float array[3] = {a, b, c};
进入一个函数说
3DLocation(float x, float y, float z)
作为
3DLocation(array[3])
而不是
3DLocation(array[0], array[1], array[2])
如此矢量化,如 R 或 Python(使用某些库)等。
有没有办法在标准库中做到这一点?
如果没有,有没有办法让一个函数只用标准库来做到这一点?
如果没有,有什么图书馆可以帮助我做到这一点?
另外,“矢量化”是我要查找的术语吗?
而且,“表达”是否正确,或者我是否应该编辑我的问题,改为说“访问”?
Is there a way to do this in the standard library(s)?
C 没有 Python 的一元运算符 *
的内置模拟(一元 *
在 C 中有不同的含义,尽管在某些方面类似)。
If not, is there a way to make a function to do this with only the standard library(s)?
您可以编写一个辅助函数来完成它:
void call_unpacked(void (*func)(float, float,float), float args[]) {
func(args[0], args[1], args[2]);
}
那么你可以无限次使用它:
call_unpacked(3DLocation, array);
您也可以将 call_unpacked()
写成一个宏,这有一些优点,或者您可以编写一个专门包装 3DLocation()
的函数或宏来代替通用包装器:
void 3DLocation_unpacked(float a[]) {
3DLocation(a[0], a[1], a[2]);
}
但是标准库中没有这样的函数或宏。
If not, what is a library that can help me do this?
请求图书馆推荐是题外话。
Also, is "vectorized" the term I'm looking for?
Python 中的常用术语(因为你提到了那种语言)涉及单词“unpack”的形式,就像我在前面使用的那样。我不认为对于你所说的内容有任何跨语言的共识。
And, is "express" right, or should I maybe edit my question to say "access" instead?
“快递”对我来说似乎不合适,虽然我明白你的意思。 “访问”更糟。就个人而言,我倾向于坚持“解压”,改写问题以使其适合。
我正在尝试输入以下数组
float array[3] = {a, b, c};
进入一个函数说
3DLocation(float x, float y, float z)
作为
3DLocation(array[3])
而不是
3DLocation(array[0], array[1], array[2])
如此矢量化,如 R 或 Python(使用某些库)等。
有没有办法在标准库中做到这一点?
如果没有,有没有办法让一个函数只用标准库来做到这一点?
如果没有,有什么图书馆可以帮助我做到这一点?
另外,“矢量化”是我要查找的术语吗?
而且,“表达”是否正确,或者我是否应该编辑我的问题,改为说“访问”?
Is there a way to do this in the standard library(s)?
C 没有 Python 的一元运算符 *
的内置模拟(一元 *
在 C 中有不同的含义,尽管在某些方面类似)。
If not, is there a way to make a function to do this with only the standard library(s)?
您可以编写一个辅助函数来完成它:
void call_unpacked(void (*func)(float, float,float), float args[]) {
func(args[0], args[1], args[2]);
}
那么你可以无限次使用它:
call_unpacked(3DLocation, array);
您也可以将 call_unpacked()
写成一个宏,这有一些优点,或者您可以编写一个专门包装 3DLocation()
的函数或宏来代替通用包装器:
void 3DLocation_unpacked(float a[]) {
3DLocation(a[0], a[1], a[2]);
}
但是标准库中没有这样的函数或宏。
If not, what is a library that can help me do this?
请求图书馆推荐是题外话。
Also, is "vectorized" the term I'm looking for?
Python 中的常用术语(因为你提到了那种语言)涉及单词“unpack”的形式,就像我在前面使用的那样。我不认为对于你所说的内容有任何跨语言的共识。
And, is "express" right, or should I maybe edit my question to say "access" instead?
“快递”对我来说似乎不合适,虽然我明白你的意思。 “访问”更糟。就个人而言,我倾向于坚持“解压”,改写问题以使其适合。