RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
iewher
Asked: 2025-03-19 13:36:21 +0000 UTC

如何释放磁盘空间

  • 5

大家好,请帮助我正确地释放空间,并且不丢失数据。

georgiy@debian-pp:~$ df -h
Файловая система                 Размер Использовано  Дост Использовано% Cмонтировано в
udev                               7,8G            0  7,8G            0% /dev
tmpfs                              1,6G         1,8M  1,6G            1% /run
/dev/sda2                          109G          98G  5,0G           96% /
tmpfs                              7,8G          27M  7,8G            1% /dev/shm
tmpfs                              5,0M          12K  5,0M            1% /run/lock
/dev/loop0                          56M          56M     0          100% /snap/core18/2846
/dev/loop2                          45M          45M     0          100% /snap/snapd/23545
/dev/loop3                          45M          45M     0          100% /snap/snapd/23771
/dev/loop1                          56M          56M     0          100% /snap/core18/2855
/dev/sda1                          511M         5,9M  506M            2% /boot/efi
/dev/sdb1                          229G         119G   98G           55% /home
192.168.88.93:/mnt/main/nfs-devs   975G          33G  942G            4% /var/nfs-devs
tmpfs                              1,6G         2,6M  1,6G            1% /run/user/1000

启动 docker 容器时,/dev/sda2空间不足并抛出错误。

占用空间截图

也许可以以某种方式连接这两个部分,最主要的是它是安全的。

linux
  • 1 个回答
  • 75 Views
Martin Hope
kroninberg
Asked: 2025-03-19 04:24:35 +0000 UTC

为什么表达式 i = ++i + i++ 在 constexpr 函数中有效?

  • 8

在 cppreference 上我看到了 ub 的说法i = ++i + i++,记得在编译阶段似乎无法执行带有 ub 的代码,我决定通过抛出一些简单的代码来检查一下:

#include <iostream>

constexpr int func(int i){
    i = ++i + i++;
    return i;
}

constexpr int glob_i = func(1);

int main()
{
    std::cout << glob_i << "\n"; // выводит 4 
    return 0;
}

我不明白为什么这不会导致编译错误?如果编译通过,为什么运行时的类似计算会给出结果 5?

godbolt 上的示例:https://godbolt.org/z/rM8b7szz5
cppreference 上的文章,一切从这里开始https://en.cppreference.com/w/cpp/language/eval_order

c++
  • 1 个回答
  • 124 Views
Martin Hope
KLYSTRON
Asked: 2025-03-19 00:42:43 +0000 UTC

如何将十进制字符串值转换为数字?

  • 7

有一个包含以下类型数据的文本文件:

    -7.271467826427747 17.84
    -7.238717596285217 17.83
    -7.203784017466519 17.82
    -7.171033787323988 17.81
    -7.138283557181459 17.80
    -7.103349978362760 17.79
    -7.068416399544062 17.78
    -7.033482820725363 17.77
    -6.998549241906665 17.76
    -6.961432314411798 17.75
    -6.924315386916930 17.74
    -6.889381808098232 17.73
    -6.852264880603365 17.72
    -6.812964604432329 17.71
    -6.775847676937462 17.70
    -6.738730749442595 17.69
    -6.699430473271558 17.68
    -6.660130197100525 17.67
    -6.618646572253319 17.66
    -6.577162947406114 17.65
    -6.537862671235079 17.64
    -6.496379046387874 17.63
    -6.452712072864502 17.62
    -6.409045099341129 17.61
    -6.365378125817755 17.60

我正在尝试将此文件转换为数组:

import numpy as np

_overall_survival = open('_overall_survival.txt').read().splitlines()
mas = np.array([line.split() for line in _overall_survival[0:]], float, order='F')

print(mas)

在输出中我们得到:

    [[-39.16145859 81.01]
     [-39.81064093 81.02]
     [-40.02431799 81.03]
     ...
     [-2.39123878 17.24]
     [-2.45739627 17.23]
     [-2.5248678 17.22]]

原则上它是有效的,但float它不能提供小数点后数字传输的准确性,这一点很重要。

我尝试使用Decimal:

from decimal import *
import numpy as np

_overall_survival = open('_overall_survival.txt').read().splitlines()
mas = np.array([line.split() for line in _overall_survival[0:]], Decimal, order='F')

print(mas)

在输出中我们得到:

    [['-39.161458590547106' '81.01']
     ['-39.810640930261251''81.02']
     ['-40.024317987368960''81.03']
     ...
     ['-2.391238778978993''17.24']
     ['-2.457396265486048''17.23']
     ['-2.524867804437093''17.22']]

在这种情况下,数组显示所有小数位,但这是字符串数据,仍然需要以某种方式转换为数字数据。

问题:如何Decimal在保持精度的同时获取数字而不是字符串?

添加:

根据CrazyElf 的Stanislav Volodarskiy的建议,Vitalizzare成功组建了该程序的工作原型。

import tkinter as tk
import numpy as np
from tkinter import ttk

with open('_overall_survival.txt') as f:
    array = np.array([list(map(float, line.split())) for line in f])
    with ((np.printoptions(precision=15))):
        mas = array


# ENGINE
# region
def calc():
    with ((np.printoptions(precision=15))):
        result = float((-0.02144927 * float(entry_a.get())
                        ) + (-0.04948455 * float(entry_b.get())
                             ) + 0.50824824)

        row = mas[np.abs(mas[:, 0] - result).argmin()]
        min_row = float(mas[np.abs(mas[:, 0]).argmin()][0])
        max_row = float(mas[np.abs(mas[:, 0]).argmax()][0])

        if min_row >= result >= max_row:
            score['text'] = mas[np.where(mas == row)][1]
            info['text'] = (f'Расчет: {result}\n'
                            f'ТОЧНОГО СОВПАДЕНИЯ НЕТ!\n'
                            f'Ближайшее значение: '
                            f'{mas[np.where(mas == row)][0]}\n'
                            f'Связанное значение: '
                            f'{mas[np.where(mas == row)][1]}')
        elif result < max_row:
            score['text'] = mas[np.where(mas == row)][1]
            info['text'] = (f'Расчет: {result}\n'
                            f'СОВПАДЕНИЙ НЕТ!\n'
                            f'Расчетное время больше: '
                            f'{mas[np.where(mas == row)][1]}')
        elif result > max_row:
            score['text'] = mas[np.where(mas == row)][1]
            info['text'] = (f'Расчет: {result}\n'
                            f'СОВПАДЕНИЙ НЕТ!\n'
                            f'Расчетное время меньше: '
                            f'{mas[np.where(mas == row)][1]}')
        elif result in mas[:, 0]:
            score['text'] = mas[np.where(mas == row)][1]
            info['text'] = (f'Расчет: {result}\n'
                            f'ЕСТЬ СОВПАДЕНИЕ!\n'
                            f'Связанное значение: '
                            f'{mas[np.where(mas == row)][1]}')


def clear():
    entry_a.delete(0, 'end')
    entry_b.delete(0, 'end')
    # combobox.set('')
    score['text'] = ''
# endregion

# WINDOW
# region
app = tk.Tk()
app.title('FRM CLEAR')
width = 600
height = 350
x = int((app.winfo_screenwidth() / 2) - (width / 2))
y = int((app.winfo_screenheight() / 2) - (height / 2))
app.geometry(f'{width}x{height}+{x}+{y}')
app.resizable(width=False, height=False)
app['background'] = '#3d505a'
# endregion

# RESOURCES
# region
ttk.Style().configure('btn.TButton', background='#56676f')
ttk.Style().configure('frm_app.TFrame', background='#3d505a')
ttk.Style().configure('frm_content.TFrame', background='#56676f')

frm_app = ttk.Frame(app, style='frm_app.TFrame', padding=[20, 20])
frm_app.place(relheight=1, relwidth=1)

frm_content = ttk.Frame(frm_app, style='frm_content.TFrame', padding=[10, 10])
frm_content.place(relheight=0.5, relwidth=1)
# endregion


# UI
# region
entry_a = ttk.Entry(frm_content)
entry_a.place(x=5, y=10, height=25, width=40)

entry_b = ttk.Entry(frm_content)
entry_b.place(x=5, y=45, height=25, width=40)

score = ttk.Label(frm_content, text='', font='Tahoma 20 bold')
score.place(x=235, y=10, height=38, width=300)

info = ttk.Label(frm_content, text='', font='Tahoma 12', 
                 foreground='#ffffff', background='#56676f')
info.place(x=235, y=50, height=77, width=300)

tk.Button(app, text="Calc", command=calc
          ).place(x=470, y=305, height=25, width=50)
tk.Button(app, text="Clear", command=clear
          ).place(x=530, y=305, height=25, width=50)
# endregion
app.mainloop()

至于尝试Decimal,我会做出这个选择,但由于将来那里不会发生太多的计算,而是搜索和与数组内容进行比较,所以不会有任何区别(或者它不会影响比较的结果)。

python
  • 1 个回答
  • 48 Views
Martin Hope
Чипапи Мунянё
Asked: 2025-03-18 19:53:54 +0000 UTC

cmd 没有看到该文件,尽管我指定了它的准确路径

  • 3

我输入了所有正确信息,复制了文件位置,然后输入了开始和文件名,但他不知道该怎么做

在此处输入图片描述

windows
  • 1 个回答
  • 36 Views
Martin Hope
Vadim Degtyaruk
Asked: 2025-03-18 16:30:08 +0000 UTC

如何确保 DI 容器(特别是 Singleton)中服务的线程安全

  • 6

使用 DI 为控制台编写了一个小应用程序。应用程序从 DI 容器中变异并公开单例状态。

程序.cs

var serviceCollection = new ServiceCollection();

serviceCollection.AddSingleton<ISingletonTest, SingletonTest>();
serviceCollection.AddSingleton<App>();

var serviceProvider = serviceCollection.BuildServiceProvider();

var app = serviceProvider?.GetService<App>();
using (var scope = serviceProvider?.CreateScope())
{
    app?.RUN();
}

我/SingletonTest.cs

public interface ISingletonTest
{
    public int COUNT { get; }
    public void increase();
}
class SingletonTest : ISingletonTest
{
    private int _count = 0;
    public int COUNT { get => _count; }

    public void increase()
    {
        _count++;
    }
}

应用程序

internal class App
{
    private readonly ISingletonTest _singletonTest;
    public App(ISingletonTest singletonTest)
    {
        _singletonTest = singletonTest;
    }

    public void RUN()
    {
        List<Thread> lst = new List<Thread>();
        for (int i = 0; i < 100; i++)
        {
            lst.Add(new Thread(() =>
            {
                _singletonTest.increase();
                Console.WriteLine("In thread:" + Environment.CurrentManagedThreadId + " value of _singletonTest.COUNT = " + _singletonTest.COUNT);
            }));
        }

        foreach (var item in lst)
        {
            item.Start();
        }
        Console.ReadLine();
    }
}

程序输出如下

在此处输入图片描述

以及更多 在此处输入图片描述

我想了解为什么会发生这种情况,因为 ServiceCollection 使用基于 IList 的线程安全集合。而事实上数据显示的顺序可能是乱的,但肯定不能有重复。是的!输出有时正常,但有时读数会重复几次。帮助我理解 DI 容器中的线程安全问题。

c#
  • 1 个回答
  • 30 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5