Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clojureで多次元配列
Search
ichisemasashi
December 23, 2020
Programming
0
450
Clojureで多次元配列
ClojureでJavaの配列を利用して数値計算を扱う。
ichisemasashi
December 23, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.3k
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
390
chocoZAPサービス予約システムをNuxtで内製化した話
rizap_tech
0
150
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
730
AIコーディングエージェント(Manus)
kondai24
0
190
Microservices rules: What good looks like
cer
PRO
0
1.4k
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
2.7k
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
120
20 years of Symfony, what's next?
fabpot
2
360
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
390
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
410
JETLS.jl ─ A New Language Server for Julia
abap34
1
410
Featured
See All Featured
Speed Design
sergeychernyshev
33
1.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Building Applications with DynamoDB
mza
96
6.8k
Being A Developer After 40
akosma
91
590k
GitHub's CSS Performance
jonrohan
1032
470k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
Designing for humans not robots
tammielis
254
26k
Transcript
@ichisemasashi 202012݄23 ClojureͰଟ࣍ݩྻ
࠷ۙؾ͍ͨɺ͕ࣗίϯϐϡʔλʔͰΓ͔ͨͬͨ͜ͱ => ʮܭࢉʯ - ͱΓ͋͑ͣɺJuliaΛͬͯษڧΛ͍͕ͯͨ͠ɺͰ͖ΕClojureͰษڧ Λ͔ͨͬͨ͠ɻ - ͰClojureʹଟ࣍ݩྻ͕ͳ͍ͱࢥ͍ͬͯͨɻ -> JavaͷྻΛ͑ྑ͍ɻ
-> tnoda͞ΜͷʮJava ͷྻΛར༻ͯ͠ϝϞϦͱ࣌ؒͷนΛಥ ഁ͢ΔɽʯʹɺJavaͷྻͷ͍ํ͕ཧ͞Ε͍ͯͨɻ
ClojureͰJavaͷྻΛར༻͢Δ ྻͷੜ user=> (def my-array (make-array Integer/TYPE 2 2)) #'user/my-array
ClojureͰJavaͷྻΛར༻͢Δ ྻͷදࣔ user=> (pprint my-array) [[0, 0], [0, 0]] nil
ClojureͰJavaͷྻΛར༻͢Δ ྻͷཁૉΛࢀর user=> (aget ^ints my-array 0 0) 0
ClojureͰJavaͷྻΛར༻͢Δ ྻͷཁૉʹσʔλΛઃఆ user=> (aset ^ints my-array 0 0 (int 100))
100 user=> (aget ^ints my-array 0 0) 100 user=> (pprint my-array) [[100, 0], [0, 0]] nil
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ֓ཁ 5x + y + z = 10 x
+ 4y + z = 12 2x + y + 3z = 13 }
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ֓ཁ 5x + y + z = 10 x
+ 4y + z = 12 2x + y + 3z = 13 } x = (10 − y − z)/5 y = (12 − x − z)/4 z = (13 − 2x − y)/3 }
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ֓ཁ 5x + y + z = 10 x
+ 4y + z = 12 2x + y + 3z = 13 } x = (10 − y − z)/5 y = (12 − x − z)/4 z = (13 − 2x − y)/3 } x y z ॳظ 1 1 1 1८ 1.600 2.350 2.483 2८ 1.033 2.121 2.938 3८ 0.988 2.019 3.002 4८ 0.996 2.001 3.002 5८ 0.999 1.999 3.001
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮ (def an-eq (make-array Double/TYPE 3 4)) (def N
(alength an-eq)) (defn set-eq [arr n x y z w] (aset ^doubles arr n 0 (double x)) (aset ^doubles arr n 1 (double y)) (aset ^doubles arr n 2 (double z)) (aset ^doubles arr n 3 (double w))) (set-eq an-eq 0 5 1 1 10) (set-eq an-eq 1 1 4 1 12) (set-eq an-eq 2 2 1 3 13) (pprint an-eq)
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (def res-arr (make-array Double/TYPE 3)) (dotimes [i N]
(aset ^doubles res-arr i (double 1))) (pprint res-arr) (def tmp-arr (make-array Double/TYPE 3)) (pprint tmp-arr) (defn eq-elm [x y] (aget ^doubles an-eq x y)) (defn res-elm [x] (aget ^doubles res-arr x)) (defn tmp-elm [x] (aget ^doubles tmp-arr x))
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (def MAX_LOOP 30) (def EPS (double 0.0001)) (def
q (atom (double 1.0))) (def ll (atom 0)) (defn display-result [] (dotimes [i N] (let [res (res-elm i)] (println (format "x%d = %9.6f" i res)))))
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (defn computing [] (let [s (atom (double 0.0))]
(dotimes [i N] (reset! s (double 0.0)) (dotimes [j N] (if (not= i j) (reset! s (+ @s (* (eq-elm i j) (res-elm j)))))) (aset ^doubles tmp-arr i (/ (- (eq-elm i N) @s) (eq-elm i i))) (reset! q (+ @q (Math/abs (- (res-elm i) (tmp-elm i))))) (aset ^double res-arr i (tmp-elm i)))))
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (while (and (< EPS @q) (>= MAX_LOOP @ll))
(do (swap! ll inc) (reset! q (double 0.0)) (computing))) (if (>= @ll MAX_LOOP) (println "ऩଋͤͣɻ") (display-result))