我正在尝试创建一个仅接受长度为 4 的内置向量(如@Vector)的多态函数。据我了解,向量的长度是编译时已知的,我想在编译时错误消息中添加更多信息。我知道它@typeName可以用于将类型转换为 comptime 字符串,但是可以用什么来转换 comptime 值呢?
/// x[3] == 1
/// x must be a built-in vector of length 4
pub fn ispoint(x: anytype) bool {
const T = @TypeOf(v);
switch (@typeInfo(T)) {
.Vector => |info| {
if (info.len != 4) {
// TODO: report length of provided argument
@compileError("Not a valid tuple, found Vector of length ???");
}
return v[3] == 1;
},
else => @compileError("`ispoint` expected a `@Vector(4, T)`, found " ++ @typeName(T)), …Run Code Online (Sandbox Code Playgroud) 当我尝试运行pip3 install pytorch或pip install pytorch
Collecting pytorch
Using cached pytorch-1.0.2.tar.gz (689 bytes)
Building wheels for collected packages: pytorch
Building wheel for pytorch (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/chaitanya/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-8rsdyb8e
cwd: /tmp/pip-install-3v4wd97t/pytorch/
Complete output (5 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-3v4wd97t/pytorch/setup.py", line 15, in <module>
raise …Run Code Online (Sandbox Code Playgroud)