- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想用另外两个数组的笛卡尔积填充一个数组。它们包含 4 位值,这些值应该位于结果数组中元素的低半字节和高半字节。
例子:
const char a1[2] = {0x1, 0x2};
const char a2[2] = {0x3, 0x4};
const char a21[4] = {0x31, 0x32, 0x41, 0x42};
我知道我可以在运行时构造它,但我想在编译时生成数组。由于程序是用C编写的,我认为预处理器是唯一的选择。
实际的数组会比示例中的大,它们将包含 16 个元素,结果将包含 256 个元素。这就是为什么我想避免自己输入值。
我需要它来加速 16 位微 Controller 上的加密例程,因为它可以处理比 4 位半字节更大的数据。
如果解决方案适用于 2 或 3,我认为我将能够使解决方案适应 16 种元素。
最佳答案
使用 Chaos以及具有良好预处理器的编译器(例如 GCC):
#include <stdio.h>
#include <stdlib.h>
#include <chaos/preprocessor/algorithm/for_each_product.h>
#include <chaos/preprocessor/recursion/expr.h>
#include <chaos/preprocessor/seq/core.h>
#include <chaos/preprocessor/seq/elem.h>
#include <chaos/preprocessor/seq/enumerate.h>
#define A(l, h) \
const unsigned char \
a1[] = { CHAOS_PP_SEQ_ENUMERATE(l) }, \
a2[] = { CHAOS_PP_SEQ_ENUMERATE(h) }, \
a21[] = { \
CHAOS_PP_SEQ_ENUMERATE( \
CHAOS_PP_EXPR(CHAOS_PP_FOR_EACH_PRODUCT( \
B, \
((CHAOS_PP_SEQ) l) \
((CHAOS_PP_SEQ) h) \
)) \
) \
}; \
/**/
#define B(s, seq) \
(CHAOS_PP_SEQ_ELEM(0, seq) | (CHAOS_PP_SEQ_ELEM(1, seq) << 4)) \
/**/
A((0x1)(0x2), (0x3)(0x4))
#undef A
#undef B
int main() {
for (int i = 0; i != sizeof(a21) / sizeof(unsigned char); ++i) {
printf("0x%x\n", a21[i]);
}
return EXIT_SUCCESS;
}
关于使用预处理器的 C 中两个数组的笛卡尔积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31267582/
我正在尝试构建不同(但每个同质)类型的可遍历项的多个交叉产品。所需的返回类型是元组的可遍历对象,其类型与输入可遍历对象中的类型相匹配。例如: List(1, 2, 3) cross Seq("a",
import java.util.Scanner; public class BooleanProduct { public static void main(String[] args) {
任务 - 数字的最大 K 积 时间限制:1 内存限制:64 M 给定一个整数序列 N(1 ≤ N ≤ 10 月,| A i | ≤ 2.10 9)和数量 K(1 ≤ K ≤ N)。找出乘积最大的 K
考虑一个大小为 48x16 的 float 矩阵 A 和一个大小为 1x48 的 float vector b。 请建议一种在常见桌面处理器 (i5/i7) 上尽可能快地计算 b×A 的方法。 背景。
假设我有一个 class Rectangle(object): def __init__(self, len
设 A 为 3x3 阶矩阵。判断矩阵A的 boolean 积可以组成多少个不同的矩阵。 这是我想出的: #include int main() { int matri
背景 生成随机权重列表后: sizes = [784,30,10] weights = [np.random.randn(y, x) for x, y in zip(sizes[:-1],sizes[
我正在开发一个 python 项目并使用 numpy。我经常需要通过单位矩阵计算矩阵的克罗内克积。这些是我代码中的一个相当大的瓶颈,所以我想优化它们。我必须服用两种产品。第一个是: np.kron(n
有人可以提供一个例子说明如何使用 uBLAS 产品来乘法吗?或者,如果有更好的 C++ 矩阵库,您可以推荐我也欢迎。这正在变成一个令人头疼的问题。 这是我的代码: vector myVec(scala
我正在尝试开发一个Javascript程序,它会提示用户输入两个整数,然后显示这两个整数的和、乘积、差和商。现在它只显示总和。我实际上不知道乘法、减法和除法命令是否正在执行。这是 jsfiddle 的
如何使用 la4j 计算 vector (叉)积? vector 乘积为 接受两个 vector 并返回 vector 。 但是他们有scalar product , product of all e
在 C++ 中使用 Lapack 让我有点头疼。我发现为 fortran 定义的函数有点古怪,所以我尝试在 C++ 上创建一些函数,以便我更容易阅读正在发生的事情。 无论如何,我没有让矩阵 vecto
是否可以使用 Apple 的 Metal Performance Shaders 执行 Hadamard 产品?我看到可以使用 this 执行普通矩阵乘法,但我特别在寻找逐元素乘法,或者一种构造乘法的
我正在尝试使用 open mp 加速稀疏矩阵 vector 乘积,代码如下: void zAx(double * z, double * data, long * colind, long * row
有没有一种方法可以使用 cv::Mat OpenCV 中的数据结构? 我检查过 the documentation并且没有内置功能。但是我在尝试将标准矩阵乘法表达式 (*) 与 cv::Mat 类型的
我是一名优秀的程序员,十分优秀!