OpenMythosのサンプルプログラムを動かしました

1.概要 前回、OpenMythosの環境構築まで実現したので、GitHubにあるサンプルプログラム(Usage)を動かしてみました。一部エラーが発生しましたが、結果出力部分なので修正をしました。その内容を記述します。 2.詳細 Usageに記載されているPythonプログラムをopenmythos_usage.pyとして作成します。 $ source ~/mypy/bin/activate (mypy) $ pythoh3 openmythos_usage.py 下記エラーとなります [MLA] Parameters: 1,538,626 [MLA] Logits shape: torch.Size([2, 16, 1000]) [MLA] Generated shape: torch.Size([2, 24]) Traceback (most recent call last):   File "/home/nakasima/openmythos/openmythos_usage.py", line 48, in <module>     rho = torch.linalg.eigvals(A).abs().max().item()           ^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: linalg.eig: The input tensor A must have at least 2 dimensions. コードの下記部分を修正します #rho = torch.linalg.eigvals(A).abs().max().item() rho = A.abs().max().item() $ source ~/mypy/bin/activate (mypy) $ pythoh3 openmythos_usage.py [MLA] Parameters: 1,538,626 [MLA] Logits shape: torch.Size([2, 16, 1000]) [MLA] Generated shape: torch.Size([2, 24]) [MLA] Spectral radius ρ(A) = 0.3679 (mus...

一般的なIPv4アドレスと数値IPv4アドレスの相互変換(python版)

1.概要

前回、shellを利用してIPアドレスを変換する処理を記述しました。しかし、国レベルに配布されているIPアドレスセグメントを変換するにはshellでは処理に時間を必要とします。

そこで、bash shellで記述した処理をpython3で書き直しました。本ブログのIP address convert using shellを参照してください。大量に変換処理をすると、bash shellよりもpython3の方が非常に高速です。今回は、この内容を記述します。

2.詳細

(1) 作成したapp(ipconvert.py)

def ip2dec(ip):
    ip = ip.split(".")
    result = 0
    for i in range(0,4):
        result = int(ip[i]) * 256 ** (3 - i) + result
    return result

def dec2ip(dec):
    result = ""
    for i in range(0,4):
        item = dec // 256 ** (3 - i)
        result = result + str(item)
        if  i != 3:
            result = result + "."
            dec  = dec - item * 256 ** (3 - i)
    return result

if  __name__ == "__main__":

    print(ip2dec("192.168.10.1"))
    print(dec2ip(3232238081))
    
(2) 実行方法

python3 ipconvert.py
3232238081
192.168.10.1 

コメント

このブログの人気の投稿

miniPCのBMAXでWindows11のsecure boot設定漏れでトラブル発生

LinuxMint-22.3にWine 11.6をサクッと入れてみました

LinuxMint 21.3にWinBoat導入を試してみました