缩放算法优化步骤详解

添加链接描述

背景

假设数据存放在在unsigned char* m_pData 里面,宽和高分别是:m_nDataWidth m_nDataHeight
给定缩放比例:fXZoom fYZoom,返回缩放后的unsigned char* dataZoom
这里采用最简单的缩放算法即:
根据比例计算原图和缩放后图坐标的对应关系:缩放后图坐标*缩放比例 = 原图坐标

原始代码 未优化

#pragma once
class zoomBlock
{
public:zoomBlock() {};~zoomBlock();void zoomDataSSE128(unsigned char* dataZoom, float  fXZoom, float fYZoom);void zoomData(unsigned char* dataZoom, float  fXZoom, float fYZoom);void test(float  fXZoom =0.5, float fYZoom=0.5);void init(int DataWidth, int DataHeight);
private:void computeSrcValues(int* srcValues, size_t size, float zoom, int dataSize);private:unsigned char* m_pData = nullptr;float m_fXZoom = 1 ;//x轴缩放比例  m_nXZoom=1时 不缩放float m_fYZoom = 1 ;//y轴缩放比例int m_nDataWidth = 0;int m_nDataHeight = 0;
};#include "zoomBlock.h"
#include <stdio.h>
#include <iostream>
#include<iomanip>
#define SAFE_DELETE_ARRAY(p) { if( (p) != NULL ) delete[] (p); (p) = NULL; }zoomBlock::~zoomBlock()
{SAFE_DELETE_ARRAY(m_pData);
}
void zoomBlock::init(int DataWidth, int DataHeight)
{m_nDataWidth = DataWidth;m_nDataHeight = DataHeight;m_pData = new unsigned char[m_nDataWidth* m_nDataHeight];for (int i = 0; i < m_nDataWidth * m_nDataHeight; ++i){m_pData[i] = static_cast<unsigned char>(i);  // Replace this with your data initialization logic}
}void zoomBlock::zoomData(unsigned char* dataZoom, float  fXZoom, float fYZoom)
{int nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;for (size_t row = 0; row < nZoomDataHeight; row++){for (size_t column = 0; column < nZoomDataWidth; column ++){//1int srcx = std::min(int(row / fYZoom), m_nDataHeight - 1);int srcy = std::min(int(column / fXZoom), m_nDataWidth - 1);//2int srcPos = srcx * m_nDataHeight + srcy;int desPos = row * nZoomDataHeight + column;dataZoom[desPos] = m_pData[srcPos];}}
}void zoomBlock::test(float  fXZoom, float fYZoom)
{init(8,8);std::cout << "Values in m_pData:" << std::endl;for (int i = 0; i < m_nDataWidth * m_nDataHeight; ++i){std::cout << std::setw(4) << static_cast<int>(m_pData[i]) << " ";if ((i + 1) % m_nDataWidth == 0) {  // Adjust the value based on your datastd::cout << std::endl;}}unsigned char* dataZoom = new unsigned char[fXZoom * m_nDataWidth * fYZoom * m_nDataHeight];zoomData(dataZoom, fXZoom, fYZoom);// Print or inspect the values in m_dataZoomint nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;std::cout << "Values in m_dataZoom:" << std::endl;for (int i = 0; i < nZoomDataHeight * nZoomDataWidth; ++i){std::cout << std::setw(4)<< static_cast<int>(dataZoom[i]) << " ";if ((i + 1) % nZoomDataWidth == 0) {  // Adjust the value based on your datastd::cout << std::endl;}}SAFE_DELETE_ARRAY(dataZoom);}

测试代码

int main()
{zoomBlock zoomBlocktest;zoomBlocktest.test(1.5,1.5);return 0;
}

在这里插入图片描述
其中函数
·void zoomBlock::zoomData(unsigned char* dataZoom, float fXZoom, float fYZoom)·
没有使用任何加速优化,现在来分析它。

sse128

我们知道sse128可以一次性处理4个int类型,所以我们把最后一层for循环改成,4个坐标的算法,不满4个的单独计算

void zoomBlock::zoomDataSSE128(unsigned char* dataZoom, float  fXZoom, float fYZoom)
{int nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;for (size_t row = 0; row < nZoomDataHeight; row++){int remian = nZoomDataWidth % 4;for (size_t column = 0; column < nZoomDataWidth - remian; column += 4){//第一个坐标int srcx = std::min(int(row / fYZoom), m_nDataHeight - 1);int srcy = std::min(int(column / fXZoom), m_nDataWidth - 1);int srcPos = srcx * m_nDataHeight + srcy;int desPos = row * nZoomDataHeight + column;dataZoom[desPos] = m_pData[srcPos];//第二个坐标int srcx1 = std::min(int((row+1) / fYZoom), m_nDataHeight - 1);int srcy1 = std::min(int((column+1) / fXZoom), m_nDataWidth - 1);int srcPos1 = srcx1 * m_nDataHeight + srcy1;int desPos1 = (row+1) * nZoomDataHeight + column+1;dataZoom[desPos1] = m_pData[srcPos1];//第3个坐标// 。。。//第4个坐标// 。。。}// Process the remaining elements (if any) without SSEfor (size_t column = nZoomDataWidth - remian; column < nZoomDataWidth; column++){int srcx = std::min(int(row / fYZoom), m_nDataHeight - 1);int srcy = std::min(int(column / fXZoom), m_nDataWidth - 1);int srcPos = srcx * m_nDataHeight + srcy;int desPos = row * nZoomDataHeight + column;dataZoom[desPos] = m_pData[srcPos];}}
}

上面 一次处理四个坐标的代码要改成sse的代码

在最里层的循环里面,每次都要计算 row / fYZoom 和 column / fXZoom,这个实际上可以挪出for循环,计算一次存到数组里

数据坐标desPos和srcPos ,必须放在最内存的循环里

所以我们用calculateSrcIndex函数单独处理 row / fYZoom 和 column / fXZoom,希望达到如下效果:

void calculateSrcIndex(int* srcValues, int size, float zoom,int max)
{for (int i = 0; i < size; i++){srcValues[i] = std::min(int(i/zoom),max);}
}

改成sse:

void calculateSrcIndex(int* srcValues, int size, float zoom,int max)
{__m128i mmIndex, mmSrcValue, mmMax;mmMax = _mm_set1_epi32(max);float zoomReciprocal = 1.0f / zoom;int remian = size % 4;for (size_t i = 0; i < size - remian; i += 4){mmIndex = _mm_set_epi32(i + 3, i + 2, i + 1, i);mmSrcValue = _mm_cvtps_epi32(_mm_mul_ps(_mm_cvtepi32_ps(mmIndex), _mm_set1_ps(zoomReciprocal)));// Ensure srcValues are within the valid range [0, max]mmSrcValue = _mm_min_epi32(mmSrcValue, mmMax);// Store the result to the srcValues array_mm_storeu_si128(reinterpret_cast<__m128i*>(&srcValues[i]), mmSrcValue);}// Process the remaining elements (if any) without SSEfor (size_t i = size - remian; i < size; i++){srcValues[i] = std::min(int(i / zoom), max);}
}

解释:
这里主要处理int型数据,为了使用sse加速,要使用__m128i类型来存储4个int

加载int到__m128i:

  1. __m128i _mm_set1_epi32(int i);
    这个指令是使用1个i,来设置__m128i,将__m128i看做4个32位的部分,则每个部分都被赋为i;

  2. __m128i _mm_set_epi32(int i3, int i2,int i1, int i0);
    说明:使用4个int(32bits)变量来设置__m128i变量;
    返回值:如果返回值__m128i,分为r0,r1,r2,r3返回值规则如下:

r0 := i0
r1 := i1
r2 := i2
r3 := i3

  1. __m128i _mm_cvtps_epi32 (__m128 a)
    Converts packed 32-bit integers in a to packed single-precision (32-bit) floating-point elements.

加载float到__m128

  1. __m128 _mm_set1_ps(float w)
    对应于_mm_load1_ps的功能,不需要字节对齐,需要多条指令。(r0 = r1 = r2 = r3 = w)
  2. __m128 _mm_cvtepi32_ps (__m128i a)
    Converts packed 32-bit integers in a to packed single-precision (32-bit) floating-point elements.

float乘法

__m128 dst = _mm_mul_ps (__m128 a, __m128 b)
将a, b中的32位浮点数相乘,结果打包给dst

取最小值

__m128i _mm_min_epi32 (__m128i a, __m128i b)
Compare packed signed 32-bit integers in a and b, and store packed minimum values in dst.
Operation
FOR j := 0 to 3
i := j*32
dst[i+31:i] := MIN(a[i+31:i], b[i+31:i])
ENDFOR

所以代码修改为

	int* srcX = new int[nZoomDataHeight];int* srcY = new int[nZoomDataWidth];calculateSrcIndex(srcX, nZoomDataHeight, fXZoom , m_nDataHeight - 1);calculateSrcIndex(srcY, nZoomDataWidth, fYZoom, m_nDataWidth - 1);for (size_t row = 0; row < nZoomDataHeight; row++){int remian = nZoomDataWidth % 4;for (size_t column = 0; column < nZoomDataWidth - remian; column += 4){//第一个坐标int srcPos = srcX[row] * m_nDataHeight + srcY[column];int desPos = row * nZoomDataHeight + column;dataZoom[desPos] = m_pData[srcPos];...}}

然后把坐标的计算转为sse

void zoomBlock::zoomDataSSE128(unsigned char* dataZoom, float  fXZoom, float fYZoom)
{int nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;int* srcX = new int[nZoomDataWidth];int* srcY = new int[nZoomDataHeight];calculateSrcIndex(srcX, nZoomDataWidth, fXZoom, m_nDataWidth - 1);calculateSrcIndex(srcY, nZoomDataHeight, fYZoom, m_nDataHeight - 1);for (size_t y = 0; y < nZoomDataHeight; y++){int remian = nZoomDataWidth % 4;for (size_t x = 0; x < nZoomDataWidth - remian; x += 4){__m128i mmsrcX = _mm_set_epi32(srcX[x + 3], srcX[x + 2], srcX[x+1], srcX[x]);__m128i srcPosIndices = _mm_add_epi32(_mm_set1_epi32(srcY[y] * m_nDataWidth),mmsrcX);__m128i desPosIndices = _mm_add_epi32(_mm_set1_epi32(y * nZoomDataWidth),_mm_set_epi32(x + 3, x + 2, x + 1, x));dataZoom[desPosIndices.m128i_i32[0]] = m_pData[srcPosIndices.m128i_i32[0]];dataZoom[desPosIndices.m128i_i32[1]] = m_pData[srcPosIndices.m128i_i32[1]];dataZoom[desPosIndices.m128i_i32[2]] = m_pData[srcPosIndices.m128i_i32[2]];dataZoom[desPosIndices.m128i_i32[3]] = m_pData[srcPosIndices.m128i_i32[3]];/*cout << "srcPosIndices: " << srcPosIndices.m128i_i32[0] << " , desPosIndices : " << desPosIndices.m128i_i32[0] << endl;cout << "srcPosIndices: " << srcPosIndices.m128i_i32[1] << " , desPosIndices : " << desPosIndices.m128i_i32[1] << endl;cout << "srcPosIndices: " << srcPosIndices.m128i_i32[2] << " , desPosIndices : " << desPosIndices.m128i_i32[2] << endl;cout << "srcPosIndices: " << srcPosIndices.m128i_i32[3] << " , desPosIndices : " << desPosIndices.m128i_i32[3] << endl;*/}// Process the remaining elements (if any) without SSEfor (size_t x = nZoomDataWidth - remian; x < nZoomDataWidth; x++){int srcy = std::min(int(y / fYZoom), m_nDataHeight - 1);int srcx = std::min(int(x / fXZoom), m_nDataWidth - 1);int srcPos = srcy * m_nDataHeight + srcx;int desPos = y * nZoomDataHeight + x;dataZoom[desPos] = m_pData[srcPos];}}delete[] srcX;delete[] srcY;
}

完整的代码

 #pragma once
class zoomBlock
{
public:zoomBlock() {};~zoomBlock();void zoomDataSSE128(unsigned char* dataZoom, float  fXZoom, float fYZoom);void zoomData(unsigned char* dataZoom, float  fXZoom, float fYZoom);void test(float  fXZoom =0.5, float fYZoom=0.5);void init(int DataWidth, int DataHeight);
private:inline void calculateSrcIndex(int* srcValues, int size, float zoom, int max);private:unsigned char* m_pData = nullptr;float m_fXZoom = 1 ;//x轴缩放比例  m_nXZoom=1时 不缩放float m_fYZoom = 1 ;//y轴缩放比例int m_nDataWidth = 0;int m_nDataHeight = 0;
};#include "zoomBlock.h"
#include <stdio.h>
#include <iostream>
#include<iomanip>
#include<immintrin.h> 
using namespace std;
#define SAFE_DELETE_ARRAY(p) { if( (p) != NULL ) delete[] (p); (p) = NULL; }zoomBlock::~zoomBlock()
{SAFE_DELETE_ARRAY(m_pData);
}
void zoomBlock::init(int DataWidth, int DataHeight)
{m_nDataWidth = DataWidth;m_nDataHeight = DataHeight;m_pData = new unsigned char[m_nDataWidth* m_nDataHeight];for (int i = 0; i < m_nDataWidth * m_nDataHeight; ++i){m_pData[i] = static_cast<unsigned char>(i);  // Replace this with your data initialization logic}
}void zoomBlock::zoomData(unsigned char* dataZoom, float  fXZoom, float fYZoom)
{int nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;for (size_t y = 0; y < nZoomDataHeight; y++){for (size_t x = 0; x < nZoomDataWidth; x ++){//1int srcy = std::min(int(y / fYZoom), m_nDataHeight - 1);int srcx = std::min(int(x / fXZoom), m_nDataWidth - 1);//2int srcPos = srcy * m_nDataWidth + srcx;int desPos = y * nZoomDataWidth + x;dataZoom[desPos] = m_pData[srcPos];}}
}inline void zoomBlock::calculateSrcIndex(int* srcValues, int size, float zoom,int max)
{__m128i mmIndex, mmSrcValue, mmMax;mmMax = _mm_set1_epi32(max);float zoomReciprocal = 1.0f / zoom;int remian = size % 4;for (size_t i = 0; i < size - remian; i += 4){mmIndex = _mm_set_epi32(i + 3, i + 2, i + 1, i);mmSrcValue = _mm_cvttps_epi32(_mm_mul_ps(_mm_cvtepi32_ps(mmIndex), _mm_set1_ps(zoomReciprocal)));// Ensure srcValues are within the valid range [0, max]mmSrcValue = _mm_min_epi32(mmSrcValue, mmMax);// Store the result to the srcValues array_mm_storeu_si128(reinterpret_cast<__m128i*>(&srcValues[i]), mmSrcValue);}// Process the remaining elements (if any) without SSEfor (size_t i = size - remian; i < size; i++){srcValues[i] = std::min(int(i / zoom), max);}
}void zoomBlock::zoomDataSSE128(unsigned char* dataZoom, float  fXZoom, float fYZoom)
{int nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;int* srcX = new int[nZoomDataWidth];int* srcY = new int[nZoomDataHeight];calculateSrcIndex(srcX, nZoomDataWidth, fXZoom, m_nDataWidth - 1);calculateSrcIndex(srcY, nZoomDataHeight, fYZoom, m_nDataHeight - 1);for (size_t y = 0; y < nZoomDataHeight; y++){int remian = nZoomDataWidth % 4;for (size_t x = 0; x < nZoomDataWidth - remian; x += 4){/*int srcPos = srcx * m_nDataHeight + srcy;int desPos = row * nZoomDataHeight + column;*///dataZoom[desPos] = m_pData[srcPos];//__m128i mmsrcY = _mm_loadu_si128((__m128i*)(srcY));__m128i mmsrcX = _mm_set_epi32(srcX[x + 3], srcX[x + 2], srcX[x+1], srcX[x]);__m128i srcPosIndices = _mm_add_epi32(_mm_set1_epi32(srcY[y] * m_nDataWidth),mmsrcX);__m128i desPosIndices = _mm_add_epi32(_mm_set1_epi32(y * nZoomDataWidth),_mm_set_epi32(x + 3, x + 2, x + 1, x));dataZoom[desPosIndices.m128i_i32[0]] = m_pData[srcPosIndices.m128i_i32[0]];dataZoom[desPosIndices.m128i_i32[1]] = m_pData[srcPosIndices.m128i_i32[1]];dataZoom[desPosIndices.m128i_i32[2]] = m_pData[srcPosIndices.m128i_i32[2]];dataZoom[desPosIndices.m128i_i32[3]] = m_pData[srcPosIndices.m128i_i32[3]];/*cout << "srcPosIndices: " << srcPosIndices.m128i_i32[0] << " , desPosIndices : " << desPosIndices.m128i_i32[0] << endl;cout << "srcPosIndices: " << srcPosIndices.m128i_i32[1] << " , desPosIndices : " << desPosIndices.m128i_i32[1] << endl;cout << "srcPosIndices: " << srcPosIndices.m128i_i32[2] << " , desPosIndices : " << desPosIndices.m128i_i32[2] << endl;cout << "srcPosIndices: " << srcPosIndices.m128i_i32[3] << " , desPosIndices : " << desPosIndices.m128i_i32[3] << endl;*/}// Process the remaining elements (if any) without SSEfor (size_t x = nZoomDataWidth - remian; x < nZoomDataWidth; x++){int srcy = std::min(int(y / fYZoom), m_nDataHeight - 1);int srcx = std::min(int(x / fXZoom), m_nDataWidth - 1);int srcPos = srcy * m_nDataHeight + srcx;int desPos = y * nZoomDataHeight + x;dataZoom[desPos] = m_pData[srcPos];}}delete[] srcX;delete[] srcY;
}void zoomBlock::test(float  fXZoom, float fYZoom)
{init(8,4);std::cout << "Values in m_pData:" << std::endl;for (int i = 0; i < m_nDataWidth * m_nDataHeight; ++i){std::cout << std::setw(4) << static_cast<int>(m_pData[i]) << " ";if ((i + 1) % m_nDataWidth == 0) {  // Adjust the value based on your datastd::cout << std::endl;}}int nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;unsigned char* dataZoom = new unsigned char[nZoomDataWidth * nZoomDataHeight];zoomDataSSE128(dataZoom, fXZoom, fYZoom);//zoomData(dataZoom, fXZoom, fYZoom);// Print or inspect the values in m_dataZoomstd::cout << "Values in m_dataZoom:" << std::endl;for (int i = 0; i < nZoomDataHeight * nZoomDataWidth; ++i){std::cout << std::setw(4)<< static_cast<int>(dataZoom[i]) << " ";if ((i + 1) % nZoomDataWidth == 0) {  // Adjust the value based on your datastd::cout << std::endl;}}SAFE_DELETE_ARRAY(dataZoom);}int main()
{zoomBlock zoomBlocktest;zoomBlocktest.test(2,1);return 0;
}

在这里插入图片描述

AVX 256

inline void zoomBlock::calculateSrcIndex256(int* srcValues, int size, float zoom, int max)
{__m256i ymmIndex, ymmSrcValue, ymmMax;ymmMax = _mm256_set1_epi32(max);float zoomReciprocal = 1.0f / zoom;int remian = size % 8;for (size_t i = 0; i < size - remian; i += 8){ymmIndex = _mm256_set_epi32(i + 7, i + 6, i + 5, i + 4, i + 3, i + 2, i + 1, i);ymmSrcValue = _mm256_cvtps_epi32(_mm256_mul_ps(_mm256_cvtepi32_ps(ymmIndex), _mm256_set1_ps(zoomReciprocal)));// Ensure srcValues are within the valid range [0, max]ymmSrcValue = _mm256_min_epi32(ymmSrcValue, ymmMax);// Store the result to the srcValues array_mm256_storeu_si256(reinterpret_cast<__m256i*>(&srcValues[i]), ymmSrcValue);}// Process the remaining elements (if any) without AVX2for (size_t i = size - remian; i < size; i++){srcValues[i] = std::min(int(i / zoom), max);}
}
void zoomBlock::zoomDataAVX2(unsigned char* dataZoom, float fXZoom, float fYZoom)
{int nZoomDataWidth = fXZoom * m_nDataWidth;int nZoomDataHeight = fYZoom * m_nDataHeight;int* srcX = new int[nZoomDataWidth];int* srcY = new int[nZoomDataHeight];calculateSrcIndex(srcX, nZoomDataWidth, fXZoom, m_nDataWidth - 1);calculateSrcIndex(srcY, nZoomDataHeight, fYZoom, m_nDataHeight - 1);for (size_t y = 0; y < nZoomDataHeight; y++){int remian = nZoomDataWidth % 8;for (size_t x = 0; x < nZoomDataWidth - remian; x += 8){__m256i ymmSrcX = _mm256_set_epi32(srcX[x + 7], srcX[x + 6], srcX[x + 5], srcX[x + 4],srcX[x + 3], srcX[x + 2], srcX[x + 1], srcX[x]);__m256i srcPosIndices = _mm256_add_epi32(_mm256_set1_epi32(srcY[y] * m_nDataWidth),ymmSrcX);__m256i desPosIndices = _mm256_add_epi32(_mm256_set1_epi32(y * nZoomDataWidth),_mm256_set_epi32(x + 7, x + 6, x + 5, x + 4, x + 3, x + 2, x + 1, x));dataZoom[desPosIndices.m256i_i32[0]] = m_pData[srcPosIndices.m256i_i32[0]];dataZoom[desPosIndices.m256i_i32[1]] = m_pData[srcPosIndices.m256i_i32[1]];dataZoom[desPosIndices.m256i_i32[2]] = m_pData[srcPosIndices.m256i_i32[2]];dataZoom[desPosIndices.m256i_i32[3]] = m_pData[srcPosIndices.m256i_i32[3]];dataZoom[desPosIndices.m256i_i32[4]] = m_pData[srcPosIndices.m256i_i32[4]];dataZoom[desPosIndices.m256i_i32[5]] = m_pData[srcPosIndices.m256i_i32[5]];dataZoom[desPosIndices.m256i_i32[6]] = m_pData[srcPosIndices.m256i_i32[6]];dataZoom[desPosIndices.m256i_i32[7]] = m_pData[srcPosIndices.m256i_i32[7]];}// Process the remaining elements (if any) without AVX2for (size_t x = nZoomDataWidth - remian; x < nZoomDataWidth; x++){int srcy = std::min(int(y / fYZoom), m_nDataHeight - 1);int srcx = std::min(int(x / fXZoom), m_nDataWidth - 1);int srcPos = srcy * m_nDataWidth + srcx;int desPos = y * nZoomDataWidth + x;dataZoom[desPos] = m_pData[srcPos];}}delete[] srcX;delete[] srcY;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/272528.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

猫头虎分享已解决Bug || 系统监控故障:MonitoringServiceDown, MetricsCollectionError

博主猫头虎的技术世界 &#x1f31f; 欢迎来到猫头虎的博客 — 探索技术的无限可能&#xff01; 专栏链接&#xff1a; &#x1f517; 精选专栏&#xff1a; 《面试题大全》 — 面试准备的宝典&#xff01;《IDEA开发秘籍》 — 提升你的IDEA技能&#xff01;《100天精通鸿蒙》 …

如何在一个pycharm项目中创建jupyter notebook文件,并切换到conda环境中

1、第一步可以直接在pycharm项目中创建jupyter notebook文件 2、假若想要切换成pytorch环境做实验例子&#xff0c;会发现报这个错误 Jupyter server process exited with code 1 C:\Users\12430\.conda\envs\pytorch3.11\python.exe: No module named jupyter在这里&#xff…

Python快速入门系列-2(Python的安装与环境设置)

第二章&#xff1a;Python的安装与环境设置 2.1 Python的下载与安装2.1.1 访问Python官网2.1.2 安装Python对于Windows用户对于macOS用户对于Linux用户 2.2 集成开发环境&#xff08;IDE&#xff09;的选择与设置2.2.1 PyCharm2.2.2 Visual Studio Code2.2.3 Jupyter Notebook2…

jvm堆概述

《java虚拟机规范》中对java堆的描述是&#xff1a;所有的对象实例以及数组都应当在运行时分配在堆上。 一个JVM实例只存在一个堆内存(就是new 出来一个对象)&#xff0c;java内存管理的核心区域 java堆区在jvm启动的时候就被创建&#xff0c;空间大小确定。是jvm管理的最大一…

力扣--滑动窗口438.找到字符串中所有字母异位词

思路分析&#xff1a; 使用两个数组snum和pnum分别记录字符串s和p中各字符出现的次数。遍历字符串p&#xff0c;统计其中各字符的出现次数&#xff0c;存储在pnum数组中。初始化snum数组&#xff0c;统计s的前m-1个字符的出现次数。从第m个字符开始遍历s&#xff0c;通过滑动窗…

STM32_3-1点亮LED灯与蜂鸣器发声

STM32之GPIO GPIO在输出模式时可以控制端口输出高低电平&#xff0c;用以驱动Led蜂鸣器等外设&#xff0c;以及模拟通信协议输出时序等。 输入模式时可以读取端口的高低电平或电压&#xff0c;用于读取按键输入&#xff0c;外接模块电平信号输入&#xff0c;ADC电压采集灯 GP…

C# WinForm AndtUI第三方库 Table控件使用记录

环境搭建 1.在NuGet中搜索AndtUI并下载至C# .NetFramework WinForm项目。 2.添加Table控件至窗体。 使用方法集合 1.单元格点击事件 获取被点击记录特定列内容 private void dgv_CellClick(object sender, MouseEventArgs args, object record, int rowIndex, int columnIn…

一篇搞懂什么是LRU缓存|一篇搞懂LRU缓存的实现|LRUCache详解和实现

LRUCache 文章目录 LRUCache前言项目代码仓库什么时候会用到缓存(Cache)缓存满了&#xff0c;怎么办&#xff1f;什么是LRUCacheLRUCache的实现LRUCache对应的OJ题实现LRUCache对应的STL风格实现 前言 这里分享我的一些博客专栏&#xff0c;都是干货满满的。 手撕数据结构专栏…

解决ts报错:类型“entry”上不存在属性“$AppTools”

uniapp ts 项目&#xff0c;已经将AppTools挂在了vue的原型上&#xff0c;但是在vue页面使用时报错&#xff0c;如图&#xff1a; 解决&#xff1a; 在项目根目录下的tsconfig.json文件添加如下配置&#xff1a; "include": ["src/**/*"],这样报错就消失…

ChatGPT数据分析应用——热力图分析

ChatGPT数据分析应用——热力图分析 ​ 热力图分析既可以算作一种可视化方法&#xff0c;也可以算作一种分析方法&#xff0c;主要用于直观地展示数据的分布情况。接下来我们让ChatGPT解释这个方法的概念并提供相应的案例。发送如下内容给ChatGPT。 ​ ChatGPT收到上述内容后&…

云计算科学与工程实践指南--章节引言收集

云计算科学与工程实践指南–章节引言收集 //本文收集 【云计算科学与工程实践指南】 书中每一章节的引言。 我已厌倦了在一本书中阅读云的定义。难道你不失望吗&#xff1f;你正在阅读一个很好的故事&#xff0c;突然间作者必须停下来介绍云。谁在乎云是什么&#xff1f; 通…

opengl 学习(二)-----你好,三角形

你好&#xff0c;三角形 分类demo效果解析 分类 opengl c demo #include "glad/glad.h" #include "glfw3.h" #include <iostream> #include <cmath> #include <vector>using namespace std;/** * 在学习此节之前&#xff0c;建议将这…

MIT6.828操作系统工程实验学习笔记(二)

前言 这篇文章是接上文的内容&#xff0c;依然是对Lab1的记录 如何启动保护模式 要启动保护模式&#xff0c;需要完成以下三个步骤&#xff1a; 在内存中加载GDT&#xff0c;设置GDTR设置CR0寄存器的PE&#xff08;Protected Enable&#xff09;位&#xff0c;启用保护模式…

【深度学习笔记】6_9 深度循环神经网络deep-rnn

注&#xff1a;本文为《动手学深度学习》开源内容&#xff0c;部分标注了个人理解&#xff0c;仅为个人学习记录&#xff0c;无抄袭搬运意图 6.9 深度循环神经网络 本章到目前为止介绍的循环神经网络只有一个单向的隐藏层&#xff0c;在深度学习应用里&#xff0c;我们通常会用…

使用API有效率地管理Dynadot域名,进行DNS域名解析

关于Dynadot Dynadot是通过ICANN认证的域名注册商&#xff0c;自2002年成立以来&#xff0c;服务于全球108个国家和地区的客户&#xff0c;为数以万计的客户提供简洁&#xff0c;优惠&#xff0c;安全的域名注册以及管理服务。 Dynadot平台操作教程索引&#xff08;包括域名邮…

算法设计与分析(超详解!) 第一节 算法概述

1.算法的定义 算法的非形式化定义&#xff1a;算法是规则的有限集合&#xff0c;是为解决特定问题而规定的一系列操作。 可以理解为&#xff1a;算法&#xff08;algorithm&#xff09;是指在解决问题时&#xff0c;按照某种机械的步骤一定可以得到问题的结果&#xff08;有的…

图形库实战丨C语言扫雷小游戏(超2w字,附图片素材)

目录 效果展示 游玩链接&#xff08;无需安装图形库及VS&#xff09; 开发环境及准备 1.VS2022版本 2.图形库 游戏初始化 1.头文件 2.创建窗口 3.主函数框架 开始界面函数 1.初始化 1-1.设置背景颜色及字体 1-2.处理背景音乐及图片素材 1-3.处理背景图位置 2.选…

【软件安装教程】Anaconda

【软件安装教程】Anaconda 系统: Windows11 64位版本: Anaconda3-2024.02-1官方地址: Anaconda网盘地址: 百度网盘 下载 点击此连接 Anaconda 进入官网下载最新版 点击此连接 百度网盘 进入网盘下载 Anaconda3-2024.02-1 安装 双击下载好的文件 点击 Next 点击 I Agree …

求根节点到叶节点数字之和

题目 题目链接 . - 力扣&#xff08;LeetCode&#xff09; 题目描述 代码实现 class Solution { public:int sumNumbers(TreeNode* root) {return _sumNumbers(root, 0);}int _sumNumbers(TreeNode* root, int preSum){preSum preSum * 10 root->val;if(root->left…

cocos creator 3.7.2使用shader实现图片扫光特效

简介 功能&#xff1a;图片实现扫光效果 引擎&#xff1a;cocos Creator 3.7.2 开发语言&#xff1a;ts 完整版链接 链接https://lengmo714.top/284d90f4.html 效果图 shader代码 // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. CCEffect %{techniques:- pas…