Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clojureで多次元配列
Search
ichisemasashi
December 23, 2020
Programming
0
440
Clojureで多次元配列
ClojureでJavaの配列を利用して数値計算を扱う。
ichisemasashi
December 23, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
Flutter with Dart MCP: All You Need - 박제창 2025 I/O Extended Busan
itsmedreamwalker
0
150
Amazon RDS 向けに提供されている MCP Server と仕組みを調べてみた/jawsug-okayama-2025-aurora-mcp
takahashiikki
1
110
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
320
ぬるぬる動かせ! Riveでアニメーション実装🐾
kno3a87
1
220
概念モデル→論理モデルで気をつけていること
sunnyone
2
180
アセットのコンパイルについて
ojun9
0
130
Azure SRE Agentで運用は楽になるのか?
kkamegawa
0
2.3k
旅行プランAIエージェント開発の裏側
ippo012
2
910
為你自己學 Python - 冷知識篇
eddie
1
350
個人軟體時代
ethanhuang13
0
320
Swift Updates - Learn Languages 2025
koher
2
480
ファインディ株式会社におけるMCP活用とサービス開発
starfish719
0
1.3k
Featured
See All Featured
Code Review Best Practice
trishagee
70
19k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
GraphQLとの向き合い方2022年版
quramy
49
14k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
520
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
GitHub's CSS Performance
jonrohan
1032
460k
Statistics for Hackers
jakevdp
799
220k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
It's Worth the Effort
3n
187
28k
Thoughts on Productivity
jonyablonski
70
4.8k
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))