我不明白以下C转换函数是如何工作的(以及为什么它们以这种方式编写); 我很确定原作者知道他在做什么:
typedef union TValue {
uint64_t u64;
double n;
struct {
uint32_t lo; /* Lower 32 bits of number. */
uint32_t hi; /* Upper 32 bits of number. */
} u32;
[...]
} TValue;
static int32_t num2bit(double n)
{
TValue o;
o.n = n + 6755399441055744.0; /* 2^52 + 2^51 */
return (int32_t)o.u32.lo;
}
static uint64_t num2u64(double n)
{
#ifdef _MSC_VER
if (n >= 9223372036854775808.0) /* They think it's a feature. */
return (uint64_t)(int64_t)(n - 18446744073709551616.0);
else
#endif
return …Run Code Online (Sandbox Code Playgroud) 给定一个产生单个列的函数/表达式,如何从Julia中的那些列构建矩阵?我尝试了以下(简化示例):
column(j) = [j, j, j] # for example
my_matrix = Float64[column(j)[i] for i in 1:3, j in 1:4]
==> 3x4 Array{Float64,2}:
1.0 2.0 3.0 4.0
1.0 2.0 3.0 4.0
1.0 2.0 3.0 4.0
Run Code Online (Sandbox Code Playgroud)
结果是正确的,但这不是我想要的,因为不必要地评估了column-vector-expression(每行一次).
我也尝试过这种替代方法:
[column(j) for j in 1:4]
==> 4-element Array{Array{Float64,1},1}:
[1.0,1.0,1.0]
[2.0,2.0,2.0]
[3.0,3.0,3.0]
[4.0,4.0,4.0]
Run Code Online (Sandbox Code Playgroud)
但我发现无法将其转换或重塑为我想要的形式(具有两个维度的矩阵而不是数组数组).
如何在朱莉娅实现这一目标?