小编pro*_*tos的帖子

如何使 Julia 中的多线程与线程数成比例?

我知道关于 Julia 中多线程性能的问题已经被问过(例如这里),但它们涉及相当复杂的代码,其中可能有很多东西在起作用。

在这里,我使用 Julia v1.5.3 在多个线程上运行一个非常简单的循环,与使用例如 Chapel 运行相同的循环相比,加速似乎并没有很好地扩展。

我想知道我做错了什么,以及如何更有效地在 Julia 中运行多线程。

顺序码

using BenchmarkTools

function slow(n::Int, digits::String)
    total = 0.0
    for i in 1:n
        if !occursin(digits, string(i))
            total += 1.0 / i
        end
    end
    println("total = ", total)
end

@btime slow(Int64(1e8), "9")
Run Code Online (Sandbox Code Playgroud)

时间:8.034s

Threads.@threads4 个线程上的共享内存并行性

using BenchmarkTools
using Base.Threads

function slow(n::Int, digits::String)
    total = Atomic{Float64}(0)
    @threads for i in 1:n
        if !occursin(digits, string(i))
            atomic_add!(total, 1.0 / i)
        end
    end
    println("total = ", total)
end

@btime slow(Int64(1e8), …
Run Code Online (Sandbox Code Playgroud)

parallel-processing performance multithreading julia chapel

10
推荐指数
1
解决办法
699
查看次数

在简码定义内使用简码

如何在另一个短代码中重用 Hugo 中的短代码?

我只找到了一种在 Markdown 中嵌套短代码的方法,但我想要做的是在另一个短代码的定义中重用一个短代码。

hugo hugo-shortcode

8
推荐指数
1
解决办法
570
查看次数

如何在 Hugo 图像标签标题元素中插入换行符?

我正在使用 blogdown 和 kakawait/hugo-tranquilpeak-theme 来写一篇简单的降价博客文章。当我添加带有短代码选项标签的图像时,例如

{{< image classes="fancybox right clear" src="image2.png"     
thumbnail="http://google.fr/images/image125.png" group="group:travel"   
thumbnail-width="150px" thumbnail-height="300px" title="A beautiful    
sunrise" >}}
Run Code Online (Sandbox Code Playgroud)

我无法打破图像的标题。我现在有

A beautiful image
Run Code Online (Sandbox Code Playgroud)

但我愿意

A beautiful 
image
Run Code Online (Sandbox Code Playgroud)

顺便说一句,这些中断:

\n
<br>
<br />
Run Code Online (Sandbox Code Playgroud)

不要为我工作。知道如何解决这个问题吗?

markdown line-breaks hugo blogdown hugo-shortcode

6
推荐指数
1
解决办法
1277
查看次数

使用 ContentEditable 复制和粘贴表格

该视频很好地代表了我面临的问题:https : //drive.google.com/file/d/1jN44lUpnbVDv_m3LuPhlJl6RFUu884jz/view。我无法复制和粘贴另一个选项卡中的表格而不破坏它。因为这使用本地存储,所以这里有一个 JSFiddle:https ://jsfiddle.net/znj537w0/1/ 。

var app = angular.module("TodoApp", ["LocalStorageModule", 'ngSanitize']);
app.controller("TodoController", function ($scope, localStorageService) {
    if (!localStorageService.get("taskListActive")) {
        $scope.tasksActive = [{
            text: "Do me next",
            priority: 1,
            complete: false
        },
        {
            text: "I'm not important",
            priority: 0,
            complete: false
        }
        ];
    } else {
        $scope.tasksActive = localStorageService.get("taskListActive");
    }

    if (!localStorageService.get("taskListComplete")) {
        $scope.tasksComplete = [{
            text: "I'm already done",
            priority: 0,
            complete: true
        }];
    } else {
        $scope.tasksComplete = localStorageService.get("taskListComplete");
    }

    $scope.totalTasks = function () { …
Run Code Online (Sandbox Code Playgroud)

html javascript css local-storage angularjs

6
推荐指数
1
解决办法
167
查看次数

如何使用 CodeStar 连接将 git 标签推送到 AWS Pipeline 中的 GitHub?

我有一个通过 CodeStar Connection 连接到 GitHub 的 AWS Pipeline。该过程如下所示:

  1. 从 GitHub 获取源代码
  2. 构建项目
  3. 运行测试
  4. 部署

在步骤 4 之前(或作为步骤 4 的一部分),我希望 AWS Pipeline 使用 git 标签标记代码,然后将其推回 GitHub 中的存储库。

我怎样才能做到这一点?

git github aws-codepipeline aws-codestar

6
推荐指数
1
解决办法
3859
查看次数

Python / Jupyter 笔记本滑动按钮不见了?

我正在使用 Jupyter Notebook 来构建幻灯片。直到昨天,CellToolBar 按钮上还有两个按钮可以启动幻灯片放映(其中一个按钮是 RISE.js)。突然间这些按钮就消失了。现在CellToolBar 按钮的右侧根本没有任何按钮。

我尝试conda update jupyterconda update -c damianavila82 rise使用终端。但我收到消息了# All requested packages already installed。所以问题似乎出在其他地方。

有谁知道我可以做什么来恢复按钮?

  • 我在 Mac 上
  • jupyter笔记本服务器的版本是4.3.1
  • RISE版本是4.0.0b1
  • 蟒蛇是 4.3.0
  • Python 3.5.2

谢谢!

python jupyter rise

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

如何在响应式 css 按钮中对齐文本中心?

我有一个图像,里面有两个按钮。我希望这些按钮具有响应性,并且文本始终居中并在图像调整大小时调整大小。这些按钮内的文本未居中,并且在调整浏览器大小或在移动设备上浏览时变得更糟。我错过了什么?下面是图片和按钮的 CSS 代码:

.container {
  position: relative;
  width: 100%;
  max-width: 2400px;
}

.container img {
  width: 150%;
  opacity: 0.85;
  height: auto;
}

.container .btn {
  width: 30%;
  height: 10%;
  opacity: 0.8;
  filter: alpha(opacity=80);
  position: absolute;
  top: 80%;
  left: 70%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background-color: #555;
  color: white;
  font-size: 1.5vw;
  padding: 12px 24px;
  border: none;
  cursor: pointer;
  border-radius: 5px;
  text-align: center;
  text-decoration: none;
  vertical-align: middle;
  line-height: 100%;
}

.container .btns {
  width: 30%;
  height: 10%;
  opacity: 0.8;
  filter: alpha(opacity=80); …
Run Code Online (Sandbox Code Playgroud)

html css button responsive

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

图像通过 RMarkdown 中的短代码使用 blogdown 不显示

我想使用 blogdown 通过 RMarkdown 文件中的短代码显示图像。我使用代码:

```{r echo=FALSE}
blogdown::shortcode("figure", src = "/img/to/path/my-picture.png", alt = "Some alt text")
```
Run Code Online (Sandbox Code Playgroud)

我没有收到错误消息,只是网站上有一个空白区域。图片不显示。简码通常有效,我用推特卡试过了。

路径是正确的,因为使用 knitr 显示相同的图片。(该路径也可用作普通.md文档中的简码。)如果我不在我的.Rmd文件中使用 alt 参数,则短代码命令的代码将显示在网站上——不仅适用于此命令,而且适用于所有其他命令(以前工作)短代码也是如此。例如,我得到了以下网页片段:

{{% figure src=/img/to/path/my-picture.png %}}
But shortcode works, here is a tweet card: {{% tweet 852205086956818432 %}}
Run Code Online (Sandbox Code Playgroud)

另一个与数字相关的问题:如果我使用标准命令:

![some alt text](/img/to/path/my-picture.png)
Run Code Online (Sandbox Code Playgroud)

网页在图片下方显示替代文字“一些替代文字”。

我正在使用 Hugo-academic 主题,这是我的会话信息:

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices …
Run Code Online (Sandbox Code Playgroud)

r r-markdown hugo blogdown hugo-shortcode

3
推荐指数
1
解决办法
377
查看次数

何时在 Python 中使用线程本地内存?

我刚开始使用 Python 并偶然发现了线程本地内存。我写了一个使用线程的小程序:

#!/usr/bin/env python3

import logging
import signal
import threading
import time

class WorkerThread(threading.Thread):
    def __init__(self, idx):
        threading.Thread.__init__(self)
        self.thread_index = idx
        self.thread_alive = True

    def run(self):
        logging.info(f'Thread {self.thread_index} is starting up!')

        while self.thread_alive:
            logging.info(f'Thread {self.thread_index} is still running.')
            time.sleep(1)

        logging.info(f'Thread {self.thread_index} is stopping!')

    def kill(self):
        self.thread_alive = False

def main():
    logging.basicConfig(format = '%(levelname)s: %(message)s', level = logging.INFO)

    def signal_handler(sig, frame):
        logging.info('Ctrl+c pressed, killing threads and shutting down ...')
        nonlocal threads
        for thread in threads:
            thread.kill()

    signal.signal(signal.SIGINT, signal_handler)

    logging.info('Signal handler …
Run Code Online (Sandbox Code Playgroud)

python multithreading python-multithreading

3
推荐指数
1
解决办法
65
查看次数

如何将数组数组转换为矩阵?

我找不到这个简单问题的答案。

我有以下几点:

A(a,j)=[a*j*i*k for i in 1:2, k in 1:2];

B=[A(a,j) for a in 1:2, j in 1:2];
Run Code Online (Sandbox Code Playgroud)

B是一个数组的数组:2×2 Array{Array{Int64,2},2}。这对于轻松访问带有索引的子数组(例如,B[2,1])很有用。但是,我还需要转换B为 4 x 4 矩阵。我试过了,hcat(B...)但会产生一个 2 x 8 的矩阵,其他选项更糟(例如,cat(Test2...;dims=(2,1)))。

有没有一种有效的方式来编写B矩阵,同时保持轻松访问其子数组的能力,尤其是当它B变得非常大时?

arrays julia

3
推荐指数
1
解决办法
143
查看次数

python解释器位于virtualenv中的什么位置?

python 解释器在虚拟环境中位于何处?

我正在制作一个 GUI 项目,但在我的虚拟环境中找到 python 解释器时卡住了。

python解释器位于虚拟环境中的什么地方?

python linux

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

Git标签消失了

我检查了一个新分支并将其命名为v0.1.1。我更改了版本以package.json匹配,并且还用来git tag创建一些标签。我最终将此分支合并到 master 中,认为标记/版本控制活动会以master某种方式“传播”。它们不但没有传播出去,还仿佛消失了,就好像我什么都没做一样。

有哪些步骤:

  • 在本地将提交标识为感兴趣的版本(无论它只是一个有用的基线还是一个实际的版本 - 区别重要吗?那是两个单独的命令吗?)
  • 确保推送后任何此类版本控制信息都可以在 GitHub 中立即识别?
  • 如果上述过程是错误的(即是否有正确/更好的方法来处理这一切)。

versioning git github

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