小编loo*_*ick的帖子

使用 Zig 中的 comptime 值格式化字符串

我正在尝试创建一个仅接受长度为 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)

string formatting metaprogramming zig

5
推荐指数
1
解决办法
971
查看次数

使用 pip 安装 PyTorch 时出错 - 无法构建轮子

当我尝试运行pip3 install pytorchpip 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)

python linux pip python-3.x pytorch

-2
推荐指数
1
解决办法
2235
查看次数

标签 统计

formatting ×1

linux ×1

metaprogramming ×1

pip ×1

python ×1

python-3.x ×1

pytorch ×1

string ×1

zig ×1