기본 콘텐츠로 건너뛰기

추천 게시물

[Go] 고루틴

런타임(Runtime) visual code에서 브라우저 실행 단축키: Alt+B Go runtime은 메모리 관리, 가비지 수집, 동시성을 포함하여 Go 프로그림의 실행을 관리하는 역할을 합니다. 이 문서에서는 Go runtime을 자세히 살펴보고 아키텍초, 특성과 장점을 살펴봅니다. Go Runtime Architecture Go runtime은 모듈식이고 유연하게 설계되었으며 개발자가 특정 요구사항에 따라 동작을 사용자 정의할 수 있는 계층적 아키텍쳐를 갖추고 있습니다. 런타임은 스케줄러(schedualer), 가비지 수집기(garbage collector), 메모리 할당자(memory alllocator) 및 스택관리(stack management)를 포함한 어려 핵심 구성 요소로 구성됩니다. Schedualer Go 런타임의 핵심은 고루틴의 실행을 관리하는 스케줄러입니다. 고루틴은 효율적인 동시성을 가능하게 하는 가벼운 스레드입니다. 스케줄러는 사용 가능한 스레드에 고루틴을 분산하고, 스레드 로컬 스토리지를 관리하고, I/O 작업을 조정하는 역할을 합니다. thread(스레드): 프로그램 내에서 실행되는 흐름의 단위로 동시에 여러 작업이나 프로그램을 실행하는 것입니다. 즉, 코드를 실행할 수 있는 각 단위를 스레드라고 합니다. 고루틴(goroutine): Go 언어로 동시에 실행되는 모든 활동을 의미합니다. 고루틴을 만드는 비용을 스레드에 비해 매우 적기 떄문에 경량 스레드라고 합니다. 모든 프로그램은 적어도 하나의 main() 함수라는 고루틴을 포함하고 고루틴은 항상 백그라운드에서 작동합니다. 메인함수가 종료되면 모든 고루틴은 종료됩니다. 그러므로 고루틴보다 main이 먼저 종료되는 것을 방지해야 합니다. Go 스케줄러는 매우 효율적이고 확장 가능하도록 설계되어 많은 수의 동시 고루틴을 손쉽게 처리할 수 있습니다. 스레드 간에 부하를 분산하여 경합을 최소화하고 성능을 개선하는 작업 훔치기 알고리즘을 사용합니다...

How to get solution of linear system?

$$\text{A}\overrightarrow{x}=\overrightarrow{b}\qquad \text{Eq.1}$$ A: m $\times$ n Matrix, Coefficient(Standard) Matrix x: Variable vector(column vector) b: Constant vector(column vector) Equation 1 is called a matrix equation or a linear combination system. The above relationship means that an appropriate solution exists. The solution of the matrix equation can be calculated by using the inverse matrix and by using the row echelon form matrix (RREF). 1. How to use inverse matrix Invertible matrix: matrix (M) in which the inverse matrix exists The basic conditions of this invertible matrix are as follows. 1) square matrix (number of rows = number of columns) 2) The determinant is not zero. $$det(M) \neq 0$$ The inverse matrix of the square matrix M is denoted by  $M^{-1}$ , and the product of these two matrices is the identity matrix (I). An identity matrix: a matrix with diagonal elements of 1 and all other elements of 0 >>> I2=np.eye(2);I2...

Linear combination

$R_n = \{\overrightarrow {v_1}, \overrightarrow {v_2}, ...., \overrightarrow {v_n}\}$ $\text{scalar} \; c=\{c_1, c_2,..., c_n\}$ For vector R and scalar c, if the following relationship Equation 7 is defined $$y=c_1 \overrightarrow {v_1} + c_2 \overrightarrow {v_2} + .... +c_n \overrightarrow {v_n},$$ This is called the linear combination of the vector R and the scalar (weight). 1. Are linear combinations in vectors a 1 , a 2 and vector b? Whether the relationship is established, $$x_1 a_1 +x_2 a_2 = b \quad x_1, x_2 : scalar(weight)$$ $$a_1 =\left[\begin{array}{r}1\\-2\\-5 \end{array}\right], \qquad a_2=\left[\begin{array}{r}2\\5\\6 \end{array}\right], \qquad b=\left[\begin{array}{r}7\\4\\3\end{array}\right]$$ $$x_1 \left[\begin{array}{r}1\\-2\\-5 \end{array}\right] + x_2 =a_2=\left[\begin{array}{r}2\\5\\6 \end{array}\right]=\left[\begin{array}{r}7\\4\\3\end{array}\right]$$ The above is arranged in the form of matrix product as follows. $$\left[\begin{array}{r}1&...

pivot position in rref

pivot position In matrix A, the pivot position is the position corresponding to leading 1 in the row echelon form matrix (rref) of the matrix. A pivot column is a column that contains a pivot position. The rref of matrix A is ? >>> from sympy import * >>> A=Matrix([[0, -3, -6,4, 9],[-1,-2,-1, 3, 1], [-2, -3, 0, 3, -1], [1, 4, 5, -9, -7]]) >>> A Matrix([ [ 0, -3, -6,  4,  9], [-1, -2, -1,  3,  1], [-2, -3,  0,  3, -1], [ 1,  4,  5, -9, -7]]) >>> A.rref() (Matrix([ [1, 0, -3, 0,  5], [0, 1,  2, 0, -3], [0, 0,  0, 1,  0], [0, 0,  0, 0,  0]]), (0, 1, 3)) In that rref, the columns containing the leading 1 are 1, 2, and 4 columns. $$\left[\begin{array}{rrrrr}1(pivot)&0&-3&0&5\\0&1(pivot)&2&0&-3\\0&0&0&1(pivot)&0 \\0&0&0&0&0\end{array}\right]$$ >>> from sympy import * >>> B=Matrix...

random module

To generate a random number, the functions provided by the random package (module) are used. Let's look at the functions provided by this module. Attaching packages uses keyword ' import '. In [1]: import random In [2] : random.random() Out[2]: 0.3741780106878482 In [2] : random.random() Out[3]: 0.8748210983554208  The random.random () function randomly returns a number between 0 and 1 (0 <x <= 1, [1, 0)). In some cases, this randomly selected number should be used later. To do this, you use the random.seed () function to specify the number of selections.. In [3] : random.seed(1) In [4] : random.random() Out[4]: 0.13436424411240122 That is, in the above case, random numbers created under random.seed(1) can be called at any time during the lifetime of the current workspace because it has a unique number of one. In [5] : random.seed(1) In [6] : random.random() Out[6]: 0.13436424411240122 The random.randrange(start, end) function extract...

shallow copy vs deep copy

Creating an object in Python has the following semantics: 1) Objects are separated by name and content, and objects of any name are referenced by contents. ( See references ) 2) You can distinguish between referring to the object itself and directly referring to each element of the object. These are called shallow copies and deep copies, respectively. In [1]: y Out[1]: [1, 2, 'a'] In [2]: x=y In [3]: x Out[3]: [1, 2, 'a'] In [4]: [id(y), id(x)] Out[4]: [2465266012296, 2465266012296] In [5]: x1=[1, 2, 'a'] In [6]: [id(y), id(x), id(x1)] Out[6]: [2465266012296, 2465266012296, 2465266090376] In [7]: [[id(y[i]), id(x[i]), id(x1[i])] for i in range(3)] Out[7]: [[1700837840, 1700837840, 1700837840],  [1700837872, 1700837872, 1700837872],  [2465036771992, 2465036771992, 2465036771992]] (The list object also refers to each element. The code [7] is the same for each element of the objects referenced by y, x, and x1. In other words, a string, list,...

reference_Python

Computer memory stores all input parts, either numbers or letters, as binary numbers, that is, 0 and 1. This stored data is recognized by Python as an object. In Python, objects are classified based on the following data types: Integer type, real type, character type, string type, list type, tuple type, dictionary type Of these, string, list, tuple, and dictionary are data types and data structures. In other words, this structure contains basic data types such as int, float, and character inside it, and is treated as a data type. id () returns a reference to an object. Use this function to: In [1]: [1,2,3] Out[1]: [1, 2, 3] In [2]: y=[1,2,3] In [3]: [id([1,2,3]),id(y)] Out[3]: [2465266218760, 2465266012296] Code [2] stores the list object created in code [1] in another object, y. According to the result of code [3], object names y and [1,2,3] are not in the same space. In other wise, object y refers to object [1,2,3] of code [1]. The list of code [1] also refers to each e...

if condition

A conditional statement is an expression for determining whether code is executed. The simplest form of this conditional statement is the ‘if’ statement. It is a frequently used syntax in most functions, and writing an ‘if’ condition statement is relatively straightforward. According to the syntax below, command1 is executed if the condition is met, otherwise command2 is executed. In this syntax, else ~ can be omitted and other ‘if’ statements can be included in the ‘if’statement. If condition:      command1 else:      command2  Python distinguishes between uppercase and lowercase letters. Therefore, 'a' and 'A' are different.  The above command1 is executed according to the ‘if’ condition. That is, in the statement structure, command1 exists in the ‘if’ statement. How does python express this structure? python uses a semicolon (;) at the end of the main statement that determines which command, and the subcomma...