به نام خداوند مهربان

آخرین مطالب

Jump search is another searching algorithm suitable for sorted arrays. It jumps ahead by a fixed number of steps and then performs a linear search in the smaller range.

Steps:

  1. Determine the block size to jump ahead.
  2. Jump ahead by block size until the target value is greater than the current block’s last element.
  3. Perform linear search within the current block to find the target value.
  4. If the target value is found, return its index.
  5. If the target value is not found after iterating through all blocks, return -1.
import math

def jump_search(arr, target):
    """
    Perform jump search to find the target value in the given sorted list.

    Parameters:
        arr (list): The sorted list to be searched.
        target: The value to be searched for.

    Returns:
        int: The index of the target value if found, otherwise -1.
    """
    n = len(arr)
    step = int(math.sqrt(n))
    prev = 0
    while arr[min(step, n) - 1] < target:
        prev = step
        step += int(math.sqrt(n))
        if prev >= n:
            return -1
    while arr[prev] < target:
        prev += 1
        if prev == min(step, n):
            return -1
    if arr[prev] == target:
        return prev
    return -1

# Example usage:
arr = [2, 3, 4, 10, 40]
target = 10
result = jump_search(sorted(arr), target)
if result != -1:
    print(f"Jump Search: Element found at index {result}")
else:
    print("Jump Search: Element not found")

 

  • حسن دلدار

Interpolation search is an improved version of binary search, especially suitable for large and uniformly distributed arrays. It calculates the probable position of the target value based on the value of the key and the range of the search space.

Steps:

  1. Calculate the probable position of the target value using interpolation formula.
  2. Compare the target value with the element at the calculated position.
  3. If the element matches the target value, return its index.
  4. If the element is less than the target value, search in the right half of the list.
  5. If the element is greater than the target value, search in the left half of the list.
  6. Repeat steps 1-5 until the target value is found or the search interval is empty.

 

import math

def interpolation_search(arr, target):
    """
    Perform interpolation search to find the target value in the given sorted list.

    Parameters:
        arr (list): The sorted list to be searched.
        target: The value to be searched for.

    Returns:
        int: The index of the target value if found, otherwise -1.
    """
    low = 0
    high = len(arr) - 1
    while low <= high and target >= arr[low] and target <= arr[high]:
        pos = low + ((high - low) // (arr[high] - arr[low])) * (target - arr[low])
        if arr[pos] == target:
            return pos
        elif arr[pos] < target:
            low = pos + 1
        else:
            high = pos - 1
    return -1

# Example usage:
arr = [2, 3, 4, 10, 40]
target = 10
result = interpolation_search(sorted(arr), target)
if result != -1:
    print(f"Interpolation Search: Element found at index {result}")
else:
    print("Interpolation Search: Element not found")

 

  • حسن دلدار

Binary search is a more efficient searching algorithm suitable for sorted lists. It repeatedly divides the search interval in half until the target value is found.

Steps:

  1. Start with the entire sorted list.
  2. Compute the middle element of the list.
  3. If the middle element is equal to the target value, return its index.
  4. If the middle element is less than the target value, search in the right half of the list.
  5. If the middle element is greater than the target value, search in the left half of the list.
  6. Repeat steps 2-5 until the target value is found or the search interval is empty.

 

def binary_search(arr, target, low, high):
    """
    Perform binary search recursively to find the target value in the given sorted list.

    Parameters:
        arr (list): The sorted list to be searched.
        target: The value to be searched for.
        low (int): The lower index of the search interval.
        high (int): The upper index of the search interval.

    Returns:
        int: The index of the target value if found, otherwise -1.
    """
    if low <= high:
        mid = (low + high) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            return binary_search(arr, target, mid + 1, high)
        else:
            return binary_search(arr, target, low, mid - 1)
    else:
        return -1

# Example usage:
arr = [2, 3, 4, 10, 40]
target = 10
result = binary_search(sorted(arr), target, 0, len(arr) - 1)
if result != -1:
    print(f"Binary Search: Element found at index {result}")
else:
    print("Binary Search: Element not found")

 

  • حسن دلدار

Linear search is the simplest searching algorithm. It sequentially checks each element of the list until it finds the target value.

Steps:

  • Start from the first element of the list.
  • Compare each element of the list with the target value.
  • If the element matches the target value, return its index.
  • If the target value is not found after iterating through the entire list, return -1.

 

def linear_search(arr, target):
    """
    Perform linear search to find the target value in the given list.

    Parameters:
        arr (list): The list to be searched.
        target: The value to be searched for.

    Returns:
        int: The index of the target value if found, otherwise -1.
    """
    for i in range(len(arr)):
        if arr[i] == target:
            return i
    return -1

# Example usage:
arr = [2, 3, 4, 10, 40]
target = 10
result = linear_search(arr, target)
if result != -1:
    print(f"Linear Search: Element found at index {result}")
else:
    print("Linear Search: Element not found")

 

  • حسن دلدار

نصب yarn :

npm install --global yarn

 
  • حسن دلدار

روش اول:
 

from huggingface_hub import login
HUGGINGFACE_API_KEY = ""
login(token=HUGGINGFACE_API_KEY)

روش دوم:

 

import os
os.environ['HUGGING_FACE_HUB_TOKEN'] = ""  # <-- Enter your hub token here

 

روش سوم:

from transformers import AutoModel
access_token = "hf_..."
model = AutoModel.from_pretrained("private/model", token=access_token)

نکته مهم قبل از هر کاری بهتر است متغییر محیطی یا environment variables  با نام HF_HOME با یک مسیر دلخواه در سیستم خود تنظیم کنید.

 

 

  • حسن دلدار
np_arr = torch_tensor.detach().cpu().numpy()
  • حسن دلدار

نمایش اطلاعات بیشتری از یک تنسور:

 

In [18]: torch.set_printoptions(edgeitems=1)

In [19]: a
Out[19]:
tensor([[-0.7698,  ..., -0.1949],
        ...,
        [-0.7321,  ...,  0.8537]])

In [20]: torch.set_printoptions(edgeitems=3)

In [21]: a
Out[21]:
tensor([[-0.7698,  1.3383,  0.5649,  ...,  1.3567,  0.6896, -0.1949],
        [-0.5761, -0.9789, -0.2058,  ..., -0.5843,  2.6311, -0.0008],
        [ 1.3152,  1.8851, -0.9761,  ...,  0.8639, -0.6237,  0.5646],
        ...,
        [ 0.2851,  0.5504, -0.9471,  ...,  0.0688, -0.7777,  0.1661],
        [ 2.9616, -0.8685, -1.5467,  ..., -1.4646,  1.1098, -1.0873],
        [-0.7321,  0.7610,  0.3182,  ...,  2.5859, -0.9709,  0.8537]])
  • حسن دلدار

:Create a symbolic link to the folder
mklink /D C:\Users\Pc\.nuget D:\sys\.nuget

 
  • حسن دلدار

 

The nvidia-smi tool can access the GPU and query information. For example:

 

> nvidia-smi
Fri Nov 11 02:08:18 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 520.61.05    Driver Version: 520.61.05    CUDA Version: 11.8     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| 50%   61C    P2   301W / 350W |  23683MiB / 24576MiB |     69%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A   2747694      C   python                          23680MiB |
+-----------------------------------------------------------------------------+

 

 

  • حسن دلدار