操作系统:Ubuntu 18.04.6 LTS
安装:
在尝试使用时遇到此问题后,我从新的使用中pipenv install jupyterlab安装了所有内容。pip installpipenv shellPython 3.8.0
pipenv shell
pip install --upgrade pip
pip install numpy matplotlib jupyterlab ipympl
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到 Jupyter Lab 安装文档。
运行pip list输出:
Package Version
-------------------- ---------
anyio 3.5.0
argon2-cffi 21.3.0
argon2-cffi-bindings 21.2.0
asttokens 2.0.5
attrs 21.4.0
Babel 2.9.1
backcall 0.2.0
black 21.12b0
bleach 4.1.0
certifi 2021.10.8
cffi 1.15.0
charset-normalizer 2.0.10
click 8.0.3
cycler 0.11.0
debugpy 1.5.1
decorator 5.1.1
defusedxml 0.7.1
entrypoints 0.3
executing …Run Code Online (Sandbox Code Playgroud) 我有一个 C 函数,它读取一个二进制文件并返回一个动态大小的无符号整数数组(大小基于二进制文件的元数据):
//example.c
#include <stdio.h>
#include <stdlib.h>
__declspec(dllexport)unsigned int *read_data(char *filename, size_t* array_size){
FILE *f = fopen(filename, "rb");
fread(array_size, sizeof(size_t), 1, f);
unsigned int *array = (unsigned int *)malloc(*array_size * sizeof(unsigned int));
fread(array, sizeof(unsigned int), *array_size, f);
fclose(f);
return array;
}
Run Code Online (Sandbox Code Playgroud)
这个答案似乎是说将创建的数组从 C 传递到 Python 的正确方法是这样的:
# example_wrap.py
from ctypes import *
import os
os.add_dll_directory(os.getcwd())
indexer_dll = CDLL("example.dll")
def read_data(filename):
filename = bytes(filename, 'utf-8')
size = c_size_t()
ptr = indexer_dll.read_data(filename, byref(size))
return ptr[:size]
Run Code Online (Sandbox Code Playgroud)
但是,当我运行 python 包装器时,代码默默地失败了,ptr[:size] …
我有一个 C 函数,涉及使用 zstd 解压缩数据。我正在尝试使用 Cython 调用该函数。
使用文档中的此页面作为指南,我可以毫无问题地编译和运行下面的代码。
(我实际上并没有在这里使用 zstd lib)
// hello.c
#include <stdio.h>
#include <zstd.h>
int hello() {
printf("Hello, World!\n");
void *next_in = malloc(0);
void *next_out = malloc(0);
return 0;
}
# Hello.pyx
cdef extern from "hello.c":
int hello()
cpdef int callHello():
hello()
# hello_wrapper.setup.py
from setuptools import setup, Extension
from Cython.Build import cythonize
ext_modules = [
Extension(
"hello_wrapper",
["hello_wrapper.pyx"],
libraries=["zstd"],
library_dirs=["path/to/zstd/lib"],
include_dirs=['path/to/zstd/include'],
)
]
setup(
ext_modules = cythonize(ext_modules, gdb_debug=True)
)
Run Code Online (Sandbox Code Playgroud)
使用如下命令我得到预期的输出:
>py hello_wrapper.setup.py build_ext --inplace
>py …Run Code Online (Sandbox Code Playgroud) 我有一个 C 函数,它执行一些 I/O 操作和解码,我想从 python 脚本调用它。
C 函数在由 Visual Studio 命令行 C 编译器编译时工作正常,并且在禁用多线程的情况下通过 Cython 调用时也工作正常。但是,当使用 OpenMP 多线程调用时,在前几百万个循环中运行良好,但在接下来的几百万个循环中 CPU 使用率慢慢下降,直到最终停止并且不会失败,但也不会继续计算。
C文件如下:
//block_reader.c
#include "block_reader.h" //contains block_data_t, decode_block, get_block_data
#include <stdio.h>
#include <stdlib.h>
#define NTHREADS 8
int decode_blocks(block_data_t *block_data_array, int num_blocks, int *values){
int block;
#pragma omp parallel for num_threads(NTHREADS)
for(block=0; block<num_blocks; block++){
decode_block(block_data_array[i], values);
}
}
int main(int argc, char *argv[]) {
int num_blocks = 250000, block_size = 4096;
block_data_t *block_data_array = get_block_data();
int *values = (long long *)malloc(num_blocks * …Run Code Online (Sandbox Code Playgroud) 我正在尝试在引导程序中进行此布局
--------------------------------------------
| |
| |
--------------------------------------------
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
--------------------------------------------
Run Code Online (Sandbox Code Playgroud)
重要的一点是,顶部占据了96px的较大部分,占屏幕的20%,而底部则占据了屏幕的其余部分。
尽管网格系统在处理列宽方面给了我很大的力量,但我在寻找如何对行高执行相同操作时遇到了麻烦。
这是我当前的结构:
<div class="container-fluid" style="height: 100vh">
<div class="row">
<div class="col">
Top Bar
</div>
</div>
<div class="row">
<div class="col-md-2">
Bottom Left
</div>
<div class="col-md-10">
Bottom Right
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:
--------------------------------------------
| |
| |
--------------------------------------------
| | |
| | |
--------------------------------------------
Run Code Online (Sandbox Code Playgroud)
在手机上看起来还可以,但在台式机上却完全没有问题。
通过将第二行div设置为height …
c ×3
python ×3
cython ×2
python-3.x ×2
bootstrap-4 ×1
ctypes ×1
dll ×1
openmp ×1
pipenv ×1
python-c-api ×1