RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

Limaximy's questions

Martin Hope
Limaximy
Asked: 2024-10-22 09:35:27 +0000 UTC

为什么Winograd-Strassen算法在matlab中速度变慢很多?

  • 5

为了您的学习,您需要比较经典的矩阵乘法算法和 Winograd-Strassen 算法。我不清楚为什么 Winograd-Strassen 算法比经典算法慢得多。据我所知,MatLab 对经典算法进行了更优化,尤其是对于超大型矩阵。使用 Winograd-Strassen 算法会浪费时间为中间矩阵等分配内存空间。但随着矩阵的大小,减速非常大 - 我将其附在图片中。图中,矩阵阶数为2^10的经典算法运行时间为几秒钟,而Winograd-Strassen算法则需要7分钟。

在此输入图像描述

这是代码,可能算法没有正确理解它。只需使用 Strassen 和 Winograd-Strassen 算法调用一个函数就需要类型参数。好像没有更多的功能了

clc;

function AA = split_to_2x2_blocks(matrix)  % разделение матрицы на 4 части
    buf = width(matrix);
    A11 = matrix(1:buf/2, 1:buf/2);
    A12 = matrix(1:buf/2, buf/2+1:buf);
    A21 =  matrix(buf/2+1:buf, 1:buf/2);
    A22 = matrix(buf/2+1:buf, buf/2+1:buf);
    
    AA = {A11, A12
            A21, A22};
end

function CC = strassen_mul_2x2(lb, rb, type) % умножение матрицы после разделения, рекурсивная чушь тут и все такое

    d = strassen_mul(cell2mat(lb(1,1)) + cell2mat(lb(2,2)), cell2mat(rb(1,1)) + cell2mat(rb(2,2)), type);
    d_1 = strassen_mul(cell2mat(lb(1,2)) - cell2mat(lb(2,2)), cell2mat(rb(2,1)) + cell2mat(rb(2,2)), type);
    d_2 = strassen_mul(cell2mat(lb(2,1)) - cell2mat(lb(1,1)), cell2mat(rb(1,1)) + cell2mat(rb(1,2)), type);
    left = strassen_mul(cell2mat(lb(2,2)), cell2mat(rb(2,1)) - cell2mat(rb(1,1)), type);
    right = strassen_mul(cell2mat(lb(1,1)), cell2mat(rb(1,2)) - cell2mat(rb(2,2)), type);
    top = strassen_mul(cell2mat(lb(1,1)) + cell2mat(lb(1,2)), cell2mat(rb(2,2)), type);
    bottom = strassen_mul(cell2mat(lb(2,1)) + cell2mat(lb(2,2)), cell2mat(rb(1,1)), type);
    
    c1 = d + d_1 + left - top;
    c2 = right + top;
    c3 = left + bottom;
    c4 = d + d_2 + right - bottom;
    CC = [c1, c2
            c3, c4];
    
end

function CC = vinograd_strassen_mul_2x2(lb, rb, type) 
    s1 = cell2mat(lb(2,1)) + cell2mat(lb(2,2));
    s2 = s1 - cell2mat(lb(1,1));
    s3 = cell2mat(lb(1,1)) - cell2mat(lb(2,1));
    s4 = cell2mat(lb(1,2)) - s2;
    s5 = cell2mat(rb(1,2)) - cell2mat(rb(1,1));
    s6 = cell2mat(rb(2,2)) - s5;
    s7 = cell2mat(rb(2,2)) - cell2mat(rb(1,2));
    s8 = s6 - cell2mat(rb(2,1));
    p1 = strassen_mul(s2, s6, type);
    p2 = strassen_mul(cell2mat(lb(1,1)), cell2mat(rb(1,1)), type);
    p3 = strassen_mul(cell2mat(lb(1,2)), cell2mat(rb(2,1)), type);
    p4 = strassen_mul(s3, s7, type);
    p5 = strassen_mul(s1, s5, type);
    p6 = strassen_mul(s4, cell2mat(rb(2,2)), type);
    p7 = strassen_mul(cell2mat(lb(2,2)), s8, type);
    t1 = p1 + p2;
    t2 = t1 + p4;
    CC = [p2 + p3, t1 + p5 + p6
            t2 - p7, t2 + p5];
    
end

function c = default_mul(left, right) % классический метод умножения матриц
    c = zeros(length(left));
    
    for ii = 1:length(left)
        for jj = 1:length(right)
            for rr = 1:length(left)

                c(ii, jj) = c(ii, jj) + left(ii, rr)* right(rr, jj);
            end
        end
    end
    
end

function c = strassen_mul(left, right, type ) % типо сюда пихаем матрицу и её будущие части, а потом решаем
    if length(left) == 2
        c = default_mul(left, right);
    else
        %if type == 0
            
        %    c = strassen_mul_2x2(split_to_2x2_blocks(left), split_to_2x2_blocks(right), type);
        %elseif type == 1
            
            c = vinograd_strassen_mul_2x2(split_to_2x2_blocks(left), split_to_2x2_blocks(right), type);
        %else
        %    disp('Не выбран вариант')
        %end
    end
end
% 
% a = [1 2 3 4
%     5 6 7 8
%     9 10 11 12
%     13 14 15 16];
% b = [1 2 3 4
%     5 6 7 8
%     9 10 11 12
%     13 14 15 16];
% a = randi([1, 10], 8);
% b = randi([1, 10], 8);
% count_mas = [0, 0, 0]; % сложение, умножение, умножение матриц
% disp(a)
% disp(b)
% c = strassen_mul(a,b);
% disp(c)
% disp(sum)
% disp(umnoj)
% disp(umnoj_mat)

max_stepen = 6;
all_time = zeros(max_stepen, 2);
for t = 1:max_stepen
    step = 2^t;
    a = randi([1,10], step);
    b = randi([1,10], step);
    tic
    c = default_mul(a, b);
    all_time(t, 1) = toc;

    tic
    c = strassen_mul(a,b, 1);
    all_time(t, 2) = toc;
end
t = 1:max_stepen;
hold on
grid on
title("График времени работы без фоновых процессов")
plot(t, all_time(:, 1),'-gs',  'LineWidth',2, 'MarkerSize',10,'Color', [0 0.4470 0.7410])
plot(t,all_time(:, 2),':gs','LineWidth',2,'MarkerSize',10, 'Color', [0.9290 0.6940 0.1250])
xlabel('Порядок матриц')
ylabel('Время работы')
legend("Классический метод", "Метод Винограда-Штрассена")
алгоритм
  • 1 个回答
  • 39 Views
Martin Hope
Limaximy
Asked: 2024-02-07 11:35:38 +0000 UTC

为什么使用 requests 和 VK API 时,我收到的页面信息不完整?

  • 5

我正在尝试使用请求模块和 VK API 来快速获取有关所需页面的信息(例如)

import requests as rq
token = "Его нельзя показывать"
version = 5.131
source = "https://api.vk.com/method/users.get"

person ="shvabar" #случайный человек
info = rq.get(source,
            params = {
                'access_token':token,
                'v':version,
                'user_ids': person,
                'fields': {'relation','bdate', 'sex', 'can_write_private_message', 'friends'}
            })

print(info)
jsoninfo = info.json()

print(jsoninfo)
relat = jsoninfo.get('response')[0].get("relation")
print(jsoninfo.get('response')[0].get("relation"))
print(jsoninfo.get('response')[0].get("bdate"))
print(jsoninfo.get('response')[0].get("sex"))
print(jsoninfo.get('response')[0].get("can_write_private_message")) 
print(jsoninfo.get('response')[0].get("friends"))

控制台输出如下

<Response [200]>
{'response': [{'id': 20210511, 'relation': 1, 'first_name': 'Mikhail', 'last_name': 'Averyanov', 'can_access_closed': True, 'is_closed': False}]}
1
None
None
None
None

运行几次,会显示所需的信息,而不是“无”。那些。该值有时是相关的,有时在 can_write_private_message 中,有时在 bdate 中

问题是什么?我该如何修复它,以便所有内容都能在一个请求中正常显示?

upd:链接是这样输入的

#https://api.vk.com/method/users.get?
#access_token= нельзя
#&v=5.131
#&user_ids=shvabar
#&fields=relation
#&fields=friends
#&fields=bdate
#&fields=sex
#&fields=can_write_private_message
python
  • 1 个回答
  • 49 Views
Martin Hope
Limaximy
Asked: 2023-07-06 00:10:05 +0000 UTC

我使用 python 和 BeautifulSoup 进行 VK 解析。需要从下面的代码中提取人名

  • 4

您需要使用 BeautifulSoup 提取名字和姓氏(Sasha;Gori-Bol)。我尝试过这种方式

ProfileName = BSFile.find_all(attrs={"class": "ProfileInfo"})

原则上,以任何方式获取元素的标签(或者在 BS 中称为类似的东西),我无法使用 .string 获取这些单词(我得到一段 html 代码)。我只是想了解BS的功能,但是我在文档中没有找到我需要的示例。如何在不使用自己的算法的情况下使用 BS 获得这些单词?这是一段代码,您需要从中提取名字和姓氏

<h2 class="OwnerPageName vkuiTitle vkuiTitle--l-2 vkuiTitle--w-1" id="owner_page_name">
Саша
<span class="OwnerPageName__icons">
<span class="OwnerPageName__noWrapText">
Гори-Боль
</span>
<span class="OwnerNameIcon-module__icon--M0gpV" tabindex="-1">
<img class="vkuiIcon" src="https://sun1-19.userapi.com/Tf0zGsL23FVFo-EOwC0cEjxv49R_9IXZghtuhQ/z_GHnNJ8M6I.png" alt="Вас заметили" width="20" height="20">
</span>
</span>
<span class="VisuallyHidden-module__root--h5HaE">&nbsp;заходила 15 минут назад
</span>
</h2>
python
  • 1 个回答
  • 27 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