This application is based upon and claims the benefit of priority from Japanese patent application No. 2023-119238, filed on Jul. 21, 2023, the disclosure of which is incorporated herein in its entirety by reference.
The present disclosure relates to an information processing apparatus, an information processing method, and a computer-readable recording medium.
Pandas is known as a de facto standard library that is used for data analysis, and as a library that is used for data analysis processing and data processing of a programming language Python (registered trademark). In addition, there are known cases where an advanced library that can execute processing at a higher speed than when pandas is used, and is compatible with pandas is used in place of pandas.
The aforementioned advanced library maintains compatibility with pandas using a fallback function. An API (Application Programming Interface) is used to call an implemented function (method) from the advanced library. On the other hand, when a function that is not implemented in the advanced library is called, pandas is used. With such a configuration, virtually there is no function (method) that is not implemented in the advanced library, and thus high compatibility can be realized.
However, when an advanced library is used in place of pandas, there is a need to edit the source codes of a module of a user program, a module of the advanced library, and a module of a library other than the advanced library.
As a related technique, Patent Document 1 (Japanese Patent Laid-Open Publication No. 2010-257103) discloses an information processing apparatus that shortens a time required for program change/recovery, which is temporarily performed on a program such as firmware that is used for debugging or information collection for market research or the like. With the information processing apparatus of Patent Document 1, the source code of a program read out from a ROM (Read Only Memory) and deployed to a RAM (Random Access Memory) is rewritten so as to execute a change module before a target module included in the program is executed.
However, when the source code of the module is edited, trouble such as an error in rewriting of the source code occurs. Therefore, the source code is not desired to be edited whenever possible.
In addition, in the information processing apparatus in Patent Document 1, a replacing module D (change module) is called from a predetermined module B, and only a module C before replacement is called.
An example object of the present disclosure is to eliminate the need to rewrite a source code of a module when an advanced library is used.
In order to achieve the example object described above, an information processing apparatus according to an example aspect includes:
Also, in order to achieve the example object described above, an information processing method that is performed by a information processing apparatus according to an example aspect includes:
Furthermore, in order to achieve the example object described above, a computer-readable recording medium according to an example aspect includes a program recorded on the computer-readable recording medium, the program including instructions that cause the computer to carry out:
According to the present disclosure as described above, even when an advanced library is used, it is possible to eliminate the need to rewrite the source code of a module.
Hereinafter, an example embodiment will be described with reference to the drawings. Note that, in the drawings described below, elements having the same functions or corresponding functions are denoted by the same reference numerals, and repeated description thereof may be omitted.
A configuration of an information processing apparatus according to an example embodiment will be described with reference to
The information processing apparatus shown in
When interrupt processing for replacing a first library with a second library that is compatible with the first library occurs, the detection unit 11 detects whether or not a code for reading a module includes a description regarding the first library.
A user program and the first library are created in a program language such as Python. Note that the program language is not limited to Python. In addition, when Python is used, the first library is, for example, pandas that is a library of Python. Note that the first library is not limited to pandas. The second library is a more advanced library than the first library. The “more advanced library” is a library that enables processing to be executed at a higher speed than when the first library is used, for example.
When a code for reading the first library is detected, the determination unit 12 refers to hierarchy information indicating the parent-child relationship for reading a first module that includes the code for reading the first library, and determines whether or not the first library or the second library is being used by a module at a higher layer than the first module.
The hierarchy information is a log indicating a parent-child relationship for reading modules, or the like. The hierarchy information is a list of file paths of modules such as that shown below, for example.
The above list indicates that the modules are read in descending order. First, “pandas/_init_” indicates that “pandas/core/api.py” is to be read, “pandas/core/api.py” indicates that “pandas/core/groupby/_init_” is to be read, and “pandas/core/groupby/_init_” indicates that “pandas/core/groupby/groupby.py” is to be read.
Note that “_init_” is a file that is read first when an instruction to read the entire folder as a module is given. When an instruction to read a file named pandas is given, for example, Python first detects pandas/_init_”.
When the first library or the second library is not being used by a module at a higher layer, the reading unit 13 replaces the first library and reads the second library.
In this manner, in the example embodiment, the first library is automatically replaced with the second library (advanced library), and thus, even when the second library is used, it is possible to eliminate the need to rewrite the source code of a module.
In addition, when the source code of a module is manually edited, a mistake such as miswriting the source code occurs. Therefore, the source code is not desired to be manually edited whenever possible.
There is the possibility that various editing errors will occur such as a case where consistency is lost as a result of rewriting a source code and undoing changes, a case where a batch edit command is executed with a wrong format, and a case where it is forgotten that a file has been copied for a second library and a different file is edited.
However, in the example embodiment, the first library is automatically replaced with the second library, and thus it is possible to eliminate the need to edit a source code.
Furthermore, when the first library is read by a module in which the first library has been replaced with the second library (for example, when a fallback function or the like is used), infinite recursion occurs.
However, in the example embodiment, a configuration can be adopted in which the first library is not replaced with the second library, and thus infinite recursion can be prevented.
Next, a configuration of the information processing apparatus 10 according to the example embodiment will be described in more detail with reference to
A system 100 shown in
The network is an ordinary network constructed using a communication line such as the Internet, a LAN (Local Area Network), a dedicated line, a phone line, an intranet, a mobile communication network, Bluetooth (registered trademark), or WiFi (Wireless Fidelity).
The information processing apparatus 10 is an information processing apparatus such as a CPU (Central Processing Unit), a programmable device such as an FPGA (Field-Programmable Gate Array), a GPU (Graphics Processing Unit), or a circuit in which one or more thereof are mounted, or a server computer.
The terminal apparatus 20 is an information processing apparatus such as a personal computer or a mobile terminal in which one of or both a CPU and an FPGA are implemented. In addition, the terminal apparatus 20 includes an input unit 21 and an output unit 22.
The input unit 21 is a device such as a touch panel, a mouse, or a keyboard. The output unit 22 obtains later-described output information subjected to conversion into a format that can be output, and outputs a generated image, sound, and the like based on the output information. The output unit 22 is an image display device that uses a liquid crystal display, an organic EL (Electro Luminescence) display, a CRT (Cathode Ray Tube), or the like. Furthermore, the image display device may include a sound output device such as a speaker. Note that the output unit 22 may be a print apparatus such as a printer.
The storage device 30 is a database, a server computer, a circuit that includes a memory, or the like. The storage device 30 stores, for example, at least information regarding a user program, a module, and the like. In the example in
Note that
The information processing apparatus will be described in detail.
The information processing apparatus 10 includes a generation unit 14, an execution unit 15, the detection unit 11, the determination unit 12, and the reading unit 13.
Before a user program is executed, the generation unit 14 generates an interrupt processing unit, and locates the generated interrupt processing unit on a former stage of the reading unit 13. The interrupt processing unit is used for replacing the first library with the second library. In addition, the interrupt processing unit is constituted by the detection unit 11 and the determination unit 12.
In this manner, the interrupt processing unit is located on a former stage of the reading unit 13, and a module is read based on a processing result of the interrupt processing unit. With such a configuration, it is possible to realize, in all areas of the user program, interrupt processing for replacing the first library with the second library.
The execution unit 15 executes a user program using interpreter software. In a case of python, for example, the user program is executed using software called “python interpreter”.
When a user program is executed using python3, for example, a command line to which a monkey patch such as that shown in
When a code for reading a module is detected, the reading unit 13 reads the module. In a case of python, for example, after an import sentence is detected as a code for reading a module, the module that is to be read and is included in the import sentence is read.
When interrupt processing for replacing the first library with the second library that is compatible with the first library occurs, the detection unit 11 first detects whether or not the code for reading the module includes a code for reading the first library.
Next, when a detection result of the detection unit 11 indicates that the source code of an obtained module does not include a code for reading the first library, the detection unit 11 instructs the reading unit 13 to read the obtained module.
The reading unit 13 then reads the module (module other than the first library and the second library) included in the code for reading the module.
If a detection result of the detection unit 11 indicates that the source code of the obtained module includes a code for reading the first library, the determination unit 12 refers to hierarchy information indicating the parent-child relationship for reading modules, and determines whether or not the first library or the second library is being used by a module at a higher layer than the reading layer of the first library.
Next, when the target module (ducks.pandas.frame) includes a code for reading the first library (pandas), layers (ducks.pandas->ducks->user program) higher than the reading layer (ducks.pandas.frame) of the first library are traced back. As a result, the target module (ducks.pandas.frame) is a portion of the second library (ducks), and thus it is determined that the first library is not to be replaced with the second library.
Next, the determination unit 12 instructs the reading unit 13 to read the second library based on the determination result. The reading unit 13 then reads the second library.
In addition, when the first library or the second library is being used by a module at a higher layer than the reading layer of the first library, the determination unit 12 determines that the first library is not to be replaced with the second library.
Next, the determination unit 12 instructs the reading unit 13 to read the first library based 20) on the determination result. The reading unit 13 then reads the first library.
Next, operations of the information processing apparatus according to the example embodiment will be described with reference to
In the following description, drawings are referenced as appropriate. In addition, in an example embodiment, an information processing method is performed by causing the information processing apparatus to operate. Thus, the following description of operations of the information processing apparatus is used as description of the information processing method according to the example embodiment.
As shown in
Next, the generation unit 14 locates the generated interrupt processing unit on a former stage of the reading unit 13 (step A2). Specifically, in step A2, the generation unit 14 causes the reading unit 13 to read a module, based on a processing result of the generated interrupt processing unit.
In the example in
Note that, when interruption related to reading of the first library has not occurred (step B1: No), execution of the program continues.
Next, interrupt processing in step B2 will be described. As shown in
Next, if a detection result of the detection unit 11 indicates that the source code of the obtained module does not include a code for reading the first library (step C1: No), the detection unit 11 instructs the reading unit 13 to read the obtained module.
The reading unit 13 then reads the module (module different from the first library and the second library) included in the code for reading the module (step C2).
In addition, if a detection result of the detection unit 11 indicates that the source code of the obtained module includes a code for reading the first library (step C1: Yes), the determination unit 12 executes determination processing (step C3).
Determination processing will be described. In the determination processing in step C3, hierarchy information indicating the parent-child relationship for reading modules is referred to, and it is determined as to whether or not the first library or the second library is being used by a module at a higher layer than the reading layer of the first library.
Next, the determination unit 12 instructs the reading unit 13 to read the second library, based on the determination result in step C3 (the first library can be replaced) (step C4: Yes). The reading unit 13 then reads the second library (step C5).
In addition, when the first library or the second library is being used by a module at a higher layer than the reading layer of the first library, it is determined that the first library is not to be replaced with the second library.
Next, the determination unit 12 instructs the reading unit 13 to read the first library, based on the determination result in step C3 (the first library cannot be replaced) (step C4: No). The reading unit 13 then reads the first library (step C2).
As described above, according to an example embodiment, the first library is automatically replaced with the second library (advanced library), and thus, even when the second library is used, it is possible to eliminate the need to the rewrite the source code of a module.
In addition, in the example embodiment, the first library is automatically replaced with the second library, and thus it is possible to eliminate the need to edit the source code.
Furthermore, in the example embodiment, a configuration can be adopted in which the first library is not replaced with the second library, and thus infinite recursion can be prevented.
A modified example will be described. Processing of the determination unit 12 takes time, and thus a large part of related libraries may be read in advance and cached before a program is executed. The related libraries are the first library and the second library.
The program according to the embodiment may be a program that causes a computer to execute steps A1 to A2 shown in
Also, the program according to the embodiment may be executed by a computer system constructed by a plurality of computers. In this case, for example, each computer may function as any of the generation unit 14, the execution unit 15, the detection unit 11, the determination unit 12, and the reading unit 13.
Here, a computer that realizes the information processing apparatus by executing the program according the example embodiment and modified example will be described with reference to
As shown in
The CPU 111 opens the program (code) according to this example embodiment, which has been stored in the storage device 113, in the main memory 112 and performs various operations by executing the program in a predetermined order. The main memory 112 is typically a volatile storage device such as a DRAM (Dynamic Random Access Memory).
Also, the program according to this example embodiment is provided in a state being stored in a computer-readable recording medium 120. Note that the program according to this example embodiment may be distributed on the Internet, which is connected through the communications interface 117. Note that the computer-readable recording medium 120 is a non-volatile recording medium.
Also, other than a hard disk drive, a semiconductor storage device such as a flash memory can be given as a specific example of the storage device 113. The input interface 114 mediates data transmission between the CPU 111 and an input device 118, which may be a keyboard or mouse. The display controller 115 is connected to a display device 119, and controls display on the display device 119.
The data reader/writer 116 mediates data transmission between the CPU 111 and the recording medium 120, and executes reading of a program from the recording medium 120 and writing of processing results in the computer 110 to the recording medium 120. The communications interface 117 mediates data transmission between the CPU 111 and other computers.
Also, general-purpose semiconductor storage devices such as CF (Compact Flash (registered trademark)) and SD (Secure Digital), a magnetic recording medium such as a Flexible Disk, or an optical recording medium such as a CD-ROM (Compact Disk Read-Only Memory) can be given as specific examples of the recording medium 120.
The information processing apparatus 10 according to the example embodiment can also be achieved using hardware corresponding to the components, instead of a computer in which a program is installed. Furthermore, a part of information processing apparatus 10 may be realized by a program and the remaining part may be realized by hardware. In the example embodiment, the computer is not limited to the computer shown in
The following supplementary notes are also disclosed in relation to the above-described example embodiments. Although at least part or all of the above-described example embodiments can be expressed as, but are not limited to, (Supplementary note 1) to (Supplementary note 12) described below.
An information processing apparatus comprising:
The information processing apparatus according to Supplementary note 1,
The information processing apparatus according to Supplementary note 1, further comprising:
The information processing apparatus according to any one of Supplementary notes 1 to 3,
An information processing method that is performed by an information processing apparatus, the method comprising:
The information processing method according to Supplementary note 5,
The information processing method according to Supplementary note 5,
The information processing method according to any one of Supplementary notes 5 to 7,
A non-transitory computer readable recording medium that includes a program recorded thereon, the program including instructions that causes a computer to carry out the steps of:
The non-transitory computer-readable recording medium for recording a program according to Supplementary note 9 further including instructions that cause the computer to: wherein, if a module at a higher layer includes the first library or the second library, reading the first library.
The non-transitory computer-readable recording medium for recording a program according to Supplementary note 9 further including instructions that cause the computer to:
The non-transitory computer-readable recording medium for recording a program according to any one of Supplementary notes 9 to 11 further including instructions that cause the computer to:
Although the invention has been described with reference to the example embodiments, the invention is not limited to the example embodiment described above. Various changes can be made to the configuration and details of the invention that can be understood by a person skilled in the art within the scope of the invention.
According to the technology described above, in this manner, in the example embodiment, the first library is automatically replaced with the second library (advanced library), and thus, even when the second library is used, it is possible to eliminate the need to rewrite the source code of a module. In addition, it is useful in a field where the reading the library is required.
While the invention has been particularly shown and described with reference to exemplary embodiments thereof, the invention is not limited to these embodiments. It will be understood by those of ordinary skill in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present invention as defined by the claims.
Number | Date | Country | Kind |
---|---|---|---|
2023-119238 | Jul 2023 | JP | national |