fortran66のブログ

fortran について書きます。

【メモ帳】ドンガラ SC22 講演 その他

Turing Award Lecture featuring Jack Dongarra

講演冒頭ドンガラがイタリア移民の子で失読症と知りました。

講演後半終わりの方では COTS の終わりと今後のアルゴリズム側からのハードウェアとのすり合わせの重要性が述べられていました。日本が成功例に上げられています。

中国に関しては、アメリカ産技術が入らなくなるので苦しくなるだろうとのこと。


www.youtube.com

富良野市議会、邪神ちゃんの内容不適切認定! 

市がふるさと納税で制作費を募ったが、一般会計決算を不認定!w

www.hokkaido-np.co.jp

すかさず当該回の限定公開する公式さすがw


www.youtube.com

秋も深まってまいりました

11月だけどw


www.youtube.com


www.youtube.com

ジャケ写がいい。

終点:月世界!

www.sankei.com

Destination Moon


www.youtube.com

Toxic: Bardcore version

コメント欄もいい味出してる。


www.youtube.com

ブリちゃん20年弱前とかw

【寝言】メモ帳 

Michel Polnareff 日本のテレビ出演

コメント欄にピクルス メンバーの書き込みがあって草


www.youtube.com

Adamo 「雪が降る」

日本語うまい。アダモも日本の歌番組に出て、日本語で歌っていたような...


www.youtube.com

Gigliola Cinquetti「雨」la pioggia

よく覚えていないのですが、昔 NHK-FM民族音楽の時間で、イタリア北部のアルプス地方出身のジリオラ・チンクエッティの歌うヨーデル風のアルプス音楽歌唱アルバムが放送された気がします。記憶違いかな?


www.youtube.com

Sergio Mendes & Brasil '66 Live At The Expo '70 大阪万博


www.youtube.com

おまけ


www.youtube.com

Grover Washington Jr. feat. Bill Withers

1,300万再生で二番煎じ三番煎じが大量発生していて草


www.youtube.com

【乞食速報】GitHub codespaces 無料化 Modern Fortran extension 可

GitHub codespaces 月60時間 無料化

www.itmedia.co.jp

新しい料金表によると、60時間分が無料で使えるのは2コアのプラン。4コアでは30時間が無料で、8コアでは15時間が無料で使えるようになります。ストレージも15GBまでは無料。

fortran

modern fortran extension も使えます。

gfortran も terminal から sudo apt update/upgrade の後なら sudo apt install gfortran で Ver.9 が入ります。

$ gfortran --version
GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gfortran-10 --version
GNU Fortran (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ソース プログラム

module uniplot
    implicit none
    private
    public :: fig_t
    type :: fig_t
        private
        integer :: nx, ny
        integer, allocatable :: array(:, :)
    contains
        procedure :: init     
        procedure :: point 
        procedure :: show  
        procedure :: line0
        procedure :: line
    end type fig_t
contains
    subroutine init(fig, nx, ny)
        class(fig_t), intent(out) :: fig 
        integer, intent(in) :: nx, ny
        fig%nx = nx
        fig%ny = ny 
        allocate(fig%array(0:(nx+1)/2, 0:(ny+3)/4) )
    end subroutine init  

    subroutine point(fig, ix, iy)
        class(fig_t), intent(in out) :: fig 
        integer, intent(in) :: ix, iy
        integer :: iax, iay
        iax = ix / 2
        iay = iy / 4
        ! clipping
        if (0<=ix .and. ix<fig%nx .and. 0<=iy .and. iy<fig%ny) then
            fig%array(iax, iay) = ior(fig%array(iax, iay), icode(mod(ix, 2), mod(iy, 4)))
        end if     
    end subroutine point

    pure elemental integer function icode(kx, ky)
        integer, intent(in) :: kx, ky
        if (ky == 3) then
            icode = 64 + 64 * kx
        else ! 0, 1, 2
            icode = 2**(ky + 3*kx)  
        end if
    end function icode
  
    subroutine line0(fig, ix0, iy0, ix1, iy1)
        class(fig_t), intent(in out) :: fig 
        integer, intent(in) :: ix0, iy0, ix1, iy1
        integer :: i, ix, iy, nx, ny
        real :: d
        nx = ix1 - ix0
        ny = iy1 - iy0
        if (nx == 0 .and. ny ==0) then
            call fig%point(ix, iy) 
        else if (abs(nx) < abs(ny)) then
            d = nx / real(ny)
            do i = 0, abs(ny)
                ix = nint(ix0 + d * sign(i, ny))
                iy = iy0 + sign(i, ny)
                call fig%point(ix, iy)
              end do  
        else
            d = ny / real(nx)
            do i = 0, abs(nx)
                iy = nint(iy0 + d * sign(i, nx))
                ix = ix0 + sign(i, nx)
                call fig%point(ix, iy)
            end do  
        end if  
    end subroutine line0
  
    subroutine show(fig)
        class(fig_t), intent(in) :: fig 
        integer :: iy
        do iy = 0, ubound(fig%array, 2)
            print '(*(a))', reverse_endian(shift_code(fig%array(:, iy)))
        end do
    end subroutine show    
  
    pure elemental integer function shift_code(k)
        integer, intent(in) :: k
        integer, parameter :: n0 = Z'E2A080' !14852224
        shift_code = n0 + 256 * (k /64) + mod(k, 64)  !E2A180, E2A280, E2A380      
    end function shift_code    
    
    pure elemental character(len = 4) function reverse_endian(i)
        integer, intent(in) :: i
        character:: tmp(4)
        tmp = transfer(i, ' ', size = 4)
        reverse_endian = transfer(tmp(4:1:-1), '    ')  !array 4 to len 4
    end function reverse_endian
    
    
    subroutine line(fig, x, y, ipen)
        class(fig_t), intent(in out) :: fig
        real, intent(in) :: x, y
        integer, intent(in) :: ipen
        integer, save :: ix0 = 0, iy0 = 0 
        integer :: ix, iy
        real, parameter :: xn = 80.0, yn = 100.0, fx = 1.0, fy = 0.85
        ix = nint( fx * x + xn)      
        iy = nint(-fy * y + yn)
        if (ipen == 1) call fig%line0(ix0, iy0, ix, iy)
        ix0 = ix
        iy0 = iy
    end subroutine line

end module uniplot


program uniplot_main
    implicit none
    real, allocatable :: x(:), y(:)
    integer, parameter :: n = 10**3
    allocate(x(n), y(n))
    call random_seed()
    call random_number(x)
    call random_number(y)

plot: block 
        use :: uniplot
        type(fig_t) :: fig1
        integer :: i, ix0, iy0, ix1, iy1, k
        k = 100
        print *
        print *, 'Monte Carlo: estimated pi =', 4.0 * count(x**2 + y**2 < 1.0) / n 
        call fig1%init(k, k)
        ! draw box
        call fig1%line0(0, 0, k-1, 0)
        call fig1%line0(0, 0, 0, k-1)
        call fig1%line0(0, k-1, k-1, k-1)
        call fig1%line0(k-1, 0, k-1, k-1)
        ! draw 1/4 circle
        ix0 = 0
        iy0 = 0
        do ix1 = 0, k - 1
            iy1 = k - 1 - int(sqrt(real((k-1)**2 - ix1**2)))
            call fig1%line0(ix0, iy0, ix1, iy1)
            ix0 = ix1
            iy0 = iy1
        end do     
        ! plot dots
        do i = 1, n 
            call fig1%point(int(k * x(i)), int(k * y(i)))
        end do 
        call fig1%show()
    end block plot
end program uniplot_main

fortrangithub action


www.youtube.com

【メモ帳】Fortran Generics 追加情報

type, deferred

先日、LFortran での Generics の試験実装について書きましたが、その追加情報が出ていました。

fortran66.hatenablog.com

requirement の例題で「type :: T; end type」というのがあって、ダサいなと思っておりましたが、「type, deferred :: T」という書き方に変えたようです。この方が他の deferred とも合っていい気がします。

追加例では、operator を requirement で指定した関数位置に送る例も出していましたが、上の記事内で紹介した YouTube 講演では operator は先送り的なことを言っていたので、また変わったのかもしれません。それはともかく operator overload はどうやるんでしょうか。普通に interface を具象名に対して書けばいいのか、generic 名で一括で出来るのか?

旧例

    requirement S(T, F0) 
        type :: T; end type
        function F0(x) result(z)
            type(T), intent(in) :: x
            type(T) :: z
        end function
    end requirement

新例

requirement binary_op(T, U, V, op)
  type, deferred :: T, U, V
  function op(x, y) result(z)
    type(T), intent(in) :: x
    type(U), intent(in) :: y
    type(V) :: z
  end function
end requirement

fortran-lang.discourse.group

それにつけても requirement の方が abstract interface より abstract 度が高い気がして草。

【寝言】皆既月食と天王星食

月食天王星

天皇陛下の御恩徳により快晴の空の元、皆既月食天王星食を眺めることが叶いました。

やはり天王星には天皇制!

しばらくぶりで天王星を(双眼鏡で)肉眼で見ました。(望遠鏡で)高校三年生ぶりでしょうか。


www.youtube.com

iphone 13 mini での写真w

Uranus

皆既中の月の下に天王星が小さな点として写っています。スバルとヒヤデス星団も写っています。

www.nao.ac.jp

M31

ついでにアンドロメダ星雲も撮ってみました。3秒しか溜め込まないので、こっちはあんまりはっきり写りませんでした。


www.youtube.com

【メモ帳】LFortran で Fortran 202Y の Generics 試用可

FortranGenerics

Fortran 202Y での導入が目指されている Generics ですが、LFortran で試験的な実装がなされ、試してみることが可能になりました。ここで Fortran 202Y とは次期規格の Fortran 202X のさらに次の規格という意味です。また Fortran 202X は、先年 X = 3 にすることが決まっています。

fortran-lang.discourse.group

LFortran は WEB 上で試すことが出来ます。

dev.lfortran.org

試行例

LFortran はユーザー定義派生型や operator overload などがまだ実装されていないので、あまり多くは試せません。

twitter にあった例題を改変して、単項演算子二項演算子を試してみました。思ったより長々グチャグチャになり、定義位置や定義順もイマイチぴんと来ない感があります。また Fortrancase insensitive なので、Template と普通の具象名が渾然混沌区別がつかぬ感もします。

プログラム

requirement の中の function 名が漏れ出して、多重定義エラーになってしまうので名前を F0 に変えました。

module template_test_m
    implicit none
    private
    public :: unary_t, binary_t
    
    

    requirement S(T, F0) 
        type :: T; end type
        function F0(x) result(z)
            type(T), intent(in) :: x
            type(T) :: z
        end function
    end requirement

    template unary_t(T, F0)
        requires S(T, F0)
        private
        public :: unary_generic
    contains
        function unary_generic(x) result(z)
            type(T), intent(in) :: x
            type(T) :: z
            z = F0(x)
        end function
    end template
    
    
    
    
    requirement R(T, F) 
        type :: T; end type
        function F(x, y) result(z)
            type(T), intent(in) :: x, y
            type(T) :: z
        end function
    end requirement

    template binary_t(T, F)
        requires R(T, F)
        private
        public :: binary_generic
    contains
        function binary_generic(x, y) result(z)
            type(T), intent(in) :: x, y
            type(T) :: z
            z = F(x, y)
        end function
    end template


contains


    real function func_minus_real(x) result(z)
        real, intent(in) :: x
        z = -x
    end function

    
    real function func_add_real(x, y) result(z)
        real, intent(in) :: x, y
        z = x + y
    end function

    real function func_sub_real(x, y) result(z)
        real, intent(in) :: x, y
        z = x - y
    end function

    real function func_mul_real(x, y) result(z)
        real, intent(in) :: x, y
        z = x * y
    end function

    real function func_div_real(x, y) result(z)
        real, intent(in) :: x, y
        z = x / y
    end function 
    


    subroutine test_template()
        instantiate unary_t(real, func_minus_real), only: minus_real => unary_generic

        instantiate binary_t(real, func_add_real), only: add_real => binary_generic
        instantiate binary_t(real, func_sub_real), only: sub_real => binary_generic       
        instantiate binary_t(real, func_mul_real), only: mul_real => binary_generic       
        instantiate binary_t(real, func_div_real), only: div_real => binary_generic       
        
        real :: x, y
        x = 5.1
        y = 7.2

        print*, "The result is ", minus_real(x)
        if (abs(minus_real(x) + x) > 1e-5) error stop


        print*, "The result is ", add_real(x, y)
        if (abs(add_real(x, y) - 12.3) > 1e-5) error stop

        print*, "The result is ", sub_real(x, y)
        if (abs(sub_real(x, y) + 2.1) > 1e-5) error stop

        print*, "The result is ", mul_real(x, y)
       if (abs(mul_real(x, y) - 36.72) > 1e-2) error stop

        print*, "The result is ", div_real(x, y)
        if (abs(div_real(x, y) - 0.7083333) > 1e-6) error stop
    end subroutine
end module

program template_test
    use template_test_m
    implicit none

    call test_template()

end program template_test
The result is  -5.099999904632568
The result is  12.299999237060547
The result is  -2.0999999046325684
The result is  36.71999740600586
The result is  0.7083333134651184

参考資料

j3-fortran generics

github.com

議論の過程で色々仕様が変化しているようです。

Everything Functional

策定に携わっている方の要点まとめ記事です。

The State of Fortran&nbsp;Genericseverythingfunctional.wordpress.com

本文中の restriction が、LFortran では requirement に変わっています。

Seminar: Generic Programming in Fortran 202Y

Dr. Thomas Clune gives a seminar on July 18, 2022 at the NCAR Mesa Lab.


www.youtube.com

質疑等細部の詳細はさっぱり理解できませんw


www.youtube.com


www.youtube.com

【寝言】学士会報 第957号 2022-VI

まともな記事があってビックリの巻

巻頭に元衆院議長の伊吹文明氏の午餐会での講演をまとめたものが載っていたのですが(「絶対的正解のないのが政治ー意思決定の難しさ」)、その内容が極めて真っ当かつ常識的で驚きました。

さわりが見られます。細田衆院議長を腐しているところまでw www.gakushikai-salon.jp

絶対的正解のないのが政治ー意思決定の難しさ  伊吹文明

要旨 

保守は、「個人は間違う」という考えを前提とするため、政治では独裁ではなく民主制を、経済では統制経済ではなく大勢の人が参加する自由主義市場経済を選ぶ。ただ民主制もポピュリズムに、自由もわがままに陥るので、その欠点を民族が長い時間をかけて培ってきた伝統的規範を身につけた個人により正そうと考えるのが保守である。

昨秋、正解を引退した元衆議院議長が、保守の矜持と意思決定の難しさについて語る。

段落

  1. 一票の格差をめぐって
  2. 昨今のインフレに思うこと
  3. 消費税減税を公約にする野党の無責任
  4. 節電も、電気代値上げも、原発再稼働も嫌がる人々
  5. MMT(現代貨幣理論)は正しいのか
  6. 自由、民主制、法の支配、人権の尊重
  7. 自由のないロシア、自由が行き過ぎの日本
  8. 自由の長所と欠点
  9. 法の支配の長所と欠点
  10. 民主制の長所と欠点
  11. ポピュリズムは民主制の欠点
  12. 統制経済と独裁
  13. 「リベラル」対「新自由主義
  14. 「リベラル」対「保守」
  15. 日本人の民族的規範を形成してきたもの
  16. 日本の危機

何事も釣り合いの精神でということで、実に真っ当に思われることが書かれていました。 ただ旧大蔵省出身のせいか財政均衡・緊縮論みたいな事も言っていますが、それはしょうがないかwという感じです。

農耕社会なら太陽の1年周期で均衡が必要でしょうが、現代日本は工業化・脱工業化社会でもっと長周期の好景気・不景気の波があるのだから、単年度会計での財政均衡固執するのもいかがなものかという気がします。また小学生も習う江戸時代の三大改革で、寛政の改革天保の改革とも緊縮財政で失敗しています。それでいて、同じ土地と人間で明治になれば一気に人口増・経済成長しています。

最近、頭のおかしいサヨ爺の寝言記事ばかり出てくるので、まっとうな政治記事を読むとビックリ仰天します。