背景:我有许多脚本通过查找前导"0x"来解析查找十六进制数字的日志文件.我们的嵌入式C库改为新的printf.新的printf比我们之前更符合标准,我的脚本破了.
在Linux机器上:
#include <stdio.h>
int main( void )
{
printf( "%#010x\n", 0 );
printf( "%#010x\n", 1 );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出(使用glibc)是:
0000000000
0x00000001
Run Code Online (Sandbox Code Playgroud)
我们公司的输出是:
0x00000000
0x00000001
Run Code Online (Sandbox Code Playgroud)
从printf(3)开始,在'#'标志字符上:"对于x和X转换,非零结果的前缀为字符串"0x"(或X转换为"0X")."
我很好奇为什么.如果没有挖掘C标准文件或为标准委员会成员购买午餐,为什么不在零价值论证中使用前导0x?
对于图像处理类,我在单色图像上进行点操作.像素是uint8 [0,255].
numpy uint8将换行.例如,235 + 30 = 9.我需要像素饱和(max = 255)或截断(min = 0)而不是包裹.
我的解决方案使用int32像素作为点数学,然后转换为uint8以保存图像.
这是最好的方法吗?或者有更快的方法吗?
#!/usr/bin/python
import sys
import numpy as np
import Image
def to_uint8( data ) :
# maximum pixel
latch = np.zeros_like( data )
latch[:] = 255
# minimum pixel
zeros = np.zeros_like( data )
# unrolled to illustrate steps
d = np.maximum( zeros, data )
d = np.minimum( latch, d )
# cast to uint8
return np.asarray( d, dtype="uint8" )
infilename=sys.argv[1]
img = Image.open(infilename)
data32 = np.asarray( …
Run Code Online (Sandbox Code Playgroud) 我有以下范围的numpy数据(usec时间戳的增量):
array([ 4.312, 4.317, 4.316, 4.32 , 4.316, 4.316, 4.319, 4.317,
4.317, 4.316, 4.318, 4.316, 4.318, 4.316, 4.318, 4.317,
4.317, 4.317, 4.316, 4.317, 4.318, 4.316, 4.318, 4.316,
4.318, 4.316, 4.317, 4.317, 4.318, 4.316, 4.317, 4.317,
4.317, 4.317, 4.317, 4.316, 4.319, 4.315, 4.319, 4.315,
4.319, 4.315, 4.316, 4.319, 4.317, 4.317, 4.317, 4.318,
4.315, 4.317, 4.317, 4.317, 4.319, 4.314, 4.32 , 4.315,
4.317, 4.318, 4.315, 4.318, 4.317, 4.317, 4.317, 4.316,
4.317, 4.318, 4.317, 4.317, 4.317, 4.315, 4.319, 4.317,
4.315, 4.319, 4.316, 4.318, …
Run Code Online (Sandbox Code Playgroud) 我的图像处理类已经分配了一个图像恢复项目.我目前正在研究反向滤波器.图像 - >降级 - >逆滤波器 - >恢复图像.我正在使用一个简单的5x5盒式过滤器来降级.
如果我在空间域中对图像进行卷积,移动到频域,然后使用内核的fft反向滤波卷积图像,我就搞得一团糟.如果我在频域中对图像进行卷积,然后对该图像进行反向滤波,我会得到一个好的图像.
频域和空间域卷积应该相同.我唯一的想法是我在做内核的错误?我正在使用5x5盒式过滤器.空间卷积将最终结果除以np.sum(方框).我试过通过以下方式对盒子进行标准化:
box = np.ones( 25 ).reshape( 5,5 ) / 25.0
Run Code Online (Sandbox Code Playgroud)
但得到相同的垃圾反向过滤图像结果.
我还注意到频率卷积图像(来自下面的代码的"g_freq.png")被移位,可能是由于FFT填充顶部和左边的图像的底部/右边.这会导致问题吗?
空间卷积:
频率卷积:注意顶部/左侧的填充.
下面是创建问题的最简单的代码.100%numpy/scipy/matplotlib.
import sys
import matplotlib
matplotlib.use( 'Agg' )
import matplotlib.pyplot as plt
import numpy as np
import scipy
from scipy import ndimage
def save_image( data, filename ) :
print "saving",filename
plt.cla()
fig = plt.figure()
ax = fig.add_subplot( 111 )
ax.imshow( data, interpolation="nearest", cmap=matplotlib.cm.gray )
fig.savefig( filename )
f = scipy.misc.lena()
save_image( f, "scipylena.png" )
# create a simple …
Run Code Online (Sandbox Code Playgroud) 我是Verilog的新手,但多年来一直是C程序员,这让我很危险.
我正在为一堂课做一些Verilog.我想在我的模拟代码中使用C assert()样式测试.https://en.wikipedia.org/wiki/Assert.h
我们没有使用System Verilog,因此没有可以找到的标准断言.我拼凑了下面的宏.
`define ASSERT_EQUALS(x,y) \
repeat(1)\
begin\
if( (x) != (y) ) \
begin\
$write( "assert failed %d != %d\n", (x), (y) );\
$finish;\
end\
end
// test the assert( should fail)
`ASSERT_EQUALS(t_data_in,16'hfffe)
Run Code Online (Sandbox Code Playgroud)
据我所知,没有办法获得一个行号.因此,如果断言失败,我只会收到一条消息,无法链接回故障位置.
assert failed 65535 != 65534
Run Code Online (Sandbox Code Playgroud)
有没有办法获得当前的行号?或者有更好的方法在Verilog中进行断言测试?
谢谢!
我正在将大型代码库移植到 Linux 内核设备驱动程序。ASIC 使用大量 DMA 通道。
我 kmalloc 内存与GFP_KERNEL|GFP_DMA
. 在启动 DMA 之前,我使用 dma_map_single 来获取硬件(物理)内存地址以提供给硬件。(也会刷新/使 dcache 中的内存无效?)我有时需要 CPU 访问数据,一旦 DMA 完成,但不经常。在通过代码访问数据之前,我执行了 dma_unmap_single 以避免缓存一致性问题。
在我不需要 CPU 访问的情况下,我还需要调用dma_unmap_single
吗?我应该dma_unmap_single
每一个指针dma_map_single
吗?是否dma_map_single
消耗dma_unmap_single
将释放的资源(例如,表条目)?
DMA-API.txt 不清楚良好的 DMA 内存卫生。
谢谢!
我正在将 3.14 移植到基于 ARM 的 SOC,该 SOC 已成功运行 3.2 内核。
我陷入了校准 jiffies 的代码中。
校准延迟收敛()-init/calibrate.c
/* wait for "start of" clock tick */
ticks = jiffies;
while (ticks == jiffies) <---- infinite loop waiting for jiffies to change
; /* nothing */
/* Go .. */
Run Code Online (Sandbox Code Playgroud)
jiffies 没有更新。jiffies 在哪里更新?我正在寻找类似 jiffies++ 或更新 jiffies 的 .S 文件的吸烟枪代码。
我进入了 Linux 中计时器和中断系统的兔子洞。定时器中断未启用(在 PL190 硬件中)。我希望如果我可以自下而上跟踪(应该调用 jiffies 的地方),我就能找到为什么没有启用中断。
numpy ×3
linux-kernel ×2
python ×2
c ×1
hex ×1
linux ×1
matplotlib ×1
printf ×1
scipy ×1
verilog ×1