我正在尝试使用Julia的ccall函数来连接C库.所有类型和指针都是正确的,下面的函数调用成功返回正确的答案(为简洁起见,此处未显示变量定义和设置).
ccall((:vDSP_convD, libacc), Void,
(Ptr{T}, Int64, Ptr{T}, Int64, Ptr{T}, Int64, UInt64, UInt64),
x_padded, 1, pointer(K, Ksize), -1, result, 1, Rsize, Ksize)
Run Code Online (Sandbox Code Playgroud)
但是,如果我希望将函数名称生成为符号,然后将其用作参数ccall,则失败.
fname = symbol(string("vDSP_conv", "D"))
ccall((fname , libacc), Void,
(Ptr{T}, Int64, Ptr{T}, Int64, Ptr{T}, Int64, UInt64, UInt64),
x_padded, 1, pointer(K, Ksize), -1, result, 1, Rsize, Ksize)
Run Code Online (Sandbox Code Playgroud)
错误是:
ERROR: LoadError: TypeError: conv: in ccall: first argument not a
pointer or valid constant expression, expected Ptr{T},
got Tuple{Symbol,ASCIIString}
Run Code Online (Sandbox Code Playgroud)
如果我打印这两个命名版本中的每一个的类型,我得到
julia> println(typeof(:vDSP_convD))
Symbol
julia> println(typeof(fname))
Symbol
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个工作?我猜我必须将它包装在一个宏中或者@eval …
我正在生成一些代码,稍后将对其进行评估。即使生成的代码是正确的,并且逐行对其进行评估也不会引起问题,但仍不能整体上正确对其进行评估。
eval(quote
macro m() "return" end
@m()
end)
Run Code Online (Sandbox Code Playgroud)
返回值:
ERROR: LoadError: UndefVarError: @m not defined
eval(quote macro m() "return" end end)
eval(@m())
Run Code Online (Sandbox Code Playgroud)
返回值: "return"
假设我有一个Dict对象和一个键值,我想看看字典中是否已有该键的条目?我该怎么做呢?
我正在使用 Symbolics.jl 包并尝试反转矩阵。但是,输出给出“true”而不是 1。代码如下:
using Symbolics
@variables x
mat=[x 0 0
0 x 0
0 0 x]
Run Code Online (Sandbox Code Playgroud)
我得到的结果是
inv(mat)= [true / x 0 0
0 true / x 0
0 0 true / x]
Run Code Online (Sandbox Code Playgroud)
有想过为什么会发生这种情况吗?
我正在寻找朱莉娅中的某些东西,比如理解但是对于矩阵而不是向量.如果我有一些单变量函数f(x),我想那是充满了一个数组f(i)的i中1..10,我可以这样做:
[f(i) for i = 1:10]
Run Code Online (Sandbox Code Playgroud)
如果我有一些双变量函数g(i,j),我想要一个i=[1,10]; j=[1,10]填充函数的矩阵,我可以这样做:
M = zeros (10,10)
for i in 1:10
for j in 1:10
M[i,j] = g(i,j)
end
end
Run Code Online (Sandbox Code Playgroud)
是否有一些快捷方式允许我以较短的方式表达它而不浪费时间分配所有的零?
我想将矩阵的每一行乘以一个随机数,例如
Y = R*X
Run Code Online (Sandbox Code Playgroud)
对角矩阵R大小的TxN含有条目从rand()与基体X尺寸的NxM与非常大的 T和N.目前我使用
r = rand(T)
Y = scale(r, X)
Run Code Online (Sandbox Code Playgroud)
但我想知道这是做得更快还是更好.例如,我认为没有必要创建向量r,但我不知道如何y[i] = rand()*X[i,:]有效/并行调用.
我正在使用 Julia 版本 1.6.2
julia> 2 < 1
false
julia> 2.0f32 < 1.0f32
false
julia> 2 < 1.0f32
true
Run Code Online (Sandbox Code Playgroud)
这是预期的行为吗?我不明白这是怎么回事。
最高位编码方式
如果一个字节以 0 开头,则它是最终字节,如果一个字节以 1 开头,则它不是最终字节
请注意,这也是 ASCII 兼容的,事实上,这就是 LLVM 位码的作用。
在 Python 中,我可以像这样对斜杠进行字符串替换:
>>> s = 'ab\c'
>>> s.replace('\\', '\\\\')
'ab\\\\c'
>>> print s.replace('\\', '\\\\')
ab\\c
Run Code Online (Sandbox Code Playgroud)
在 Julia 中,当我可以这样做时:
julia> s = "ab\\c"
"ab\\c"
julia> replace(s, "\\\\", "\\\\\\\\")
"ab\\c"
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它会引发一些语法错误:
julia> replace(s, r"\", r"\\")
ERROR: syntax: "\" is not a unary operator
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的ELF可执行文件:
$ readelf -l ./plt.out
Elf file type is EXEC (Executable file)
Entry point 0x400338
There are 7 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x00000000003ff040 0x00000000003ff040
0x0000000000000188 0x0000000000000188 R E 8
LOAD 0x0000000000000000 0x00000000003ff000 0x00000000003ff000
0x0000000000001000 0x0000000000001000 RW 1000
INTERP 0x00000000000001c8 0x00000000003ff1c8 0x00000000003ff1c8
0x0000000000000032 0x0000000000000032 R 1
[Requesting program interpreter: /data/keno/new_glibc/usr/lib/ld-linux-x86-64.so.2]
LOAD 0x0000000000001000 0x0000000000400000 0x0000000000400000
0x00000000000003b0 0x00000000000003b0 R E 1000
LOAD 0x0000000000001ea0 0x0000000000600ea0 0x0000000000600ea0
0x0000000000000180 0x0000000000000180 RW 1000 …Run Code Online (Sandbox Code Playgroud) 这是我在 Julia 平台中的代码,我想加快速度。无论如何,我可以让这个更快吗?50k*50k的数据集需要0.5秒。我原以为 Julia 会比这快得多,否则我不确定我是否在做一个愚蠢的实现。
ar = [[1,2,3,4,5], [2,3,4,5,6,7,8], [4,7,8,9], [9,10], [2,3,4,5]]
SV = rand(10,5)
function h_score_0(ar ,SV)
m = length(ar)
SC = Array{Float64,2}(undef, size(SV, 2), m)
for iter = 1:m
nodes = ar[iter]
for jj = 1:size(SV, 2)
mx = maximum(SV[nodes, jj])
mn = minimum(SV[nodes, jj])
term1 = (mx - mn)^2;
SC[jj, iter] = (term1);
end
end
return score = sum(SC, dims = 1)
end
Run Code Online (Sandbox Code Playgroud)