Search is not available for this dataset
text
string
meta
dict
-- 2012-02-13 Andreas: testing correct polarity of data types -- sized types are the only source of subtyping, I think... {-# OPTIONS --sized-types #-} module DataPolarity where open import Common.Size data Nat : {size : Size} -> Set where zero : {size : Size} -> Nat {↑ size} suc : {size : Size} -> Nat {size} -> Nat {↑ size} data Pair (A : Set) : Set where _,_ : A -> A -> Pair A split : {i : Size} → Nat {i} → Pair (Nat {i}) split zero = zero , zero split (suc n) with split n ... | (l , r) = suc r , l -- this should work, due to the monotonicity of Pair -- without subtyping, Agda would complain about i != ↑ i MyPair : Nat → Set → Set MyPair zero A = Pair A MyPair (suc n) A = MyPair n A -- polarity should be preserved by functions mysplit : {i : Size} → (n : Nat {i}) → MyPair (suc zero) (Nat {i}) mysplit zero = zero , zero mysplit (suc n) with mysplit n ... | (l , r) = suc r , l
{ "alphanum_fraction": 0.6205752212, "avg_line_length": 28.25, "ext": "agda", "hexsha": "ce920c3d3d994c1bb8403f9189906e1a26ba9ceb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/agda-kanso", "max_forks_repo_path": "test/succeed/DataPolarity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/agda-kanso", "max_issues_repo_path": "test/succeed/DataPolarity.agda", "max_line_length": 66, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/DataPolarity.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 296, "size": 904 }
{-# OPTIONS --allow-unsolved-metas #-} module Control.Lens where open import Function using (id; _∘_; const; flip) open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Axiom.FunctionExtensionality open import Util.Equality open import Control.Functor renaming (Comp to _•_) open import Control.Functor.NaturalTransformation renaming (Id to Nid; Comp to _·_) -- S-combinator. apply : ∀ {A B C : Set} → (A → B → C) → (A → B) → A → C apply f g a = f a (g a) -- Flipped S-combinator (flipped apply). flipply : ∀ {O A B : Set} → (A → O → B) → (O → A) → O → B flipply f g o = f (g o) o record GetSetLens (O I : Set) : Set where -- Operations. field get : O → I set : I → O → O -- Laws. field set-set : ∀ {i j} → set i ∘ set j ≡ set i get-set : ∀ {i} → get ∘ set i ≡ const i set-get : flipply set get ≡ id -- ∀ {o} → set (get o) o ≡ o -- A variant of GetSetLens record GetsModifyLens (O I : Set) : Set₁ where -- Operations. field gets : ∀ {J} → (I → J) → O → J modify : (I → I) → O → O -- Laws. field -- modify is an endofunctor in the discrete category I. modify-id : modify id ≡ id modify-∘ : ∀ {f g} → modify g ∘ modify f ≡ modify (g ∘ f) -- Free theorem for gets. gets-free : ∀ {J K} {f : J → K} (g : I → J) → f ∘ gets g ≡ gets (f ∘ g) gets-modify : ∀ {J} {f : I → I} {g : I → J} → gets g ∘ modify f ≡ gets (g ∘ f) -- set (get o) o ≡ o -- modify (const (gets id o)) o ≡ o -- modify (const (gets f o)) o ≡ modify f o -- modify (λ i → g (gets f o) i) o ≡ modify (λ i → g i (f i)) o -- apply (flip modify) (g ∘ gets f) ≡ modify (apply g f) modify-gets : ∀ {J} {g : I → J} (s : J → I → I) → flipply modify (s ∘ gets g) ≡ modify (flipply s g) getSetLens : GetSetLens O I getSetLens = record { get = gets id ; set = modify ∘ const ; set-set = modify-∘ ; get-set = get-set ; set-get = set-get } where get : O → I get = gets id set : I → O → O set = modify ∘ const get-set : ∀ {i} → get ∘ set i ≡ const i get-set {i} = begin get ∘ set i ≡⟨⟩ gets id ∘ modify (const i) ≡⟨ gets-modify ⟩ gets (id ∘ const i) ≡⟨⟩ gets (const i ∘ id) ≡⟨ sym (gets-free id) ⟩ const i ∘ get ≡⟨⟩ const i ∎ set-get : flipply set get ≡ id set-get = begin flipply set get ≡⟨⟩ flipply (modify ∘ const) (gets id) ≡⟨⟩ flipply modify (const ∘ gets id) ≡⟨ modify-gets const ⟩ modify (flipply const id) ≡⟨⟩ modify id ≡⟨ modify-id ⟩ id ∎ open GetSetLens getSetLens public -- van Laarhoven lenses record Lens (O I : Set) : Set₁ where -- Single operation: Functorial modify. field modify! : ∀ (FF : Functor) → let F = Functor.F FF in (I → F I) → (O → F O) -- Laws -- 0. Free theorem: field modify!-free : (FF GG : Functor) (N : NatTrans FF GG) → let open Functor FF using () renaming (F to F; map to mapF) in let open Functor GG using () renaming (F to G; map to mapG) in let open NatTrans N using () renaming (eta to η) in (f : I → F I) → η ∘ modify! FF f ≡ modify! GG (η ∘ f) -- 1. Identity law: -- Generalize? modify!-id : modify! Id id ≡ id -- 2. Composition law: modify!-∘ : (FF GG : Functor) → let open Functor FF using () renaming (F to F; map to mapF) in let open Functor GG using () renaming (F to G; map to mapG) in {f : I → F I} → {g : I → G I} → mapF (modify! GG g) ∘ modify! FF f ≡ modify! (FF • GG) (mapF g ∘ f) getsModifyLens : GetsModifyLens O I getsModifyLens = record { gets = gets ; modify = modify ; modify-id = modify!-id ; modify-∘ = modify-∘ ; gets-free = λ {J}{K}{f} g → gets-free f g ; gets-modify = gets-modify ; modify-gets = modify-gets } where -- gets and modify gets : ∀ {J} → (I → J) → (O → J) gets {J = J} = modify! (Const J) modify : (I → I) → O → O modify = modify! Id -- Laws of gets and modify. modify-∘ : ∀ {f g} → modify g ∘ modify f ≡ modify (g ∘ f) modify-∘ = modify!-∘ Id Id gets-free : ∀ {J K} (f : J → K) (g : I → J) → f ∘ gets g ≡ gets (f ∘ g) gets-free {J = J}{K = K} f g = modify!-free (Const J) (Const K) (ConstNat f) g gets-modify : ∀ {J} {f : I → I} {g : I → J} → gets g ∘ modify f ≡ gets (g ∘ f) gets-modify {J = J} = modify!-∘ Id (Const J) modify-gets : ∀ {J} {g : I → J} (s : J → I → I) → flipply modify (s ∘ gets g) ≡ modify (flipply s g) modify-gets = {!!} -- TODO! Difficult. open GetsModifyLens getsModifyLens public -- Every GetSetLens is a van Laarhoven lens ?? lensFromGetSet : ∀ {O I} → GetSetLens O I → Lens O I lensFromGetSet {O = O}{I = I} l = record { modify! = modify! ; modify!-free = {!!} ; modify!-id = set-get ; modify!-∘ = modify!-∘ } where open GetSetLens l module Define-modify! (FF : Functor) where open Functor FF modify! : (I → F I) → (O → F O) modify! f = apply (map ∘ flip set) (f ∘ get) derivation-of-modify : ∀ f → modify! f ≡ apply (map ∘ flip set) (f ∘ get) derivation-of-modify f = begin modify! f ≡⟨⟩ (λ o → f (get o) <&> λ i → set i o) ≡⟨⟩ (λ o → ((λ o → map (λ i → set i o)) o) ((f ∘ get) o)) ≡⟨⟩ apply (λ o → map (λ i → set i o)) (f ∘ get) ≡⟨⟩ apply (λ o → map (flip set o)) (f ∘ get) ≡⟨⟩ apply (map ∘ flip set) (f ∘ get) ∎ open Define-modify! modify!-free : (FF GG : Functor) (N : NatTrans FF GG) → let open Functor FF using () renaming (F to F; map to mapF) in let open Functor GG using () renaming (F to G; map to mapG) in let open NatTrans N using () renaming (eta to η) in (f : I → F I) → η ∘ modify! FF f ≡ modify! GG (η ∘ f) modify!-free FF GG N f = fun-ext λ o → begin η (modify! FF f o) ≡⟨⟩ η (mapF (λ i → set i o) (f (get o))) ≡⟨ app-naturality (flip set) (f ∘ get) o ⟩ mapG (λ i → set i o) (η (f (get o))) ≡⟨⟩ modify! GG (η ∘ f) o ∎ where open Functor FF using () renaming (F to F; map to mapF; map-∘ to mapF-∘) open Functor GG using () renaming (F to G; map to mapG; map-∘ to mapG-∘) open NatTrans N using (app-naturality) renaming (eta to η) modify!-id : modify! Id id ≡ id modify!-id = fun-ext λ o → begin (Functor.map Id) (λ i → set i o) (id (get o)) ≡⟨⟩ (λ i → set i o) (get o) ≡⟨⟩ set (get o) o ≡⟨⟩ flipply set get o ≡⟨ app-≡ o set-get ⟩ id o ≡⟨⟩ o ∎ modify!-∘ : (FF GG : Functor) → let open Functor FF using () renaming (F to F; map to mapF) in let open Functor GG using () renaming (F to G; map to mapG) in {f : I → F I} → {g : I → G I} → mapF (modify! GG g) ∘ modify! FF f ≡ modify! (FF • GG) (mapF g ∘ f) modify!-∘ FF GG {f = f} {g = g} = fun-ext λ o → begin mapF (modify! GG g) (modify! FF f o) ≡⟨⟩ mapF (λ o → mapG (λ i → set i o) (g (get o))) (mapF (λ i → set i o) (f (get o))) ≡⟨ app-≡ _ (sym mapF-∘) ⟩ mapF ((λ o → mapG (λ i → set i o) (g (get o))) ∘ (λ i → set i o))(f (get o)) ≡⟨⟩ mapF (λ j → mapG (λ i → set i (set j o)) (g (get (set j o)))) (f (get o)) ≡⟨ {!set-set!} ⟩ mapF (λ j → mapG (λ i → set i o) (g (get (set j o)))) (f (get o)) ≡⟨ {!get-set!} ⟩ mapF (λ j → mapG (λ i → set i o) (g j)) (f (get o)) ≡⟨⟩ mapF (mapG (λ i → set i o) ∘ g) (f (get o)) ≡⟨ app-≡ _ mapF-∘ ⟩ mapF (mapG (λ i → set i o)) (mapF g (f (get o))) ≡⟨⟩ mapFG (λ i → set i o) (mapF g (f (get o))) ≡⟨⟩ modify! (FF • GG) (mapF g ∘ f) o ∎ where open Functor FF using () renaming (F to F; map to mapF; map-∘ to mapF-∘) open Functor GG using () renaming (F to G; map to mapG; map-∘ to mapG-∘) mapFG = Functor.map (FF • GG) {- Lens operations: get : Lens I O → O → I get l o = l (mapK I) id o set : Len I O → I → O → O set l i o = l mapId (const i) o Lens laws: a. set-set set l i ∘ set l j = set l i Prove from 2. b. get-set get l (set l i o) = i Prove from 0. + 2. c. set-get set l o (get l o) = o This states that set is surjective, it is equivalent to ∀ o → ∃₂ λ i o′ → set l o′ i = o Independence of 0, 1, 2. ----------------------- A. 0 does not imply 2. Counterexample: -- An impossible lens, since ⊤ contains nothing, especially not Bool l : Lens Bool ⊤ l map f = map (const tt) (f true) ( get l _ = false ) ( set l _ _ = tt ) does not satisfy 2. (Lens composition) mapId (l (mapK Bool) id) ∘ l mapId not = const ((mapK Bool) (const tt) true) = const true l (mapK Bool) (id ∘ not) = const ((mapK Bool) (const tt) (not true) = const false B. 0, 2 are not sufficent to prove c. Counterexample: -- Lens focusing on nothing. l : Lens ⊤ Bool l map f _ = map (const true) (f tt) ( get l _ = tt ) ( set l _ _ = true ) so, set l false (get l false) /= false Proof of 2: -}
{ "alphanum_fraction": 0.4654678391, "avg_line_length": 26.4947643979, "ext": "agda", "hexsha": "6fbca9889c1998016580117532042eee7d46b2b2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/cubical", "max_forks_repo_path": "src/Control/Lens.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/cubical", "max_issues_repo_path": "src/Control/Lens.agda", "max_line_length": 94, "max_stars_count": null, "max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/cubical", "max_stars_repo_path": "src/Control/Lens.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3562, "size": 10121 }
-- This module closely follows a section of Martín Escardó's HoTT lecture notes: -- https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#unicharac {-# OPTIONS --without-K #-} module Util.HoTT.Univalence.ContrFormulation where open import Util.Data.Product using (map₂) open import Util.Prelude open import Util.HoTT.Equiv open import Util.HoTT.HLevel.Core open import Util.HoTT.Singleton open import Util.HoTT.Univalence.Axiom open import Util.HoTT.Univalence.Statement private variable α β γ : Level UnivalenceContr : ∀ α → Set (lsuc α) UnivalenceContr α = (A : Set α) → IsContr (Σ[ B ∈ Set α ] (A ≃ B)) UnivalenceProp : ∀ α → Set (lsuc α) UnivalenceProp α = (A : Set α) → IsProp (Σ[ B ∈ Set α ] (A ≃ B)) abstract IsEquiv→Σ-IsContr : {A : Set α} {B : A → Set β} (x : A) → (f : ∀ y → x ≡ y → B y) → (∀ y → IsEquiv (f y)) → IsContr (Σ A B) IsEquiv→Σ-IsContr {A = A} {B = B} x f f-equiv = ≃-pres-IsContr Singleton≃ΣB IsContr-Singleton′ where ≡≃B : ∀ y → (x ≡ y) ≃ B y ≡≃B y .forth = f y ≡≃B y .isEquiv = f-equiv y Singleton≃ΣB : Singleton′ x ≃ Σ A B Singleton≃ΣB = Σ-≃⁺ ≡≃B Σ-IsContr→IsEquiv : {A : Set α} {B : A → Set β} (x : A) → (f : ∀ y → x ≡ y → B y) → IsContr (Σ A B) → ∀ y → IsEquiv (f y) Σ-IsContr→IsEquiv {A = A} {B = B} x f Σ-contr = IsEquiv-map₂-f→IsEquiv-f f f-equiv where f-equiv : IsEquiv (map₂ f) f-equiv = IsContr→IsEquiv IsContr-Singleton′ Σ-contr (map₂ f) Univalence→UnivalenceContr : Univalence α → UnivalenceContr α Univalence→UnivalenceContr ua A = IsEquiv→Σ-IsContr A (λ B → ≡→≃) (λ B → ua) UnivalenceContr→Univalence : UnivalenceContr α → Univalence α UnivalenceContr→Univalence ua {A} {B} = Σ-IsContr→IsEquiv A (λ B → ≡→≃) (ua A) B univalenceContr : (A : Set α) → IsContr (Σ[ B ∈ Set α ] (A ≃ B)) univalenceContr = Univalence→UnivalenceContr univalence UnivalenceContr→UnivalenceProp : UnivalenceContr α → UnivalenceProp α UnivalenceContr→UnivalenceProp ua = IsContr→IsProp ∘ ua UnivalenceProp→UnivalenceContr : UnivalenceProp α → UnivalenceContr α UnivalenceProp→UnivalenceContr ua A = IsProp∧Pointed→IsContr (ua A) (A , ≃-refl) Univalence→UnivalenceProp : Univalence α → UnivalenceProp α Univalence→UnivalenceProp = UnivalenceContr→UnivalenceProp ∘ Univalence→UnivalenceContr UnivalenceProp→Univalence : UnivalenceProp α → Univalence α UnivalenceProp→Univalence = UnivalenceContr→Univalence ∘ UnivalenceProp→UnivalenceContr univalenceProp : ∀ {α} → UnivalenceProp α univalenceProp = Univalence→UnivalenceProp univalence
{ "alphanum_fraction": 0.6672975019, "avg_line_length": 29.6853932584, "ext": "agda", "hexsha": "cf3d9fe2b89b049b5c584ef3a50563d3801365e2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/msc-thesis-code", "max_forks_repo_path": "src/Util/HoTT/Univalence/ContrFormulation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JLimperg/msc-thesis-code", "max_issues_repo_path": "src/Util/HoTT/Univalence/ContrFormulation.agda", "max_line_length": 91, "max_stars_count": 5, "max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/msc-thesis-code", "max_stars_repo_path": "src/Util/HoTT/Univalence/ContrFormulation.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z", "num_tokens": 961, "size": 2642 }
{-# OPTIONS --safe --no-sized-types #-} open import Agda.Builtin.Size record Stream (A : Set) (i : Size) : Set where coinductive field head : A tail : {j : Size< i} → Stream A j open Stream destroy-guardedness : ∀ {A i} → Stream A i → Stream A i destroy-guardedness xs .head = xs .head destroy-guardedness xs .tail = xs .tail repeat : ∀ {A i} → A → Stream A i repeat x .head = x repeat x .tail = destroy-guardedness (repeat x)
{ "alphanum_fraction": 0.6463963964, "avg_line_length": 22.2, "ext": "agda", "hexsha": "4a1572d181db3826c806c2a2ad2ad68df8aca789", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue1209-4.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue1209-4.agda", "max_line_length": 55, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue1209-4.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 141, "size": 444 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Group.Notation where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Algebra.Group.Base module GroupNotationG {ℓ : Level} ((_ , G) : Group {ℓ}) where 0ᴳ = GroupStr.0g G _+ᴳ_ = GroupStr._+_ G -ᴳ_ = GroupStr.-_ G _-ᴳ_ = GroupStr._-_ G lIdᴳ = GroupStr.lid G rIdᴳ = GroupStr.rid G lCancelᴳ = GroupStr.invl G rCancelᴳ = GroupStr.invr G assocᴳ = GroupStr.assoc G setᴳ = GroupStr.is-set G module GroupNotationᴴ {ℓ : Level} ((_ , G) : Group {ℓ}) where 0ᴴ = GroupStr.0g G _+ᴴ_ = GroupStr._+_ G -ᴴ_ = GroupStr.-_ G _-ᴴ_ = GroupStr._-_ G lIdᴴ = GroupStr.lid G rIdᴴ = GroupStr.rid G lCancelᴴ = GroupStr.invl G rCancelᴴ = GroupStr.invr G assocᴴ = GroupStr.assoc G setᴴ = GroupStr.is-set G module GroupNotation₀ {ℓ : Level} ((_ , G) : Group {ℓ}) where 0₀ = GroupStr.0g G _+₀_ = GroupStr._+_ G -₀_ = GroupStr.-_ G _-₀_ = GroupStr._-_ G lId₀ = GroupStr.lid G rId₀ = GroupStr.rid G lCancel₀ = GroupStr.invl G rCancel₀ = GroupStr.invr G assoc₀ = GroupStr.assoc G set₀ = GroupStr.is-set G module GroupNotation₁ {ℓ : Level} ((_ , G) : Group {ℓ}) where 0₁ = GroupStr.0g G _+₁_ = GroupStr._+_ G -₁_ = GroupStr.-_ G _-₁_ = GroupStr._-_ G lId₁ = GroupStr.lid G rId₁ = GroupStr.rid G lCancel₁ = GroupStr.invl G rCancel₁ = GroupStr.invr G assoc₁ = GroupStr.assoc G set₁ = GroupStr.is-set G
{ "alphanum_fraction": 0.6693766938, "avg_line_length": 26.3571428571, "ext": "agda", "hexsha": "00c959c9f51d3027d581f09171ded5f281f0a7cb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_path": "Cubical/Algebra/Group/Notation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_path": "Cubical/Algebra/Group/Notation.agda", "max_line_length": 61, "max_stars_count": null, "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_path": "Cubical/Algebra/Group/Notation.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 632, "size": 1476 }
{-# OPTIONS --without-K --rewriting #-} module Set where
{ "alphanum_fraction": 0.6229508197, "avg_line_length": 12.2, "ext": "agda", "hexsha": "bce19807e539207c9b59340147db4ece09f54609", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "glangmead/formalization", "max_forks_repo_path": "cohesion/david_jaz_261/Set.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "glangmead/formalization", "max_issues_repo_path": "cohesion/david_jaz_261/Set.agda", "max_line_length": 39, "max_stars_count": 6, "max_stars_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "glangmead/formalization", "max_stars_repo_path": "cohesion/david_jaz_261/Set.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-13T05:51:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-06T17:39:22.000Z", "num_tokens": 13, "size": 61 }
{-# OPTIONS --without-K --safe #-} -- Enriched category over a Monoidal category V open import Categories.Category using (module Commutation) renaming (Category to Setoid-Category) open import Categories.Category.Monoidal using (Monoidal) module Categories.Enriched.Category {o ℓ e} {V : Setoid-Category o ℓ e} (M : Monoidal V) where open import Level open import Categories.Category.Monoidal.Reasoning M open import Categories.Category.Monoidal.Utilities M using (module Shorthands) open import Categories.Morphism.Reasoning V using (pullˡ; pullʳ; pushˡ) open Setoid-Category V renaming (Obj to ObjV; id to idV) using (_⇒_; _∘_) open Commutation V open Monoidal M using (unit; _⊗₀_; _⊗₁_; module associator; module unitorˡ; module unitorʳ; assoc-commute-from) open Shorthands record Category (v : Level) : Set (o ⊔ ℓ ⊔ e ⊔ suc v) where field Obj : Set v hom : (A B : Obj) → ObjV id : {A : Obj} → unit ⇒ hom A A ⊚ : {A B C : Obj} → hom B C ⊗₀ hom A B ⇒ hom A C ⊚-assoc : {A B C D : Obj} → [ (hom C D ⊗₀ hom B C) ⊗₀ hom A B ⇒ hom A D ]⟨ ⊚ ⊗₁ idV ⇒⟨ hom B D ⊗₀ hom A B ⟩ ⊚ ≈ associator.from ⇒⟨ hom C D ⊗₀ (hom B C ⊗₀ hom A B) ⟩ idV ⊗₁ ⊚ ⇒⟨ hom C D ⊗₀ hom A C ⟩ ⊚ ⟩ unitˡ : {A B : Obj} → [ unit ⊗₀ hom A B ⇒ hom A B ]⟨ id ⊗₁ idV ⇒⟨ hom B B ⊗₀ hom A B ⟩ ⊚ ≈ unitorˡ.from ⟩ unitʳ : {A B : Obj} → [ hom A B ⊗₀ unit ⇒ hom A B ]⟨ idV ⊗₁ id ⇒⟨ hom A B ⊗₀ hom A A ⟩ ⊚ ≈ unitorʳ.from ⟩ -- A version of ⊚-assoc using generalized hom-variables. -- -- In this version of associativity, the generalized variables f, g -- and h represent V-morphisms, or rather, morphism-valued maps, -- such as V-natural transformations or V-functorial actions. This -- version is therefore well-suited for proving derived equations, -- such as functorial laws or commuting diagrams, that involve such -- maps. For examples, see Underlying.assoc below, or the modules -- Enriched.Functor and Enriched.NaturalTransformation. ⊚-assoc-var : {X Y Z : ObjV} {A B C D : Obj} {f : X ⇒ hom C D} {g : Y ⇒ hom B C} {h : Z ⇒ hom A B} → [ (X ⊗₀ Y) ⊗₀ Z ⇒ hom A D ]⟨ (⊚ ∘ f ⊗₁ g) ⊗₁ h ⇒⟨ hom B D ⊗₀ hom A B ⟩ ⊚ ≈ associator.from ⇒⟨ X ⊗₀ (Y ⊗₀ Z) ⟩ f ⊗₁ (⊚ ∘ g ⊗₁ h) ⇒⟨ hom C D ⊗₀ hom A C ⟩ ⊚ ⟩ ⊚-assoc-var {f = f} {g} {h} = begin ⊚ ∘ (⊚ ∘ f ⊗₁ g) ⊗₁ h ≈⟨ refl⟩∘⟨ split₁ˡ ⟩ ⊚ ∘ ⊚ ⊗₁ idV ∘ (f ⊗₁ g) ⊗₁ h ≈⟨ pullˡ ⊚-assoc ⟩ (⊚ ∘ idV ⊗₁ ⊚ ∘ α⇒) ∘ (f ⊗₁ g) ⊗₁ h ≈⟨ pullʳ (pullʳ assoc-commute-from) ⟩ ⊚ ∘ idV ⊗₁ ⊚ ∘ f ⊗₁ (g ⊗₁ h) ∘ α⇒ ≈˘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ ⊚ ∘ f ⊗₁ (⊚ ∘ g ⊗₁ h) ∘ α⇒ ∎ -- The usual shorthand for hom-objects of an arbitrary category. infix 15 _[_,_] _[_,_] : ∀ {c} (C : Category c) (X Y : Category.Obj C) → ObjV _[_,_] = Category.hom
{ "alphanum_fraction": 0.5453639083, "avg_line_length": 35.8214285714, "ext": "agda", "hexsha": "8a485e046d2582a6bb59bff7f275d8b600a206aa", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Enriched/Category.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Enriched/Category.agda", "max_line_length": 97, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Enriched/Category.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 1186, "size": 3009 }
{- This second-order term syntax was created from the following second-order syntax description: syntax Combinatory | CL type * : 0-ary term app : * * -> * | _$_ l20 i : * k : * s : * theory (IA) x |> app (i, x) = x (KA) x y |> app (app(k, x), y) = x (SA) x y z |> app (app (app (s, x), y), z) = app (app(x, z), app(y, z)) -} module Combinatory.Syntax where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Families.Core open import SOAS.Construction.Structure open import SOAS.ContextMaps.Inductive open import SOAS.Metatheory.Syntax open import Combinatory.Signature private variable Γ Δ Π : Ctx α : *T 𝔛 : Familyₛ -- Inductive term declaration module CL:Terms (𝔛 : Familyₛ) where data CL : Familyₛ where var : ℐ ⇾̣ CL mvar : 𝔛 α Π → Sub CL Π Γ → CL α Γ _$_ : CL * Γ → CL * Γ → CL * Γ I : CL * Γ K : CL * Γ S : CL * Γ infixl 20 _$_ open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛 CLᵃ : MetaAlg CL CLᵃ = record { 𝑎𝑙𝑔 = λ where (appₒ ⋮ a , b) → _$_ a b (iₒ ⋮ _) → I (kₒ ⋮ _) → K (sₒ ⋮ _) → S ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) } module CLᵃ = MetaAlg CLᵃ module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where open MetaAlg 𝒜ᵃ 𝕤𝕖𝕞 : CL ⇾̣ 𝒜 𝕊 : Sub CL Π Γ → Π ~[ 𝒜 ]↝ Γ 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t 𝕊 (t ◂ σ) (old v) = 𝕊 σ v 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε) 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v 𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b) 𝕤𝕖𝕞 I = 𝑎𝑙𝑔 (iₒ ⋮ tt) 𝕤𝕖𝕞 K = 𝑎𝑙𝑔 (kₒ ⋮ tt) 𝕤𝕖𝕞 S = 𝑎𝑙𝑔 (sₒ ⋮ tt) 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ CLᵃ 𝒜ᵃ 𝕤𝕖𝕞 𝕤𝕖𝕞ᵃ⇒ = record { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t } ; ⟨𝑣𝑎𝑟⟩ = refl ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } } where open ≡-Reasoning ⟨𝑎𝑙𝑔⟩ : (t : ⅀ CL α Γ) → 𝕤𝕖𝕞 (CLᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t) ⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (iₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (kₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (sₒ ⋮ _) = refl 𝕊-tab : (mε : Π ~[ CL ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v) 𝕊-tab mε new = refl 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v module _ (g : CL ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ CLᵃ 𝒜ᵃ g) where open MetaAlg⇒ gᵃ⇒ 𝕤𝕖𝕞! : (t : CL α Γ) → 𝕤𝕖𝕞 t ≡ g t 𝕊-ix : (mε : Sub CL Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v) 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε)) = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε)) 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩ 𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! I = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! K = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! S = sym ⟨𝑎𝑙𝑔⟩ -- Syntax instance for the signature CL:Syn : Syntax CL:Syn = record { ⅀F = ⅀F ; ⅀:CS = ⅀:CompatStr ; mvarᵢ = CL:Terms.mvar ; 𝕋:Init = λ 𝔛 → let open CL:Terms 𝔛 in record { ⊥ = CL ⋉ CLᵃ ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ } ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } } -- Instantiation of the syntax and metatheory open Syntax CL:Syn public open CL:Terms public open import SOAS.Families.Build public open import SOAS.Syntax.Shorthands CLᵃ public open import SOAS.Metatheory CL:Syn public
{ "alphanum_fraction": 0.5148782687, "avg_line_length": 24.4632352941, "ext": "agda", "hexsha": "2e2d428338d6b115e2fb3c98ec4c61e5703647ee", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_path": "out/Combinatory/Syntax.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_path": "out/Combinatory/Syntax.agda", "max_line_length": 93, "max_stars_count": 39, "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_path": "out/Combinatory/Syntax.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "num_tokens": 2060, "size": 3327 }
{-# OPTIONS --without-K --safe #-} module Definition.Conversion.Consequences.Completeness where open import Definition.Untyped open import Definition.Typed open import Definition.Conversion open import Definition.Conversion.EqRelInstance open import Definition.LogicalRelation open import Definition.LogicalRelation.Substitution open import Definition.LogicalRelation.Substitution.Escape open import Definition.LogicalRelation.Fundamental open import Tools.Product -- Algorithmic equality is derivable from judgemental equality of types. completeEq : ∀ {A B Γ} → Γ ⊢ A ≡ B → Γ ⊢ A [conv↑] B completeEq A≡B = let [Γ] , [A] , [B] , [A≡B] = fundamentalEq A≡B in escapeEqᵛ [Γ] [A] [A≡B] -- Algorithmic equality is derivable from judgemental equality of terms. completeEqTerm : ∀ {t u A Γ} → Γ ⊢ t ≡ u ∷ A → Γ ⊢ t [conv↑] u ∷ A completeEqTerm t≡u = let [Γ] , modelsTermEq [A] [t] [u] [t≡u] = fundamentalTermEq t≡u in escapeEqTermᵛ [Γ] [A] [t≡u]
{ "alphanum_fraction": 0.7314524556, "avg_line_length": 33, "ext": "agda", "hexsha": "e7eac67bf24dad7b64ed5e869a905b22d43f7798", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Vtec234/logrel-mltt", "max_forks_repo_path": "Definition/Conversion/Consequences/Completeness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Vtec234/logrel-mltt", "max_issues_repo_path": "Definition/Conversion/Consequences/Completeness.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Vtec234/logrel-mltt", "max_stars_repo_path": "Definition/Conversion/Consequences/Completeness.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 301, "size": 957 }
------------------------------------------------------------------------------ -- All the Peano arithmetic modules ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module PA.Everything where open import PA.Axiomatic.Mendelson.Base open import PA.Axiomatic.Mendelson.Base.Consistency.Axioms open import PA.Axiomatic.Mendelson.PropertiesATP open import PA.Axiomatic.Mendelson.PropertiesI open import PA.Axiomatic.Mendelson.Relation.Binary.EqReasoning open import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityI open import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityATP open import PA.Axiomatic.Standard.Base open import PA.Axiomatic.Standard.Base.Consistency.Axioms open import PA.Axiomatic.Standard.PropertiesATP open import PA.Axiomatic.Standard.PropertiesI open import PA.Inductive.Base open import PA.Inductive.Base.Core open import PA.Inductive.Existential open import PA.Inductive.PropertiesATP open import PA.Inductive.PropertiesI open import PA.Inductive.PropertiesByInduction open import PA.Inductive.PropertiesByInductionATP open import PA.Inductive.PropertiesByInductionI open import PA.Inductive.Relation.Binary.EqReasoning open import PA.Inductive.Relation.Binary.PropositionalEquality open import PA.Inductive2Mendelson open import PA.Inductive2Standard
{ "alphanum_fraction": 0.729747676, "avg_line_length": 39.6315789474, "ext": "agda", "hexsha": "988107def442b34f8f5de3568b1e7136fc063a28", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/PA/Everything.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/PA/Everything.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/PA/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 331, "size": 1506 }
module Computability.Data.Fin.Opposite where open import Computability.Prelude open import Data.Nat using (_≤_; _<_; s≤s; z≤n) open import Data.Nat.Properties using (≤-step) open import Data.Fin using (Fin; zero; suc; inject₁; fromℕ; fromℕ<; toℕ; opposite) opposite-fromℕ : ∀ k → opposite (fromℕ k) ≡ zero opposite-fromℕ zero = refl opposite-fromℕ (suc k) rewrite opposite-fromℕ k = refl opposite-inject₁-suc : ∀{k}(i : Fin k) → opposite (inject₁ i) ≡ suc (opposite i) opposite-inject₁-suc zero = refl opposite-inject₁-suc (suc i) rewrite opposite-inject₁-suc i = refl opposite-opposite : ∀{k}(i : Fin k) → opposite (opposite i) ≡ i opposite-opposite {suc k} zero rewrite opposite-fromℕ k = refl opposite-opposite (suc i) rewrite opposite-inject₁-suc (opposite i) | opposite-opposite i = refl opposite-fromℕ< : ∀ a b (lt : a < b) → opposite (fromℕ< (≤-step lt)) ≡ suc (opposite (fromℕ< lt)) opposite-fromℕ< zero .(suc _) (s≤s le) = refl opposite-fromℕ< (suc a) .(suc _) (s≤s le) rewrite opposite-fromℕ< _ _ le = refl
{ "alphanum_fraction": 0.6989351404, "avg_line_length": 39.7307692308, "ext": "agda", "hexsha": "a923e5667a056938f41d688e6a8df8097df26d5c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jesyspa/computability-in-agda", "max_forks_repo_path": "Computability/Data/Fin/Opposite.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jesyspa/computability-in-agda", "max_issues_repo_path": "Computability/Data/Fin/Opposite.agda", "max_line_length": 97, "max_stars_count": 2, "max_stars_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jesyspa/computability-in-agda", "max_stars_repo_path": "Computability/Data/Fin/Opposite.agda", "max_stars_repo_stars_event_max_datetime": "2021-04-30T11:15:51.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-19T15:51:22.000Z", "num_tokens": 375, "size": 1033 }
module Type.Properties.Decidable.Proofs where open import Data open import Data.Proofs open import Data.Boolean using (if_then_else_) open import Data.Boolean.Stmt open import Data.Either as Either using (_‖_) open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Functional import Lvl open import Data.Boolean using (Bool ; 𝑇 ; 𝐹) import Data.Boolean.Operators open Data.Boolean.Operators.Programming open import Lang.Inspect open import Logic open import Logic.Classical open import Logic.Predicate open import Logic.Propositional open import Numeral.Natural open import Relator.Equals.Proofs.Equiv open import Type.Properties.Decidable open import Type.Properties.Empty open import Type.Properties.Inhabited open import Type.Properties.Singleton.Proofs open import Type private variable ℓ ℓₚ : Lvl.Level private variable A B C P Q R T : Type{ℓ} private variable b b₁ b₂ d : Bool private variable f : A → B module _ (P : Stmt{ℓ}) where decider-classical : ⦃ dec : Decider₀(P)(d) ⦄ → Classical(P) Classical.excluded-middle (decider-classical ⦃ dec = dec ⦄) = elim(\_ → (P ∨ (¬ P))) [∨]-introₗ [∨]-introᵣ dec classical-decidable : ⦃ classical : Classical(P) ⦄ → Decidable(0)(P) ∃.witness classical-decidable = Either.isLeft(excluded-middle(P)) ∃.proof classical-decidable with excluded-middle(P) | inspect Either.isLeft(excluded-middle(P)) ... | Either.Left p | _ = true p ... | Either.Right np | _ = false np module _ {ℓ₂} {x y : R} {Pred : (P ∨ (¬ P)) → R → Type{ℓ₂}} where decider-if-intro : ∀{f} ⦃ dec : Decider₀(P)(f) ⦄ → ((p : P) → Pred(Either.Left p)(x)) → ((np : (¬ P)) → Pred(Either.Right np)(y)) → Pred(excluded-middle(P) ⦃ decider-classical ⦄)(if f then x else y) decider-if-intro {f = 𝑇} ⦃ true p ⦄ fp _ = fp p decider-if-intro {f = 𝐹} ⦃ false np ⦄ _ fnp = fnp np decider-to-classical : ⦃ dec : Decider₀(P)(d) ⦄ → Classical(P) decider-to-classical{P = P} = decider-classical(P) classical-to-decidable : ⦃ classical : Classical(P) ⦄ → Decidable(0)(P) classical-to-decidable{P = P} = classical-decidable(P) classical-to-decider : ⦃ classical : Classical(P) ⦄ → Decider(0)(P)([∃]-witness classical-to-decidable) classical-to-decider{P = P} = [∃]-proof classical-to-decidable decider-true : ⦃ dec : Decider₀(P)(b) ⦄ → (P ↔ IsTrue(b)) decider-true ⦃ dec = true p ⦄ = [↔]-intro (const p) (const <>) decider-true ⦃ dec = false np ⦄ = [↔]-intro empty (empty ∘ np) decider-false : ⦃ dec : Decider₀(P)(b) ⦄ → ((P → Empty{ℓ}) ↔ IsFalse(b)) decider-false ⦃ dec = true p ⦄ = [↔]-intro empty (empty ∘ apply p) decider-false ⦃ dec = false np ⦄ = [↔]-intro (const(empty ∘ np)) (const <>) isempty-decider : ⦃ empty : IsEmpty(P) ⦄ → Decider₀(P)(𝐹) isempty-decider ⦃ intro p ⦄ = false (empty ∘ p) inhabited-decider : ⦃ inhab : (◊ P) ⦄ → Decider₀(P)(𝑇) inhabited-decider ⦃ intro ⦃ p ⦄ ⦄ = true p empty-decider : Decider₀(Empty{ℓ})(𝐹) empty-decider = isempty-decider unit-decider : Decider₀(Unit{ℓ})(𝑇) unit-decider = inhabited-decider ⦃ unit-is-pos ⦄ instance tuple-decider : ⦃ dec-P : Decider₀(P)(b₁) ⦄ → ⦃ dec-Q : Decider₀(Q)(b₂) ⦄ → Decider₀(P ⨯ Q)(b₁ && b₂) tuple-decider ⦃ true p ⦄ ⦃ true q ⦄ = true(p , q) tuple-decider ⦃ true p ⦄ ⦃ false nq ⦄ = false(nq ∘ Tuple.right) tuple-decider ⦃ false np ⦄ ⦃ true q ⦄ = false(np ∘ Tuple.left) tuple-decider ⦃ false np ⦄ ⦃ false nq ⦄ = false(np ∘ Tuple.left) instance either-decider : ⦃ dec-P : Decider₀(P)(b₁) ⦄ → ⦃ dec-Q : Decider₀(Q)(b₂) ⦄ → Decider₀(P ‖ Q)(b₁ || b₂) either-decider ⦃ true p ⦄ ⦃ true q ⦄ = true (Either.Left p) either-decider ⦃ true p ⦄ ⦃ false nq ⦄ = true (Either.Left p) either-decider ⦃ false np ⦄ ⦃ true q ⦄ = true (Either.Right q) either-decider ⦃ false np ⦄ ⦃ false nq ⦄ = false (Either.elim np nq) instance function-decider : ⦃ dec-P : Decider₀(P)(b₁) ⦄ → ⦃ dec-Q : Decider₀(Q)(b₂) ⦄ → Decider₀(P → Q)((! b₁) || b₂) function-decider ⦃ true p ⦄ ⦃ true q ⦄ = true (const q) function-decider ⦃ true p ⦄ ⦃ false nq ⦄ = false (apply p ∘ (nq ∘_)) function-decider ⦃ false np ⦄ ⦃ true q ⦄ = true (const q) function-decider ⦃ false np ⦄ ⦃ false nq ⦄ = true (empty ∘ np) instance not-decider : ⦃ dec : Decider₀(P)(b) ⦄ → Decider₀(¬ P)(! b) not-decider = function-decider {b₂ = 𝐹} ⦃ dec-Q = empty-decider ⦄ instance IsTrue-decider : Decider₀(IsTrue(b))(b) IsTrue-decider {𝑇} = true <> IsTrue-decider {𝐹} = false id
{ "alphanum_fraction": 0.649321267, "avg_line_length": 42.0952380952, "ext": "agda", "hexsha": "f3fe2c119bf3f636091f61831215847a5da7e534", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Type/Properties/Decidable/Proofs.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Type/Properties/Decidable/Proofs.agda", "max_line_length": 202, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Type/Properties/Decidable/Proofs.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 1752, "size": 4420 }
{-# OPTIONS --cubical --safe #-} module Data.List.Properties where open import Data.List open import Prelude open import Data.Fin map-length : (f : A → B) (xs : List A) → length xs ≡ length (map f xs) map-length f [] _ = zero map-length f (x ∷ xs) i = suc (map-length f xs i) map-ind : (f : A → B) (xs : List A) → PathP (λ i → Fin (map-length f xs i) → B) (f ∘ (xs !_)) (map f xs !_) map-ind f [] i () map-ind f (x ∷ xs) i f0 = f x map-ind f (x ∷ xs) i (fs n) = map-ind f xs i n tab-length : ∀ n (f : Fin n → A) → length (tabulate n f) ≡ n tab-length zero f _ = zero tab-length (suc n) f i = suc (tab-length n (f ∘ fs) i) tab-distrib : ∀ n (f : Fin n → A) m → ∃[ i ] (f i ≡ tabulate n f ! m) tab-distrib (suc n) f f0 = f0 , refl tab-distrib (suc n) f (fs m) = let i , p = tab-distrib n (f ∘ fs) m in fs i , p tab-id : ∀ n (f : Fin n → A) → PathP (λ i → Fin (tab-length n f i) → A) (_!_ (tabulate n f)) f tab-id zero f _ () tab-id (suc n) f i f0 = f f0 tab-id (suc n) f i (fs m) = tab-id n (f ∘ fs) i m
{ "alphanum_fraction": 0.5496108949, "avg_line_length": 32.125, "ext": "agda", "hexsha": "4879349f46567772261e9baa0b2a333da0aaec7e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Data/List/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Data/List/Properties.agda", "max_line_length": 94, "max_stars_count": 4, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Data/List/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z", "num_tokens": 410, "size": 1028 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} import LibraBFT.Impl.Types.CryptoProxies as CryptoProxies import LibraBFT.Impl.Types.LedgerInfo as LedgerInfo import LibraBFT.Impl.Types.LedgerInfoWithSignatures as LedgerInfoWithSignatures import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Consensus.Types.EpochIndep open import Optics.All open import Util.Prelude module LibraBFT.Impl.OBM.Genesis where ------------------------------------------------------------------------------ obmMkLedgerInfoWithEpochState : ValidatorSet → Either ErrLog LedgerInfo ------------------------------------------------------------------------------ obmMkGenesisLedgerInfoWithSignatures : List ValidatorSigner → ValidatorSet → Either ErrLog LedgerInfoWithSignatures obmMkGenesisLedgerInfoWithSignatures vss0 vs0 = do liwes ← obmMkLedgerInfoWithEpochState vs0 let sigs = fmap (λ vs → (vs ^∙ vsAuthor , ValidatorSigner.sign vs liwes)) vss0 pure $ foldl' (λ acc (a , sig) → CryptoProxies.addToLi a sig acc) (LedgerInfoWithSignatures.obmNewNoSigs liwes) sigs obmMkLedgerInfoWithEpochState vs = do li ← LedgerInfo.mockGenesis (just vs) vv ← ValidatorVerifier.from-e-abs vs pure (li & liCommitInfo ∙ biNextEpochState ?~ EpochState∙new (li ^∙ liEpoch) vv)
{ "alphanum_fraction": 0.6784064665, "avg_line_length": 43.3, "ext": "agda", "hexsha": "87bf31977bedf5a28bfcac35ac6153f10821727e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Impl/OBM/Genesis.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/OBM/Genesis.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Impl/OBM/Genesis.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 455, "size": 1732 }
module PreludeInt where open import AlonzoPrelude import RTP int : Nat -> Int int = RTP.primNatToInt _+_ : Int -> Int -> Int _+_ = RTP.primIntAdd _-_ : Int -> Int -> Int _-_ = RTP.primIntSub _*_ : Int -> Int -> Int _*_ = RTP.primIntMul div : Int -> Int -> Int div = RTP.primIntDiv mod : Int -> Int -> Int mod = RTP.primIntMod
{ "alphanum_fraction": 0.6369047619, "avg_line_length": 12.9230769231, "ext": "agda", "hexsha": "01ae9148524c2f1c3acb24c9384128dbdd04ec22", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "examples/outdated-and-incorrect/Alonzo/PreludeInt.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/Alonzo/PreludeInt.agda", "max_line_length": 25, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/outdated-and-incorrect/Alonzo/PreludeInt.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 114, "size": 336 }
------------------------------------------------------------------------ -- Some theory of equivalences with erased "proofs", defined in terms -- of partly erased contractible fibres, developed using Cubical Agda ------------------------------------------------------------------------ -- This module instantiates and reexports code from -- Equivalence.Erased.Contractible-preimages. {-# OPTIONS --erased-cubical --safe #-} import Equality.Path as P module Equivalence.Erased.Contractible-preimages.Cubical {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Erased.Cubical eq import Equivalence.Erased.Contractible-preimages open Equivalence.Erased.Contractible-preimages equality-with-J public hiding (module []-cong) open Equivalence.Erased.Contractible-preimages.[]-cong equality-with-J instance-of-[]-cong-axiomatisation public
{ "alphanum_fraction": 0.6538461538, "avg_line_length": 35, "ext": "agda", "hexsha": "72887cf59ffc8f2d4f377fc2235cce9c5bf14b1e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Equivalence/Erased/Contractible-preimages/Cubical.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/equality", "max_issues_repo_path": "src/Equivalence/Erased/Contractible-preimages/Cubical.agda", "max_line_length": 72, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Equivalence/Erased/Contractible-preimages/Cubical.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 208, "size": 910 }
module Integer.Difference where open import Data.Product as Σ open import Data.Product.Relation.Pointwise.NonDependent open import Data.Unit open import Equality open import Natural as ℕ open import Quotient as / open import Relation.Binary open import Syntax infixl 6 _–_ pattern _–_ a b = _,_ a b ⟦ℤ⟧ = ℕ × ℕ ⟦ℤ²⟧ = ⟦ℤ⟧ × ⟦ℤ⟧ _≈_ : ⟦ℤ⟧ → ⟦ℤ⟧ → Set (a – b) ≈ (c – d) = a + d ≡ c + b ≈-refl : ∀ {x} → x ≈ x ≈-refl = refl ℤ = ⟦ℤ⟧ / _≈_ ℤ² = ⟦ℤ²⟧ / Pointwise _≈_ _≈_ instance ⟦ℤ⟧-Number : Number ⟦ℤ⟧ ⟦ℤ⟧-Number = record { Constraint = λ _ → ⊤ ; fromNat = λ x → x – 0 } ℤ-Number : Number ℤ ℤ-Number = record { Constraint = λ _ → ⊤ ; fromNat = λ x → ⟦ fromNat x ⟧ } ⟦ℤ⟧-Negative : Negative ⟦ℤ⟧ ⟦ℤ⟧-Negative = record { Constraint = λ _ → ⊤ ; fromNeg = λ x → 0 – x } ℤ-Negative : Negative ℤ ℤ-Negative = record { Constraint = λ _ → ⊤ ; fromNeg = λ x → ⟦ fromNeg x ⟧ } suc–suc-injective : ∀ a b → Path ℤ ⟦ suc a – suc b ⟧ ⟦ a – b ⟧ suc–suc-injective a b = equiv (suc a – suc b) (a – b) (sym (+-suc a b )) ⟦negate⟧ : ⟦ℤ⟧ → ⟦ℤ⟧ ⟦negate⟧ (a – b) = b – a negate : ℤ → ℤ negate = ⟦negate⟧ // λ where (a – b) (c – d) p → ⟨ +-comm b c ⟩ ≫ sym p ≫ ⟨ +-comm a d ⟩ ⟦plus⟧ : ⟦ℤ²⟧ → ⟦ℤ⟧ ⟦plus⟧ ((a – b) , (c – d)) = (a + c) – (d + b) plus : ℤ² → ℤ plus = ⟦plus⟧ // λ where ((a – b) , (c – d)) ((e – f) , (g – h)) (p , q) → (a + c) + (h + f) ≡⟨ sym (ℕ.+-assoc a _ _) ⟩ a + (c + (h + f)) ≡⟨ cong (a +_) (ℕ.+-assoc c _ _) ⟩ a + ((c + h) + f) ≡⟨ cong (λ z → a + (z + f)) q ⟩ a + ((g + d) + f) ≡⟨ cong (a +_) ⟨ ℕ.+-comm (g + d) _ ⟩ ⟩ a + (f + (g + d)) ≡⟨ ℕ.+-assoc a _ _ ⟩ (a + f) + (g + d) ≡⟨ cong (_+ (g + d)) p ⟩ (e + b) + (g + d) ≡⟨ ℕ.+-cross e _ _ _ ⟩ (e + g) + (b + d) ≡⟨ cong ((e + g) +_) ⟨ ℕ.+-comm b _ ⟩ ⟩ (e + g) + (d + b) ∎ instance ⟦ℤ⟧-plus-syntax : plus-syntax-simple ⟦ℤ⟧ ⟦ℤ⟧ ⟦ℤ⟧ ⟦ℤ⟧-plus-syntax = λ where ._+_ x y → ⟦plus⟧ (x , y) ⟦ℤ⟧-minus-syntax : minus-syntax-simple ⟦ℤ⟧ ⟦ℤ⟧ ⟦ℤ⟧ ⟦ℤ⟧-minus-syntax = λ where ._-_ x y → ⟦plus⟧ (x , ⟦negate⟧ y) ℕ-⟦ℤ⟧-minus-syntax : minus-syntax-simple ℕ ℕ ⟦ℤ⟧ ℕ-⟦ℤ⟧-minus-syntax = λ where ._-_ → _–_ ℤ-plus-syntax : plus-syntax-simple ℤ ℤ ℤ ℤ-plus-syntax = λ where ._+_ → /.uncurry refl refl plus ℤ-minus-syntax : minus-syntax-simple ℤ ℤ ℤ ℤ-minus-syntax = λ where ._-_ x y → x + negate y ℕ-ℤ-minus-syntax : minus-syntax-simple ℕ ℕ ℤ ℕ-ℤ-minus-syntax = λ where ._-_ x y → ⟦ x – y ⟧
{ "alphanum_fraction": 0.4868525896, "avg_line_length": 26.1458333333, "ext": "agda", "hexsha": "28ee89aa35de7dfed623a79a1c6357e7e731d136", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "67ea7b96228c592daf79e800ebe4a7c12ed7221e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "kcsmnt0/numbers", "max_forks_repo_path": "src/Integer/Difference.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "67ea7b96228c592daf79e800ebe4a7c12ed7221e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "kcsmnt0/numbers", "max_issues_repo_path": "src/Integer/Difference.agda", "max_line_length": 78, "max_stars_count": 9, "max_stars_repo_head_hexsha": "67ea7b96228c592daf79e800ebe4a7c12ed7221e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "kcsmnt0/numbers", "max_stars_repo_path": "src/Integer/Difference.agda", "max_stars_repo_stars_event_max_datetime": "2020-01-16T07:16:26.000Z", "max_stars_repo_stars_event_min_datetime": "2019-05-20T01:29:41.000Z", "num_tokens": 1204, "size": 2510 }
module MissingTypeSignature where data Nat : Set where zero : Nat suc : Nat -> Nat pred zero = zero pred (suc n) = n
{ "alphanum_fraction": 0.6434108527, "avg_line_length": 11.7272727273, "ext": "agda", "hexsha": "b83685d1d9788bd891d41e9756afdcbc05bc25ff", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/MissingTypeSignature.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/MissingTypeSignature.agda", "max_line_length": 33, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/MissingTypeSignature.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 41, "size": 129 }
module ProofUtilities where -- open import Data.Nat hiding (_>_) open import StdLibStuff open import Syntax open import FSC mutual hn-left-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t β) (G : Form Γ-t α) → Γ ⊢ α ∋ S (headNorm m F) ↔ G → Γ ⊢ α ∋ S F ↔ G hn-left-i m S (app F H) G p = hn-left-i m (λ x → S (app x H)) F G (hn-left-i' m S (headNorm m F) H G p) hn-left-i _ _ (var _ _) _ p = p hn-left-i _ _ N _ p = p hn-left-i _ _ A _ p = p hn-left-i _ _ Π _ p = p hn-left-i _ _ i _ p = p hn-left-i _ _ (lam _ _) _ p = p hn-left-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t α) → Γ ⊢ α ∋ S (headNorm' m F H) ↔ G → Γ ⊢ α ∋ S (app F H) ↔ G hn-left-i' (suc m) S (lam _ F) H G p with hn-left-i m S (sub H F) G p hn-left-i' (suc _) S (lam _ _) _ _ _ | p' = reduce-l {_} {_} {_} {_} {_} {_} {S} p' hn-left-i' 0 _ (lam _ _) _ _ p = p hn-left-i' zero _ (var _ _) _ _ p = p hn-left-i' (suc _) _ (var _ _) _ _ p = p hn-left-i' zero _ N _ _ p = p hn-left-i' (suc _) _ N _ _ p = p hn-left-i' zero _ A _ _ p = p hn-left-i' (suc _) _ A _ _ p = p hn-left-i' zero _ Π _ _ p = p hn-left-i' (suc _) _ Π _ _ p = p hn-left-i' zero _ i _ _ p = p hn-left-i' (suc _) _ i _ _ p = p hn-left-i' zero _ (app _ _) _ _ p = p hn-left-i' (suc _) _ (app _ _) _ _ p = p hn-left : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t α) (G : Form Γ-t α) → Γ ⊢ α ∋ headNorm m F ↔ G → Γ ⊢ α ∋ F ↔ G hn-left m F G p = hn-left-i m (λ x → x) F G p mutual hn-right-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t β) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ S (headNorm m F) → Γ ⊢ α ∋ G ↔ S F hn-right-i m S (app F H) G p = hn-right-i m (λ x → S (app x H)) F G (hn-right-i' m S (headNorm m F) H G p) hn-right-i _ _ (var _ _) _ p = p hn-right-i _ _ N _ p = p hn-right-i _ _ A _ p = p hn-right-i _ _ Π _ p = p hn-right-i _ _ i _ p = p hn-right-i _ _ (lam _ _) _ p = p hn-right-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ S (headNorm' m F H) → Γ ⊢ α ∋ G ↔ S (app F H) hn-right-i' (suc m) S (lam _ F) H G p with hn-right-i m S (sub H F) G p hn-right-i' (suc _) S (lam _ _) _ _ _ | p' = reduce-r {_} {_} {_} {_} {_} {_} {S} p' hn-right-i' 0 _ (lam _ _) _ _ p = p hn-right-i' zero _ (var _ _) _ _ p = p hn-right-i' (suc _) _ (var _ _) _ _ p = p hn-right-i' zero _ N _ _ p = p hn-right-i' (suc _) _ N _ _ p = p hn-right-i' zero _ A _ _ p = p hn-right-i' (suc _) _ A _ _ p = p hn-right-i' zero _ Π _ _ p = p hn-right-i' (suc _) _ Π _ _ p = p hn-right-i' zero _ i _ _ p = p hn-right-i' (suc _) _ i _ _ p = p hn-right-i' zero _ (app _ _) _ _ p = p hn-right-i' (suc _) _ (app _ _) _ _ p = p hn-right : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t α) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ headNorm m F → Γ ⊢ α ∋ G ↔ F hn-right m F G p = hn-right-i m (λ x → x) F G p mutual hn-succ-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) → Γ ⊢ S (headNorm m F) → Γ ⊢ S F hn-succ-i m S (app F H) p = hn-succ-i m (λ x → S (app x H)) F (hn-succ-i' m S (headNorm m F) H p) hn-succ-i _ _ (var _ _) p = p hn-succ-i _ _ N p = p hn-succ-i _ _ A p = p hn-succ-i _ _ Π p = p hn-succ-i _ _ i p = p hn-succ-i _ _ (lam _ _) p = p hn-succ-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) → Γ ⊢ S (headNorm' m F H) → Γ ⊢ S (app F H) hn-succ-i' (suc m) S (lam _ F) H p with hn-succ-i m S (sub H F) p hn-succ-i' (suc _) S (lam _ _) _ _ | p' = reduce {_} {_} {_} {_} {_} {S} p' hn-succ-i' 0 _ (lam _ _) _ p = p hn-succ-i' zero _ (var _ _) _ p = p hn-succ-i' (suc _) _ (var _ _) _ p = p hn-succ-i' zero _ N _ p = p hn-succ-i' (suc _) _ N _ p = p hn-succ-i' zero _ A _ p = p hn-succ-i' (suc _) _ A _ p = p hn-succ-i' zero _ Π _ p = p hn-succ-i' (suc _) _ Π _ p = p hn-succ-i' zero _ i _ p = p hn-succ-i' (suc _) _ i _ p = p hn-succ-i' zero _ (app _ _) _ p = p hn-succ-i' (suc _) _ (app _ _) _ p = p hn-succ : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} (m : ℕ) (F : Form Γ-t $o) → Γ ⊢ headNorm m F → Γ ⊢ F hn-succ m F p = hn-succ-i m (λ x → x) F p mutual hn-ante-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) (G : Form Γ-t $o) → Γ , S (headNorm m F) ⊢ G → Γ , S F ⊢ G hn-ante-i m S (app F H) G p = hn-ante-i m (λ x → S (app x H)) F G (hn-ante-i' m S (headNorm m F) H G p) hn-ante-i _ _ (var _ _) _ p = p hn-ante-i _ _ N _ p = p hn-ante-i _ _ A _ p = p hn-ante-i _ _ Π _ p = p hn-ante-i _ _ i _ p = p hn-ante-i _ _ (lam _ _) _ p = p hn-ante-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t $o) → Γ , S (headNorm' m F H) ⊢ G → Γ , S (app F H) ⊢ G hn-ante-i' (suc m) S (lam _ F) H G p with hn-ante-i m S (sub H F) G p hn-ante-i' (suc _) S (lam _ _) _ _ _ | p' = reduce {_} {_} {_} {_} {_} {S} p' hn-ante-i' 0 _ (lam _ _) _ _ p = p hn-ante-i' zero _ (var _ _) _ _ p = p hn-ante-i' (suc _) _ (var _ _) _ _ p = p hn-ante-i' zero _ N _ _ p = p hn-ante-i' (suc _) _ N _ _ p = p hn-ante-i' zero _ A _ _ p = p hn-ante-i' (suc _) _ A _ _ p = p hn-ante-i' zero _ Π _ _ p = p hn-ante-i' (suc _) _ Π _ _ p = p hn-ante-i' zero _ i _ _ p = p hn-ante-i' (suc _) _ i _ _ p = p hn-ante-i' zero _ (app _ _) _ _ p = p hn-ante-i' (suc _) _ (app _ _) _ _ p = p hn-ante : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} (m : ℕ) (F : Form Γ-t $o) (G : Form Γ-t $o) → Γ , headNorm m F ⊢ G → Γ , F ⊢ G hn-ante m F G p = hn-ante-i m (λ x → x) F G p mutual hn-ante-eq-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) (G H : Form Γ-t α) → Γ , S (headNorm m F) ⊢ G == H → Γ , S F ⊢ G == H hn-ante-eq-i m S (app F I) G H p = hn-ante-eq-i m (λ x → S (app x I)) F G H (hn-ante-eq-i' m S (headNorm m F) I G H p) hn-ante-eq-i _ _ (var _ _) _ _ p = p hn-ante-eq-i _ _ N _ _ p = p hn-ante-eq-i _ _ A _ _ p = p hn-ante-eq-i _ _ Π _ _ p = p hn-ante-eq-i _ _ i _ _ p = p hn-ante-eq-i _ _ (lam _ _) _ _ p = p hn-ante-eq-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (I : Form Γ-t γ) (G H : Form Γ-t α) → Γ , S (headNorm' m F I) ⊢ G == H → Γ , S (app F I) ⊢ G == H hn-ante-eq-i' (suc m) S (lam _ F) I G H p with hn-ante-eq-i m S (sub I F) G H p hn-ante-eq-i' (suc _) S (lam _ _) _ _ _ _ | p' = reduce {_} {_} {_} {_} {_} {_} {S} p' hn-ante-eq-i' 0 _ (lam _ _) _ _ _ p = p hn-ante-eq-i' zero _ (var _ _) _ _ _ p = p hn-ante-eq-i' (suc _) _ (var _ _) _ _ _ p = p hn-ante-eq-i' zero _ N _ _ _ p = p hn-ante-eq-i' (suc _) _ N _ _ _ p = p hn-ante-eq-i' zero _ A _ _ _ p = p hn-ante-eq-i' (suc _) _ A _ _ _ p = p hn-ante-eq-i' zero _ Π _ _ _ p = p hn-ante-eq-i' (suc _) _ Π _ _ _ p = p hn-ante-eq-i' zero _ i _ _ _ p = p hn-ante-eq-i' (suc _) _ i _ _ _ p = p hn-ante-eq-i' zero _ (app _ _) _ _ _ p = p hn-ante-eq-i' (suc _) _ (app _ _) _ _ _ p = p hn-ante-eq : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t $o) (G H : Form Γ-t α) → Γ , headNorm m F ⊢ G == H → Γ , F ⊢ G == H hn-ante-eq m F G H p = hn-ante-eq-i m (λ x → x) F G H p -- ------------------------------------ head-& : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ & G₁) ↔ (F₂ & G₂) head-& p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-const _ N)) (simp (head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₁)))) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₂)))) head-|| : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ || G₁) ↔ (F₂ || G₂) head-|| p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) p₁)) p₂ head-=> : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ => G₁) ↔ (F₂ => G₂) head-=> p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₁)))) p₂ head-~ : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ (~ F₁) ↔ (~ F₂) head-~ p = head-app _ _ _ _ _ _ (simp (head-const _ N)) p head-== : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} {F₁ F₂ G₁ G₂ : Form Γ-t α} → Γ ⊢ α ∋ F₁ == F₂ → Γ ⊢ α ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ == G₁) ↔ (F₂ == G₂) head-== p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ _)) p₁)) p₂
{ "alphanum_fraction": 0.4902003723, "avg_line_length": 48.0684210526, "ext": "agda", "hexsha": "12e085c420e60842fbe5d9d97dcbdb61ae7e08b5", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-15T11:51:19.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-17T20:28:10.000Z", "max_forks_repo_head_hexsha": "032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "frelindb/agsyHOL", "max_forks_repo_path": "soundness/ProofUtilities.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "frelindb/agsyHOL", "max_issues_repo_path": "soundness/ProofUtilities.agda", "max_line_length": 257, "max_stars_count": 17, "max_stars_repo_head_hexsha": "032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "frelindb/agsyHOL", "max_stars_repo_path": "soundness/ProofUtilities.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-19T20:53:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-04T14:38:28.000Z", "num_tokens": 4415, "size": 9133 }
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.Exactness open import cohomology.Choice module cohomology.Theory where record CohomologyTheory i : Type (lsucc i) where field C : ℤ → Ptd i → Group i CEl : ℤ → Ptd i → Type i CEl n X = Group.El (C n X) Cid : (n : ℤ) (X : Ptd i) → CEl n X Cid n X = GroupStructure.ident (Group.group-struct (C n X)) ⊙CEl : ℤ → Ptd i → Ptd i ⊙CEl n X = ⊙[ CEl n X , Cid n X ] field CF-hom : (n : ℤ) {X Y : Ptd i} → fst (X ⊙→ Y) → (C n Y →ᴳ C n X) CF-ident : (n : ℤ) {X : Ptd i} → CF-hom n {X} {X} (⊙idf X) == idhom (C n X) CF-comp : (n : ℤ) {X Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y)) → CF-hom n (g ⊙∘ f) == CF-hom n f ∘ᴳ CF-hom n g CF : (n : ℤ) {X Y : Ptd i} → fst (X ⊙→ Y) → fst (⊙CEl n Y ⊙→ ⊙CEl n X) CF n f = GroupHom.⊙f (CF-hom n f) field C-abelian : (n : ℤ) (X : Ptd i) → is-abelian (C n X) C-Susp : (n : ℤ) (X : Ptd i) → C (succ n) (⊙Susp X) == C n X C-exact : (n : ℤ) {X Y : Ptd i} (f : fst (X ⊙→ Y)) → is-exact (CF n (⊙cfcod f)) (CF n f) C-additive : (n : ℤ) {I : Type i} (Z : I → Ptd i) → ((W : I → Type i) → has-choice ⟨0⟩ I W) → C n (⊙BigWedge Z) == Πᴳ I (C n ∘ Z) {- A quick useful special case of C-additive: C n (X ∨ Y) == C n X × C n Y -} C-binary-additive : (n : ℤ) (X Y : Ptd i) → C n (X ⊙∨ Y) == C n X ×ᴳ C n Y C-binary-additive n X Y = ap (C n) (! (BigWedge-Bool-⊙path Pick)) ∙ C-additive n _ (λ _ → Bool-has-choice) ∙ Πᴳ-Bool-is-×ᴳ (C n ∘ Pick) where Pick : Lift {j = i} Bool → Ptd i Pick (lift true) = X Pick (lift false) = Y record OrdinaryTheory i : Type (lsucc i) where constructor ordinary-theory field cohomology-theory : CohomologyTheory i open CohomologyTheory cohomology-theory public field C-dimension : (n : ℤ) → n ≠ O → C n (⊙Sphere O) == 0ᴳ
{ "alphanum_fraction": 0.5179704017, "avg_line_length": 29.1076923077, "ext": "agda", "hexsha": "9eaf37205e7bad45f704e23fda3dfcc982a832a3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_path": "cohomology/Theory.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "danbornside/HoTT-Agda", "max_issues_repo_path": "cohomology/Theory.agda", "max_line_length": 75, "max_stars_count": null, "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_path": "cohomology/Theory.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 854, "size": 1892 }
{-# OPTIONS --cubical --safe #-} module Relation.Nullary.Discrete.FromBoolean where open import Prelude open import Relation.Nullary.Discrete module _ {a} {A : Type a} (_≡ᴮ_ : A → A → Bool) (sound : ∀ x y → T (x ≡ᴮ y) → x ≡ y) (complete : ∀ x → T (x ≡ᴮ x)) where from-bool-eq : Discrete A from-bool-eq x y = iff-dec (sound x y iff flip (subst (λ z → T (x ≡ᴮ z))) (complete x)) (T? (x ≡ᴮ y))
{ "alphanum_fraction": 0.545045045, "avg_line_length": 26.1176470588, "ext": "agda", "hexsha": "de39b5a2ce0ed793101de9f43e947226a4c986d8", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Relation/Nullary/Discrete/FromBoolean.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Relation/Nullary/Discrete/FromBoolean.agda", "max_line_length": 86, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Relation/Nullary/Discrete/FromBoolean.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 163, "size": 444 }
module calculus-examples where open import Data.List using (List ; _∷_ ; [] ; _++_) open import Data.List.Any using (here ; there ; any) open import Data.List.Any.Properties open import Data.OrderedListMap open import Data.Sum using (inj₁ ; inj₂ ; _⊎_) open import Data.Maybe.Base open import Data.Empty using (⊥ ; ⊥-elim) open import Data.Bool.Base using (true ; false) open import Relation.Nullary using (Dec ; yes ; no ; ¬_) open import Agda.Builtin.Equality using (refl ; _≡_) open import Relation.Nullary.Decidable using (⌊_⌋) open import Relation.Binary.PropositionalEquality using (subst ; cong ; sym ; trans) open import calculus open import utility open import Esterel.Environment as Env open import Esterel.Variable.Signal as Signal using (Signal ; _ₛ ; unknown ; present ; absent ; _≟ₛₜ_) open import Esterel.Variable.Shared as SharedVar using (SharedVar) open import Esterel.Variable.Sequential as SeqVar using (SeqVar) open import Esterel.Lang open import Esterel.Lang.CanFunction open import Esterel.Lang.CanFunction.Properties open import Esterel.Lang.CanFunction.SetSigMonotonic using (canₛ-set-sig-monotonic) open import Esterel.Lang.Properties open import Esterel.Lang.Binding open import Esterel.Context open import Esterel.CompletionCode as Code using () renaming (CompletionCode to Code) open import context-properties open import Esterel.Lang.CanFunction.Base using (canₛ-⊆-FV) open import Data.Nat as Nat using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_) open import Data.Nat.Properties.Simple using (+-comm) open import Data.Product using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_) open import eval {- This example is not true (and not provable under the current calculus) {- rewriting a present to the true branch -} {- cannot prove without the `signal` form -} ex1 : ∀ S p q -> CB p -> signl S (emit S >> (present S ∣⇒ p ∣⇒ q)) ≡ₑ signl S (emit S >> p) # [] ex1 S p q CBp = calc where θS→unk : Env θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] [] S∈θS→unk : SigMap.∈Dom S (sig θS→unk) S∈θS→unk = sig-∈-single S Signal.unknown θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk θS→pre : Env θS→pre = set-sig{S} θS→unk S∈θS→unk Signal.present S∈θS→pre : SigMap.∈Dom S (sig θS→pre) S∈θS→pre = sig-set-mono' {S} {S} {θS→unk} {Signal.present} {S∈θS→unk} S∈θS→unk θS→pre[S]≡pre : sig-stats{S = S} θS→pre S∈θS→pre ≡ Signal.present θS→pre[S]≡pre = sig-putget{S} {θS→unk} {Signal.present} S∈θS→unk S∈θS→pre θS→unk[S]≠absent : ¬ sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.absent θS→unk[S]≠absent is rewrite θS→unk[S]≡unk = unknotabs is where unknotabs : Signal.unknown ≡ Signal.absent → ⊥ unknotabs () CBsignalS[emitS>>p] : CB (signl S (emit S >> p)) CBsignalS[emitS>>p] = CBsig (CBseq (CBemit{S}) CBp ((λ z → λ ()) , (λ z → λ ()) , (λ z → λ ()))) calc : signl S (emit S >> (present S ∣⇒ p ∣⇒ q)) ≡ₑ signl S (emit S >> p) # [] calc = ≡ₑtran {r = (ρ θS→unk · (emit S >> (present S ∣⇒ p ∣⇒ q)))} (≡ₑstep [raise-signal]) (≡ₑtran {r = (ρ θS→pre · (nothin >> (present S ∣⇒ p ∣⇒ q)))} (≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole))) (≡ₑtran {r = (ρ θS→pre · (present S ∣⇒ p ∣⇒ q))} (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [seq-done])) (≡ₑtran {r = (ρ θS→pre · p)} (≡ₑstep ([is-present] S S∈θS→pre θS→pre[S]≡pre dehole)) (≡ₑsymm CBsignalS[emitS>>p] (≡ₑtran {r = (ρ θS→unk · (emit S >> p))} (≡ₑstep [raise-signal]) (≡ₑtran {r = (ρ θS→pre · (nothin >> p))} (≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole))) (≡ₑtran {r = ρ θS→pre · p} (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [seq-done])) ≡ₑrefl))))))) -} Canₛpresent-fact : ∀ S p q -> (Signal.unwrap S) ∈ Canₛ (present S ∣⇒ p ∣⇒ q) (Θ SigMap.[ S ↦ Signal.unknown ] [] []) -> (Signal.unwrap S ∈ Canₛ p (Θ SigMap.[ S ↦ Signal.unknown ] [] [])) ⊎ (Signal.unwrap S ∈ Canₛ q (Θ SigMap.[ S ↦ Signal.unknown ] [] [])) Canₛpresent-fact S p q S∈Canₛ[presentSpq] with Env.Sig∈ S (Θ SigMap.[ S ↦ Signal.unknown ] [] []) Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ with ⌊ present ≟ₛₜ (Env.sig-stats{S} (Θ SigMap.[ S ↦ Signal.unknown ] [] []) S∈) ⌋ Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | true = inj₁ S∈Canₛ[presentSpq] Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | false with ⌊ absent ≟ₛₜ Env.sig-stats{S} (Θ SigMap.[ S ↦ Signal.unknown ] [] []) S∈ ⌋ Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | false | true = inj₂ S∈Canₛ[presentSpq] Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | false | false = ++⁻ (Canₛ p (Θ SigMap.[ S ↦ Signal.unknown ] [] [])) S∈Canₛ[presentSpq] Canₛpresent-fact S p q _ | no ¬p = ⊥-elim (¬p (SigMap.update-in-keys [] S unknown)) {- rewriting a present to the false branch -} ex2b : ∀ S p q C -> CB (C ⟦ signl S q ⟧c) -> Signal.unwrap S ∉ (Canₛ p (Θ SigMap.[ S ↦ unknown ] [] [])) -> Signal.unwrap S ∉ (Canₛ q (Θ SigMap.[ S ↦ unknown ] [] [])) -> signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ signl S q # C ex2b S p q C CBq s∉Canₛp s∉Canₛq = calc where θS→unk : Env θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] [] S∈θS→unk : SigMap.∈Dom S (sig θS→unk) S∈θS→unk = sig-∈-single S Signal.unknown θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk θS→abs : Env θS→abs = set-sig{S} θS→unk S∈θS→unk Signal.absent S∈θS→abs : SigMap.∈Dom S (sig θS→abs) S∈θS→abs = sig-set-mono' {S} {S} {θS→unk} {Signal.absent} {S∈θS→unk} S∈θS→unk θS→abs[S]≡abs : sig-stats{S = S} θS→abs S∈θS→abs ≡ Signal.absent θS→abs[S]≡abs = sig-putget{S} {θS→unk} {Signal.absent} S∈θS→unk S∈θS→abs S∉Canθₛq : Signal.unwrap S ∉ Canθₛ SigMap.[ S ↦ unknown ] 0 q []env S∉Canθₛq S∈Canθₛq = s∉Canₛq (Canθₛunknown->Canₛunknown S q S∈Canθₛq) S∉CanθₛpresentSpq : Signal.unwrap S ∉ Canθₛ SigMap.[ S ↦ unknown ] 0 (present S ∣⇒ p ∣⇒ q) []env S∉CanθₛpresentSpq S∈Canθₛ with Canθₛunknown->Canₛunknown S (present S ∣⇒ p ∣⇒ q) S∈Canθₛ ... | fact with Canₛpresent-fact S p q fact ... | inj₁ s∈Canₛp = s∉Canₛp s∈Canₛp ... | inj₂ s∈Canₛq = s∉Canₛq s∈Canₛq bwd : signl S q ≡ₑ (ρ⟨ θS→abs , WAIT ⟩· q) # C bwd = ≡ₑtran (≡ₑstep [raise-signal]) (≡ₑtran (≡ₑstep ([absence] S S∈θS→unk θS→unk[S]≡unk S∉Canθₛq)) ≡ₑrefl) fwd : signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ (ρ⟨ θS→abs , WAIT ⟩· q) # C fwd = ≡ₑtran (≡ₑstep [raise-signal]) (≡ₑtran (≡ₑstep ([absence] S S∈θS→unk θS→unk[S]≡unk S∉CanθₛpresentSpq)) (≡ₑtran (≡ₑstep ([is-absent] S S∈θS→abs θS→abs[S]≡abs dehole)) ≡ₑrefl)) where calc : signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ signl S q # C calc = ≡ₑtran fwd (≡ₑsymm CBq bwd) ex2 : ∀ S p q C -> CB (C ⟦ signl S q ⟧c) -> (∀ status -> Signal.unwrap S ∉ (Canₛ p (Θ SigMap.[ S ↦ status ] [] []))) -> (∀ status -> Signal.unwrap S ∉ (Canₛ q (Θ SigMap.[ S ↦ status ] [] []))) -> signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ signl S q # C ex2 S p q C CB noSp noSq = ex2b S p q C CB (noSp unknown) (noSq unknown) {- Although true, the this example is not provable under the current calculus {- lifting an emit out of a par -} ex3 : ∀ S p q -> CB (p ∥ q) -> signl S ((emit S >> p) ∥ q) ≡ₑ signl S (emit S >> (p ∥ q)) # [] ex3 S p q CBp∥q = calc where θS→unk : Env θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] [] S∈θS→unk : SigMap.∈Dom S (sig θS→unk) S∈θS→unk = sig-∈-single S Signal.unknown θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk θS→pre : Env θS→pre = set-sig{S} θS→unk S∈θS→unk Signal.present θS→unk[S]≠absent : ¬ sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.absent θS→unk[S]≠absent is rewrite θS→unk[S]≡unk = unknotabs is where unknotabs : Signal.unknown ≡ Signal.absent → ⊥ unknotabs () calc : signl S ((emit S >> p) ∥ q) ≡ₑ signl S (emit S >> (p ∥ q)) # [] calc = ≡ₑtran {r = ρ⟨ θS→unk · ((emit S >> p) ∥ q)} (≡ₑstep [raise-signal]) (≡ₑtran {r = ρ θS→pre · (nothin >> p ∥ q)} (≡ₑstep ([emit]{S = S} S∈θS→unk θS→unk[S]≠absent (depar₁ (deseq dehole)))) (≡ₑtran {r = ρ θS→pre · (p ∥ q)} (≡ₑctxt (dcenv (dcpar₁ dchole)) (dcenv (dcpar₁ dchole)) (≡ₑstep [seq-done])) (≡ₑsymm (CBsig (CBseq CBemit CBp∥q (((λ z → λ ()) , (λ z → λ ()) , (λ z → λ ()))))) (≡ₑtran {r = ρ θS→unk · (emit S >> (p ∥ q))} (≡ₑstep [raise-signal]) (≡ₑtran (≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole))) (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [seq-done]))))))) -} {- pushing a trap across a par -} ex4 : ∀ n p q -> CB p -> done q -> p ≡ₑ q # [] -> (trap (exit (suc n) ∥ p)) ≡ₑ (exit n ∥ trap p) # [] ex4 = ex4-split where basealwaysdistinct : ∀ x -> distinct base x basealwaysdistinct x = (λ { z () x₂ }) , (λ { z () x₂ }) , (λ { z () x₂}) CBplugrpartrap : ∀ n -> ∀ {r r′ BVp FVp} -> CorrectBinding r BVp FVp → r′ ≐ ceval (epar₂ (exit n)) ∷ ceval etrap ∷ [] ⟦ r ⟧c → CB r′ CBplugrpartrap n {p} {p′} {BVp} {FVp} CBp r′dc with BVFVcorrect p BVp FVp CBp | unplugc r′dc ... | refl , refl | refl = CBpar CBexit (CBtrap CBp) (basealwaysdistinct BVp) (basealwaysdistinct (BVars p)) (basealwaysdistinct (FVars p)) (λ { _ () _ }) CBplugtraprpar : ∀ n -> {r r′ : Term} {BVp FVp : Σ (List ℕ) (λ x → List ℕ × List ℕ)} → CorrectBinding r BVp FVp → r′ ≐ ceval etrap ∷ ceval (epar₂ (exit (suc n))) ∷ [] ⟦ r ⟧c → CB r′ CBplugtraprpar n {r} {r′} {BVp} {FVp} CBr r′C with unplugc r′C ... | refl with BVFVcorrect r BVp FVp CBr ... | refl , refl = CBtrap (CBpar CBexit CBr (basealwaysdistinct BVp) (basealwaysdistinct (BVars r)) (basealwaysdistinct (FVars r)) (λ { _ () _})) ex4-split : ∀ n p q -> CB p -> done q -> p ≡ₑ q # [] -> (trap (exit (suc n) ∥ p)) ≡ₑ (exit n ∥ trap p) # [] ex4-split n p .nothin CBp (dhalted hnothin) p≡ₑnothin = ≡ₑtran {r = trap (exit (suc n) ∥ nothin)} (≡ₑctxt (dctrap (dcpar₂ dchole)) (dctrap (dcpar₂ dchole)) (≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑnothin)) (≡ₑtran {r = trap (exit (suc n))} (≡ₑctxt (dctrap dchole) (dctrap dchole) (≡ₑtran (≡ₑstep [par-swap]) (≡ₑstep ([par-nothing] (dhalted (hexit (suc n))))))) (≡ₑtran {r = exit n} (≡ₑstep ([trap-done] (hexit (suc n)))) (≡ₑsymm (CBpar CBexit (CBtrap CBp) (basealwaysdistinct (BVars p)) (basealwaysdistinct (BVars p)) (basealwaysdistinct (FVars p)) (λ { _ () _ })) (≡ₑtran {r = exit n ∥ trap nothin} (≡ₑctxt (dcpar₂ (dctrap dchole)) (dcpar₂ (dctrap dchole)) (≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑnothin)) (≡ₑtran {r = exit n ∥ nothin} (≡ₑctxt (dcpar₂ dchole) (dcpar₂ dchole) (≡ₑstep ([trap-done] hnothin))) (≡ₑtran {r = nothin ∥ exit n} (≡ₑstep [par-swap]) (≡ₑtran {r = exit n} (≡ₑstep ([par-nothing] (dhalted (hexit n)))) ≡ₑrefl))))))) ex4-split n p .(exit 0) CBp (dhalted (hexit 0)) p≡ₑexit0 = ≡ₑtran {r = trap (exit (suc n) ∥ exit 0) } (≡ₑctxt (dctrap (dcpar₂ dchole)) (dctrap (dcpar₂ dchole)) (≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑexit0)) (≡ₑtran {r = trap (exit (suc n))} (≡ₑctxt (dctrap dchole) (dctrap dchole) (≡ₑstep ([par-2exit] (suc n) zero))) (≡ₑtran {r = exit n} (≡ₑstep ([trap-done] (hexit (suc n)))) (≡ₑsymm (CBpar CBexit (CBtrap CBp) (basealwaysdistinct (BVars p)) (basealwaysdistinct (BVars p)) (basealwaysdistinct (FVars p)) (λ { _ () _ })) (≡ₑtran {r = exit n ∥ trap (exit 0)} (≡ₑctxt (dcpar₂ (dctrap dchole)) (dcpar₂ (dctrap dchole)) (≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑexit0)) (≡ₑtran {r = exit n ∥ nothin } (≡ₑctxt (dcpar₂ dchole) (dcpar₂ dchole) (≡ₑstep ([trap-done] (hexit zero)))) (≡ₑtran {r = nothin ∥ exit n} (≡ₑstep [par-swap]) (≡ₑtran {r = exit n} (≡ₑstep ([par-nothing] (dhalted (hexit n)))) ≡ₑrefl))))))) ex4-split n p .(exit (suc m)) CBp (dhalted (hexit (suc m))) p≡ₑexitm = ≡ₑtran {r = trap (exit (suc n) ∥ exit (suc m)) } (≡ₑctxt (dctrap (dcpar₂ dchole)) (dctrap (dcpar₂ dchole)) (≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑexitm)) (≡ₑtran {r = trap (exit (suc n ⊔ℕ (suc m)))} (≡ₑctxt (dctrap dchole) (dctrap dchole) (≡ₑstep ([par-2exit] (suc n) (suc m)))) (≡ₑtran {r = ↓_ {p = (exit (suc n ⊔ℕ (suc m)))} (hexit (suc n ⊔ℕ (suc m))) } (≡ₑstep ([trap-done] (hexit (suc (n ⊔ℕ m))))) (≡ₑsymm (CBpar CBexit (CBtrap CBp) (basealwaysdistinct (BVars p)) (basealwaysdistinct (BVars p)) (basealwaysdistinct (FVars p)) (λ { _ () _ })) (≡ₑtran {r = exit n ∥ trap (exit (suc m))} (≡ₑctxt (dcpar₂ (dctrap dchole)) (dcpar₂ (dctrap dchole)) (≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑexitm)) (≡ₑtran {r = exit n ∥ ↓_ {p = exit (suc m)} (hexit (suc m))} (≡ₑctxt (dcpar₂ dchole) (dcpar₂ dchole) (≡ₑstep ([trap-done] (hexit (suc m)))) ) (≡ₑtran {r = ↓_ {p = (exit (suc n ⊔ℕ (suc m)))} (hexit (suc n ⊔ℕ (suc m))) } (≡ₑstep ([par-2exit] n m)) ≡ₑrefl)))))) ex4-split n p q CBp (dpaused pausedq) p≡ₑq = ≡ₑtran {r = trap (exit (suc n) ∥ q)} (≡ₑctxt (dctrap (dcpar₂ dchole)) (dctrap (dcpar₂ dchole)) (≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑq)) (≡ₑtran {r = trap (exit (suc n))} (≡ₑctxt (dctrap dchole) (dctrap dchole) (≡ₑstep ([par-1exit] (suc n) pausedq))) (≡ₑtran {r = exit n} (≡ₑstep ([trap-done] (hexit (suc n)))) (≡ₑsymm (CBpar CBexit (CBtrap CBp) (basealwaysdistinct (BVars p)) (basealwaysdistinct (BVars p)) (basealwaysdistinct (FVars p)) (λ { _ () _ })) (≡ₑtran {r = exit n ∥ trap q} (≡ₑctxt (dcpar₂ (dctrap dchole)) (dcpar₂ (dctrap dchole)) (≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑq)) (≡ₑtran {r = exit n} (≡ₑstep ([par-1exit] n (ptrap pausedq))) ≡ₑrefl))))) {- lifting a signal out of an evaluation context -} ex5 : ∀ S p q r E -> CB r -> q ≐ E ⟦(signl S p)⟧e -> r ≐ E ⟦ p ⟧e -> (ρ⟨ []env , WAIT ⟩· q) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S r)) # [] ex5 S p q r E CBr decomp1 decomp2 = calc where θS→unk : Env θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] [] replugit : q ≐ Data.List.map ceval E ⟦ signl S p ⟧c -> E ⟦ ρ⟨ θS→unk , WAIT ⟩· p ⟧e ≐ Data.List.map ceval E ⟦ ρ⟨ θS→unk , WAIT ⟩· p ⟧c replugit x = ⟦⟧e-to-⟦⟧c Erefl calc : (ρ⟨ []env , WAIT ⟩· q) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S r)) # [] calc = ≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (E ⟦ (ρ⟨ θS→unk , WAIT ⟩· p) ⟧e)} (≡ₑctxt (dcenv (⟦⟧e-to-⟦⟧c decomp1)) (dcenv (replugit (⟦⟧e-to-⟦⟧c decomp1))) (≡ₑstep [raise-signal])) (≡ₑtran {r = ρ⟨ θS→unk , WAIT ⟩· (E ⟦ p ⟧e)} (≡ₑstep ([merge]{E = E} Erefl)) (≡ₑsymm (CBρ (CBsig CBr)) (≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (ρ⟨ θS→unk , WAIT ⟩· r)} (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [raise-signal])) (≡ₑstep ([merge] {E = []} (subst (\ x -> ρ⟨ θS→unk , WAIT ⟩· x ≐ [] ⟦ ρ⟨ θS→unk , WAIT ⟩· E ⟦ p ⟧e ⟧e) (unplug decomp2) dehole)))))) {- two specific examples of lifting a signal out of an evaluation context -} ex6 : ∀ S p q -> CB (p ∥ q) -> (ρ⟨ []env , WAIT ⟩· ((signl S p) ∥ q)) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S (p ∥ q))) # [] ex6 S p q CBp∥q = ex5 S p (signl S p ∥ q) (p ∥ q) ((epar₁ q) ∷ []) CBp∥q (depar₁ dehole) (depar₁ dehole) ex7 : ∀ S p q -> CB (p >> q) -> (ρ⟨ []env , WAIT ⟩· ((signl S p) >> q)) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S (p >> q))) # [] ex7 S p q CBp>>q = ex5 S p (signl S p >> q) (p >> q) ((eseq q) ∷ []) CBp>>q (deseq dehole) (deseq dehole) {- pushing a seq into a binding form (a signal in this case). this shows the need for the outer environment ρ [} · _ in order to manipulate the environment. -} ex8-worker : ∀ {BV FV} S p q -> CorrectBinding ((signl S p) >> q) BV FV -> (ρ⟨ []env , WAIT ⟩· (signl S p) >> q) ≡ₑ (ρ⟨ []env , WAIT ⟩· signl S (p >> q)) # [] ex8-worker S p q (CBseq {BVp = BVsigS·p} {FVq = FVq} (CBsig {BV = BVp} CBp) CBq BVsigS·p≠FVq) = ≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (ρ⟨ [S]-env S , WAIT ⟩· p) >> q} {C = []} (≡ₑctxt {C = []} {C′ = cenv []env WAIT ∷ ceval (eseq q) ∷ []} Crefl Crefl (≡ₑstep ([raise-signal] {p} {S}))) (≡ₑtran {r = ρ⟨ [S]-env S , WAIT ⟩· p >> q} {C = []} (≡ₑstep ([merge] (deseq dehole))) (≡ₑsymm (CBρ (CBsig (CBseq CBp CBq (⊆-respect-distinct-left (∪ʳ (+S S base) ⊆-refl) BVsigS·p≠FVq)))) (≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (ρ⟨ [S]-env S , WAIT ⟩· p >> q)} {C = []} (≡ₑctxt {C = []} {C′ = cenv []env WAIT ∷ []} Crefl Crefl (≡ₑstep ([raise-signal] {p >> q} {S}))) (≡ₑstep ([merge] dehole))))) ex8 : ∀ S p q -> CB ((signl S p) >> q) -> (ρ⟨ []env , WAIT ⟩· (signl S p) >> q) ≡ₑ (ρ⟨ []env , WAIT ⟩· signl S (p >> q)) # [] ex8 S p q cb = ex8-worker S p q cb {- rearranging signal forms -} ex9 : ∀ S1 S2 p -> CB p -> signl S1 (signl S2 p) ≡ₑ signl S2 (signl S1 p) # [] ex9 S1 S2 p CBp = ≡ₑtran {r = ρ⟨ (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) , WAIT ⟩· (signl S2 p)} (≡ₑstep [raise-signal]) (≡ₑtran {r = (ρ⟨ Θ SigMap.[ S1 ↦ Signal.unknown ] [] [] , WAIT ⟩· (ρ⟨ Θ SigMap.[ S2 ↦ Signal.unknown ] [] [] , WAIT ⟩· p))} (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [raise-signal])) (≡ₑtran {r = (ρ⟨ (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) ← (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) , A-max WAIT WAIT ⟩· p)} (≡ₑstep ([merge] dehole)) (≡ₑsymm (CBsig (CBsig CBp)) (≡ₑtran {r = ρ⟨ (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) , WAIT ⟩· (signl S1 p)} (≡ₑstep [raise-signal]) (≡ₑtran {r = (ρ⟨ Θ SigMap.[ S2 ↦ Signal.unknown ] [] [] , WAIT ⟩· (ρ⟨ Θ SigMap.[ S1 ↦ Signal.unknown ] [] [] , WAIT ⟩· p))} (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [raise-signal])) (≡ₑtran {r = (ρ⟨ (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) ← (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) , A-max WAIT WAIT ⟩· p)} (≡ₑstep ([merge] dehole)) (map-order-irr S1 S2 WAIT p))))))) where distinct-Ss-env'' : ∀ S1 S2 S3 -> ¬ Signal.unwrap S1 ≡ Signal.unwrap S2 -> Data.List.Any.Any (_≡_ S3) (Signal.unwrap S1 ∷ []) -> Data.List.Any.Any (_≡_ S3) (Signal.unwrap S2 ∷ []) -> ⊥ distinct-Ss-env'' S1 S2 S3 S1≠S2 (here S3=S1) (here S3=S2) rewrite S3=S1 = S1≠S2 S3=S2 distinct-Ss-env'' S1 S2 S3 S1≠S2 (here px) (there ()) distinct-Ss-env'' S1 S2 S3 S1≠S2 (there ()) S3∈Domθ2 distinct-Ss-env' : ∀ S1 S2 S3 -> ¬ Signal.unwrap S1 ≡ Signal.unwrap S2 -> Data.List.Any.Any (_≡_ S3) (Signal.unwrap S1 ∷ []) -> S3 ∈ proj₁ (Dom (Θ SigMap.[ S2 ↦ Signal.unknown ] [] [])) -> ⊥ distinct-Ss-env' S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2 rewrite SigMap.keys-1map S2 Signal.unknown = distinct-Ss-env'' S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2 distinct-Ss-env : ∀ S1 S2 S3 -> ¬ Signal.unwrap S1 ≡ Signal.unwrap S2 -> S3 ∈ proj₁ (Dom (Θ SigMap.[ S1 ↦ Signal.unknown ] [] [])) -> S3 ∈ proj₁ (Dom (Θ SigMap.[ S2 ↦ Signal.unknown ] [] [])) -> ⊥ distinct-Ss-env S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2 rewrite SigMap.keys-1map S1 Signal.unknown = distinct-Ss-env' S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2 distinct-doms : ∀ S1 S2 -> ¬ (Signal.unwrap S1 ≡ Signal.unwrap S2) -> distinct (Env.Dom (Θ SigMap.[ S1 ↦ Signal.unknown ] [] [])) (Env.Dom (Θ SigMap.[ S2 ↦ Signal.unknown ] [] [])) distinct-doms S1 S2 S1≠S2 = (λ {S3 S3∈θ1 S3∈θ2 -> distinct-Ss-env S1 S2 S3 S1≠S2 S3∈θ1 S3∈θ2}) , (λ x₁ x₂ → λ ()) , (λ x₁ x₂ → λ ()) map-order-irr' : ∀ S1 S2 -> (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) ← (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) ≡ (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) ← (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) map-order-irr' S1 S2 with (Signal.unwrap S1) Nat.≟ (Signal.unwrap S2) map-order-irr' S1 S2 | yes S1=S2 rewrite S1=S2 = refl map-order-irr' S1 S2 | no ¬S1=S2 = Env.←-comm ((Θ SigMap.[ S1 ↦ Signal.unknown ] [] [])) ((Θ SigMap.[ S2 ↦ Signal.unknown ] [] [])) (distinct-doms S1 S2 ¬S1=S2) map-order-irr : ∀ S1 S2 A p -> (ρ⟨ Θ SigMap.[ S2 ↦ Signal.unknown ] [] [] ← Θ SigMap.[ S1 ↦ Signal.unknown ] [] [] , A ⟩· p) ≡ₑ (ρ⟨ Θ SigMap.[ S1 ↦ Signal.unknown ] [] [] ← Θ SigMap.[ S2 ↦ Signal.unknown ] [] [] , A ⟩· p) # [] map-order-irr S1 S2 A p rewrite map-order-irr' S1 S2 = ≡ₑrefl {- dropping a loop whose body is just `exit` -} ex10 : ∀ C n -> (loop (exit n)) ≡ₑ (exit n) # C ex10 C n = ≡ₑtran (≡ₑstep [loop-unroll]) (≡ₑstep [loopˢ-exit]) {- (nothin ∥ p) ≡ₑ p, but only if we know that p goes to something that's done -} ex11 : ∀ p q -> CB p -> done q -> p ≡ₑ q # [] -> (nothin ∥ p) ≡ₑ p # [] ex11 = calc where ex11-pq : ∀ q C -> done q -> (nothin ∥ q) ≡ₑ q # C ex11-pq .nothin C (dhalted hnothin) = ≡ₑtran (≡ₑstep [par-swap]) (≡ₑstep ([par-nothing] (dhalted hnothin))) ex11-pq .(exit n) C (dhalted (hexit n)) = ≡ₑstep ([par-nothing] (dhalted (hexit n))) ex11-pq q C (dpaused p/paused) = ≡ₑstep ([par-nothing] (dpaused p/paused)) basealwaysdistinct : ∀ x -> distinct base x basealwaysdistinct x = (λ { z () x₂ }) , (λ { z () x₂ }) , (λ { z () x₂}) CBp->CBnothingp : {r r′ : Term} {BVp FVp : Σ (List ℕ) (λ x → List ℕ × List ℕ)} → CorrectBinding r BVp FVp → r′ ≐ ceval (epar₂ nothin) ∷ [] ⟦ r ⟧c → CB r′ CBp->CBnothingp {r} CBr r′dc with sym (unplugc r′dc) | BVFVcorrect _ _ _ CBr ... | refl | refl , refl = CBpar CBnothing CBr (basealwaysdistinct (BVars r)) (basealwaysdistinct (BVars r)) (basealwaysdistinct (FVars r)) (λ { _ () _ }) calc : ∀ p q -> CB p -> done q -> p ≡ₑ q # [] -> (nothin ∥ p) ≡ₑ p # [] calc p q CBp doneq p≡ₑq = ≡ₑtran {r = (nothin ∥ q)} (≡ₑctxt (dcpar₂ dchole) (dcpar₂ dchole) (≡ₑ-context [] _ CBp->CBnothingp p≡ₑq)) (≡ₑtran {r = q} (ex11-pq q [] doneq) (≡ₑsymm CBp p≡ₑq)) {- although true, can no longer prove {- an emit (first) in sequence is the same as emit in parallel -} ex12 : ∀ S p q -> CB p -> done q -> p ≡ₑ q # [] -> (signl S ((emit S) ∥ p)) ≡ₑ (signl S ((emit S) >> p)) # [] ex12 S p q CBp doneq p≡ₑq = calc where θS→unk : Env θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] [] S∈θS→unk : SigMap.∈Dom S (sig θS→unk) S∈θS→unk = sig-∈-single S Signal.unknown θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk θS→pre : Env θS→pre = set-sig{S} θS→unk S∈θS→unk Signal.present θS→unk[S]≠absent : ¬ sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.absent θS→unk[S]≠absent is rewrite θS→unk[S]≡unk = unknotabs is where unknotabs : Signal.unknown ≡ Signal.absent → ⊥ unknotabs () CBp->CBρθSp : {r r′ : Term} {BVp FVp : Σ (List ℕ) (λ x → List ℕ × List ℕ)} → CorrectBinding r BVp FVp → r′ ≐ cenv θS→pre ∷ [] ⟦ r ⟧c → CB r′ CBp->CBρθSp {r} CBr r′dc with sym (unplugc r′dc) | BVFVcorrect _ _ _ CBr ... | refl | refl , refl = CBρ CBr basealwaysdistinct : ∀ x -> distinct base x basealwaysdistinct x = (λ { z () x₂ }) , (λ { z () x₂ }) , (λ { z () x₂}) CBsiglSemitS>>p : CB (signl S (emit S >> p)) CBsiglSemitS>>p = CBsig (CBseq CBemit CBp (basealwaysdistinct (FVars p))) calc : (signl S ((emit S) ∥ p)) ≡ₑ (signl S ((emit S) >> p)) # [] calc = ≡ₑtran {r = ρ θS→unk · ((emit S) ∥ p)} (≡ₑstep [raise-signal]) (≡ₑtran {r = ρ θS→pre · (nothin ∥ p)} (≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (depar₁ dehole))) (≡ₑtran {r = ρ θS→pre · p} (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑ-context [] (cenv _ ∷ []) CBp->CBρθSp (ex11 p q CBp doneq p≡ₑq))) (≡ₑsymm CBsiglSemitS>>p (≡ₑtran {r = ρ θS→unk · (emit S >> p)} (≡ₑstep [raise-signal]) (≡ₑtran {r = ρ θS→pre · nothin >> p} (≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole))) (≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [seq-done]))))))) -}
{ "alphanum_fraction": 0.4970829333, "avg_line_length": 41.095599393, "ext": "agda", "hexsha": "626106d4dcfbad614d373c94f75f95f2947f4f05", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "florence/esterel-calculus", "max_forks_repo_path": "agda/calculus-examples.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "florence/esterel-calculus", "max_issues_repo_path": "agda/calculus-examples.agda", "max_line_length": 95, "max_stars_count": 3, "max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "florence/esterel-calculus", "max_stars_repo_path": "agda/calculus-examples.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z", "num_tokens": 10916, "size": 27082 }
interleaved mutual -- we don't do `data A : Set` data A where -- you don't have to actually define any constructor to trigger the error, the "where" is enough data B where b : B
{ "alphanum_fraction": 0.6683937824, "avg_line_length": 24.125, "ext": "agda", "hexsha": "7cb9e080dd42a518558c4128a6b42f0a1b0779a9", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue5558.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue5558.agda", "max_line_length": 100, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue5558.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 55, "size": 193 }
module getline where -- https://github.com/alhassy/AgdaCheatSheet#interacting-with-the-real-world-compilation-haskell-and-io open import Data.Nat using (ℕ; suc) open import Data.Nat.Show using (show) open import Data.Char using (Char) open import Data.List as L using (map; sum; upTo) open import Function using (_$_; const; _∘_) open import Data.String as S using (String; _++_; fromList) open import Agda.Builtin.Unit using (⊤) open import Codata.Musical.Colist using (take) open import Codata.Musical.Costring using (Costring) open import Data.Vec.Bounded as B using (toList) open import Agda.Builtin.Coinduction using (♯_) open import IO as IO using (run ; putStrLn ; IO) import IO.Primitive as Primitive infixr 1 _>>=_ _>>_ _>>=_ : ∀ {ℓ} {α β : Set ℓ} → IO α → (α → IO β) → IO β this >>= f = ♯ this IO.>>= λ x → ♯ f x _>>_ : ∀{ℓ} {α β : Set ℓ} → IO α → IO β → IO β x >> y = x >>= const y postulate getLine∞ : Primitive.IO Costring {-# FOREIGN GHC toColist :: [a] -> MAlonzo.Code.Codata.Musical.Colist.AgdaColist a toColist [] = MAlonzo.Code.Codata.Musical.Colist.Nil toColist (x : xs) = MAlonzo.Code.Codata.Musical.Colist.Cons x (MAlonzo.RTE.Sharp (toColist xs)) #-} {- Haskell's prelude is implicitly available; this is for demonstration. -} {-# FOREIGN GHC import Prelude as Haskell #-} {-# COMPILE GHC getLine∞ = fmap toColist Haskell.getLine #-} -- (1) -- getLine : IO Costring -- getLine = IO.lift getLine∞ getLine : IO String getLine = IO.lift $ getLine∞ Primitive.>>= (Primitive.return ∘ S.fromList ∘ B.toList ∘ take 100) postulate readInt : L.List Char → ℕ {-# COMPILE GHC readInt = \x -> read x :: Integer #-} main : Primitive.IO ⊤ main = run do putStrLn "Hello, world! I'm a compiled Agda program!" IO.putStrLn "What is your name?:" name ← getLine IO.putStrLn "Please enter a number:" num ← getLine let tri = show $ sum $ upTo $ suc $ readInt $ S.toList num putStrLn $ "The triangle number of " ++ num ++ " is " ++ tri putStrLn ("Bye, " ++ name) -- IO.putStrLn∞ ("Bye, " ++ name) {- If using approach (1) above. -}
{ "alphanum_fraction": 0.626344086, "avg_line_length": 33.3134328358, "ext": "agda", "hexsha": "b2b26610472573ed25960188b522cd7c9ce2b0f0", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/examples-that-run/getline/src-agda/getline.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/examples-that-run/getline/src-agda/getline.agda", "max_line_length": 103, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/examples-that-run/getline/src-agda/getline.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 679, "size": 2232 }
open import Level using () renaming (_⊔_ to _⊔ˡ_) open import Relation.Binary using (_⇒_; TotalOrder; Reflexive; Symmetric; Transitive; IsEquivalence; IsPreorder; Antisymmetric) module AKS.Extended {c ℓ₁ ℓ₂} (≤-totalOrder : TotalOrder c ℓ₁ ℓ₂) where open TotalOrder ≤-totalOrder using (_≈_; _≤_; total; isEquivalence) renaming (Carrier to C; refl to ≤-refl; reflexive to ≤-reflexive; trans to ≤-trans ) open IsEquivalence isEquivalence using () renaming (refl to ≈-refl; sym to ≈-sym; trans to ≈-trans) data Extended : Set c where -∞ : Extended ⟨_⟩ : C → Extended infixl 4 _≈ᵉ_ data _≈ᵉ_ : Extended → Extended → Set (c ⊔ˡ ℓ₁) where -∞≈ : -∞ ≈ᵉ -∞ ⟨_⟩ : ∀ {b t} → b ≈ t → ⟨ b ⟩ ≈ᵉ ⟨ t ⟩ ≈ᵉ-refl : Reflexive _≈ᵉ_ ≈ᵉ-refl { -∞} = -∞≈ ≈ᵉ-refl {⟨ _ ⟩} = ⟨ ≈-refl ⟩ ≈ᵉ-sym : Symmetric _≈ᵉ_ ≈ᵉ-sym -∞≈ = -∞≈ ≈ᵉ-sym ⟨ x≈y ⟩ = ⟨ ≈-sym x≈y ⟩ ≈ᵉ-trans : Transitive _≈ᵉ_ ≈ᵉ-trans -∞≈ -∞≈ = -∞≈ ≈ᵉ-trans ⟨ x≈y ⟩ ⟨ y≈z ⟩ = ⟨ ≈-trans x≈y y≈z ⟩ ≈ᵉ-isEquivalence : IsEquivalence _≈ᵉ_ ≈ᵉ-isEquivalence = record { refl = ≈ᵉ-refl ; sym = ≈ᵉ-sym ; trans = ≈ᵉ-trans } infixl 4 _≤ᵉ_ data _≤ᵉ_ : Extended → Extended → Set (c ⊔ˡ ℓ₂) where -∞≤_ : ∀ t → -∞ ≤ᵉ t ⟨_⟩ : ∀ {b t} → b ≤ t → ⟨ b ⟩ ≤ᵉ ⟨ t ⟩ ≤ᵉ-refl : Reflexive _≤ᵉ_ ≤ᵉ-refl { -∞} = -∞≤ -∞ ≤ᵉ-refl {⟨ _ ⟩} = ⟨ ≤-refl ⟩ ≤ᵉ-reflexive : _≈ᵉ_ ⇒ _≤ᵉ_ ≤ᵉ-reflexive -∞≈ = -∞≤ -∞ ≤ᵉ-reflexive ⟨ x≈y ⟩ = ⟨ ≤-reflexive x≈y ⟩ ≤ᵉ-trans : Transitive _≤ᵉ_ ≤ᵉ-trans {x} {y} {z} (-∞≤ _) (-∞≤ t) = -∞≤ t ≤ᵉ-trans {x} {y} {z} (-∞≤ _) ⟨ _ ⟩ = -∞≤ z ≤ᵉ-trans {x} {y} {z} ⟨ x≤y ⟩ ⟨ y≤z ⟩ = ⟨ (≤-trans x≤y y≤z) ⟩ ≤ᵉ-isPreorder : IsPreorder _≈ᵉ_ _≤ᵉ_ ≤ᵉ-isPreorder = record { isEquivalence = ≈ᵉ-isEquivalence ; reflexive = ≤ᵉ-reflexive ; trans = ≤ᵉ-trans } module ≤ᵉ-Reasoning where open import Relation.Binary.Reasoning.Base.Double ≤ᵉ-isPreorder public
{ "alphanum_fraction": 0.5728476821, "avg_line_length": 28.3125, "ext": "agda", "hexsha": "364d2e6145eee959a87dc3e119076e4cb7f18ca9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/thesis", "max_forks_repo_path": "proofs/AKS/Extended.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mckeankylej/thesis", "max_issues_repo_path": "proofs/AKS/Extended.agda", "max_line_length": 127, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/thesis", "max_stars_repo_path": "proofs/AKS/Extended.agda", "max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z", "num_tokens": 1010, "size": 1812 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.NType2 open import lib.types.Empty open import lib.types.Group open import lib.types.Int open import lib.types.List open import lib.types.Nat open import lib.types.Pi open import lib.types.Sigma module lib.types.Word {i} where module _ (A : Type i) where PlusMinus : Type i PlusMinus = Coprod A A Word : Type i Word = List PlusMinus module _ {A : Type i} where flip : PlusMinus A → PlusMinus A flip (inl a) = inr a flip (inr a) = inl a flip-flip : ∀ x → flip (flip x) == x flip-flip (inl x) = idp flip-flip (inr x) = idp Word-flip : Word A → Word A Word-flip = map flip Word-flip-flip : ∀ w → Word-flip (Word-flip w) == w Word-flip-flip nil = idp Word-flip-flip (x :: l) = ap2 _::_ (flip-flip x) (Word-flip-flip l) Word-exp : A → ℤ → Word A Word-exp a (pos 0) = nil Word-exp a (pos (S n)) = inl a :: Word-exp a (pos n) Word-exp a (negsucc 0) = inr a :: nil Word-exp a (negsucc (S n)) = inr a :: Word-exp a (negsucc n) module _ {A : Type i} {j} (G : Group j) where private module G = Group G PlusMinus-extendᴳ : (A → G.El) → (PlusMinus A → G.El) PlusMinus-extendᴳ f (inl a) = f a PlusMinus-extendᴳ f (inr a) = G.inv (f a) Word-extendᴳ : (A → G.El) → (Word A → G.El) Word-extendᴳ f = foldr G.comp G.ident ∘ map (PlusMinus-extendᴳ f) abstract Word-extendᴳ-++ : ∀ f l₁ l₂ → Word-extendᴳ f (l₁ ++ l₂) == G.comp (Word-extendᴳ f l₁) (Word-extendᴳ f l₂) Word-extendᴳ-++ f nil l₂ = ! $ G.unit-l _ Word-extendᴳ-++ f (x :: l₁) l₂ = ap (G.comp (PlusMinus-extendᴳ f x)) (Word-extendᴳ-++ f l₁ l₂) ∙ ! (G.assoc (PlusMinus-extendᴳ f x) (Word-extendᴳ f l₁) (Word-extendᴳ f l₂)) module _ {A : Type i} {j} (G : AbGroup j) where private module G = AbGroup G abstract PlusMinus-extendᴳ-comp : ∀ (f g : A → G.El) x → PlusMinus-extendᴳ G.grp (λ a → G.comp (f a) (g a)) x == G.comp (PlusMinus-extendᴳ G.grp f x) (PlusMinus-extendᴳ G.grp g x) PlusMinus-extendᴳ-comp f g (inl a) = idp PlusMinus-extendᴳ-comp f g (inr a) = G.inv-comp (f a) (g a) ∙ G.comm (G.inv (g a)) (G.inv (f a)) Word-extendᴳ-comp : ∀ (f g : A → G.El) l → Word-extendᴳ G.grp (λ a → G.comp (f a) (g a)) l == G.comp (Word-extendᴳ G.grp f l) (Word-extendᴳ G.grp g l) Word-extendᴳ-comp f g nil = ! (G.unit-l G.ident) Word-extendᴳ-comp f g (x :: l) = ap2 G.comp (PlusMinus-extendᴳ-comp f g x) (Word-extendᴳ-comp f g l) ∙ G.interchange (PlusMinus-extendᴳ G.grp f x) (PlusMinus-extendᴳ G.grp g x) (Word-extendᴳ G.grp f l) (Word-extendᴳ G.grp g l)
{ "alphanum_fraction": 0.6054319125, "avg_line_length": 31.5595238095, "ext": "agda", "hexsha": "e1cff052319d1acab1992b2ae3268d8f45a5b277", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "core/lib/types/Word.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_path": "core/lib/types/Word.agda", "max_line_length": 100, "max_stars_count": null, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "core/lib/types/Word.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1063, "size": 2651 }
open import Agda.Builtin.List open import Agda.Builtin.Nat open import Agda.Builtin.Reflection open import Agda.Builtin.Unit open import Common.Product {-# TERMINATING #-} Loop : Set Loop = Loop postulate loop : Loop data Box (A : Set) : Set where box : A → Box A {-# TERMINATING #-} Boxed-loop : Set Boxed-loop = Box Boxed-loop postulate boxed-loop : Boxed-loop test₁ : Boxed-loop test₁ = quoteGoal g in boxed-loop test₂ : Term test₂ = quoteTerm Loop test₃ : Loop → List (Arg Term) test₃ _ = quoteContext macro m₄ : Term → Term → TC ⊤ m₄ _ hole = unify hole (def (quote ⊤) []) test₄ : Set test₄ = m₄ Loop macro m₅ : Term → TC ⊤ m₅ hole = bindTC (inferType (def (quote loop) [])) λ A → unify hole A test₅ : Set test₅ = m₅ macro m₆ : Term → TC ⊤ m₆ hole = bindTC (checkType (def (quote Loop) []) (agda-sort (lit 0))) λ A → unify hole A test₆ : Set test₆ = m₆ macro m₇ : Term → TC ⊤ m₇ hole = bindTC (quoteTC Loop) λ A → unify hole A test₇ : Set test₇ = m₇ Vec : Set → Nat → Set Vec A zero = ⊤ Vec A (suc n) = A × Vec A n macro m₈ : Term → TC ⊤ m₈ hole = bindTC (reduce V) λ V → unify hole V where varg = arg (arg-info visible relevant) V = def (quote Vec) (varg (def (quote Boxed-loop) []) ∷ varg (lit (nat 1)) ∷ []) test₈ : Set test₈ = m₈
{ "alphanum_fraction": 0.5895788722, "avg_line_length": 15.5666666667, "ext": "agda", "hexsha": "97eda2536f2db7d98c197c20c1af5f557ed7187b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "hborum/agda", "max_forks_repo_path": "test/Succeed/Less-normalisation-in-reflection-machinery.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Succeed/Less-normalisation-in-reflection-machinery.agda", "max_line_length": 70, "max_stars_count": 3, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Succeed/Less-normalisation-in-reflection-machinery.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 503, "size": 1401 }
-- V: letpair (x,y) = (V,W) in E --> E[ V,W / x,y ] module Properties.StepPair where open import Data.List open import Data.List.All open import Data.Product open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Typing open import Syntax open import Global open import Values open import Session open import Properties.Base -- this will require multiple steps to execute mklhs : ∀ {Φ t₁ t₂} → Expr (t₁ ∷ t₂ ∷ Φ) TUnit → Expr (t₁ ∷ t₂ ∷ Φ) TUnit mklhs {Φ} E = letbind (left (left (split-all-right Φ))) (pair (left (rght [])) (here []) (here [])) (letpair (left (split-all-right Φ)) (here []) E) reduction : ∀ {t₁ t₂} → (E : Expr (t₁ ∷ t₂ ∷ []) TUnit) → (v₁ : Val [] t₁) → (v₂ : Val [] t₂) → let ϱ = vcons ss-[] v₁ (vcons ss-[] v₂ (vnil []-inactive)) in let lhs = (run (left (left [])) ss-[] (mklhs E) ϱ (halt []-inactive UUnit)) in let rhs = (run (left (left [])) ss-[] E ϱ (halt []-inactive UUnit)) in restart lhs ≡ rhs reduction E v₁ v₂ with split-env (left (left [])) (vcons ss-[] v₁ (vcons ss-[] v₂ (vnil []-inactive))) ... | spe = refl reduction-open-type : Set reduction-open-type = ∀ {Φ t₁ t₂} (E : Expr (t₁ ∷ t₂ ∷ Φ) TUnit) (ϱ : VEnv [] (t₁ ∷ t₂ ∷ Φ)) → let lhs = run (left (left (split-all-left Φ))) ss-[] (mklhs E) ϱ (halt []-inactive UUnit) in let rhs = run (left (left (split-all-left _))) ss-[] E ϱ (halt []-inactive UUnit) in restart lhs ≡ rhs reduction-open : reduction-open-type reduction-open {Φ} E (vcons ss-[] v (vcons ss-[] v₁ ϱ)) rewrite split-rotate-lemma {Φ} | split-env-right-lemma0 ϱ with ssplit-compose3 ss-[] ss-[] ... | ssc3 rewrite split-env-right-lemma0 ϱ | split-rotate-lemma {Φ} = refl
{ "alphanum_fraction": 0.6130334487, "avg_line_length": 29.8965517241, "ext": "agda", "hexsha": "cdb49d2651e2ff6cec220d8b1f8033b8c8efaf12", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "peterthiemann/definitional-session", "max_forks_repo_path": "src/Properties/StepPair.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "peterthiemann/definitional-session", "max_issues_repo_path": "src/Properties/StepPair.agda", "max_line_length": 96, "max_stars_count": 9, "max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "peterthiemann/definitional-session", "max_stars_repo_path": "src/Properties/StepPair.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z", "num_tokens": 642, "size": 1734 }
{-# OPTIONS --without-K #-} module Explore.README where -- The core types behind exploration functions open import Explore.Core -- The core properties behind exploration functions open import Explore.Properties -- Lifting the dependent axiom of choice to sums and products open import Explore.BigDistr -- Constructions on top of exploration functions open import Explore.Explorable -- Specific constructions on top of summation functions open import Explore.Summable -- Exploration of Cartesian products (and Σ-types) open import Explore.Product -- Exploration of disjoint sums open import Explore.Sum -- Exploration of base types 𝟘, 𝟙, 𝟚, Fin n open import Explore.Zero open import Explore.One open import Explore.Two open import Explore.Fin -- A type universe of explorable types open import Explore.Universe.Type open import Explore.Universe.Base open import Explore.Universe -- Transporting explorations across isomorphisms open import Explore.Isomorphism -- From binary trees to explorations and back open import Explore.BinTree -- Exploration functions form a monad open import Explore.Monad -- Some high-level properties about group homomorphisms and -- group isomorphisms. -- For instance the indistinguisability (One-time-pad like) for groups open import Explore.Group -- In a (bit) guessing game, open import Explore.GuessingGameFlipping -- An example with a specific type: 6 sided dice open import Explore.Dice -- TODO unfinished -- BROKEN open import Explore.Function.Fin open import Explore.Subset
{ "alphanum_fraction": 0.7989521938, "avg_line_length": 25.8813559322, "ext": "agda", "hexsha": "2b2682ad5832947a9e7825f5781feeedf2cdb60d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_path": "lib/Explore/README.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_path": "lib/Explore/README.agda", "max_line_length": 70, "max_stars_count": 2, "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_path": "lib/Explore/README.agda", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "num_tokens": 340, "size": 1527 }
open import Relation.Binary using (IsDecEquivalence) open import Agda.Builtin.Equality module UnifyMguCorrectG (FunctionName : Set) ⦃ isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) ⦄ (PredicateName VariableName : Set) where open import UnifyTermF FunctionName open import UnifyMguF FunctionName open import UnifyMguCorrectF FunctionName open import Data.Nat open import Data.Vec open import Function open import Data.Fin renaming (thin to thinF; thick to thickF) data Formula (n : ℕ) : Set where atomic : PredicateName → ∀ {t} → Vec (Term n) t → Formula n logical : Formula n → Formula n → Formula n quantified : Formula (suc n) → Formula n open import Relation.Binary.PropositionalEquality instance ThinFormula : Thin Formula Thin.thin ThinFormula x (atomic x₁ x₂) = atomic x₁ (thin x x₂) Thin.thin ThinFormula x (logical x₁ x₂) = logical (thin x x₁) (thin x x₂) Thin.thin ThinFormula x (quantified x₁) = quantified (thin zero x₁) Thin.thinfact1 ThinFormula f {atomic pn1 ts1} {atomic pn2 ts2} r = {!!} Thin.thinfact1 ThinFormula f {atomic x x₁} {logical y y₁} () Thin.thinfact1 ThinFormula f {atomic x x₁} {quantified y} () Thin.thinfact1 ThinFormula f {logical x x₁} {atomic x₂ x₃} () Thin.thinfact1 ThinFormula f {logical x x₁} {logical y y₁} x₂ = {!!} Thin.thinfact1 ThinFormula f {logical x x₁} {quantified y} () Thin.thinfact1 ThinFormula f {quantified x} {atomic x₁ x₂} () Thin.thinfact1 ThinFormula f {quantified x} {logical y y₁} () Thin.thinfact1 ThinFormula f {quantified x} {quantified y} x₁ = {!!} foo~ : ∀ {m₁ n₁} → (Fin m₁ → Term n₁) → Fin (suc m₁) → Term (suc n₁) foo~ f = (λ { zero → i zero ; (suc x) → thin zero (f x)}) foo~i≐i : ∀ {m} → foo~ {m} i ≐ i foo~i≐i zero = refl foo~i≐i (suc x) = refl instance SubstitutionFormula : Substitution Formula Substitution._◃_ SubstitutionFormula = _◃′_ where _◃′_ : ∀ {m n} -> (f : m ~> n) -> Formula m -> Formula n f ◃′ atomic 𝑃 τs = atomic 𝑃 (f ◃ τs) f ◃′ logical φ₁ φ₂ = logical (f ◃ φ₁) (f ◃ φ₂) f ◃′ quantified φ = quantified (foo~ f ◃ φ) instance SubstitutionExtensionalityFormula : SubstitutionExtensionality Formula SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (atomic x₁ x₂) = cong (atomic x₁) (◃ext x x₂) SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (logical t t₁) = cong₂ logical (◃ext x t) (◃ext x t₁) SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (quantified t) = cong quantified ((◃ext (λ { zero → refl ; (suc x₁) → cong (mapTerm suc) (x x₁)}) t)) -- instance SubFact1Formula : Sub.Fact1 Formula Sub.Fact1.fact1 SubFact1Formula (atomic x x₁) = cong (atomic x) (Sub.fact1 x₁) Sub.Fact1.fact1 SubFact1Formula (logical t t₁) = cong₂ logical (Sub.fact1 t) (Sub.fact1 t₁) Sub.Fact1.fact1 SubFact1Formula {n} (quantified φ) = cong quantified (trans (◃ext {Formula} {_} {_} {foo~ {_} i} {i} (foo~i≐i {_}) φ) (Sub.fact1 φ)) Unifies⋆F : ∀ {m} (s t : Formula m) -> Property⋆ m Unifies⋆F s t f = f ◃ s ≡ f ◃ t
{ "alphanum_fraction": 0.7023178808, "avg_line_length": 44.4117647059, "ext": "agda", "hexsha": "72ea0474c69abe1c522a64c00ad95e2d356f4678", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-1/UnifyMguCorrectG.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-1/UnifyMguCorrectG.agda", "max_line_length": 172, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-1/UnifyMguCorrectG.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1045, "size": 3020 }
module Ordinals where import Level open import Data.Product open import Relation.Binary.PropositionalEquality open import Function open import Data.Nat using (ℕ) renaming (zero to z; suc to s) open import Data.Empty postulate ext₀ : Extensionality Level.zero Level.zero ext₁ : Extensionality Level.zero (Level.suc Level.zero) data Ord : Set₁ where zero : Ord succ : Ord → Ord sup : (A : Set) → (f : A → Ord) → Ord infixl 10 _≤_ module CountableOrdinals where inj-ℕ-Ord : ℕ → Ord inj-ℕ-Ord z = zero inj-ℕ-Ord (s n) = succ (inj-ℕ-Ord n) ω : Ord ω = sup ℕ inj-ℕ-Ord _∔_ : Ord → ℕ → Ord α ∔ z = α α ∔ (s n) = succ (α ∔ n) _ẋ_ : Ord → ℕ → Ord α ẋ z = zero α ẋ (s n) = sup ℕ (λ k → (α ẋ n) ∔ k) _^^_ : Ord → ℕ → Ord α ^^ z = succ zero α ^^ (s n) = sup ℕ (λ k → (α ^^ n) ẋ k) ω+ : ℕ → Ord ω+ n = ω ∔ n ω× : ℕ → Ord ω× n = ω ẋ n ω^ : ℕ → Ord ω^ n = ω ^^ n ω+1≢ω : sup ℕ (succ ∘ inj-ℕ-Ord) ≡ ω → ⊥ ω+1≢ω p = {!!} -- This should not be provable! -- succ-sup : ∀ A f → sup A (succ ∘ f) ≡ succ (sup A f) -- succ-sup A f = {!!} _+_ : Ord → Ord → Ord α + zero = α α + succ β = succ (α + β) α + sup A f = sup A (λ x → α + f x) zeroₗ : ∀ α → zero + α ≡ α zeroₗ zero = refl zeroₗ (succ α) = cong succ (zeroₗ α) zeroₗ (sup A f) = cong (sup A) (ext₁ (λ x → zeroₗ (f x))) succₗ : ∀ α β → succ α + β ≡ succ (α + β) succₗ α zero = refl succₗ α (succ β) = cong succ (succₗ α β) succₗ α (sup A f) = {!!} -- trans (cong (sup A) (ext₁ (λ x → succₗ α (f x)))) -- (succ-sup A (λ x → α + f x)) _≤_ : Ord → Ord → Set₁ α ≤ β = ∃ λ γ → α + γ ≡ β ≤-refl : ∀ α → α ≤ α ≤-refl α = (zero , refl) zero-min : ∀ α → zero ≤ α zero-min α = (α , zeroₗ α) ≤-succ : ∀ α β → α ≤ β → succ α ≤ succ β ≤-succ α β (γ , p) = (γ , trans (succₗ α γ) (cong succ p)) ≤-step : ∀ α β → α ≤ β → α ≤ succ β ≤-step α β (γ , p) = (succ γ , cong succ p) ≤-sup-step : ∀ α A f → (∀ x → α ≤ f x) → α ≤ sup A f ≤-sup-step α A f p = (sup A (proj₁ ∘ p) , cong (sup A) (ext₁ (proj₂ ∘ p))) ≤-supₗ : ∀ A f β → (∀ x → f x ≤ β) → sup A f ≤ β ≤-supₗ A f β p = (sup A (proj₁ ∘ p) , {!!}) where q : (x : A) → (f x + proj₁ (p x)) ≡ β q = proj₂ ∘ p ≤-sup : ∀ A f g → (∀ x → f x ≤ g x) → sup A f ≤ sup A g ≤-sup A f g p = (sup A (proj₁ ∘ p) , {!!}) -- cong (sup A) (ext₁ {!!})) where q : (x : A) → (f x + proj₁ (p x)) ≡ g x q = proj₂ ∘ p q' : (x : A) → (sup A f + (proj₁ ∘ p) x) ≡ g x q' = {!!} lem₁ : ∀ α β → α ≤ α + β lem₁ α zero = ≤-refl α lem₁ α (succ β) = ≤-step α (α + β) (lem₁ α β) lem₁ α (sup A f) = ≤-sup-step α A (λ x → α + f x) (λ x → lem₁ α (f x)) lem₂ : ∀ α β → β ≤ α + β lem₂ α zero = zero-min (α + zero) lem₂ α (succ β) = ≤-succ β (α + β) (lem₂ α β) lem₂ α (sup A f) = ≤-sup A f (λ x → α + f x) (λ x → lem₂ α (f x))
{ "alphanum_fraction": 0.4833569405, "avg_line_length": 24.3448275862, "ext": "agda", "hexsha": "ba6f76cfc2ca90e53197480766342c73ea859ebe", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "TypeTheory/Ordinals.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "TypeTheory/Ordinals.agda", "max_line_length": 74, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "TypeTheory/Ordinals.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1300, "size": 2824 }
//**************************************************************************\ //* This file is property of and copyright by the ALICE Project *\ //* ALICE Experiment at CERN, All rights reserved. *\ //* *\ //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *\ //* for The ALICE HLT Project. *\ //* *\ //* Permission to use, copy, modify and distribute this software and its *\ //* documentation strictly for non-commercial purposes is hereby granted *\ //* without fee, provided that the above copyright notice appears in all *\ //* copies and that both the copyright notice and this permission notice *\ //* appear in the supporting documentation. The authors make no claims *\ //* about the suitability of this software for any purpose. It is *\ //* provided "as is" without express or implied warranty. *\ //************************************************************************** /// \file GPUQA.h /// \author David Rohr #ifndef GPUQA_H #define GPUQA_H #include "GPUSettings.h" struct AliHLTTPCClusterMCWeight; class TH1F; class TH2F; class TCanvas; class TPad; class TLegend; class TPad; class TH1; class TFile; class TH1D; class TObjArray; class TColor; typedef short int Color_t; #if !defined(GPUCA_BUILD_QA) || defined(GPUCA_GPUCODE) namespace GPUCA_NAMESPACE { namespace gpu { class GPUChainTracking; class GPUQA { public: GPUQA(GPUChainTracking* chain) {} ~GPUQA() = default; int InitQA(int tasks = 0) { return 1; } void RunQA(bool matchOnly = false) {} int DrawQAHistograms() { return 1; } void SetMCTrackRange(int min, int max) {} bool SuppressTrack(int iTrack) const { return false; } bool SuppressHit(int iHit) const { return false; } int HitAttachStatus(int iHit) const { return false; } int GetMCTrackLabel(unsigned int trackId) const { return -1; } bool clusterRemovable(int attach, bool prot) const { return false; } static bool QAAvailable() { return false; } static bool IsInitialized() { return false; } }; } // namespace gpu } // namespace GPUCA_NAMESPACE #else #include "GPUTPCDef.h" #include <cmath> #include <vector> #include <memory> #ifdef GPUCA_TPC_GEOMETRY_O2 #include <gsl/span> #endif namespace o2 { class MCCompLabel; namespace tpc { class TrackTPC; struct ClusterNativeAccess; } // namespace tpc } // namespace o2 struct AliHLTTPCClusterMCLabel; namespace GPUCA_NAMESPACE::gpu { class GPUChainTracking; class GPUParam; struct GPUTPCMCInfo; struct GPUQAGarbageCollection; class GPUQA { public: GPUQA(); GPUQA(GPUChainTracking* chain, const GPUSettingsQA* config = nullptr, const GPUParam* param = nullptr); ~GPUQA(); int InitQA(int tasks = -1); void RunQA(bool matchOnly = false, const std::vector<o2::tpc::TrackTPC>* tracksExternal = nullptr, const std::vector<o2::MCCompLabel>* tracksExtMC = nullptr, const o2::tpc::ClusterNativeAccess* clNative = nullptr); int DrawQAHistograms(TObjArray* qcout = nullptr); void DrawQAHistogramsCleanup(); // Needed after call to DrawQAHistograms with qcout != nullptr when GPUSettingsQA.shipToQCAsCanvas = true to clean up the Canvases etc. void SetMCTrackRange(int min, int max); bool SuppressTrack(int iTrack) const; bool SuppressHit(int iHit) const; int HitAttachStatus(int iHit) const; int GetMCTrackLabel(unsigned int trackId) const; bool clusterRemovable(int attach, bool prot) const; static bool QAAvailable() { return true; } bool IsInitialized() { return mQAInitialized; } const std::vector<TH1F>& getHistograms1D() const { return *mHist1D; } const std::vector<TH2F>& getHistograms2D() const { return *mHist2D; } const std::vector<TH1D>& getHistograms1Dd() const { return *mHist1Dd; } void resetHists(); int loadHistograms(std::vector<TH1F>& i1, std::vector<TH2F>& i2, std::vector<TH1D>& i3, int tasks = -1); static constexpr int N_CLS_HIST = 8; static constexpr int N_CLS_TYPE = 3; static constexpr int MC_LABEL_INVALID = -1e9; enum QA_TASKS { taskTrackingEff = 1, taskTrackingRes = 2, taskTrackingResPull = 4, taskClusterAttach = 8, taskTrackStatistics = 16, taskClusterCounts = 32, taskDefault = 63, taskDefaultPostprocess = 31 }; private: struct additionalMCParameters { float pt, phi, theta, eta, nWeightCls; }; struct additionalClusterParameters { int attached, fakeAttached, adjacent, fakeAdjacent; float pt; }; int InitQACreateHistograms(); int DoClusterCounts(unsigned long long int* attachClusterCounts, int mode = 0); void PrintClusterCount(int mode, int& num, const char* name, unsigned long long int n, unsigned long long int normalization); void SetAxisSize(TH1F* e); void SetLegend(TLegend* l); double* CreateLogAxis(int nbins, float xmin, float xmax); void ChangePadTitleSize(TPad* p, float size); void DrawHisto(TH1* histo, char* filename, char* options); void doPerfFigure(float x, float y, float size); void GetName(char* fname, int k); template <class T> T* GetHist(T*& ee, std::vector<std::unique_ptr<TFile>>& tin, int k, int nNewInput); #ifdef GPUCA_TPC_GEOMETRY_O2 using mcLabels_t = gsl::span<const o2::MCCompLabel>; using mcLabel_t = o2::MCCompLabel; using mcLabelI_t = mcLabel_t; using mcInfo_t = GPUTPCMCInfo; mcLabels_t GetMCLabel(unsigned int i); mcLabel_t GetMCLabel(unsigned int i, unsigned int j); #else using mcLabels_t = AliHLTTPCClusterMCLabel; using mcLabel_t = AliHLTTPCClusterMCWeight; struct mcLabelI_t { int getTrackID() const { return AbsLabelID(track); } int getEventID() const { return 0; } long int getTrackEventSourceID() const { return getTrackID(); } bool isFake() const { return track < 0; } bool isValid() const { return track != MC_LABEL_INVALID; } void invalidate() { track = MC_LABEL_INVALID; } void setFakeFlag(bool v = true) { track = v ? FakeLabelID(track) : AbsLabelID(track); } void setNoise() { track = MC_LABEL_INVALID; } bool operator==(const mcLabel_t& l); bool operator!=(const mcLabel_t& l) { return !(*this == l); } mcLabelI_t() = default; mcLabelI_t(const mcLabel_t& l); int track = MC_LABEL_INVALID; }; using mcInfo_t = GPUTPCMCInfo; const mcLabels_t& GetMCLabel(unsigned int i); const mcLabel_t& GetMCLabel(unsigned int i, unsigned int j); const mcInfo_t& GetMCTrack(const mcLabelI_t& label); static int FakeLabelID(const int id); static int AbsLabelID(const int id); #endif template <class T> static auto& GetMCTrackObj(T& obj, const mcLabelI_t& l); unsigned int GetNMCCollissions(); unsigned int GetNMCTracks(int iCol); unsigned int GetNMCLabels(); const mcInfo_t& GetMCTrack(unsigned int iTrk, unsigned int iCol); const mcInfo_t& GetMCTrack(const mcLabel_t& label); int GetMCLabelNID(const mcLabels_t& label); int GetMCLabelNID(unsigned int i); int GetMCLabelID(unsigned int i, unsigned int j); int GetMCLabelCol(unsigned int i, unsigned int j); static int GetMCLabelID(const mcLabels_t& label, unsigned int j); static int GetMCLabelID(const mcLabel_t& label); float GetMCLabelWeight(unsigned int i, unsigned int j); float GetMCLabelWeight(const mcLabels_t& label, unsigned int j); float GetMCLabelWeight(const mcLabel_t& label); const auto& GetClusterLabels(); bool mcPresent(); static bool MCComp(const mcLabel_t& a, const mcLabel_t& b); GPUChainTracking* mTracking; const GPUSettingsQA& mConfig; const GPUParam& mParam; const char* str_perf_figure_1 = "ALICE Performance 2018/03/20"; // const char* str_perf_figure_2 = "2015, MC pp, #sqrt{s} = 5.02 TeV"; const char* str_perf_figure_2 = "2015, MC Pb-Pb, #sqrt{s_{NN}} = 5.02 TeV"; //------------------------- std::vector<mcLabelI_t> mTrackMCLabels; #ifdef GPUCA_TPC_GEOMETRY_O2 std::vector<std::vector<int>> mTrackMCLabelsReverse; std::vector<std::vector<int>> mRecTracks; std::vector<std::vector<int>> mFakeTracks; std::vector<std::vector<additionalMCParameters>> mMCParam; std::vector<std::vector<mcInfo_t>> mMCInfos; std::vector<int> mNColTracks; #else std::vector<int> mTrackMCLabelsReverse[1]; std::vector<int> mRecTracks[1]; std::vector<int> mFakeTracks[1]; std::vector<additionalMCParameters> mMCParam[1]; #endif std::vector<additionalClusterParameters> mClusterParam; int mNTotalFakes = 0; TH1F* mEff[4][2][2][5][2]; // eff,clone,fake,all - findable - secondaries - y,z,phi,eta,pt - work,result TCanvas* mCEff[6]; TPad* mPEff[6][4]; TLegend* mLEff[6]; TH1F* mRes[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean TH2F* mRes2[5][5]; TCanvas* mCRes[7]; TPad* mPRes[7][5]; TLegend* mLRes[6]; TH1F* mPull[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean TH2F* mPull2[5][5]; TCanvas* mCPull[7]; TPad* mPPull[7][5]; TLegend* mLPull[6]; enum CL_types { CL_attached = 0, CL_fake = 1, CL_att_adj = 2, CL_fakeAdj = 3, CL_tracks = 4, CL_physics = 5, CL_prot = 6, CL_all = 7 }; TH1D* mClusters[N_CLS_TYPE * N_CLS_HIST - 1]; // attached, fakeAttached, attach+adjacent, fakeAdjacent, physics, protected, tracks, all / count, rel, integral TCanvas* mCClust[N_CLS_TYPE]; TPad* mPClust[N_CLS_TYPE]; TLegend* mLClust[N_CLS_TYPE]; struct counts_t { long long int nRejected = 0, nTube = 0, nTube200 = 0, nLoopers = 0, nLowPt = 0, n200MeV = 0, nPhysics = 0, nProt = 0, nUnattached = 0, nTotal = 0, nHighIncl = 0, nAbove400 = 0, nFakeRemove400 = 0, nFullFakeRemove400 = 0, nBelow40 = 0, nFakeProtect40 = 0, nMergedLooper = 0; double nUnaccessible = 0; } mClusterCounts; TH1F* mTracks; TCanvas* mCTracks; TPad* mPTracks; TLegend* mLTracks; TH1F* mNCl; TCanvas* mCNCl; TPad* mPNCl; TLegend* mLNCl; std::vector<TH2F*> mHistClusterCount; std::vector<TH1F>* mHist1D = nullptr; std::vector<TH2F>* mHist2D = nullptr; std::vector<TH1D>* mHist1Dd = nullptr; bool mHaveExternalHists = false; std::vector<TH1F**> mHist1D_pos{}; std::vector<TH2F**> mHist2D_pos{}; std::vector<TH1D**> mHist1Dd_pos{}; template <class T> auto getHistArray(); template <class T, typename... Args> void createHist(T*& h, const char* name, Args... args); std::unique_ptr<GPUQAGarbageCollection> mGarbageCollector; template <class T, typename... Args> T* createGarbageCollected(Args... args); void clearGarbagageCollector(); int mNEvents = 0; bool mQAInitialized = false; int mQATasks = 0; std::vector<std::vector<int>> mcEffBuffer; std::vector<std::vector<int>> mcLabelBuffer; std::vector<std::vector<bool>> mGoodTracks; std::vector<std::vector<bool>> mGoodHits; static std::vector<TColor*> mColors; static int initColors(); int mMCTrackMin = -1, mMCTrackMax = -1; const o2::tpc::ClusterNativeAccess* mClNative = nullptr; }; inline bool GPUQA::SuppressTrack(int iTrack) const { return (mConfig.matchMCLabels.size() && !mGoodTracks[mNEvents][iTrack]); } inline bool GPUQA::SuppressHit(int iHit) const { return (mConfig.matchMCLabels.size() && !mGoodHits[mNEvents - 1][iHit]); } inline int GPUQA::HitAttachStatus(int iHit) const { return (mClusterParam.size() && mClusterParam[iHit].fakeAttached ? (mClusterParam[iHit].attached ? 1 : 2) : 0); } } // namespace GPUCA_NAMESPACE::gpu #endif #endif
{ "alphanum_fraction": 0.6823529412, "avg_line_length": 35.0303030303, "ext": "h", "hexsha": "b861c1a5be077b1b9bef941d8e0763c576bf1fc6", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2017-12-15T09:46:36.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-15T09:46:36.000Z", "max_forks_repo_head_hexsha": "52edd953c66dfddf00c80fc970409bbe6cfcc349", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "iarsene/AliRoot", "max_forks_repo_path": "GPU/GPUTracking/Standalone/qa/GPUQA.h", "max_issues_count": 21, "max_issues_repo_head_hexsha": "52edd953c66dfddf00c80fc970409bbe6cfcc349", "max_issues_repo_issues_event_max_datetime": "2020-05-09T06:03:12.000Z", "max_issues_repo_issues_event_min_datetime": "2017-10-25T10:01:30.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "iarsene/AliRoot", "max_issues_repo_path": "GPU/GPUTracking/Standalone/qa/GPUQA.h", "max_line_length": 277, "max_stars_count": null, "max_stars_repo_head_hexsha": "52edd953c66dfddf00c80fc970409bbe6cfcc349", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "iarsene/AliRoot", "max_stars_repo_path": "GPU/GPUTracking/Standalone/qa/GPUQA.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3407, "size": 11560 }
/* rng/slatec.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /** * ====================================================================== * NIST Guide to Available Math Software. * Source for module RAND from package CMLIB. * Retrieved from TIBER on Fri Oct 11 11:43:42 1996. * ====================================================================== FUNCTION RAND(R) C***BEGIN PROLOGUE RAND C***DATE WRITTEN 770401 (YYMMDD) C***REVISION DATE 820801 (YYMMDD) C***CATEGORY NO. L6A21 C***KEYWORDS RANDOM NUMBER,SPECIAL FUNCTION,UNIFORM C***AUTHOR FULLERTON, W., (LANL) C***PURPOSE Generates a uniformly distributed random number. C***DESCRIPTION C C This pseudo-random number generator is portable among a wide C variety of computers. RAND(R) undoubtedly is not as good as many C readily available installation dependent versions, and so this C routine is not recommended for widespread usage. Its redeeming C feature is that the exact same random numbers (to within final round- C off error) can be generated from machine to machine. Thus, programs C that make use of random numbers can be easily transported to and C checked in a new environment. C The random numbers are generated by the linear congruential C method described, e.g., by Knuth in Seminumerical Methods (p.9), C Addison-Wesley, 1969. Given the I-th number of a pseudo-random C sequence, the I+1 -st number is generated from C X(I+1) = (A*X(I) + C) MOD M, C where here M = 2**22 = 4194304, C = 1731 and several suitable values C of the multiplier A are discussed below. Both the multiplier A and C random number X are represented in double precision as two 11-bit C words. The constants are chosen so that the period is the maximum C possible, 4194304. C In order that the same numbers be generated from machine to C machine, it is necessary that 23-bit integers be reducible modulo C 2**11 exactly, that 23-bit integers be added exactly, and that 11-bit C integers be multiplied exactly. Furthermore, if the restart option C is used (where R is between 0 and 1), then the product R*2**22 = C R*4194304 must be correct to the nearest integer. C The first four random numbers should be .0004127026, C .6750836372, .1614754200, and .9086198807. The tenth random number C is .5527787209, and the hundredth is .3600893021 . The thousandth C number should be .2176990509 . C In order to generate several effectively independent sequences C with the same generator, it is necessary to know the random number C for several widely spaced calls. The I-th random number times 2**22, C where I=K*P/8 and P is the period of the sequence (P = 2**22), is C still of the form L*P/8. In particular we find the I-th random C number multiplied by 2**22 is given by C I = 0 1*P/8 2*P/8 3*P/8 4*P/8 5*P/8 6*P/8 7*P/8 8*P/8 C RAND= 0 5*P/8 2*P/8 7*P/8 4*P/8 1*P/8 6*P/8 3*P/8 0 C Thus the 4*P/8 = 2097152 random number is 2097152/2**22. C Several multipliers have been subjected to the spectral test C (see Knuth, p. 82). Four suitable multipliers roughly in order of C goodness according to the spectral test are C 3146757 = 1536*2048 + 1029 = 2**21 + 2**20 + 2**10 + 5 C 2098181 = 1024*2048 + 1029 = 2**21 + 2**10 + 5 C 3146245 = 1536*2048 + 517 = 2**21 + 2**20 + 2**9 + 5 C 2776669 = 1355*2048 + 1629 = 5**9 + 7**7 + 1 C C In the table below LOG10(NU(I)) gives roughly the number of C random decimal digits in the random numbers considered I at a time. C C is the primary measure of goodness. In both cases bigger is better. C C LOG10 NU(I) C(I) C A I=2 I=3 I=4 I=5 I=2 I=3 I=4 I=5 C C 3146757 3.3 2.0 1.6 1.3 3.1 1.3 4.6 2.6 C 2098181 3.3 2.0 1.6 1.2 3.2 1.3 4.6 1.7 C 3146245 3.3 2.2 1.5 1.1 3.2 4.2 1.1 0.4 C 2776669 3.3 2.1 1.6 1.3 2.5 2.0 1.9 2.6 C Best C Possible 3.3 2.3 1.7 1.4 3.6 5.9 9.7 14.9 C C Input Argument -- C R If R=0., the next random number of the sequence is generated. C If R .LT. 0., the last generated number will be returned for C possible use in a restart procedure. C If R .GT. 0., the sequence of random numbers will start with C the seed R mod 1. This seed is also returned as the value of C RAND provided the arithmetic is done exactly. C C Output Value -- C RAND a pseudo-random number between 0. and 1. C***REFERENCES (NONE) C***ROUTINES CALLED (NONE) C***END PROLOGUE RAND DATA IA1, IA0, IA1MA0 /1536, 1029, 507/ DATA IC /1731/ DATA IX1, IX0 /0, 0/ C***FIRST EXECUTABLE STATEMENT RAND IF (R.LT.0.) GO TO 10 IF (R.GT.0.) GO TO 20 C C A*X = 2**22*IA1*IX1 + 2**11*(IA1*IX1 + (IA1-IA0)*(IX0-IX1) C + IA0*IX0) + IA0*IX0 C IY0 = IA0*IX0 IY1 = IA1*IX1 + IA1MA0*(IX0-IX1) + IY0 IY0 = IY0 + IC IX0 = MOD (IY0, 2048) IY1 = IY1 + (IY0-IX0)/2048 IX1 = MOD (IY1, 2048) C 10 RAND = IX1*2048 + IX0 RAND = RAND / 4194304. RETURN C 20 IX1 = AMOD(R,1.)*4194304. + 0.5 IX0 = MOD (IX1, 2048) IX1 = (IX1-IX0)/2048 GO TO 10 C END **/ #include <config.h> #include <stdlib.h> #include <gsl/gsl_rng.h> static inline unsigned long int slatec_get (void *vstate); static double slatec_get_double (void *vstate); static void slatec_set (void *state, unsigned long int s); typedef struct { long int x0, x1; } slatec_state_t; static const long P = 4194304; static const long a1 = 1536; static const long a0 = 1029; static const long a1ma0 = 507; static const long c = 1731; static inline unsigned long int slatec_get (void *vstate) { long y0, y1; slatec_state_t *state = (slatec_state_t *) vstate; y0 = a0 * state->x0; y1 = a1 * state->x1 + a1ma0 * (state->x0 - state->x1) + y0; y0 = y0 + c; state->x0 = y0 % 2048; y1 = y1 + (y0 - state->x0) / 2048; state->x1 = y1 % 2048; return state->x1 * 2048 + state->x0; } static double slatec_get_double (void *vstate) { return slatec_get (vstate) / 4194304.0 ; } static void slatec_set (void *vstate, unsigned long int s) { slatec_state_t *state = (slatec_state_t *) vstate; /* Only eight seeds are permitted. This is pretty limiting, but at least we are guaranteed that the eight sequences are different */ s = s % 8; s *= P / 8; state->x0 = s % 2048; state->x1 = (s - state->x0) / 2048; } static const gsl_rng_type slatec_type = {"slatec", /* name */ 4194303, /* RAND_MAX */ 0, /* RAND_MIN */ sizeof (slatec_state_t), &slatec_set, &slatec_get, &slatec_get_double}; const gsl_rng_type *gsl_rng_slatec = &slatec_type;
{ "alphanum_fraction": 0.6523542001, "avg_line_length": 36.2912621359, "ext": "c", "hexsha": "aa82a414357334dea5993bc29acba8004dfd4c4e", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ICML14MoMCompare/spectral-learn", "max_forks_repo_path": "code/em/treba/gsl-1.0/rng/slatec.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ICML14MoMCompare/spectral-learn", "max_issues_repo_path": "code/em/treba/gsl-1.0/rng/slatec.c", "max_line_length": 73, "max_stars_count": 14, "max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ICML14MoMCompare/spectral-learn", "max_stars_repo_path": "code/em/treba/gsl-1.0/rng/slatec.c", "max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z", "num_tokens": 2584, "size": 7476 }
/********************* * Time intergral KDK scheme. * kick and drifts. * * This code was initially modified by Jun Koda, * from the original serial COLA code * by Svetlin Tassev. * * The kick and drift still supports a COLA compat-mode. * Most of the nasty factors are for COLA compat-mode * (not needed in PM) * We also added a 2LPT mode that does just 2LPT. * * Yu Feng <rainwoodman@gmail.com> * */ #include <math.h> #include <string.h> #include <assert.h> #include <alloca.h> #include <mpi.h> #include <gsl/gsl_integration.h> #include <gsl/gsl_roots.h> #include <gsl/gsl_sf_hyperg.h> #include <gsl/gsl_errno.h> #include <fastpm/libfastpm.h> #include <fastpm/logging.h> #include "pmpfft.h" #include "vpm.h" static double Sq(double ai, double af, double aRef, double nLPT, FastPMCosmology * c, int USE_NONSTDDA); static double Sphi(double ai, double af, double aRef, double nLPT, FastPMCosmology * c, int USE_NONSTDDA); static inline void fastpm_drift_lookup(FastPMDriftFactor * drift, double af, double * dyyy, double * da1, double * da2) { double ind; if(af == drift->af) { *dyyy = drift->dyyy[drift->nsamples - 1]; *da1 = drift->da1[drift->nsamples - 1]; *da2 = drift->da2[drift->nsamples - 1]; return; } if(af == drift->ai) { *dyyy = drift->dyyy[0]; *da1 = drift->da1[0]; *da2 = drift->da2[0]; return; } { ind = (af - drift->ai) / (drift->af - drift->ai) * (drift->nsamples - 1); int l = floor(ind); double u = l + 1 - ind; double v = ind - l; if(l + 1 >= drift->nsamples) { fastpm_raise(-1, "drift beyond factor's available range. "); } *dyyy = drift->dyyy[l] * u + drift->dyyy[l + 1] * v; *da1 = drift->da1[l] * u + drift->da1[l + 1] * v; *da2 = drift->da2[l] * u + drift->da2[l + 1] * v; } } inline void fastpm_drift_one(FastPMDriftFactor * drift, FastPMStore * p, ptrdiff_t i, double xo[3], double af) { double dyyy_f, da1_f, da2_f; double dyyy_i, da1_i, da2_i; double dyyy, da1, da2; fastpm_drift_lookup(drift, af, &dyyy_f, &da1_f, &da2_f); fastpm_drift_lookup(drift, p->meta.a_x, &dyyy_i, &da1_i, &da2_i); dyyy = dyyy_f - dyyy_i; da1 = da1_f - da1_i; da2 = da2_f - da2_i; int d; for(d = 0; d < 3; d ++) { double v; switch(drift->forcemode) { case FASTPM_FORCE_2LPT: xo[d] = p->x[i][d] + p->dx1[i][d] * da1 + p->dx2[i][d] * da2; break; case FASTPM_FORCE_ZA: xo[d] = p->x[i][d] + p->dx1[i][d] * da1; break; case FASTPM_FORCE_FASTPM: case FASTPM_FORCE_PM: xo[d] = p->x[i][d] + p->v[i][d] * dyyy; break; case FASTPM_FORCE_COLA: /* For cola, remove the lpt velocity to find the residual velocity v*/ v = p->v[i][d] - (p->dx1[i][d]*drift->Dv1 + p->dx2[i][d]*drift->Dv2); xo[d] = p->x[i][d] + v * dyyy; xo[d] += p->dx1[i][d] * da1 + p->dx2[i][d] * da2; break; } /* if PGDCorrection is enabled, add it */ if(p->pgdc) { /* no drift; to protect the pgdc line */ if (drift->ai == drift->af) continue; xo[d] += 0.5 * p->pgdc[i][d] * dyyy / drift->dyyy[drift->nsamples-1]; } } } static inline void fastpm_kick_lookup(FastPMKickFactor * kick, double af, double * dda, double * Dv1, double * Dv2) { double ind; if(af == kick->af) { *dda = kick->dda[kick->nsamples - 1]; *Dv1 = kick->Dv1[kick->nsamples - 1]; *Dv2 = kick->Dv2[kick->nsamples - 1]; return; } if(af == kick->ai) { *dda = kick->dda[0]; *Dv1 = kick->Dv1[0]; *Dv2 = kick->Dv2[0]; return; } { ind = (af - kick->ai) / (kick->af - kick->ai) * (kick->nsamples - 1); int l = floor(ind); double u = l + 1 - ind; double v = ind - l; if(l + 1 >= kick->nsamples) { fastpm_raise(-1, "kick beyond factor's available range. "); } *dda = kick->dda[l] * u + kick->dda[l + 1] * v; *Dv1 = kick->Dv1[l] * u + kick->Dv1[l + 1] * v; *Dv2 = kick->Dv2[l] * u + kick->Dv2[l + 1] * v; } } inline void fastpm_kick_one(FastPMKickFactor * kick, FastPMStore * p, ptrdiff_t i, float vo[3], double af) { double dda_i, Dv1_i, Dv2_i; double dda_f, Dv1_f, Dv2_f; double dda, Dv1, Dv2; fastpm_kick_lookup(kick, af, &dda_f, &Dv1_f, &Dv2_f); fastpm_kick_lookup(kick, p->meta.a_v, &dda_i, &Dv1_i, &Dv2_i); dda = dda_f - dda_i; Dv1 = Dv1_f - Dv1_i; Dv2 = Dv2_f - Dv2_i; int d; for(d = 0; d < 3; d++) { float ax = p->acc[i][d]; // unlike a_x, which means a at which x is calcd if(kick->forcemode == FASTPM_FORCE_COLA) { ax += (p->dx1[i][d]*kick->q1 + p->dx2[i][d]*kick->q2); } vo[d] = p->v[i][d] + ax * dda; if(kick->forcemode == FASTPM_FORCE_COLA) { vo[d] += (p->dx1[i][d] * Dv1 + p->dx2[i][d] * Dv2); } } } // Leap frog time integration void fastpm_kick_store(FastPMKickFactor * kick, FastPMStore * pi, FastPMStore * po, double af) { int np = pi->np; // Kick using acceleration at a= ac // Assume forces at a=ac is in particles->force int i; #pragma omp parallel for for(i=0; i<np; i++) { int d; float vo[3]; fastpm_kick_one(kick, pi, i, vo, af); for(d = 0; d < 3; d++) { po->v[i][d] = vo[d]; } } //velocity is now at a= avel1 po->meta.a_v = af; } static double G_p(FastPMGrowthInfo * growth_info) { /* integral of G_p */ return growth_info->D1; } static double g_p(FastPMGrowthInfo * growth_info) { return DGrowthFactorDa(growth_info); } static double G_f(FastPMGrowthInfo * growth_info) { /* integral of g_f */ double a = growth_info->a; return a * a * a * HubbleEa(a, growth_info->c) * g_p(growth_info); } static double g_f(FastPMGrowthInfo * growth_info) { double a = growth_info->a; FastPMCosmology * c = growth_info->c; double E = HubbleEa(a, c); double dEda = DHubbleEaDa(a, c); double dDda = g_p(growth_info); double d2Dda2 = D2GrowthFactorDa2(growth_info); double g_f = 3 * a * a * E * dDda + a * a * a * dEda * dDda + a * a * a * E * d2Dda2; return g_f; } void fastpm_kick_init(FastPMKickFactor * kick, FastPMSolver * fastpm, double ai, double ac, double af) { FastPMCosmology * c = fastpm->cosmology; kick->forcemode = fastpm->config->FORCE_TYPE; FastPMGrowthInfo gi_i; FastPMGrowthInfo gi_c; FastPMGrowthInfo gi_e; fastpm_growth_info_init(&gi_i, ai, c); fastpm_growth_info_init(&gi_c, ac, c); double E_i = HubbleEa(ai, c); double E_c = HubbleEa(ac, c); double D1_i = gi_i.D1; double D2_i = gi_i.D2; double f1_i = gi_i.f1; double f2_i = gi_i.f2; double D1_c = gi_c.D1; double D2_c = gi_c.D2; double Omega_m0 = Omega_source(1, c); double Omega_mc = Omega_source(ac, c); // kick->q1,2 are used for the COLA force implementation. // growth_mode = ODE and LCDM should match for an LCDM background, // but neither is guaranteed accurate for a background with radiaiton. // We advise using LCDM mode for forcemode = FASTPM_FORCE_COLA, as in the // original implementation of FastPM. kick->q1 = D1_c; switch (c->growth_mode){ case FASTPM_GROWTH_MODE_LCDM: kick->q2 = D1_c*D1_c * (1.0 + 7.0/3.0 * pow(Omega_mc, 1.0/143.0)); break; case FASTPM_GROWTH_MODE_ODE: kick->q2 = D1_c*D1_c * (1 - D1_c*D1_c/D2_c); break; default: fastpm_raise(-1, "Please enter a valid growth mode.\n"); } kick->nsamples = 32; int i; double Dv1i = D1_i * ai * ai * E_i * f1_i; double Dv2i = D2_i * ai * ai * E_i * f2_i; for(i = 0; i < kick->nsamples; i ++) { double ae = ai * (1.0 * (kick->nsamples - 1 - i) / (kick->nsamples - 1)) + af * (1.0 * i / (kick->nsamples - 1)); fastpm_growth_info_init(&gi_e, ae, c); double D1_e = gi_e.D1; double f1_e = gi_e.f1; double D2_e = gi_e.D2; double f2_e = gi_e.f2; double E_e = HubbleEa(ae, c); if(kick->forcemode == FASTPM_FORCE_FASTPM) { kick->dda[i] = -1.5 * Omega_mc * ac * E_c * (G_f(&gi_e) - G_f(&gi_i)) / g_f(&gi_c); } else { kick->dda[i] = -1.5 * Omega_m0 * Sphi(ai, ae, ac, fastpm->config->nLPT, c, kick->forcemode == FASTPM_FORCE_COLA); } kick->Dv1[i] = D1_e * ae * ae * E_e * f1_e - Dv1i; kick->Dv2[i] = D2_e * ae * ae * E_e * f2_e - Dv2i; } kick->ai = ai; kick->ac = ac; kick->af = af; /* Output growth and FastPM factor at af for reference. This is a weird place to put this, but it's convenient because G and g are static */ fastpm_info("Growth/FastPM factors at a = %6.4f: D1=%g, D2=%g, f1=%g, f2=%g, G_p=%g, G_f=%g, g_p=%g, g_f=%g\n", ai, gi_i.D1, gi_i.D2, gi_i.f1, gi_i.f2, G_p(&gi_i), G_f(&gi_i), g_p(&gi_i), g_f(&gi_i)); } void fastpm_drift_init(FastPMDriftFactor * drift, FastPMSolver * fastpm, double ai, double ac, double af) { FastPMCosmology * c = fastpm->cosmology; drift->forcemode = fastpm->config->FORCE_TYPE; FastPMGrowthInfo gi_i; FastPMGrowthInfo gi_c; FastPMGrowthInfo gi_e; fastpm_growth_info_init(&gi_i, ai, c); fastpm_growth_info_init(&gi_c, ac, c); double E_c = HubbleEa(ac, c); double D1_i = gi_i.D1; double D2_i = gi_i.D2; double D1_c = gi_c.D1; double D2_c = gi_c.D2; double f1_c = gi_c.f1; double f2_c = gi_c.f2; drift->nsamples = 32; int i; for(i = 0; i < drift->nsamples; i ++ ) { double ae = ai * (1.0 * (drift->nsamples - 1 - i) / (drift->nsamples - 1)) + af * (1.0 * i / (drift->nsamples - 1)); fastpm_growth_info_init(&gi_e, ae, c); // overwrite each iteration double D1_e = gi_e.D1; double D2_e = gi_e.D2; if (drift->forcemode == FASTPM_FORCE_FASTPM) { drift->dyyy[i] = 1 / (ac * ac * ac * E_c) * (G_p(&gi_e) - G_p(&gi_i)) / g_p(&gi_c); } else { drift->dyyy[i] = Sq(ai, ae, ac, fastpm->config->nLPT, c, drift->forcemode == FASTPM_FORCE_COLA); } drift->da1[i] = D1_e - D1_i; // change in D_1lpt drift->da2[i] = D2_e - D2_i; // change in D_2lpt } drift->af = af; drift->ai = ai; drift->ac = ac; drift->Dv1 = D1_c * ac * ac * E_c * f1_c; drift->Dv2 = D2_c * ac * ac * E_c * f2_c; } void fastpm_drift_store(FastPMDriftFactor * drift, FastPMStore * pi, FastPMStore * po, double af) { int np = pi->np; int i; // Drift #pragma omp parallel for for(i=0; i<np; i++) { double xo[3] = {0}; fastpm_drift_one(drift, pi, i, xo, af); int d; for(d = 0; d < 3; d ++) { po->x[i][d] = xo[d]; } } po->meta.a_x = af; } // // Functions for our modified time-stepping (used when StdDA=0): // struct iparam { FastPMCosmology * cosmology; double nLPT; }; double gpQ(double a, double nLPT) { return pow(a, nLPT); } static double stddriftfunc (double a, struct iparam * iparam) { return 1 / (pow(a, 3) * HubbleEa(a, iparam->cosmology)); } static double nonstddriftfunc (double a, struct iparam * iparam) { return gpQ(a, iparam->nLPT)/(pow(a, 3) * HubbleEa(a, iparam->cosmology)); } static double stdkickfunc (double a, struct iparam * iparam) { return 1/ (pow(a, 2) * HubbleEa(a, iparam->cosmology)); } static double integrand(double a, void * params) { void ** p = (void**) params; double (*func)(double a, struct iparam * s) = p[0]; struct iparam * s = p[1]; return func(a, s); } double integrate(double ai, double af, struct iparam * iparam, double (*func)(double , struct iparam * )) { gsl_integration_workspace * w = gsl_integration_workspace_alloc (5000); gsl_function F; double error; double result; F.params = (void*[]){func, iparam}; F.function = integrand; gsl_integration_qag (&F, ai, af, 0, 1e-8, 5000, 6, w, &result, &error); gsl_integration_workspace_free (w); return result; } /* When StdDA=0, one needs to set nLPT. assumes time dep. for velocity = B a^nLPT nLPT is a real number. Sane values lie in the range (-4,3.5). Cannot be 0, but of course can be -> 0 (say 0.001). See Section A.3 of TZE. */ static double Sq(double ai, double af, double aRef, double nLPT, FastPMCosmology * c, int USE_NONSTDDA) { double resultstd, result; struct iparam iparam[1]; iparam->cosmology = c; iparam->nLPT = nLPT; resultstd = integrate(ai, af, iparam, stddriftfunc); result = integrate(ai, af, iparam, nonstddriftfunc); result /= gpQ(aRef, nLPT); /* fastpm_info("ref time = %6.4f, std drift =%g, non std drift = %g \n", aRef, resultstd, result); */ if (USE_NONSTDDA) return result; else return resultstd; } double DERgpQ(double a, double nLPT) { /* This must return d(gpQ)/da */ return nLPT*pow(a, nLPT-1); } static double Sphi(double ai, double af, double aRef, double nLPT, FastPMCosmology * c, int USE_NONSTDDA) { double result; double resultstd; struct iparam iparam[1]; iparam->cosmology = c; iparam->nLPT = nLPT; result = (gpQ(af, nLPT) - gpQ(ai, nLPT)) * aRef / (pow(aRef, 3) * HubbleEa(aRef, c) * DERgpQ(aRef, nLPT)); resultstd = integrate(ai, af, iparam, stdkickfunc); /* fastpm_info("ref time = %6.4f, std kick = %g, non std kick = %g\n", aRef, resultstd, result); */ if (USE_NONSTDDA) { return result; } else { return resultstd; } }
{ "alphanum_fraction": 0.5551757812, "avg_line_length": 28.2761341223, "ext": "c", "hexsha": "00d42b2d1e162f5735809da9fb0cf478c0e6743b", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-14T23:24:19.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-14T23:24:19.000Z", "max_forks_repo_head_hexsha": "f38f6e69c603fb699436b645fe7b4eb418ee82c2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sbird/FastPMRunner", "max_forks_repo_path": "fastpm/libfastpm/factors.c", "max_issues_count": 4, "max_issues_repo_head_hexsha": "f38f6e69c603fb699436b645fe7b4eb418ee82c2", "max_issues_repo_issues_event_max_datetime": "2022-01-24T05:51:04.000Z", "max_issues_repo_issues_event_min_datetime": "2021-04-19T23:01:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "sbird/FastPMRunner", "max_issues_repo_path": "fastpm/libfastpm/factors.c", "max_line_length": 120, "max_stars_count": null, "max_stars_repo_head_hexsha": "f38f6e69c603fb699436b645fe7b4eb418ee82c2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "sbird/FastPMRunner", "max_stars_repo_path": "fastpm/libfastpm/factors.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4880, "size": 14336 }
/* tz_3dgeom_utils.c * * 17-Jan-2008 Initial write: Ting Zhao */ #include <stdio.h> #include <math.h> #include "tz_geo3d_utils.h" #ifdef HAVE_LIBGSL # if defined(HAVE_INLINE) # undef HAVE_INLINE # define INLINE_SUPPRESSED # endif #include <gsl/gsl_vector.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_eigen.h> # if defined(INLINE_SUPPRESSED) # define HAVE_INLINE # endif #endif #include "tz_error.h" #include "tz_utilities.h" #include "tz_constant.h" #include "tz_geoangle_utils.h" #include "tz_geometry.h" #include "tz_3dgeom.h" #include "tz_darray.h" #include "tz_math.h" #define TZ_DIST_3D_EPS 0.0000000000001 /* rounding torelance */ /* Geo3d_Translate_Coordinate(): 3D coordinate translation. * * Args: x - x coordinate to translate. It stores the result after return; * y - y coordinate to translate. It stores the result after return; * z - z coordinate to translate. It stores the result after return; * dx - x axis translation; * dy - y axis translation; * dz - z axis translation. * * Return: void. */ void Geo3d_Translate_Coordinate(double *x, double *y, double *z, double dx, double dy, double dz) { *x += dx; *y += dy; *z += dz; } /* Geo3d_Coordinate_Offset(): 3D coordinates offset. * * Args: x1, y1, z1 - start coordinate; * x2, y2, z2 - end coordinate; * dx, dy, dz - store the result. * * Return: void. */ void Geo3d_Coordinate_Offset(double x1, double y1, double z1, double x2, double y2, double z2, double *dx, double *dy, double *dz) { *dx = x2 - x1; *dy = y2 - y1; *dz = z2 - z1; } /* * Geo3d_Rotate_Coordinate(): 3D rotation. * * Args: x, y, z - the point to be rotated; * theta - angle around the X axis; * psi - angle around the Z axis; * reverse - reverse the rotation or not. * * Return: void. */ void Geo3d_Rotate_Coordinate(double *x, double *y, double *z, double theta, double psi, BOOL reverse) { double p[3] = {*x, *y, *z}; Rotate_XZ(p, p, 1, theta, psi, reverse); *x = p[0]; *y = p[1]; *z = p[2]; } /* Geo3d_Orientation_Normal(): calculate the normal vector at a certain * direction. * * Args: theta - radian around X axis; * psi - radian around Z axis; * x - resulted x coordinate; * y - resulted y coordinate; * z - resulted z coordinate. * * Return: void. */ void Geo3d_Orientation_Normal(double theta, double psi, double *x, double *y, double *z) { /* rotaion of the vector (0, 0, 1) */ double sin_theta = sin(theta); *x = sin_theta * sin(psi); *y = -sin_theta * cos(psi); //*z = cos(theta); *z = sqrt(1.0 - sin_theta * sin_theta); } void Geo3d_Normal_Orientation(double x, double y, double z, double *theta, double *psi) { /* *theta = acos(z); *psi = Vector_Angle(x, y) + TZ_PI_2; */ //*psi = Vector_Angle(x, y) + TZ_PI_2 * 3.0; /* The range of theta will be [-pi, pi] and * the range of psi will be [-pi/2, pi/2]. */ *theta = acos(z); if (*theta < GEOANGLE_COMPARE_EPS) { *psi = 0.0; } else { if (y >= 0.0) { *theta = -*theta; *psi = Vector_Angle(x, y) - TZ_PI_2; } else { *psi = Vector_Angle(x, y) - TZ_PI_2 * 3.0; } } } void Geo3d_Coord_Orientation(double x, double y, double z, double *theta, double *psi) { double r = Geo3d_Orgdist(x, y, z); if (r > TZ_DIST_3D_EPS) { x /= r; y /= r; z /= r; Geo3d_Normal_Orientation(x, y, z, theta, psi); } else { *theta = 0.0; *psi = 0.0; } } void Geo3d_Rotate_Orientation(double rtheta, double rpsi, double *theta, double *psi) { double coord[3]; Geo3d_Orientation_Normal(*theta, *psi, coord, coord + 1, coord + 2); Rotate_XZ(coord, coord, 1, rtheta, rpsi, 0); Geo3d_Normal_Orientation(coord[0], coord[1], coord[2], theta, psi); } double Geo3d_Dot_Product(double x1, double y1, double z1, double x2, double y2, double z2) { return x1 * x2 + y1 * y2 + z1 * z2; } void Geo3d_Cross_Product(double x1, double y1, double z1, double x2, double y2, double z2, double *x, double *y, double *z) { *x = y1 * z2 - y2 * z1; *y = x2 * z1 - x1 * z2; *z = x1 * y2 - x2 * y1; } double Geo3d_Orgdist_Sqr(double x, double y, double z) { return x * x + y * y + z * z; } double Geo3d_Orgdist(double x, double y, double z) { return sqrt(x * x + y * y + z * z); } double Geo3d_Dist_Sqr(double x1, double y1, double z1, double x2, double y2, double z2) { double dx = x1 - x2; double dy = y1 - y2; double dz = z1 - z2; return dx * dx + dy * dy + dz * dz; } double Geo3d_Dist(double x1, double y1, double z1, double x2, double y2, double z2) { double dx = x1 - x2; double dy = y1 - y2; double dz = z1 - z2; return sqrt(dx * dx + dy * dy + dz * dz); } double Geo3d_Angle2(double x1, double y1, double z1, double x2, double y2, double z2) { double d1 = Geo3d_Orgdist_Sqr(x1, y1, z1); if (d1 == 0.0) { return 0.0; } double d2 = Geo3d_Orgdist_Sqr(x2, y2, z2); if (d2 == 0.0) { return 0.0; } double d12 = Geo3d_Dot_Product(x1, y1, z1, x2, y2, z2) / sqrt(d1 * d2); /* to avoid invalid value caused by rounding error */ d12 = (fabs(d12) > 1.0) ? round(d12) : d12; return acos(d12); } void Geo3d_Lineseg_Break(const double *line_start, const double *line_end, double lambda, double *point) { int i; for (i = 0; i < 3; i++) { point[i] = (1 - lambda) * line_start[i] + lambda * line_end[i]; } } #define GEO3D_LINESEG_DIST2_EPS TZ_DIST_3D_EPS /* * reference: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline3d/ */ static int geo3d_line_line_dist(const double *line1_start, const double *line1_end, const double *line2_start, const double *line2_end, double *dc1, double *dc2, double *intersect1, double *intersect2, double eps) { double ds[3]; /*13*/ double de[3]; /*24*/ int i; for (i = 0; i < 3; i++) { dc1[i] = line1_end[i] - line1_start[i]; /*21*/ dc2[i] = line2_end[i] - line2_start[i]; /*43*/ ds[i] = line1_start[i] - line2_start[i]; de[i] = line1_end[i] - line2_end[i]; } double d2121 = dc1[0] * dc1[0] + dc1[1] * dc1[1] + dc1[2] * dc1[2]; double d4343 = dc2[0] * dc2[0] + dc2[1] * dc2[1] + dc2[2] * dc2[2]; if (d2121 < eps) { if (d4343 < eps) { return -3; } return -1; } if (d4343 < eps) { return -2; } double d4321 = dc2[0] * dc1[0] + dc2[1] * dc1[1] + dc2[2] * dc1[2]; double denom = d2121 * d4343 - d4321 * d4321; double d1343 = ds[0] * dc2[0] + ds[1] * dc2[1] + ds[2] * dc2[2]; double d1321 = ds[0] * dc1[0] + ds[1] * dc1[1] + ds[2] * dc1[2]; double numer = d1343 * d4321 - d1321 * d4343; /* parallel */ if (denom <= eps) { return 0; } *intersect1 = numer / denom; *intersect2 = (d1343 + d4321 * (*intersect1)) / d4343; return 1; } static int geo3d_point_line_dist(const double *point, const double *line_start, const double *line_end, double *lamda, double eps) { double line_vec[3]; double point_vec[3]; int i; for (i = 0; i < 3; i++) { line_vec[i] = line_end[i] - line_start[i]; point_vec[i] = point[i] - line_start[i]; } double length_sqr = Geo3d_Orgdist_Sqr(line_vec[0], line_vec[1], line_vec[2]); if (length_sqr < eps) { return 0; } /* projection from point to line */ double dot = point_vec[0] * line_vec[0] + point_vec[1] * line_vec[1] + point_vec[2] * line_vec[2]; *lamda = dot / length_sqr; return 1; } double Geo3d_Line_Line_Dist(double line1_start[], double line1_end[], double line2_start[], double line2_end[]) { double intersect1, intersect2; double dc1[3], dc2[3]; double lamda; switch (geo3d_line_line_dist(line1_start, line1_end, line2_start, line2_end, dc1, dc2, &intersect1, &intersect2, TZ_DIST_3D_EPS)) { case -3: /* point to point */ return Geo3d_Dist(line1_start[0], line1_start[1], line1_start[2], line2_start[0], line2_start[1], line2_start[2]); case -1: /* point to line2 */ geo3d_point_line_dist(line1_start, line2_start, line2_end, &lamda, TZ_DIST_3D_EPS); return Geo3d_Dist(line1_start[0], line1_start[1], line1_start[2], line2_start[0] + lamda * dc2[0], line2_start[1] + lamda * dc2[1], line2_start[2] + lamda * dc2[2]); case -2: /* point to line 1 */ geo3d_point_line_dist(line2_start, line1_start, line1_end, &lamda, TZ_DIST_3D_EPS); return Geo3d_Dist(line2_start[0], line2_start[1], line2_start[2], line1_start[0] + lamda * dc1[0], line1_start[1] + lamda * dc1[1], line1_start[2] + lamda * dc1[2]); case 0: /* parallel */ geo3d_point_line_dist(line1_start, line2_start, line2_end, &lamda, TZ_DIST_3D_EPS); return Geo3d_Dist(line1_start[0], line1_start[1], line1_start[2], line2_start[0] + lamda * dc2[0], line2_start[1] + lamda * dc2[1], line2_start[2] + lamda * dc2[2]); default: /* line to line */ return sqrt(Geo3d_Dist_Sqr(line1_start[0] + intersect1 * dc1[0], line1_start[1] + intersect1 * dc1[1], line1_start[2] + intersect1 * dc1[2], line2_start[0] + intersect2 * dc2[0], line2_start[1] + intersect2 * dc2[1], line2_start[2] + intersect2 * dc2[2])); } } double Geo3d_Lineseg_Lineseg_Dist(double line1_start[], double line1_end[], double line2_start[], double line2_end[], double *intersect1, double *intersect2, int *cond) { double dc1[3]; /*21*/ double dc2[3]; /*43*/ double d1, d2; switch (geo3d_line_line_dist(line1_start, line1_end, line2_start, line2_end, dc1, dc2, intersect1, intersect2, TZ_DIST_3D_EPS)) { case 0: /* parallel */ *cond = 9; d1 = Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect1); d2 = Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2); if (d1 <= d2) { *intersect2 = *intersect1; *intersect1 = 1.0; return d1; } else { *intersect1 = 0.0; return d2; } case -1: *intersect1 = 0.0; *cond = 10; return Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2); case -2: *intersect2= 0.0; *cond = 10; return Geo3d_Point_Lineseg_Dist(line2_start, line1_start, line1_end, intersect1); case -3: *cond = 10; *intersect1 = 0.0; *intersect2 = 0.0; return Geo3d_Dist(line1_start[0], line1_start[1], line1_start[2], line2_start[0], line2_start[1], line2_start[2]); default: #if defined BREAK_IS_IN_RANGE # undef BREAK_IS_IN_RANGE #endif #define BREAK_IS_IN_RANGE(mu) ((mu >= 0.0) && (mu <= 1.0)) if (BREAK_IS_IN_RANGE(*intersect1) && BREAK_IS_IN_RANGE(*intersect2)) { *cond = 0; return sqrt(Geo3d_Dist_Sqr(line1_start[0] + *intersect1 * dc1[0], line1_start[1] + *intersect1 * dc1[1], line1_start[2] + *intersect1 * dc1[2], line2_start[0] + *intersect2 * dc2[0], line2_start[1] + *intersect2 * dc2[1], line2_start[2] + *intersect2 * dc2[2])); } else if ((*intersect1 < 0.0) && BREAK_IS_IN_RANGE(*intersect2)) { *cond = 1; *intersect1 = 0.0; return Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2); } else if ((*intersect1 > 0.0) && BREAK_IS_IN_RANGE(*intersect2)) { *cond = 2; *intersect1 = 1.0; return Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect2); } else if ((*intersect2 < 0.0) && BREAK_IS_IN_RANGE(*intersect1)) { *cond = 3; *intersect2 = 0.0; return Geo3d_Point_Lineseg_Dist(line2_start, line1_start, line1_end, intersect1); } else if ((*intersect2 > 1.0) && BREAK_IS_IN_RANGE(*intersect1)) { *cond = 4; *intersect2 = 1.0; return Geo3d_Point_Lineseg_Dist(line2_end, line1_start, line1_end, intersect1); } else if ((*intersect1 < 0.0) && (*intersect2 < 0.0)) { *cond = 5; d1 = Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2); d2 = Geo3d_Point_Lineseg_Dist(line2_start, line1_start, line1_end, intersect1); if (d1 <= d2) { *intersect1 = 0.0; return d1; } else { *intersect2 = 0.0; return d2; } } else if ((*intersect1 > 1.0) && (*intersect2 < 0.0)) { *cond = 6; d1 = Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect2); d2 = Geo3d_Point_Lineseg_Dist(line2_start, line1_start, line1_end, intersect1); if (d1 <= d2) { *intersect1 = 1.0; return d1; } else { *intersect2 = 0.0; return d2; } } else if ((*intersect1 < 0.0) && (*intersect2 > 1.0)) { *cond = 7; d1 = Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2); d2 = Geo3d_Point_Lineseg_Dist(line2_end, line1_start, line1_end, intersect1); if (d1 <= d2) { *intersect1 = 0.0; return d1; } else { *intersect2 = 1.0; return d2; } } else if ((*intersect1 > 1.0) && (*intersect2 > 1.0)) { *cond = 8; d1 = Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect2); d2 = Geo3d_Point_Lineseg_Dist(line2_end, line1_start, line1_end, intersect1); if (d1<= d2) { *intersect1 = 1.0; return d1; } else { *intersect2 = 1.0; return d2; } } } return -1.0; } double Geo3d_Lineseg_Dist2(double line1_start[], double line1_end[], double line2_start[], double line2_end[], double *intersect1, double *intersect2, int *cond) { double dc1[3]; /*21*/ double dc2[3]; /*43*/ double ds[3]; /*13*/ double de[3]; /*24*/ int i; for (i = 0; i < 3; i++) { dc1[i] = line1_end[i] - line1_start[i]; dc2[i] = line2_end[i] - line2_start[i]; ds[i] = line1_start[i] - line2_start[i]; de[i] = line1_end[i] - line2_end[i]; } double d2121 = dc1[0] * dc1[0] + dc1[1] * dc1[1] + dc1[2] * dc1[2]; double d4343 = dc2[0] * dc2[0] + dc2[1] * dc2[1] + dc2[2] * dc2[2]; ASSERT(d2121 > GEO3D_LINESEG_DIST2_EPS, "invalid length"); ASSERT(d4343 > GEO3D_LINESEG_DIST2_EPS, "invalid length"); double d4321 = dc2[0] * dc1[0] + dc2[1] * dc1[1] + dc2[2] * dc1[2]; double denom = d2121 * d4343 - d4321 * d4321; double d1343 = ds[0] * dc2[0] + ds[1] * dc2[1] + ds[2] * dc2[2]; double d1321 = ds[0] * dc1[0] + ds[1] * dc1[1] + ds[2] * dc1[2]; double numer = d1343 * d4321 - d1321 * d4343; if (denom <= GEO3D_LINESEG_DIST2_EPS) { *cond = 9; return dmin2(Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect1), Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2) ); } *intersect1 = numer / denom; *intersect2 = (d1343 + d4321 * (*intersect1)) / d4343; #if defined BREAK_IS_IN_RANGE # undef BREAK_IS_IN_RANGE #endif #define BREAK_IS_IN_RANGE(mu) ((mu >= 0.0) && (mu <= 1.0)) if (BREAK_IS_IN_RANGE(*intersect1) && BREAK_IS_IN_RANGE(*intersect2)) { *cond = 0; return sqrt(Geo3d_Dist_Sqr(line1_start[0] + *intersect1 * dc1[0], line1_start[1] + *intersect1 * dc1[1], line1_start[2] + *intersect1 * dc1[2], line2_start[0] + *intersect2 * dc2[0], line2_start[1] + *intersect2 * dc2[1], line2_start[2] + *intersect2 * dc2[2])); } else if ((*intersect1 < 0.0) && BREAK_IS_IN_RANGE(*intersect2)) { *cond = 1; return Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2); } else if ((*intersect1 > 0.0) && BREAK_IS_IN_RANGE(*intersect2)) { *cond = 2; return Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect2); } else if ((*intersect2 < 0.0) && BREAK_IS_IN_RANGE(*intersect1)) { *cond = 3; return Geo3d_Point_Lineseg_Dist(line2_start, line1_start, line1_end, intersect1); } else if ((*intersect2 > 1.0) && BREAK_IS_IN_RANGE(*intersect1)) { *cond = 4; return Geo3d_Point_Lineseg_Dist(line2_end, line1_start, line1_end, intersect1); } else if ((*intersect1 < 0.0) && (*intersect2 < 0.0)) { *cond = 5; return dmin2(Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2), Geo3d_Point_Lineseg_Dist(line2_start, line1_start, line1_end, intersect1) ); } else if ((*intersect1 > 1.0) && (*intersect2 < 0.0)) { *cond = 6; return dmin2(Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect2), Geo3d_Point_Lineseg_Dist(line2_start, line1_start, line1_end, intersect1) ); } else if ((*intersect1 < 0.0) && (*intersect2 > 1.0)) { *cond = 7; return dmin2(Geo3d_Point_Lineseg_Dist(line1_start, line2_start, line2_end, intersect2), Geo3d_Point_Lineseg_Dist(line2_end, line1_start, line1_end, intersect1) ); } else if ((*intersect1 > 1.0) && (*intersect2 > 1.0)) { *cond = 8; return dmin2(Geo3d_Point_Lineseg_Dist(line1_end, line2_start, line2_end, intersect2), Geo3d_Point_Lineseg_Dist(line2_end, line1_start, line1_end, intersect1) ); } return -1.0; } #define GEO3D_POINT_LINESEG_EPS 0.0000000000001 double Geo3d_Point_Lineseg_Dist(const double *point, const double *line_start, const double *line_end, double *lamda) { double tmp_lamda; int status = geo3d_point_line_dist(point, line_start, line_end, &tmp_lamda, GEO3D_POINT_LINESEG_EPS); double dist; if (status == 0) { dist = Geo3d_Dist(line_start[0], line_start[1], line_start[2], point[0], point[1], point[2]); } else { if ((tmp_lamda >= 0.0) && (tmp_lamda <= 1.0)) { dist = Geo3d_Dist(point[0], point[1], point[2], (1.0 - tmp_lamda) * line_start[0] + tmp_lamda * line_end[0], (1.0 - tmp_lamda) * line_start[1] + tmp_lamda * line_end[1], (1.0 - tmp_lamda) * line_start[2] + tmp_lamda * line_end[2]); } else if (tmp_lamda < 0.0) { tmp_lamda = 0.0; dist = sqrt(Geo3d_Dist_Sqr(line_start[0], line_start[1], line_start[2], point[0], point[1], point[2])); } else { tmp_lamda = 1.0; dist = sqrt(Geo3d_Dist_Sqr(line_end[0], line_end[1], line_end[2], point[0], point[1], point[2])); } } /* double line_vec[3]; double point_vec[3]; int i; for (i = 0; i < 3; i++) { line_vec[i] = line_end[i] - line_start[i]; point_vec[i] = point[i] - line_start[i]; } double length_sqr = Geo3d_Orgdist_Sqr(line_vec[0], line_vec[1], line_vec[2]); double tmp_lamda = 0.0; double dist = -1.0; if (length_sqr <= GEO3D_POINT_LINESEG_EPS) { dist = sqrt(Geo3d_Dist_Sqr(line_start[0], line_start[1], line_start[2], point[0], point[1], point[2])); } else { double dot = point_vec[0] * line_vec[0] + point_vec[1] * line_vec[1] + point_vec[2] * line_vec[2]; double point_vec_lensqr = Geo3d_Orgdist_Sqr(point_vec[0], point_vec[1], point_vec[2]); if (point_vec_lensqr <= GEO3D_POINT_LINESEG_EPS) { dist = 0.0; } else { tmp_lamda = dot / length_sqr; if ((tmp_lamda >= 0.0) && (tmp_lamda <= 1.0)) { dist = sqrt(point_vec_lensqr - dot * dot / length_sqr); } else if (tmp_lamda < 0.0) { dist = sqrt(Geo3d_Dist_Sqr(line_start[0], line_start[1], line_start[2], point[0], point[1], point[2])); } else { dist = sqrt(Geo3d_Dist_Sqr(line_end[0], line_end[1], line_end[2], point[0], point[1], point[2])); } } } */ if (lamda != NULL) { *lamda = tmp_lamda; } return dist; } void Geo3d_Cov_Orientation(double *cov, double *vec, double *ext) { #ifdef HAVE_LIBGSL gsl_matrix_view gmv = gsl_matrix_view_array(cov, 3, 3); gsl_vector *eval = gsl_vector_alloc(3); gsl_matrix *evec = gsl_matrix_alloc(3,3); gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(3); gsl_eigen_symmv(&(gmv.matrix), eval, evec, w); gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_VAL_DESC); if(ext != NULL) { darraycpy(ext, gsl_vector_const_ptr(eval, 0), 0, 3); } gsl_vector_view v = gsl_vector_view_array(vec, 3); gsl_matrix_get_col(&(v.vector), evec, 0); gsl_vector_free(eval); gsl_matrix_free(evec); gsl_eigen_symmv_free(w); #else double eigv[3]; Matrix_Eigen_Value_Cs(cov[0], cov[4], cov[8], cov[1], cov[2], cov[5], eigv); Matrix_Eigen_Vector_Cs(cov[0], cov[4], cov[8], cov[1], cov[2], cov[5], eigv[0], vec); if(ext != NULL) { darraycpy(ext, eigv, 0, 3); } #endif }
{ "alphanum_fraction": 0.6131902137, "avg_line_length": 28.5268965517, "ext": "c", "hexsha": "3d2c09eaa37580008543228ab3af8d12f9bca58e", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "zzhmark/vaa3d_tools", "max_forks_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/tz_geo3d_utils.c", "max_issues_count": 1, "max_issues_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d", "max_issues_repo_issues_event_max_datetime": "2016-12-03T05:33:13.000Z", "max_issues_repo_issues_event_min_datetime": "2016-12-03T05:33:13.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "zzhmark/vaa3d_tools", "max_issues_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/tz_geo3d_utils.c", "max_line_length": 79, "max_stars_count": 1, "max_stars_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "zzhmark/vaa3d_tools", "max_stars_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/tz_geo3d_utils.c", "max_stars_repo_stars_event_max_datetime": "2021-12-27T19:14:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-12-27T19:14:03.000Z", "num_tokens": 7306, "size": 20682 }
// Copyright (C) 2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 #ifndef _HEBench_ClearText_MatMult_H_7e5fa8c2415240ea93eff148ed73539b #define _HEBench_ClearText_MatMult_H_7e5fa8c2415240ea93eff148ed73539b #include <gsl/gsl> #include "hebench/api_bridge/cpp/hebench.hpp" #include "clear_benchmark.h" template <class T> class MatMult_Benchmark : public ClearTextBenchmark { private: HEBERROR_DECLARE_CLASS_NAME(MatMult_Benchmark) public: MatMult_Benchmark(hebench::cpp::BaseEngine &engine, const hebench::APIBridge::BenchmarkDescriptor &bench_desc, const hebench::APIBridge::WorkloadParams &bench_params); ~MatMult_Benchmark() override; hebench::APIBridge::Handle encode(const hebench::APIBridge::PackedData *p_parameters) override; void decode(hebench::APIBridge::Handle encoded_data, hebench::APIBridge::PackedData *p_native) override; hebench::APIBridge::Handle load(const hebench::APIBridge::Handle *p_local_data, std::uint64_t count) override; void store(hebench::APIBridge::Handle remote_data, hebench::APIBridge::Handle *p_local_data, std::uint64_t count) override; hebench::APIBridge::Handle operate(hebench::APIBridge::Handle h_remote_packed, const hebench::APIBridge::ParameterIndexer *p_param_indexers) override; //std::int64_t classTag() const override { return BaseBenchmark::classTag() | ClearTextBenchmark::tag; } protected: std::array<std::uint64_t, 2> m_rows; std::array<std::uint64_t, 2> m_cols; private: static void matMult(gsl::span<T> &result, const gsl::span<const T> &M0, const gsl::span<const T> &M1, std::size_t columns); }; #include "inl/bench_matmult.inl" #endif // defined _HEBench_ClearText_MatMult_H_7e5fa8c2415240ea93eff148ed73539b
{ "alphanum_fraction": 0.7229299363, "avg_line_length": 36.9411764706, "ext": "h", "hexsha": "6c82c7c102f93ed782eb30b7b56c44724fff9271", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ff74311abd749809b732f1f2f63fe78e245c726d", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "jlakness-intel/backend-cpu-helib", "max_forks_repo_path": "benchmarks/Matrix/MatMult/include/bench_matmult.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "ff74311abd749809b732f1f2f63fe78e245c726d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "jlakness-intel/backend-cpu-helib", "max_issues_repo_path": "benchmarks/Matrix/MatMult/include/bench_matmult.h", "max_line_length": 114, "max_stars_count": null, "max_stars_repo_head_hexsha": "ff74311abd749809b732f1f2f63fe78e245c726d", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "jlakness-intel/backend-cpu-helib", "max_stars_repo_path": "benchmarks/Matrix/MatMult/include/bench_matmult.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 509, "size": 1884 }
#include <stdlib.h> #include <stdio.h> #include <math.h> #include <assert.h> #include <gsl/gsl_math.h> #include "cosmocalc.h" double weff(double a) { if(a != 1.0) return cosmoData.w0 + cosmoData.wa - cosmoData.wa*(a - 1.0)/log(a); else return cosmoData.w0; } double hubble_noscale(double a) { return sqrt(cosmoData.OmegaM/a/a/a + cosmoData.OmegaK/a/a + cosmoData.OmegaL/pow(a,3.0*(1.0 + weff(a)))); }
{ "alphanum_fraction": 0.6634844869, "avg_line_length": 19.9523809524, "ext": "c", "hexsha": "493f3ba62b7b48934d4d067a659f4ede698079a3", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2017-08-11T17:31:51.000Z", "max_forks_repo_forks_event_min_datetime": "2017-07-14T12:17:31.000Z", "max_forks_repo_head_hexsha": "aa7d7cb58f05a36d446e02b45a9117d93eb16556", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "beckermr/cosmocalc", "max_forks_repo_path": "src/hubble.c", "max_issues_count": 1, "max_issues_repo_head_hexsha": "aa7d7cb58f05a36d446e02b45a9117d93eb16556", "max_issues_repo_issues_event_max_datetime": "2016-04-05T19:36:21.000Z", "max_issues_repo_issues_event_min_datetime": "2016-04-05T19:10:45.000Z", "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "beckermr/cosmocalc", "max_issues_repo_path": "src/hubble.c", "max_line_length": 107, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa7d7cb58f05a36d446e02b45a9117d93eb16556", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "beckermr/cosmocalc", "max_stars_repo_path": "src/hubble.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 151, "size": 419 }
#pragma once #include <gsl/gsl_vector.h> #include "BooleanNodes.h" #include "BooleanDAG.h" #include "NodeVisitor.h" #include "VarStore.h" #include <map> #include "FloatSupport.h" #include <glpk.h> #include <iostream> #include <fstream> using namespace std; class Line { // m(x - x0) + d < 0 (x0 is fixed for a particular evaluator, hence not stored in the line) public: double d; gsl_vector* m; Line(double _d, gsl_vector* _m): d(_d), m(_m) {} ~Line(void) { delete m; } double getOffset(const gsl_vector* x0) { // m.x0 - d double r = 0.0; for (int i = 0; i < x0->size; i++) { r += gsl_vector_get(x0, i) * gsl_vector_get(m, i); } return r - d; } double getCoeff(int i) { return gsl_vector_get(m, i); } double getDist() { double r = 0; for (int i = 0; i < m->size; i++) { r += gsl_vector_get(m, i) * gsl_vector_get(m, i); } return d/sqrt(r); } string print() { stringstream str; str << "<"; for (int i = 0; i < m->size; i++) { str << gsl_vector_get(m, i) << " "; } str << d << ">"; return str.str(); } }; class Region { // Intersection of lines public: vector<Line*> lines; int size() { return lines.size(); } Line* get(int i) { return lines[i]; } void addLine(Line* l) { if (find(lines.begin(), lines.end(), l) == lines.end()) { lines.push_back(l); } } static Region* intersect(Region* r1, Region* r2) { Region* r = new Region(); for (int i = 0; i < r1->size(); i++) { r->addLine(r1->get(i)); } for (int i = 0; i < r2->size(); i++) { r->addLine(r2->get(i)); } return r; } static Region* copy(Region* r1) { Region* r = new Region(); for (int i = 0; i < r1->size(); i++) { r->addLine(r1->get(i)); } return r; } double getMaxDist() { double d = - numeric_limits<double>::max(); for (int i = 0; i < lines.size(); i++) { if (lines[i]->getDist() > d) { d = lines[i]->getDist(); } } return d; } gsl_vector* getMaxGrad() { double d = - numeric_limits<double>::max(); gsl_vector* g; for (int i = 0; i < lines.size(); i++) { if (lines[i]->d > d) { d = lines[i]->d; g = lines[i]->m; } } return g; } ~Region(void) { for (int i = 0; i < lines.size(); i++) { delete lines[i]; } } string print() { stringstream str; str << "{"; for (int i = 0; i < lines.size(); i++) { str << lines[i]->print() << " "; } str << "}"; return str.str(); } }; class Value { public: double val; gsl_vector* grad; Value(double v, gsl_vector* g): val(v), grad(g) {} ~Value(void) { delete grad; } double getOffset(const gsl_vector* x0) { // d - m.x0 double r = 0.0; for (int i = 0; i < x0->size; i++) { r += gsl_vector_get(x0, i) * gsl_vector_get(grad, i); } return val - r; } double getCoeff(int i) { return gsl_vector_get(grad, i); } static Value* add(Value* v1, Value* v2); static Value* mult(Value* v1, Value* v2); static Value* div(Value* v1, Value* v2); static Value* neg(Value* v1); static Value* copy(Value* v1); static Value* arctan(Value* v1); static Value* tan(Value* v1); static Value* cos(Value* v1); static Value* sin(Value* v1); static Value* sqrt(Value* v1); static Value* square(Value* v1); string print() { stringstream str; str << "<"; for (int i = 0; i < grad->size; i++) { str << gsl_vector_get(grad, i) << " "; } str << val << ">"; return str.str(); } }; class RegionValuePair { public: Region* r; Value* v; RegionValuePair(Region* _r, Value* _v): r(_r), v(_v) {} string print() { stringstream str; str << r->print() << " -> " << v->print(); return str.str(); } }; typedef vector<RegionValuePair*> ValuesList; class LP { glp_prob* lp; int ia[1+1000], ja[1+1000]; double ar[1+1000]; double LOWBND = -32.0; // TODO: don;t hardcode double HIGHBND = 32.0; double PRECISION = 1e-5; public: double optimize(RegionValuePair* rv, const gsl_vector* x0) { lp = glp_create_prob(); glp_set_obj_dir(lp, GLP_MIN); int numrows = rv->r->size(); if (numrows > 0) { glp_add_rows(lp, numrows); for (int i = 0; i < numrows; i++) { glp_set_row_name(lp, (i+1), "r" + (i+1)); double c = rv->r->lines[i]->getOffset(x0); glp_set_row_bnds(lp, (i+1), GLP_UP, 0.0, c - PRECISION); } } int numcols = x0->size; glp_add_cols(lp, numcols); for (int i = 0; i < numcols; i++) { glp_set_col_name(lp, (i+1), "x" + (i+1)); glp_set_col_bnds(lp, (i+1), GLP_DB, LOWBND, HIGHBND); glp_set_obj_coef(lp, (i+1), rv->v->getCoeff(i)); } int counter = 1; for (int i = 0; i < numrows; i++) { for (int j = 0; j < numcols; j++) { ia[counter] = (i+1); ja[counter] = (j+1); ar[counter] = rv->r->lines[i]->getCoeff(j); counter++; } } Assert(counter-1 <= 1000, "Out of bounds"); glp_load_matrix(lp, counter-1, ia, ja, ar); glp_simplex(lp, NULL); int status = glp_get_prim_stat(lp); cout << "status: " << status << endl; if (status == GLP_FEAS) { double z = glp_get_obj_val(lp); cout << "z = " << z; for (int i = 0; i < numcols; i++) { cout << " x" << i << " = " << glp_get_col_prim(lp, (i+1)); } glp_delete_prob(lp); return z + rv->v->getOffset(x0); } else { return 1000; } } bool check(Region* r, const gsl_vector* x0) { int numrows = r->size(); if (numrows == 0) return true; lp = glp_create_prob(); glp_set_obj_dir(lp, GLP_MIN); glp_add_rows(lp, numrows); for (int i = 0; i < numrows; i++) { stringstream str; str << "r" << (i+1); glp_set_row_name(lp, (i+1), str.str().c_str()); double c = r->lines[i]->getOffset(x0); glp_set_row_bnds(lp, (i+1), GLP_UP, 0.0, c-PRECISION); } int numcols = x0->size; glp_add_cols(lp, numcols); for (int i = 0; i < numcols; i++) { stringstream str; str << "x" << (i+1); glp_set_col_name(lp, (i+1), str.str().c_str()); glp_set_col_bnds(lp, (i+1), GLP_DB, LOWBND, HIGHBND); glp_set_obj_coef(lp, (i+1), 0.0); } int counter = 1; for (int i = 0; i < numrows; i++) { for (int j = 0; j < numcols; j++) { ia[counter] = (i+1); ja[counter] = (j+1); ar[counter] = r->lines[i]->getCoeff(j); counter++; } } glp_load_matrix(lp, counter-1, ia, ja, ar); glp_smcp param; glp_init_smcp(&param); param.msg_lev = GLP_MSG_ERR; glp_simplex(lp, &param); int status = glp_get_prim_stat(lp); glp_delete_prob(lp); if (status == GLP_FEAS) { return true; } else { return false; } } }; class GlobalEvaluator: NodeVisitor { FloatManager& floats; BooleanDAG& bdag; map<string, int> floatCtrls; // Maps float ctrl names to indices with grad vectors int nctrls; // number of float ctrls gsl_vector* ctrls; // Ctrl values vector<ValuesList> values; // Keeps track of values for each node for different regions map<int, int> inputValues; // Maps node id to values set by the SAT solver double error = 0.0; gsl_vector* errorGrad; int DEFAULT_INP = -1; static gsl_vector* tmp; LP* lp; int MAX_REGIONS = 16; int ctr = 0; public: GlobalEvaluator(BooleanDAG& bdag_p, FloatManager& _floats, const map<string, int>& floatCtrls_p); ~GlobalEvaluator(void); virtual void visit( SRC_node& node ); virtual void visit( DST_node& node ); virtual void visit( CTRL_node& node ); virtual void visit( PLUS_node& node ); virtual void visit( TIMES_node& node ); virtual void visit( ARRACC_node& node ); virtual void visit( DIV_node& node ); virtual void visit( MOD_node& node ); virtual void visit( NEG_node& node ); virtual void visit( CONST_node& node ); virtual void visit( LT_node& node ); virtual void visit( EQ_node& node ); virtual void visit( AND_node& node ); virtual void visit( OR_node& node ); virtual void visit( NOT_node& node ); virtual void visit( ARRASS_node& node ); virtual void visit( UFUN_node& node ); virtual void visit( TUPLE_R_node& node ); virtual void visit( ASSERT_node& node ); double run(const gsl_vector* ctrls_p, map<int, int>& inputValues_p, gsl_vector* errorGrad_p); void truncate(ValuesList& vl, const gsl_vector* x0, int numRegions); void truncate(vector<Region*>& vl, const gsl_vector* x0, int numRegions); void truncateUnfeasibleRegions(ValuesList& vl, const gsl_vector* x0); void truncateUnfeasibleRegions(vector<Region*>& vl, const gsl_vector* x0); void truncateFarRegions(ValuesList& vl, const gsl_vector* x0, int numRegions); void truncateFarRegions(vector<Region*>& vl, const gsl_vector* x0, int numRegions); void setvalues(bool_node& bn, ValuesList& v) { values[bn.id] = v; } ValuesList& getvalues(bool_node& bn) { return values[bn.id]; } ValuesList& getvalues(bool_node* bn) { return getvalues(*bn); } void print() { for (int i = 0; i < bdag.size(); i++) { cout << bdag[i]->lprint() << endl; } } bool isFloat(bool_node& bn) { return (bn.getOtype() == OutType::FLOAT); } bool isFloat(bool_node* bn) { return (bn->getOtype() == OutType::FLOAT); } int getInputValue(bool_node& bn) { if (inputValues.find(bn.id) != inputValues.end()) { int val = inputValues[bn.id]; Assert(val == 0 || val == 1, "NYI: Integer values"); return val; } else { return DEFAULT_INP; } } int getInputValue(bool_node* bn) { return getInputValue(*bn); } static gsl_vector* default_grad(int nctrls) { gsl_vector* g = gsl_vector_alloc(nctrls); for (int i = 0; i < nctrls; i++) { gsl_vector_set(g, i, 0); } return g; } static gsl_vector* add_grad(gsl_vector* g1, gsl_vector* g2); static gsl_vector* mult_grad(double v1, double v2, gsl_vector* g1, gsl_vector* g2); static gsl_vector* div_grad(double v1, double v2, gsl_vector* g1, gsl_vector* g2); static gsl_vector* neg_grad(gsl_vector* g1); static gsl_vector* copy_grad(gsl_vector* g1); static gsl_vector* sub_grad(gsl_vector* g1, gsl_vector* g2); static gsl_vector* arctan_grad(double v1, gsl_vector* g1); static gsl_vector* tan_grad(double v1, gsl_vector* g1); static gsl_vector* cos_grad(double v1, gsl_vector* g1); static gsl_vector* sin_grad(double v1, gsl_vector* g1); static gsl_vector* sqrt_grad(double v1, gsl_vector* g1); static gsl_vector* square_grad(double v1, gsl_vector* g1); };
{ "alphanum_fraction": 0.6196463654, "avg_line_length": 24.6489104116, "ext": "h", "hexsha": "ef9ca57184aa6eadc3ae0e0b984d96a10c7931d5", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "6ecbb6f724149d50d290997fef5e2e1e92ab3d9e", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "natebragg/sketch-backend", "max_forks_repo_path": "src/SketchSolver/NumericalSynthesis/SymbolicEvaluators/GlobalEvaluator.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "6ecbb6f724149d50d290997fef5e2e1e92ab3d9e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "natebragg/sketch-backend", "max_issues_repo_path": "src/SketchSolver/NumericalSynthesis/SymbolicEvaluators/GlobalEvaluator.h", "max_line_length": 104, "max_stars_count": null, "max_stars_repo_head_hexsha": "6ecbb6f724149d50d290997fef5e2e1e92ab3d9e", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "natebragg/sketch-backend", "max_stars_repo_path": "src/SketchSolver/NumericalSynthesis/SymbolicEvaluators/GlobalEvaluator.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3392, "size": 10180 }
#include <omp.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #include <string.h> #include <errno.h> #include <gsl/gsl_statistics.h> #include <gsl/gsl_linalg.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_sf.h> #include <gsl/gsl_statistics.h> #include <gsl/gsl_math.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_permute_vector.h> #include <gsl/gsl_blas.h> #include "mpi.h" //data specific parameters #define KMEANS 3 //number of cluster groups #define DIMENSIONS 4 //number of dimensions of data #define DATA_ROWS 150 //run specific parameters #define THREAD_COUNT 6 //count of thread used by OpenMP #define FITNESS_FUNCTION fitness5 //specify fitness function used, 5 possibilities (fitness1,fitness2,...,fitness5) #define SWARM_SIZE (200) #define MAX_ITERATIONS (10000) #define GEN_MUTATION 4 //how many parts of genes will be mutated #define ELITE 4 //how many genes will be preserved without change #define REAL long double #define size_t int #define ROOT 0 long double vectors[DATA_ROWS][DIMENSIONS]; //here are stored data vectors long double fitness[SWARM_SIZE]; int chrom[SWARM_SIZE][DATA_ROWS]; int new_chromosoms[SWARM_SIZE][DATA_ROWS]; long double fit_data_vectors[KMEANS][DIMENSIONS][DATA_ROWS]; //used to compute fitness #pragma omp threadprivate(fit_data_vectors) char dataset[100]; /* * FITNEES FUNCTION * fitness1 - vseobecne kriterium (VVV) * fitness2 - spriemerovane kovariancne matice sa pouziju na fitness (EEE) * fitness3 - stopa kovariancnych matic (VII) * fitness4 - sucet stvorcov euklidovskych vzdialenosti fitness (KMEANS) * fitness5 - spriemerovane stopy kovariancnych matic (EII) */ long double my_mean(const long double data[], const size_t stride, const size_t size) { long double mean = 0; size_t i; for (i = 0; i < size; i++) { mean += (data[i * stride] - mean) / (i + 1); } return mean; } long double _my_covariance(const long double data1[], const size_t stride1, const long double data2[], const size_t stride2, const size_t n, const long double mean1, const long double mean2) { long double covariance = 0; size_t i; /* find the sum of the squares */ for (i = 0; i < n; i++) { const long double delta1 = (data1[i * stride1] - mean1); const long double delta2 = (data2[i * stride2] - mean2); covariance += (delta1 * delta2 - covariance) / (i + 1); } return covariance; } long double my_gsl_stats_covariance(const long double data1[], const size_t stride1, const long double data2[], const size_t stride2, const size_t n) { const long double mean1 = my_mean(data1, stride1, n); const long double mean2 = my_mean(data2, stride2, n); return _my_covariance(data1, stride1, data2, stride2, n, mean1, mean2); } long double my_gsl_linalg_LU_det(gsl_matrix_long_double * LU, int signum) { size_t i, n = LU->size1; long double det = (long double) signum; for (i = 0; i < n; i++) { det *= gsl_matrix_long_double_get(LU, i, i); } return det; } void my_gsl_linalg_LU_decomp(gsl_matrix_long_double * A, gsl_permutation * p, int *signum) { if (A->size1 != A->size2) { printf("LU decomposition requires square matrix"); } else if (p->size != A->size1) { printf("permutation length must match matrix size"); } else { const size_t N = A->size1; size_t i, j, k; *signum = 1; gsl_permutation_init(p); for (j = 0; j < N - 1; j++) { /* Find maximum in the j-th column */ long double ajj, max = fabs(gsl_matrix_long_double_get(A, j, j)); size_t i_pivot = j; for (i = j + 1; i < N; i++) { long double aij = fabs(gsl_matrix_long_double_get(A, i, j)); if (aij > max) { max = aij; i_pivot = i; } } if (i_pivot != j) { gsl_matrix_long_double_swap_rows(A, j, i_pivot); gsl_permutation_swap(p, j, i_pivot); *signum = -(*signum); } ajj = gsl_matrix_long_double_get(A, j, j); if (ajj != 0.0) { for (i = j + 1; i < N; i++) { long double aij = gsl_matrix_long_double_get(A, i, j) / ajj; gsl_matrix_long_double_set(A, i, j, aij); for (k = j + 1; k < N; k++) { long double aik = gsl_matrix_long_double_get(A, i, k); long double ajk = gsl_matrix_long_double_get(A, j, k); gsl_matrix_long_double_set(A, i, k, aik - aij * ajk); } } } } } } int random_int(int min_num, int max_num) { int result = 0; result = (rand() % (max_num - min_num)) + min_num; return result; } int my_ceil(float num) { int inum = (int) num; if (num == (float) inum) { return inum; } return inum + 1; } void my_export(char filename[100]) { int i; FILE *fp; fp = fopen(filename, "w"); for (i = 0; i < DATA_ROWS; i++) { fprintf(fp, "%d\n", chrom[0][i] + 1); } fclose(fp); } long double fitness1(int i) { int j, k, h, s; long double det; int fit_cluster_volume[KMEANS]; gsl_matrix_long_double *fit_matrix[KMEANS]; gsl_permutation * p = gsl_permutation_alloc(DIMENSIONS); long double result = 0; for (j = 0; j < KMEANS; j++) { fit_cluster_volume[j] = 0; } for (j = 0; j < DATA_ROWS; j++) { for (h = 0; h < DIMENSIONS; h++) { fit_data_vectors[chrom[i][j]][h][fit_cluster_volume[chrom[i][j]]] = vectors[j][h]; } fit_cluster_volume[chrom[i][j]]++; } for (j = 0; j < KMEANS; j++) { fit_matrix[j] = gsl_matrix_long_double_calloc(DIMENSIONS, DIMENSIONS); for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { gsl_matrix_long_double_set(fit_matrix[j], k, h, my_gsl_stats_covariance(fit_data_vectors[j][k], 1, fit_data_vectors[j][h], 1, fit_cluster_volume[j])); } } } for (j = 0; j < KMEANS; j++) { s = 1; my_gsl_linalg_LU_decomp(fit_matrix[j], p, &s); det = my_gsl_linalg_LU_det(fit_matrix[j], s); if (det != 0.0) { result += gsl_sf_log_abs(det) * (double) fit_cluster_volume[j]; } gsl_matrix_long_double_free(fit_matrix[j]); } return result; } long double fitness2(int i) { int j, k, h, s; long double m, det; int fit_cluster_volume[KMEANS]; gsl_matrix_long_double *fit_matrix[KMEANS]; gsl_matrix_long_double *fit_reuslt_matrix; gsl_permutation * p = gsl_permutation_alloc(DIMENSIONS); long double result = 0; for (j = 0; j < KMEANS; j++) { fit_cluster_volume[j] = 0; } for (j = 0; j < DATA_ROWS; j++) { for (h = 0; h < DIMENSIONS; h++) { fit_data_vectors[chrom[i][j]][h][fit_cluster_volume[chrom[i][j]]] = vectors[j][h]; } fit_cluster_volume[chrom[i][j]]++; } for (j = 0; j < KMEANS; j++) { fit_matrix[j] = gsl_matrix_long_double_calloc(DIMENSIONS, DIMENSIONS); for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { gsl_matrix_long_double_set(fit_matrix[j], k, h, my_gsl_stats_covariance(fit_data_vectors[j][k], 1, fit_data_vectors[j][h], 1, fit_cluster_volume[j])); } } } fit_reuslt_matrix = gsl_matrix_long_double_calloc(DIMENSIONS, DIMENSIONS); for (j = 0; j < KMEANS; j++) { for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { m = gsl_matrix_long_double_get(fit_reuslt_matrix, k, h); m += fit_cluster_volume[j] * gsl_matrix_long_double_get(fit_matrix[j], k, h); gsl_matrix_long_double_set(fit_reuslt_matrix, k, h, m); } } gsl_matrix_long_double_free(fit_matrix[j]); } for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { m = gsl_matrix_long_double_get(fit_reuslt_matrix, k, h); m = m / (double) DATA_ROWS; gsl_matrix_long_double_set(fit_reuslt_matrix, k, h, m); } } s = 1; my_gsl_linalg_LU_decomp(fit_reuslt_matrix, p, &s); det = my_gsl_linalg_LU_det(fit_reuslt_matrix, s); if (det != 0.0) { result += gsl_sf_log_abs(det); } gsl_matrix_long_double_free(fit_reuslt_matrix); return result; } long double fitness3(int i) { int j, k, h; int fit_cluster_volume[KMEANS]; gsl_matrix_long_double *fit_matrix[KMEANS]; long double result = 0; for (j = 0; j < KMEANS; j++) { fit_cluster_volume[j] = 0; } for (j = 0; j < DATA_ROWS; j++) { for (h = 0; h < DIMENSIONS; h++) { fit_data_vectors[chrom[i][j]][h][fit_cluster_volume[chrom[i][j]]] = vectors[j][h]; } fit_cluster_volume[chrom[i][j]]++; } for (j = 0; j < KMEANS; j++) { fit_matrix[j] = gsl_matrix_long_double_calloc(DIMENSIONS, DIMENSIONS); for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { gsl_matrix_long_double_set(fit_matrix[j], k, h, my_gsl_stats_covariance(fit_data_vectors[j][k], 1, fit_data_vectors[j][h], 1, fit_cluster_volume[j])); } } } for (j = 0; j < KMEANS; j++) { for (k = 0; k < DIMENSIONS; k++) { result += gsl_matrix_long_double_get(fit_matrix[j], k, k); } gsl_matrix_long_double_free(fit_matrix[j]); } return result; } long double fitness4(int agent) { int i, j, v; int weight_matrix[DATA_ROWS][KMEANS]; long double center_matrix[KMEANS][DIMENSIONS]; long double sum_w; long double sum_wx; long double result = 0; for (i = 0; i < DATA_ROWS; i++) { for (j = 0; j < KMEANS; j++) { if (chrom[agent][i] == j) { weight_matrix[i][j] = 1; } else { weight_matrix[i][j] = 0; } } } for (j = 0; j < KMEANS; j++) { for (v = 0; v < DIMENSIONS; v++) { sum_w = 0.0; for (i = 0; i < DATA_ROWS; i++) { sum_w += weight_matrix[i][j]; } sum_wx = 0.0; for (i = 0; i < DATA_ROWS; i++) { sum_wx += weight_matrix[i][j] * vectors[i][v]; } center_matrix[j][v] = sum_wx / sum_w; } } for (j = 0; j < KMEANS; j++) { for (i = 0; i < DATA_ROWS; i++) { sum_w = 0.0; for (v = 0; v < DIMENSIONS; v++) { sum_w += weight_matrix[i][j] * ((vectors[i][v] - center_matrix[j][v]) * (vectors[i][v] - center_matrix[j][v])); } result += sqrt(sum_w); } } return result; } long double fitness5(int i) { int j, k, h; long double m; int fit_cluster_volume[KMEANS]; gsl_matrix_long_double *fit_matrix[KMEANS]; gsl_matrix_long_double *fit_reuslt_matrix; long double result = 0; for (j = 0; j < KMEANS; j++) { fit_cluster_volume[j] = 0; } for (j = 0; j < DATA_ROWS; j++) { for (h = 0; h < DIMENSIONS; h++) { fit_data_vectors[chrom[i][j]][h][fit_cluster_volume[chrom[i][j]]] = vectors[j][h]; } fit_cluster_volume[chrom[i][j]]++; } for (j = 0; j < KMEANS; j++) { fit_matrix[j] = gsl_matrix_long_double_calloc(DIMENSIONS, DIMENSIONS); for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { gsl_matrix_long_double_set(fit_matrix[j], k, h, my_gsl_stats_covariance(fit_data_vectors[j][k], 1, fit_data_vectors[j][h], 1, fit_cluster_volume[j])); } } } fit_reuslt_matrix = gsl_matrix_long_double_calloc(DIMENSIONS, DIMENSIONS); for (j = 0; j < KMEANS; j++) { for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { m = gsl_matrix_long_double_get(fit_reuslt_matrix, k, h); m += fit_cluster_volume[j] * gsl_matrix_long_double_get(fit_matrix[j], k, h); gsl_matrix_long_double_set(fit_reuslt_matrix, k, h, m); } } gsl_matrix_long_double_free(fit_matrix[j]); } for (k = 0; k < DIMENSIONS; k++) { for (h = 0; h < DIMENSIONS; h++) { m = gsl_matrix_long_double_get(fit_reuslt_matrix, k, h); m = m / (double) DATA_ROWS; gsl_matrix_long_double_set(fit_reuslt_matrix, k, h, m); } } for (k = 0; k < DIMENSIONS; k++) { result += gsl_matrix_long_double_get(fit_reuslt_matrix, k, k); } gsl_matrix_long_double_free(fit_reuslt_matrix); return result; } void quicksort(long double list[], int ch[][DATA_ROWS], int n) { int i, j; long double pivot; long double temp; int temp_ch[DATA_ROWS]; if (n < 2) return; pivot = list[n / 2]; for (i = 0, j = n - 1;; i++, j--) { while (list[i] < pivot) i++; while (pivot < list[j]) j--; if (i >= j) break; //swap temp = list[i]; list[i] = list[j]; list[j] = temp; memcpy(&temp_ch, &ch[i][0], sizeof(int) * DATA_ROWS); memcpy(&ch[i][0], &ch[j][0], sizeof(int) * DATA_ROWS); memcpy(&ch[j][0], &temp_ch, sizeof(int) * DATA_ROWS); } quicksort(list, ch, i); quicksort(list + i, ch + i, n - i); } int *int_array_2dto1d(int array[][DATA_ROWS], int first_dimension, int second_dimension) { int i, j; int *subarray = malloc(sizeof(int) * first_dimension * second_dimension); for (i = 0; i < first_dimension; i++) { for (j = 0; j < second_dimension; j++) { subarray[i * second_dimension + j] = array[i][j]; } } return subarray; } void int_array_1dto2d(int *array, int solver, int elements_per_proc, int first_dimension, int second_dimension) { int i, j; for (i = 0; i < first_dimension; i++) { for (j = 0; j < second_dimension; j++) { chrom[solver * elements_per_proc + i][j] = array[i * second_dimension + j]; } } } int main(int argc, char *argv[]) { int i, j, k, h, it; int temp_ch[DATA_ROWS]; int *sub_chrom; int * chrom1d = NULL; long double *sub_fitness; unsigned long long int mating_h[SWARM_SIZE]; unsigned long long int max_mating = 0; int mates[SWARM_SIZE]; int r1, r2; time_t t, tt; int solver, solvers_count; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &solver); MPI_Comm_size(MPI_COMM_WORLD, &solvers_count); MPI_Datatype my_type_scatter; MPI_Type_contiguous(DATA_ROWS, MPI_INT, &my_type_scatter); MPI_Type_commit(&my_type_scatter); if (SWARM_SIZE % 2 == 1) { printf("SWARM SIZE need to be dividable/partible by 2\n"); exit(1); } if (argc >= 2) { strcpy(dataset, argv[1]); } else { printf("Program argument (dataset to read) not found.\n"); exit(1); } if (SWARM_SIZE % solvers_count != 0) { printf( "SWARM_SIZE need to be divadable/partible by count of mpi solvers\n"); exit(1); } srand(time(NULL)); omp_set_num_threads(THREAD_COUNT); if (solver == ROOT) { for (i = 0; i < SWARM_SIZE / 2; i++) { mating_h[i] = gsl_pow_int((SWARM_SIZE / 2 - i), 5); max_mating += mating_h[i]; mating_h[i + SWARM_SIZE / 2] = 0; } } //read data FILE *fp; char *token; fp = fopen(dataset, "r"); if (fp != NULL) { int lineNumber = 0; char line[1024]; while (fgets(line, sizeof line, fp) != NULL) { token = strtok(line, ","); for (i = 0; i < DIMENSIONS - 1; i++) { vectors[lineNumber][i] = atof(token); token = strtok(NULL, ","); } vectors[lineNumber][DIMENSIONS - 1] = atof(token); lineNumber++; } fclose(fp); } else { printf("%s\n", strerror(errno)); exit(1); } //end of read data time(&t); //Generate initial population. if (solver == ROOT) { for (i = 0; i < SWARM_SIZE; i++) { for (j = 0; j < DATA_ROWS; j++) { chrom[i][j] = random_int(0, KMEANS); } } } //Compute fitness of each chromosome. #pragma omp parallel for shared(i,fitness) for (i = 0; i < SWARM_SIZE; i++) { fitness[i] = FITNESS_FUNCTION(i); } quicksort(fitness, chrom, SWARM_SIZE); for (it = 0; it < MAX_ITERATIONS; it++) { //Natural selection. Select mates. if (solver == ROOT) { for (i = 0; i < SWARM_SIZE; i++) { j = random_int(1, max_mating); h = 0; k = mating_h[h]; while (j > k) { k += mating_h[++h]; } mates[i] = h; } } //Mating if (solver == ROOT) { for (i = 0; i < SWARM_SIZE; i++) { do { r1 = random_int(0, DATA_ROWS); r2 = random_int(0, DATA_ROWS); } while (r1 == r2); if (r1 < r2) { j = r1; k = r2; } else { j = r2; k = r1; } //first kid memcpy(&temp_ch[0], &chrom[mates[i]][0], j * sizeof(int)); memcpy(&temp_ch[j], &chrom[mates[i + 1]][j], (k - j) * sizeof(int)); memcpy(&temp_ch[k], &chrom[mates[i]][k], (DATA_ROWS - k) * sizeof(int)); memcpy(new_chromosoms[i], temp_ch, DATA_ROWS * sizeof(int)); //second kid memcpy(&temp_ch[0], &chrom[mates[i + 1]][0], j * sizeof(int)); memcpy(&temp_ch[j], &chrom[mates[i]][j], (k - j) * sizeof(int)); memcpy(&temp_ch[k], &chrom[mates[i + 1]][k], (DATA_ROWS - k) * sizeof(int)); memcpy(new_chromosoms[i + 1], temp_ch, DATA_ROWS * sizeof(int)); i++; } } //copy new population if (solver == ROOT) { for (i = ELITE; i < SWARM_SIZE; i++) { memcpy(&chrom[i], &new_chromosoms[i], sizeof(int) * DATA_ROWS); } } //Mutation. if (solver == ROOT) { for (i = ELITE; i < SWARM_SIZE; i++) { for (j = 0; j < GEN_MUTATION; j++) { k = random_int(0, DATA_ROWS); chrom[i][k] = random_int(0, KMEANS); } } } //mpi section if (solver == ROOT) { chrom1d = int_array_2dto1d(chrom, SWARM_SIZE, DATA_ROWS); } sub_chrom = malloc( sizeof(int) * (SWARM_SIZE / solvers_count) * DATA_ROWS); MPI_Scatter(chrom1d, SWARM_SIZE / solvers_count, my_type_scatter, sub_chrom, SWARM_SIZE / solvers_count, my_type_scatter, ROOT, MPI_COMM_WORLD); int_array_1dto2d(sub_chrom, solver, SWARM_SIZE / solvers_count, SWARM_SIZE / solvers_count, DATA_ROWS); sub_fitness = malloc( sizeof(long double) * (SWARM_SIZE / solvers_count)); //Compute fitness of each chromosome. #pragma omp parallel for shared(i,fitness,sub_fitness) for (i = solver * (SWARM_SIZE / solvers_count); i < solver * (SWARM_SIZE / solvers_count) + (SWARM_SIZE / solvers_count); i++) { sub_fitness[i - solver * (SWARM_SIZE / solvers_count)] = FITNESS_FUNCTION(i); } MPI_Gather(sub_fitness, SWARM_SIZE / solvers_count, MPI_LONG_DOUBLE, fitness, SWARM_SIZE / solvers_count, MPI_LONG_DOUBLE, ROOT, MPI_COMM_WORLD); free(sub_chrom); free(sub_fitness); if (solver == ROOT && chrom1d != NULL) { free(chrom1d); } //end of mpi section //Order population if (solver == ROOT) { quicksort(fitness, chrom, SWARM_SIZE); } } if (solver == ROOT) { time(&tt); printf("Program bezal %.f sekund.\n", difftime(tt, t)); printf("fitness: %Lf\n", fitness[0]); if (argc >= 3) { my_export(argv[2]); } else { my_export("/home/lukas/workspace_parallel/mpi_gen/export.txt"); } printf("SWARM SIZE: %d\n", SWARM_SIZE); printf("MAX_ITERATIONS: %d\n", MAX_ITERATIONS); printf("GEN_MUTATION: %d\n", GEN_MUTATION); printf("ELITE: %d\n", ELITE); printf("DIMENSIONS: %d\n", DIMENSIONS); printf("KMEANS: %d\n", KMEANS); printf("THREAD_COUNT per instance: %d\n", THREAD_COUNT); printf("mpi solvers_count: %d\n", solvers_count); printf(" FITNESS_FUNCTION "); } MPI_Finalize(); return 0; }
{ "alphanum_fraction": 0.630643927, "avg_line_length": 24.6218034993, "ext": "c", "hexsha": "a1be0ffee4ddd139fcb04383082a2742ef3eeb1f", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7dbf99a958fea4bd10b0bbd0b112fd81059c6a00", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "PetoLau/GenClust", "max_forks_repo_path": "Impl of clus alg/GenClust/MPI_GenClust.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "7dbf99a958fea4bd10b0bbd0b112fd81059c6a00", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "PetoLau/GenClust", "max_issues_repo_path": "Impl of clus alg/GenClust/MPI_GenClust.c", "max_line_length": 115, "max_stars_count": null, "max_stars_repo_head_hexsha": "7dbf99a958fea4bd10b0bbd0b112fd81059c6a00", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "PetoLau/GenClust", "max_stars_repo_path": "Impl of clus alg/GenClust/MPI_GenClust.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6130, "size": 18294 }
#ifndef CONSUMER_H #define CONSUMER_H #include <gsl/gsl> #include <producer.h> class consumer { public: explicit consumer(gsl::not_null<producer *> p) { p->print_msg(); } ~consumer() = default; public: consumer(consumer &&) noexcept = default; consumer &operator=(consumer &&) noexcept = default; consumer(const consumer &) = delete; consumer &operator=(const consumer &) = delete; }; #endif
{ "alphanum_fraction": 0.5904365904, "avg_line_length": 17.8148148148, "ext": "h", "hexsha": "1222e53dd636c6cc1fc59019a68c2ed0303215d4", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "719d990d75f208aeee69be71fa5a6285cef69fb2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "rutujar/ci_helloworld", "max_forks_repo_path": "include/consumer.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "719d990d75f208aeee69be71fa5a6285cef69fb2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "rutujar/ci_helloworld", "max_issues_repo_path": "include/consumer.h", "max_line_length": 60, "max_stars_count": null, "max_stars_repo_head_hexsha": "719d990d75f208aeee69be71fa5a6285cef69fb2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rutujar/ci_helloworld", "max_stars_repo_path": "include/consumer.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 107, "size": 481 }
#include <gsl/gsl_poly.h> size_t remove_leading_zeros(double *h, size_t n) { size_t m = 0; double small = 1e-5; size_t i; for(i=n; i>0; i--) { if (fabs(h[i-1]) > small) { m = i; break; } } return m; } size_t find_roots(double *z, double *h, size_t n) { size_t m; m = remove_leading_zeros(&h[0], n); if (m > 1) { gsl_poly_complex_workspace *w = gsl_poly_complex_workspace_alloc(m); gsl_poly_complex_solve(h, m, w, z); gsl_poly_complex_workspace_free (w); } return m; }
{ "alphanum_fraction": 0.5262295082, "avg_line_length": 14.1860465116, "ext": "c", "hexsha": "acb3ca0f41e509a34179c992e0e740e79a687ff2", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "127603a519ae25979de6c6197810a7ea38ec945b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "aluchies/particle_packing", "max_forks_repo_path": "particle_packing/cython/c/polynomial.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "127603a519ae25979de6c6197810a7ea38ec945b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "aluchies/particle_packing", "max_issues_repo_path": "particle_packing/cython/c/polynomial.c", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "127603a519ae25979de6c6197810a7ea38ec945b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "aluchies/particle_packing", "max_stars_repo_path": "particle_packing/cython/c/polynomial.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 183, "size": 610 }
/* # Copyright (C) 2009-2013 Thierry Sousbie # University of Tokyo / CNRS, 2009 # # This file is part of porject DisPerSE # # Author : Thierry Sousbie # Contact : tsousbie@gmail.com # # Licenses : This file is 'dual-licensed', you have to choose one # of the two licenses below to apply. # # CeCILL-C # The CeCILL-C license is close to the GNU LGPL. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html ) # # or CeCILL v2.0 # The CeCILL license is compatible with the GNU GPL. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # This software is governed either by the CeCILL or the CeCILL-C license # under French law and abiding by the rules of distribution of free software. # You can use, modify and or redistribute the software under the terms of # the CeCILL or CeCILL-C licenses as circulated by CEA, CNRS and INRIA # at the following URL : "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL and CeCILL-C licenses and that you accept its terms. */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include "simplex.h" #ifdef HAVE_GSL #include <gsl/gsl_linalg.h> #include <gsl/gsl_blas.h> double SimplexVolumed(double **coord,int nvert, int ndims) { int i,j,k; double det; int s; double m_data[(nvert-1)*(nvert-1)]; double w_data[(nvert-1)*(nvert-1)]; /* double w_data[3*3] = {1.,0.,0., 1.,1.,0., 1.,1.,1.};*/ //double wt_data[(nvert-1)*ndims]; gsl_permutation * perm; gsl_matrix_view m = gsl_matrix_view_array (m_data, nvert-1, nvert-1); gsl_matrix_view w = gsl_matrix_view_array (w_data, nvert-1, ndims); //gsl_matrix_view wt = gsl_matrix_view_array (wt_data, nvert-1,ndims); if (nvert==2) { for (i=0,det=0;i<ndims;i++) det+=(coord[1][i]-coord[0][i])*(coord[1][i]-coord[0][i]); return sqrt(det); } perm = gsl_permutation_alloc (nvert-1); for (i=0,k=0;i<nvert-1;i++) for (j=0;j<nvert-1;j++,k++) w_data[k]=coord[i+1][j]-coord[0][j]; //gsl_matrix_transpose_memcpy (wt,w); gsl_blas_dgemm (CblasNoTrans, CblasTrans, 1.0, &w.matrix, &w.matrix, 0.0, &m.matrix); gsl_linalg_LU_decomp(&m.matrix,perm,&s); det=gsl_linalg_LU_det(&m.matrix,s); gsl_permutation_free(perm); for (i=2,j=1;i<=nvert-1;i++) j*=i; return sqrt(fabs(det))/j; } double SimplexVolumef(float **coord,int nvert, int ndims) { int i,j,k; double det; int s; double m_data[(nvert-1)*(nvert-1)]; double w_data[(nvert-1)*(nvert-1)]; /* double w_data[3*3] = {1.,0.,0., 1.,1.,0., 1.,1.,1.};*/ //double wt_data[(nvert-1)*ndims]; gsl_permutation * perm; gsl_matrix_view m = gsl_matrix_view_array (m_data, nvert-1, nvert-1); gsl_matrix_view w = gsl_matrix_view_array (w_data, nvert-1, ndims); //gsl_matrix_view wt = gsl_matrix_view_array (wt_data, nvert-1,ndims); if (nvert==2) { for (i=0,det=0;i<ndims;i++) det+=(double)(coord[1][i]-coord[0][i])*(double)(coord[1][i]-coord[0][i]); return sqrt(det); } perm = gsl_permutation_alloc (nvert-1); for (i=0,k=0;i<nvert-1;i++) for (j=0;j<nvert-1;j++,k++) w_data[k]=coord[i+1][j]-coord[0][j]; //gsl_matrix_transpose_memcpy (wt,w); gsl_blas_dgemm (CblasNoTrans, CblasTrans, 1.0, &w.matrix, &w.matrix, 0.0, &m.matrix); gsl_linalg_LU_decomp(&m.matrix,perm,&s); det=gsl_linalg_LU_det(&m.matrix,s); gsl_permutation_free(perm); for (i=2,j=1;i<=nvert-1;i++) j*=i; return sqrt(fabs(det))/j; } // center must be allocated to ndims vals at least. // coord are the vertice coords // center is the center of the resulting ndims-sphere // function returns its radius squared double SimplexSphere(double **coord, int ndims,double *center) { double a_data[ndims*ndims]; double b_data[ndims]; gsl_matrix_view m=gsl_matrix_view_array (a_data, ndims, ndims); gsl_vector_view b=gsl_vector_view_array (b_data, ndims); gsl_vector_view x = gsl_vector_view_array (center,ndims); gsl_permutation * p = gsl_permutation_alloc (ndims); int s; int i,j,k; double d; for (i=0,k=0;i<ndims;i++) { b_data[i]=0; for (j=0;j<ndims;j++,k++) { a_data[k]=((double)coord[0][j]-(double)coord[i+1][j]); b_data[i]+=((double)coord[0][j]*(double)coord[0][j]-(double)coord[i+1][j]*(double)coord[i+1][j]); } b_data[i]*=0.5; } gsl_linalg_LU_decomp (&m.matrix, p, &s); gsl_linalg_LU_solve (&m.matrix, p, &b.vector, &x.vector); gsl_permutation_free (p); for (i=0,d=0;i<ndims;i++) d+=((double)center[i]-(double)coord[0][i])*((double)center[i]-(double)coord[0][i]); return d; } #else double SimplexVolumef(float **coord,int nvert, int ndims) { int i; double det; if (nvert==2) { for (i=0,det=0;i<ndims;i++) det+=(double)(coord[1][i]-coord[0][i])*(double)(coord[1][i]-coord[0][i]); return sqrt(det); } fprintf(stderr,"ERROR: Function 'SimplexVolume' needs GSL.\n"); fprintf(stderr,"Please, recompile with GSL.\n"); return -1; } double SimplexSphere(double **coords, int ndims,double *center) { fprintf(stderr,"ERROR: Function 'SimplexSphere' needs GSL.\n"); fprintf(stderr,"Please, recompile with GSL.\n"); return -1; } #endif
{ "alphanum_fraction": 0.6356085775, "avg_line_length": 29.8288288288, "ext": "c", "hexsha": "8636bbee6fea2013136577ae4efdfc3766633668", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-30T18:12:10.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-30T13:12:22.000Z", "max_forks_repo_head_hexsha": "5bb07c7901062452a34b73f376057cabc15a13c3", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "anmartinezs/pyseg_system", "max_forks_repo_path": "sys/install/disperse/0.9.24/disperse/src/C/simplex.c", "max_issues_count": 8, "max_issues_repo_head_hexsha": "5bb07c7901062452a34b73f376057cabc15a13c3", "max_issues_repo_issues_event_max_datetime": "2022-03-10T10:11:28.000Z", "max_issues_repo_issues_event_min_datetime": "2019-12-19T19:34:56.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "anmartinezs/pyseg_system", "max_issues_repo_path": "sys/install/disperse/0.9.24/disperse/src/C/simplex.c", "max_line_length": 102, "max_stars_count": 12, "max_stars_repo_head_hexsha": "5bb07c7901062452a34b73f376057cabc15a13c3", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "anmartinezs/pyseg_system", "max_stars_repo_path": "sys/install/disperse/0.9.24/disperse/src/C/simplex.c", "max_stars_repo_stars_event_max_datetime": "2022-03-16T00:25:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-01-08T01:33:02.000Z", "num_tokens": 2045, "size": 6622 }
/* * Copyright (c) 2016-2021 lymastee, All rights reserved. * Contact: lymastee@hotmail.com * * This file is part of the gslib project. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #pragma once #ifndef rbtree_ebcaa429_edae_4ac6_b9a5_2fe774778822_h #define rbtree_ebcaa429_edae_4ac6_b9a5_2fe774778822_h #include <assert.h> #include <gslib/std.h> __gslib_begin__ struct _rbtree_trait_copy {}; struct _rbtree_trait_detach {}; enum rbtree_color { rb_red, rb_black, }; template<class _ty> struct _rbtreenode_cpy_wrapper { typedef _ty value; typedef _rbtreenode_cpy_wrapper<_ty> myref; typedef _rbtree_trait_copy tsf_behavior; typedef rbtree_color color; value _value; myref* _left; myref* _right; myref* _parent; color _color; myref() { _left = _right = _parent = nullptr; _color = rb_black; } value* get_ptr() { return &_value; } const value* const_ptr() const { return &_value; } value& get_ref() { return _value; } const value& const_ref() const { return _value; } void born() {} void kill() {} template<class _ctor> void born() {} template<class _ctor> void kill() {} void copy(const myref* a) { get_ref() = a->const_ref(); } void attach(myref* a) { assert(0); } void swap_data(myref* a) { std::swap(_value, a->_value); } void set_color(color c) { _color = c; } color get_color() const { return _color; } bool is_red() const { return _color == rb_red; } }; template<class _ty> struct _rbtreenode_wrapper { typedef _ty value; typedef _rbtreenode_wrapper<_ty> myref; typedef _rbtree_trait_detach tsf_behavior; typedef rbtree_color color; value* _value; myref* _left; myref* _right; myref* _parent; color _color; myref() { _left = _right = _parent = nullptr; _value = nullptr; _color = rb_black; } value* get_ptr() { return _value; } const value* const_ptr() const { return _value; } value& get_ref() { return *_value; } const value& const_ref() const { return *_value; } void copy(const myref* a) { get_ref() = a->const_ref(); } void born() { !! } template<class _ctor> void born() { _value = new _ctor; } void kill() { if(_value) { delete _value; _value = nullptr; } } template<class _ctor> void kill() { if(_value) { delete _value; _value = nullptr; } } void attach(myref* a) { assert(a && a->_value); kill(); _value = a->_value; a->_value = nullptr; } void swap_data(myref* a) { gs_swap(_value, a->_value); } void set_color(color c) { _color = c; } color get_color() const { return _color; } bool is_red() const { return _color == rb_red; } }; template<class _wrapper> struct _rbtree_allocator { typedef _wrapper wrapper; static wrapper* born() { return new wrapper; } static void kill(wrapper* w) { delete w; } }; template<class _val> struct _rbtreenode_val { typedef _val value; typedef const _val const_value; typedef _rbtreenode_val<_val> myref; typedef rbtree_color color; union { value* _vptr; const_value* _cvptr; }; myref() { _vptr = nullptr; } value* get_wrapper() const { return _vptr; } operator bool() const { return _vptr != nullptr; } bool is_left() const { return (_cvptr && _cvptr->_parent) ? _cvptr->_parent->_left == _cvptr : false; } bool is_right() const { return (_cvptr && _cvptr->_parent) ? _cvptr->_parent->_right == _cvptr : false; } bool is_root() const { return _cvptr ? (!_cvptr->_parent) : false; } bool is_leaf() const { return _cvptr ? (!_cvptr->_left && !_cvptr->_right) : false; } int up_depth() const { int depth = 0; for(value* p = _vptr; p; p = p->_parent, depth ++); return depth; } int down_depth() const { return _down_depth(_vptr, 0); } bool operator==(const value* v) const { return _vptr == v; } bool operator!=(const value* v) const { return _vptr != v; } color get_color() const { return _vptr->_color; } void set_color(color c) { _vptr->_color = c; } void swap_data(myref& a) { _vptr->swap_data(a._vptr); } public: static void connect_left_child(value* p, value* l) { assert(p); p->_left = l; if(l) l->_parent = p; } static void connect_right_child(value* p, value* r) { assert(p); p->_right = r; if(r) r->_parent = p; } static bool disconnect_parent_child(value* p, value* c) { assert(p && c && (c->_parent == p)); if(p->_left == c) { p->_left = c->_parent = nullptr; return true; } assert(p->_right == c); p->_right = c->_parent = nullptr; return false; } private: static int _down_depth(value* v, int ctr) { if(v == nullptr) return ctr; ctr ++; return gs_max(_down_depth(v->_left, ctr), _down_depth(v->_right, ctr) ); } protected: value* vleft() const { return _vptr ? _vptr->_left : nullptr; } value* vright() const { return _vptr ? _vptr->_right : nullptr; } value* vparent() const { return _vptr ? _vptr->_parent : nullptr; } value* vsibling() const { if(!_vptr || !_vptr->_parent) return nullptr; if(is_left()) return _vptr->_right; else if(is_right()) return _vptr->_left; assert(!"unexpected."); return nullptr; } value* vroot() const { if(!_vptr) return nullptr; value* p = _vptr; for( ; p->_parent; p = p->_parent); return p; } protected: template<class _lambda, class _value> static void preorder_traversal(_lambda lam, _value* v) { assert(v); lam(v); if(v->_left) preorder_traversal(lam, v->_left); if(v->_right) preorder_traversal(lam, v->_right); } template<class _lambda, class _value> static void inorder_traversal(_lambda lam, _value* v) { assert(v); if(v->_left) inorder_traversal(lam, v->_left); lam(v); if(v->_right) inorder_traversal(lam, v->_right); } template<class _lambda, class _value> static void postorder_traversal(_lambda lam, _value* v) { assert(v); if(v->_left) postorder_traversal(lam, v->_left); if(v->_right) postorder_traversal(lam, v->-right); lam(v); } public: template<class _lambda> void inorder_traversal(_lambda lam) { if(_vptr) inorder_traversal(lam, _vptr); } template<class _lambda> void inorder_traversal(_lambda lam) const { if(_cvptr) inorder_traversal(lam, _cvptr); } template<class _lambda> void preorder_traversal(_lambda lam) { if(_vptr) preorder_traversal(lam, _vptr); } template<class _lambda> void preorder_traversal(_lambda lam) const { if(_cvptr) preorder_traversal(lam, _cvptr); } template<class _lambda> void postorder_traversal(_lambda lam) { if(_vptr) postorder_traversal(lam, _vptr); } template<class _lambda> void postorder_traversal(_lambda lam) const { if(_cvptr) postorder_traversal(lam, _cvptr); } }; template<class _ty, class _wrapper = _rbtreenode_cpy_wrapper<_ty> > class _rbtree_const_iterator: public _rbtreenode_val<_wrapper> { public: typedef _ty value; typedef _wrapper wrapper; typedef _rbtree_const_iterator<_ty, _wrapper> iterator; public: iterator(const wrapper* w = nullptr) { _cvptr = w; } bool is_valid() const { return _cvptr != nullptr; } const value* get_ptr() const { return _cvptr->const_ptr(); } const value* operator->() const { return _cvptr->const_ptr(); } const value& operator*() const { return _cvptr->const_ref(); } iterator left() const { return iterator(vleft()); } iterator right() const { return iterator(vright()); } iterator parent() const { return iterator(vparent()); } iterator sibling() const { return iterator(vsibling()); } iterator root() const { return iterator(vroot()); } bool operator==(const iterator& that) const { return _cvptr == that._cvptr; } bool operator!=(const iterator& that) const { return _cvptr != that._cvptr; } }; template<class _ty, class _wrapper = _rbtreenode_cpy_wrapper<_ty> > class _rbtree_iterator: public _rbtree_const_iterator<_ty, _wrapper> { public: typedef _ty value; typedef _wrapper wrapper; typedef _rbtree_const_iterator<_ty, _wrapper> const_iterator; typedef _rbtree_const_iterator<_ty, _wrapper> superref; typedef _rbtree_iterator<_ty, _wrapper> iterator; public: iterator(wrapper* w): superref(w) {} value* get_ptr() const { return _vptr->get_ptr(); } value* operator->() const { return _vptr->get_ptr(); } value& operator*() const { return _vptr->get_ref(); } bool operator==(const iterator& that) const { return _vptr == that._vptr; } bool operator!=(const iterator& that) const { return _vptr != that._vptr; } bool operator==(const const_iterator& that) const { return _vptr == that._vptr; } bool operator!=(const const_iterator& that) const { return _vptr != that._vptr; } operator const_iterator() { return const_iterator(_cvptr); } void to_root() { _vptr = vroot(); } void to_left() { _vptr = vleft(); } void to_right() { _vptr = vright(); } void to_sibling() { _vptr = vsibling(); } void to_parent() { _vptr = vparent(); } iterator left() const { return iterator(vleft()); } iterator right() const { return iterator(vright()); } iterator parent() const { return iterator(vparent()); } iterator sibling() const { return iterator(vsibling()); } iterator root() const { return iterator(vroot()); } }; template<class _ty, class _wrapper = _rbtreenode_cpy_wrapper<_ty>, class _alloc = _rbtree_allocator<_wrapper> > class rbtree: public _rbtreenode_val<_wrapper> { public: typedef _ty value; typedef _wrapper wrapper; typedef _alloc alloc; typedef rbtree<value, wrapper, alloc> myref; typedef _rbtree_const_iterator<_ty, _wrapper> const_iterator; typedef _rbtree_iterator<_ty, _wrapper> iterator; typedef rbtree_color color; public: rbtree() { _vptr = nullptr; } ~rbtree() { clear(); } void clear() { destroy(get_root()); } void destroy(iterator i) { if(!i.is_valid()) return; if(iterator p = i.parent()) disconnect_parent_child(p.get_wrapper(), i.get_wrapper()); else { assert(is_root(i)); _vptr = nullptr; } _destroy(i); } void adopt(wrapper* w) { assert(!_vptr && "use attach method."); _vptr = w; } iterator get_root() const { return iterator(_vptr); } const_iterator const_root() const { return const_iterator(_cvptr); } bool is_root(iterator i) const { return i ? (_vptr == i.get_wrapper()) : false; } bool is_valid() const { return _cvptr != nullptr; } bool is_mine(iterator i) const { if(!i.is_valid()) return false; i.to_root(); return i.get_wrapper() == _vptr; } int depth() const { return _cvptr->down_depth(); } void swap(myref& that) { gs_swap(_vptr, that._vptr); } iterator find(const value& v) const { return find(get_root(), v); } iterator find(iterator i, const value& v) const { if(!i) { if(!is_valid()) return i; i = get_root(); } assert(i); wrapper* f = _find(i.get_wrapper(), v); assert(f); if(!(f->const_ref() == v)) f = nullptr; return iterator(f); } template<class _ctor = value> iterator insert(const value& v) { wrapper* f = nullptr; if(_vptr) { f = _find(_vptr, v); assert(f); if(f->const_ref() == v) return iterator(f); } wrapper* n = initval<_ctor, wrapper::tsf_behavior>::run(alloc::born(), v); n->set_color(rb_red); if(!f) _vptr = n; else { (v < f->const_ref()) ? connect_left_child(f, n) : connect_right_child(f, n); } _fix_insert(n); return iterator(n); } void erase(iterator i) { assert(i); wrapper* n = i.get_wrapper(); wrapper *c, *p; rbtree_color cr; if(!n->_left) c = n->_right; else if(!n->_right) c = n->_left; else { wrapper* b = n, *l; n = n->_right; for(; l = n->_left; n = l); if(!b->_parent) _vptr = n; else { (b->_parent->_left == b) ? b->_parent->_left = n : b->_parent->_right = n; } c = n->_right; p = n->_parent; cr = n->_color; if(p == b) p = n; else { if(c) c->_parent = p; p->_left = c; n->_right = b->_right; b->_right->_parent = n; } n->_parent = b->_parent; n->_color = b->_color; n->_left = b->_left; b->_left->_parent = n; if(cr == rb_black) _fix_erase(c, p); return; } p = n->_parent; cr = n->_color; if(c) c->_parent = p; if(!p) _vptr = c; else { (p->_left == n) ? p->_left = c : p->_right = c; } if(cr == rb_black) _fix_erase(c, p); } void erase(const value& v) { if(iterator i = find(v)) erase(i); } /* The detach and attach methods, provide subtree operations */ myref& detach(myref& subtree, iterator i) { assert(i && is_mine(i)); if(subtree.is_valid()) subtree.clear(); detach<myref>(subtree, i); return subtree; } template<class _cont> void detach(_cont& cont) { cont.adopt(_vptr); _vptr = nullptr; } template<class _cont> void detach(_cont& cont, iterator i) { assert(i && is_mine(i)); if(i == get_root()) return detach(cont); iterator p = i.parent(); assert(p); disconnect_parent_child(p.get_wrapper(), i.get_wrapper()); cont.adopt(i.get_wrapper()); } iterator attach(myref& subtree, iterator i) { assert(i && is_mine(i) && i.is_leaf()); if(i.is_root()) { swap(subtree); return get_root(); } iterator p = i.parent(); assert(p); bool leftp = disconnect_parent_child(p.get_wrapper(), i.get_wrapper()); gs_swap(subtree._vptr, i._vptr); leftp ? connect_left_child(p.get_wrapper(), i.get_wrapper()) : connect_right_child(p.get_wrapper(), i.get_wrapper()); subtree.clear(); return i; } public: template<class _lambda> void preorder_for_each(_lambda lam) { preorder_traversal([](wrapper* w) { lam(w->get_ptr()); }); } template<class _lambda> void preorder_const_for_each(_lambda lam) const { preorder_traversal([](const wrapper* w) { lam(w->const_ptr()); }); } template<class _lambda> void inorder_for_each(_lambda lam) { inorder_traversal([](wrapper* w) { lam(w->get_ptr()); }); } template<class _lambda> void inorder_const_for_each(_lambda lam) const { inorder_traversal([](const wrapper* w) { lam(w->const_ptr()); }); } template<class _lambda> void postorder_for_each(_lambda lam) { postorder_traversal([](wrapper* w) { lam(w->get_ptr()); }); } template<class _lambda> void postorder_const_for_each(_lambda lam) const { postorder_traversal([](const wrapper* w) { lam(w->const_ptr()); }); } protected: void _destroy(iterator i) { if(!i.is_valid()) return; _destroy(i.left()); _destroy(i.right()); wrapper* w = i.get_wrapper(); w->kill(); alloc::kill(w); } wrapper* _find(wrapper* w, const value& v) const { assert(w); wrapper* n = w; for(;;) { wrapper* m = nullptr; const value& r = n->const_ref(); if(v < r) m = n->_left; else if(r < v) m = n->_right; if(!m) return n; n = m; } return nullptr; } void _left_rotate(wrapper* n) { assert(n); wrapper* r = n->_right; if(n->_right = r->_left) r->_left->_parent = n; r->_left = n; if(!(r->_parent = n->_parent)) _vptr = r; else { (n == n->_parent->_right) ? n->_parent->_right = r : n->_parent->_left = r; } n->_parent = r; } void _right_rotate(wrapper* n) { assert(n); wrapper* l = n->_left; if(n->_left = l->_right) l->_right->_parent = n; l->_right = n; if(!(l->_parent = n->_parent)) _vptr = l; else { (n == n->_parent->_right) ? n->_parent->_right = l : n->_parent->_left = l; } n->_parent = l; } void _fix_insert(wrapper* n) { assert(n); wrapper *p, *g, *u; while((p = n->_parent) && p->is_red()) { g = p->_parent; if(p == g->_left) { u = g->_right; if(u && u->is_red()) { u->set_color(rb_black); p->set_color(rb_black); g->set_color(rb_red); n = g; } else { if(p->_right == n) { _left_rotate(p); gs_swap(p, n); } p->set_color(rb_black); g->set_color(rb_red); _right_rotate(g); } } else { u = g->_left; if(u && u->is_red()) { u->set_color(rb_black); p->set_color(rb_black); g->set_color(rb_red); n = g; } else { if(p->_left == n) { _right_rotate(p); gs_swap(p, n); } p->set_color(rb_black); g->set_color(rb_red); _left_rotate(g); } } } _vptr->set_color(rb_black); } void _fix_erase(wrapper* n, wrapper* p) { wrapper *s, *sl, *sr; while((!n || !n->is_red()) && n != _vptr) { if(p->_left == n) { s = p->_right; if(s->is_red()) { s->set_color(rb_black); p->set_color(rb_red); _left_rotate(p); s = p->_right; } if((!s->_left || !s->_left->is_red()) && (!s->_right || !s->_right->is_red()) ) { s->set_color(rb_red); n = p; p = n->_parent; } else { if(!s->_right || !s->_right->is_red()) { if(sl = s->_left) sl->set_color(rb_black); s->set_color(rb_red); _right_rotate(s); s = p->_right; } s->set_color(p->get_color()); p->set_color(rb_black); if(sr = s->_right) sr->set_color(rb_black); _left_rotate(p); n = _vptr; break; } } else { s = p->_left; if(s->is_red()) { s->set_color(rb_black); p->set_color(rb_red); _right_rotate(p); s = p->_left; } if((!s->_left || !s->_left->is_red()) && (!s->_right || !s->_right->is_red()) ) { s->set_color(rb_red); n = p; p = n->_parent; } else { if(!s->_left || !s->_left->is_red()) { if(sr = s->_right) sr->set_color(rb_black); s->set_color(rb_red); _left_rotate(s); s = p->_left; } s->set_color(p->get_color()); p->set_color(rb_black); if(sl = s->_left) sl->set_color(rb_black); _right_rotate(p); n = _vptr; break; } } } if(n) n->set_color(rb_black); } protected: friend struct initval; template<class _ctor, class _tsftrait> struct initval; template<class _ctor> struct initval<_ctor, _rbtree_trait_copy> { static wrapper* run(wrapper* w, const value& v) { assert(w); w->get_ref() = v; return w; } }; template<class _ctor> struct initval<_ctor, _rbtree_trait_detach> { static wrapper* run(wrapper* w, const value& v) { assert(w); w->_value = &v; /* or duplicate? */ return w; } }; }; __gslib_end__ #endif
{ "alphanum_fraction": 0.5089601264, "avg_line_length": 32.4137466307, "ext": "h", "hexsha": "f4e49f8a14b7627cbedcaae14a1a4dda38fc716c", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-10-19T15:20:58.000Z", "max_forks_repo_forks_event_min_datetime": "2016-10-19T15:20:58.000Z", "max_forks_repo_head_hexsha": "1b165b7a812526c4b2a3179588df9a7c2ff602a6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lymastee/gslib", "max_forks_repo_path": "include/gslib/rbtree.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b165b7a812526c4b2a3179588df9a7c2ff602a6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "lymastee/gslib", "max_issues_repo_path": "include/gslib/rbtree.h", "max_line_length": 125, "max_stars_count": 9, "max_stars_repo_head_hexsha": "1b165b7a812526c4b2a3179588df9a7c2ff602a6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lymastee/gslib", "max_stars_repo_path": "include/gslib/rbtree.h", "max_stars_repo_stars_event_max_datetime": "2022-02-11T09:44:51.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-18T09:40:09.000Z", "num_tokens": 5802, "size": 24051 }
#ifndef _PYGSL_SOLVER_H_ #define _PYGSL_SOLVER_H_ 1 #include <pygsl/intern.h> #include <pygsl/block_helpers.h> /* Not directly needed here, but provides a lot of convienience functions */ #include <pygsl/error_helpers.h> #include <gsl/gsl_math.h> #include <setjmp.h> /* * Many functions are "just" accessor methods. These different methods are * listed here. * * Convention: they all end with "m_t" short for method type. This emphasises * that this type is pointer to a method. */ typedef int (*int_m_t)(void *); typedef size_t (*size_t_m_t)(void *); typedef void (*void_m_t)(void *); typedef void *(*void_a_t)(const void *); typedef void *(*void_an_t)(const void *, size_t n); typedef void *(*void_anp_t)(const void *, size_t n, size_t p); typedef const char * (*name_m_t)(void *); typedef double (*double_m_t)(void *); typedef gsl_vector *(*ret_vec)(void *); typedef int (*set_m_t)(void *, void *, const gsl_vector *); typedef int (*set_m_d_t) (void *, gsl_function *, double); typedef int (*set_m_ddd_t) (void *, gsl_function *, double, double, double); typedef int (*int_f_vd_t)(const gsl_vector *, double); typedef int (*int_f_vvdd_t)(const gsl_vector *, const gsl_vector *, double, double); struct _PyGSLSolverObject; /* * GSL Methods which are implemented as C functions. The specifiy pointer to * the solver struct are passed as (void *) pointers. */ struct _GSLMethods{ /* Method to be called to free the GSL solver */ void_m_t free; /* * Some solvers provide a restart method. If not available set it to NULL. */ void_m_t restart; /* returns a string with the name of the solver */ name_m_t name; /* takes one more step towards the solution */ int_m_t iterate; }; struct _SolverStatic{ struct _GSLMethods cmethods; /* How many callbacks will be used? */ int n_cbs; /* Additional methods not provided by the basis solver. */ PyMethodDef *pymethods; /* Describes the type of the solver. e. g. F-Minimizer */ const char * type_name; }; struct pygsl_array_cache{ double * data; PyArrayObject * ref; }; #define PyGSL_SOLVER_NCBS_MAX 4 #define PyGSL_SOLVER_PB_ND_MAX 2 #define PyGSL_SOLVER_N_ARRAYS 10 struct _PyGSLSolverObject{ PyObject_HEAD /* * Some solvers do not propagate errors. Here I use longjmp if an error * is raised by the evaluator. */ jmp_buf buffer; /* * Array generation is a vital part of the callback process. To increase * the calculation speed, I want to store them here, thus I can reuse them * if not stored by the user for later evaluation. */ struct pygsl_array_cache *cache; /* * The Python callback methods. */ PyObject* cbs[PyGSL_SOLVER_NCBS_MAX]; /* * Additional arguments passed to the callbacks */ PyObject* args; /* * The solver itself. */ void * solver; /* * The space needed to store the variables for the C functions .... */ void * c_sys; /* * The dimensionality of the problem. Typically one or two numbers ... */ int problem_dimensions[PyGSL_SOLVER_PB_ND_MAX]; /* * The methods of the solver. */ const struct _SolverStatic* mstatic; /* before one can iterate the solver the method set() must be called!*/ int set_called; /* Used as a flag if the jmp_buf is set */ int isset; }; typedef struct _PyGSLSolverObject PyGSL_solver; typedef struct{ const void * type; void* alloc; const struct _SolverStatic* mstatic; } solver_alloc_struct; #ifndef _PyGSL_SOLVER_API_MODULE #define PyGSL_SOLVER_API_EXTERN extern #else #define PyGSL_SOLVER_API_EXTERN static #endif /* * Initalises a solver * * The internal structure is set up and the * nd: number of dimensions * 0 ... zero dimensional e.g. minimize, root * 1 ... one dimensional e.g. multimin * 2 ... two dimensional e.g. multifit_nlin * * 3 ... only initalise the structure * */ PyGSL_SOLVER_API_EXTERN PyObject * PyGSL_solver_dn_init(PyObject *self, PyObject *args, const solver_alloc_struct * alloc, int nd); /* * Accessor methods. * * These methods allow to access parameters of the C structure using the access * methods _m_t func */ PyGSL_SOLVER_API_EXTERN PyObject* PyGSL_solver_ret_double(PyGSL_solver *self, PyObject *args, double_m_t func); PyGSL_SOLVER_API_EXTERN PyObject* PyGSL_solver_ret_int(PyGSL_solver *self, PyObject *args, int_m_t func); PyGSL_SOLVER_API_EXTERN PyObject* PyGSL_solver_ret_size_t(PyGSL_solver *self, PyObject *args, size_t_m_t func); PyGSL_SOLVER_API_EXTERN PyObject* PyGSL_solver_ret_vec(PyGSL_solver *self, PyObject *args, ret_vec func); /* * evaluates a C function taking an vector and a double as input and returning a status. */ #define PyGSL_CALLABLE_CHECK(ob, name) \ (PyCallable_Check(ob) ? GSL_SUCCESS : PyGSL_Callable_Check(ob, name)) PyGSL_SOLVER_API_EXTERN int PyGSL_Callable_Check(PyObject *f, const char * myname); PyGSL_SOLVER_API_EXTERN int PyGSL_function_wrap_On_O(const gsl_vector * x, PyObject *callback, PyObject *arguments, double *result1, gsl_vector *result2, int n, const char * c_func_name); PyGSL_SOLVER_API_EXTERN int PyGSL_function_wrap_OnOn_On(const gsl_vector *x, const gsl_vector *v, gsl_vector *hv, PyObject *callback, PyObject *arguments, int n, const char *c_func_name); PyGSL_SOLVER_API_EXTERN int PyGSL_function_wrap_Op_On_Opn(const gsl_vector *x, gsl_vector *f1, gsl_matrix *f2, PyObject *callback, PyObject *arguments, int n, int p, const char *c_func_name); PyGSL_SOLVER_API_EXTERN int PyGSL_function_wrap_Op_On(const gsl_vector * x, gsl_vector *f, PyObject *callback, PyObject * arguments, int n, int p, const char *c_func_name); PyGSL_SOLVER_API_EXTERN int PyGSL_function_wrap_Op_Opn(const gsl_vector * x, gsl_matrix *f, PyObject *callback, PyObject *arguments, int n, int p, const char * c_func_name); /* * evaluates a C function taking an vector and a double as input and returning a status. */ PyGSL_SOLVER_API_EXTERN PyObject* PyGSL_solver_vd_i(PyObject * self, PyObject *args, int_f_vd_t func); PyGSL_SOLVER_API_EXTERN PyObject * PyGSL_solver_vvdd_i(PyObject * self, PyObject * args, int_f_vvdd_t func); struct pygsl_solver_n_set{ int is_fdf; void *c_sys; set_m_t set; }; PyGSL_SOLVER_API_EXTERN PyObject * PyGSL_solver_n_set(PyGSL_solver *self, PyObject *pyargs, PyObject *kw, const struct pygsl_solver_n_set * info); /* * */ PyGSL_SOLVER_API_EXTERN int PyGSL_solver_func_set(PyGSL_solver *self, PyObject *args, PyObject *f, PyObject *df, PyObject *fdf); PyGSL_SOLVER_API_EXTERN PyObject* PyGSL_solver_set_f(PyGSL_solver *self, PyObject *pyargs, PyObject *kw, void *fptr, int isfdf); #define _GET(name, cast, func) \ PyObject * PyGSL_ ## name(PyGSL_solver *self, PyObject *args) \ { \ return PyGSL_solver_ ## func(self, args, (cast) gsl_ ## name); \ } #define GETDOUBLE(name) _GET(name, double_m_t, ret_double) #define GETSIZET(name) _GET(name, size_t_m_t, ret_size_t) #define GETINT(name) _GET(name, int_m_t, ret_int) #define GETVEC(name) _GET(name, ret_vec, ret_vec) /* * Get or set a double .... */ enum PyGSL_GETSET_typemode { PyGSL_MODE_DOUBLE = 0, PyGSL_MODE_INT, PyGSL_MODE_SIZE_T }; PyGSL_SOLVER_API_EXTERN PyObject * PyGSL_solver_GetSet(PyObject *self, PyObject *args, void * address, enum PyGSL_GETSET_typemode mode); #ifndef _PyGSL_SOLVER_API_MODULE #define PyGSL_function_wrap_Op_On \ (* (int (*)(const gsl_vector *, gsl_vector *, PyObject *, PyObject *, int, int, const char *))\ PyGSL_API[PyGSL_function_wrap_Op_On_NUM]) #define PyGSL_function_wrap_On_O \ (* (int (*)(const gsl_vector *, PyObject *, PyObject *, double *, gsl_vector *, int, const char *))\ PyGSL_API[PyGSL_function_wrap_On_O_NUM]) #define PyGSL_function_wrap_OnOn_On \ (* (int (*)(const gsl_vector *, const gsl_vector *, gsl_vector *, PyObject *, PyObject *,int, const char *))\ PyGSL_API[PyGSL_function_wrap_OnOn_On_NUM]) #define PyGSL_function_wrap_Op_On_Opn \ (* (int (*)(const gsl_vector *, gsl_vector *, gsl_matrix *, PyObject *, PyObject *, int, int, const char *))\ PyGSL_API[PyGSL_function_wrap_Op_On_Opn_NUM]) #define PyGSL_function_wrap_Op_Opn \ (* (int (*)(const gsl_vector *, gsl_matrix *, PyObject *, PyObject *, int, int, const char *))\ PyGSL_API[PyGSL_function_wrap_Op_Opn_NUM]) #define PyGSL_solver_ret_int \ (*(PyObject * (*) (PyGSL_solver *, PyObject *, int_m_t func)) PyGSL_API[PyGSL_solver_ret_int_NUM]) #define PyGSL_solver_ret_double \ (*(PyObject * (*) (PyGSL_solver *, PyObject *, double_m_t func)) PyGSL_API[PyGSL_solver_ret_double_NUM]) #define PyGSL_solver_ret_size_t \ (*(PyObject * (*) (PyGSL_solver *, PyObject *, size_t_m_t func)) PyGSL_API[PyGSL_solver_ret_size_t_NUM]) #define PyGSL_solver_ret_vec \ (*(PyObject * (*) (PyGSL_solver *, PyObject *, ret_vec func)) PyGSL_API[PyGSL_solver_ret_vec_NUM]) #define PyGSL_solver_dn_init \ (*(PyObject * (*)(PyObject *, PyObject *, const solver_alloc_struct *, int))PyGSL_API[PyGSL_solver_dn_init_NUM]) #define PyGSL_Callable_Check \ (*(int (*)(PyObject *, const char *)) PyGSL_API[PyGSL_Callable_Check_NUM]) #define PyGSL_solver_vd_i \ (*(PyObject * (*) (PyObject *, PyObject *, int_f_vd_t)) PyGSL_API[PyGSL_solver_vd_i_NUM]) #define PyGSL_solver_vvdd_i \ (*(PyObject * (*) (PyObject *, PyObject *, int_f_vvdd_t)) PyGSL_API[PyGSL_solver_vvdd_i_NUM]) #define PyGSL_solver_func_set \ (*(int (*)(PyGSL_solver *, PyObject *, PyObject *, PyObject *, PyObject *)) PyGSL_API[PyGSL_solver_func_set_NUM]) #define PyGSL_solver_n_set \ (*(PyObject * (*)(PyGSL_solver *, PyObject *, PyObject *, const struct pygsl_solver_n_set *)) PyGSL_API[PyGSL_solver_n_set_NUM]) #define PyGSL_solver_set_f \ (* (PyObject * (*)(PyGSL_solver *, PyObject *, PyObject *, void *, int )) PyGSL_API[PyGSL_solver_set_f_NUM]) #define PyGSL_solver_GetSet \ (* (PyObject * (*) (PyObject *, PyObject *, void *, enum PyGSL_GETSET_typemode mode)) PyGSL_API[PyGSL_solver_getset_NUM]) #define PyGSL_solver_check(ob) (((ob)->ob_type) == (PyGSL_API[PyGSL_solver_type_NUM])) #define import_pygsl_solver() \ { \ init_pygsl(); \ if (PyImport_ImportModule("pygsl.testing.solver") != NULL) { \ ;\ } else { \ fprintf(stderr, "failed to import pygsl solver!!\n"); \ } \ } #else /* _PyGSL_API_MODULE */ #define PyGSL_solver_check(ob) ((ob)->ob_type == &PyGSL_solver_pytype) #endif /* _PyGSL_API_MODULE */ #endif /* _PYGSL_SOLVER_H_ */
{ "alphanum_fraction": 0.7150780222, "avg_line_length": 32.8333333333, "ext": "h", "hexsha": "edde8c05aa020f5da5b0001295a9df1bb11095a1", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-10-02T06:18:07.000Z", "max_forks_repo_forks_event_min_datetime": "2018-10-02T06:18:07.000Z", "max_forks_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "juhnowski/FishingRod", "max_forks_repo_path": "production/pygsl-0.9.5/Include/pygsl/solver.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "juhnowski/FishingRod", "max_issues_repo_path": "production/pygsl-0.9.5/Include/pygsl/solver.h", "max_line_length": 129, "max_stars_count": null, "max_stars_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "juhnowski/FishingRod", "max_stars_repo_path": "production/pygsl-0.9.5/Include/pygsl/solver.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2909, "size": 10638 }
/** * * @file core_cpltmg.c * * PLASMA core_blas kernel * PLASMA is a software package provided by Univ. of Tennessee, * Univ. of California Berkeley and Univ. of Colorado Denver * * @version 2.6.0 * @author Ichitaro Yamazaki * @author Julien Herrmann * @author Mathieu Faverge * @date 2010-11-15 * @generated c Tue Jan 7 11:44:47 2014 * **/ #include <math.h> #include <lapacke.h> #include "common.h" #define pi (3.1415926535897932384626433832795028841971693992) /***************************************************************************//** * * @ingroup CORE_PLASMA_Complex32_t * * CORE_cpltmg initialize a tile of a random matrix from the MatLab * gallery configured with the default parameters, and a few other * specific matrices. * ******************************************************************************* * * @param[in] mtxtype * Possible types are: PlasmaMatrixRandom, PlasmaMatrixHadamard, * PlasmaMatrixParter, PlasmaMatrixRis, PlasmaMatrixKms, * PlasmaMatrixMoler, PlasmaMatrixCompan, PlasmaMatrixRiemann, * PlasmaMatrixLehmer, PlasmaMatrixMinij, PlasmaMatrixDorr, * PlasmaMatrixDemmel, PlasmaMatrixInvhess, PlasmaMatrixCauchy, * PlasmaMatrixHilb, PlasmaMatrixLotkin, PlasmaMatrixOrthog, * PlasmaMatrixWilkinson, PlasmaMatrixFoster, PlasmaMatrixWright, * PlasmaMatrixLangou * (See further in the code for more details) * * @param[in] M * The number of rows of the tile A. M >= 0. * * @param[in] N * The number of columns of the tile A. N >= 0. * * @param[in,out] A * On entry, the M-by-N tile to be initialized. * On exit, the tile initialized in the mtxtype format. * * @param[in] LDA * The leading dimension of the tile A. LDA >= max(1,M). * * @param[in] gM * The global number of rows of the full matrix, A is belonging to. gM >= (m0+M). * * @param[in] gN * The global number of columns of the full matrix, A is belonging to. gN >= (n0+gN). * * @param[in] m0 * The index of the first row of tile A in the full matrix. m0 >= 0. * * @param[in] n0 * The index of the first column of tile A in the full matrix. n0 >= 0. * * @param[in] seed * The seed used for random generation. Must be the same for * all tiles initialized with this routine. * ******************************************************************************* * * @return * \retval PLASMA_SUCCESS successful exit * \retval <0 if INFO = -k, the k-th argument had an illegal value * ******************************************************************************/ #if defined(PLASMA_HAVE_WEAK) #pragma weak CORE_cpltmg = PCORE_cpltmg #define CORE_cpltmg PCORE_cpltmg #define CORE_cplrnt PCORE_cplrnt void CORE_cplrnt( int M, int N, PLASMA_Complex32_t *A, int LDA, int gM, int m0, int n0, unsigned long long int seed ); #endif int CORE_cpltmg( PLASMA_enum mtxtype, int M, int N, PLASMA_Complex32_t *A, int LDA, int gM, int gN, int m0, int n0, unsigned long long int seed ) { int i, j; /* Check input arguments */ if (M < 0) { coreblas_error(2, "Illegal value of M"); return -3; } if (N < 0) { coreblas_error(3, "Illegal value of N"); return -3; } if ((LDA < max(1,M)) && (M > 0)) { coreblas_error(5, "Illegal value of LDA"); return -5; } if (m0 < 0) { coreblas_error(8, "Illegal value of m0"); return -8; } if (n0 < 0) { coreblas_error(9, "Illegal value of n0"); return -9; } if (gM < m0+M) { coreblas_error(6, "Illegal value of gM"); return -6; } if (gN < n0+N) { coreblas_error(7, "Illegal value of gN"); return -7; } /* Quick return */ if ((M == 0) || (N == 0)) return PLASMA_SUCCESS; switch( mtxtype ) { case PlasmaMatrixRandom: { CORE_cplrnt( M, N, A, LDA, gM, m0, n0, seed ); } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/hadamard.html * * Initialize the tile A to create the Hadamard matrix of order gN. * * Hadamard matrices are matrices of 1's and -1's whose columns are orthogonal, * * H'*H = gN*I * * where [gN gN]=size(H) and I = eye(gN,gN) ,. * * They have applications in several different areas, including * combinatorics, signal processing, and numerical analysis. * * An n-by-n Hadamard matrix with n > 2 exists only if rem(n,4) = * 0. This function handles only the cases where n is a power of * 2. */ case PlasmaMatrixHadamard: { int tmp, nbone; /* Extra parameters check */ if (gM != gN) { coreblas_error(6, "Illegal value of gM (Matrix must be square)"); return -6; } tmp = gM; while ( tmp > 1 ) { if( tmp % 2 != 0 ) { coreblas_error(6, "Illegal value of gM (Matrix dimension must be a power of 2)"); return -6; } tmp /= 2; } for (j=0; j<N; j++) { for (i=0; i<M; i++) { tmp = ((m0 + i) & (n0 + j)); nbone = 0; while ( tmp != 0 ) { nbone += ( tmp & 1 ); tmp >>= 1; } A[j*LDA+i] = (PLASMA_Complex32_t)(1. - 2. * ( nbone % 2 )); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000116 * * Toeplitz matrix with singular values near pi. * Returns the tile A, such that the elment of the matrix are 1/(i-j+0.5). * * C is a Cauchy matrix and a Toeplitz matrix. Most of the * singular values of C are very close to pi. * */ case PlasmaMatrixParter: { PLASMA_Complex32_t tmp; if (gM != gN) { coreblas_error(6, "Illegal value of gM (Matrix must be square for Parter)"); return -6; } tmp = (PLASMA_Complex32_t)( .5 + m0 - n0 ); for (j=0; j<N; j++) { for (i=0; i<M; i++) { A[j*LDA+i] = (PLASMA_Complex32_t)1. / (PLASMA_Complex32_t)( tmp + i - j ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000243 * * Symmetric Hankel matrix * Returns a symmetric gN-by-gN Hankel matrix with elements. * * A(i,j) = 0.5/(n-i-j+1.5) * * The eigenvalues of A cluster around π/2 and –π/2. This matrix * was invented by F.N. Ris. * */ case PlasmaMatrixRis: { PLASMA_Complex32_t tmp; if (gM != gN) { coreblas_error(6, "Illegal value of gM (Matrix must be square for RIS)"); return -6; } tmp = (PLASMA_Complex32_t)( gM - m0 - n0 - 0.5 ); for (j=0; j<N; j++) { for (i=0; i<M; i++) { A[j*LDA+i] = (PLASMA_Complex32_t).5 / (PLASMA_Complex32_t)( tmp - i - j ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000026 * * Kac-Murdock-Szego Toeplitz matrix * * Returns the n-by-n Kac-Murdock-Szego Toeplitz matrix such that * A(i,j) = rho^(abs(i-j)), for real rho. * * For complex rho, the same formula holds except that elements * below the diagonal are conjfugated. rho defaults to 0.5. * * The KMS matrix A has these properties: * - An LDL' factorization with L inv(gallery('triw',n,-rho,1))', * and D(i,i) (1-abs(rho)^2)*eye(n), except D(1,1) = 1. * - Positive definite if and only if 0 < abs(rho) < 1. * - The inverse inv(A) is tridiagonal.Symmetric Hankel matrix * * In this function, rho is set to 0.5 and cannot be changed. */ case PlasmaMatrixKms: { PLASMA_Complex32_t rho; if (gM != gN) { coreblas_error(6, "Illegal value of gM (Matrix must be square for KMS)"); return -6; } rho = .5; for (j=0; j<N; j++) { for (i=0; i<M; i++) { A[j*LDA+i] = (PLASMA_Complex32_t)( cpowf( rho, fabs( (float)( m0 + i - n0 - j ) ) ) ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000074 * * Symmetric positive definite matrix * * Returns the symmetric positive definite n-by-n matrix U'*U, * where U = gallery('triw',n,alpha). * * For the default alpha = -1, A(i,j) = min(i,j)-2, and A(i,i) = * i. One of the eigenvalues of A is small. * */ case PlasmaMatrixMoler: { int ii, jj; for (j=0,jj=n0; j<N; j++,jj++) { for (i=0,ii=m0; i<M; i++,ii++) { if ( ii == jj ) { A[j*LDA+i] = (PLASMA_Complex32_t)( ii + 1. ); } else { A[j*LDA+i] = (PLASMA_Complex32_t)( min( ii, jj ) - 1. ); } } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/compan.html * * Companion matrix * * A = compan(u) returns the corresponding companion matrix whose first row is * -u(2:n)/u(1), where u is a vector of polynomial coefficients. The * eigenvalues of compan(u) are the roots of the polynomial. * */ case PlasmaMatrixCompan: { int jj; LAPACKE_claset_work(LAPACK_COL_MAJOR, 'A', M, N, 0., 0., A, LDA); /* First row */ if ( m0 == 0 ) { PLASMA_Complex32_t v0; /* Get V0 */ CORE_cplrnt( 1, 1, &v0, 1, 1, 1, 0, seed ); v0 = 1. / v0 ; /* Initialize random vector */ CORE_cplrnt( 1, N, A, LDA, 1, 1, n0, seed ); cblas_cscal( N, CBLAS_SADDR(v0), A, LDA); /* Restore A(0,0) */ if ( n0 == 0 ) A[0] = 0.; } /* Sub diagonal*/ for (j=0,jj=n0; j<N; j++,jj++) { i = jj + 1 - m0; if ( ( i > 0 ) && (i < M) ) { A[j*LDA+i] = 1.; } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000232 * * Matrix associated with the Riemann hypothesis * * Returns an n-by-n matrix for which the Riemann hypothesis is * true if and only if for every eps > 0. * * The Riemann matrix is defined by: * * A = B(2:n+1,2:n+1) * * where B(i,j) = i-1 if i divides j, and B(i,j) = -1 otherwise. * * The Riemann matrix has these properties: * - Each eigenvalue e(i) satisfies abs(e(i)) <= m-1/m, where m = n+1. * - i <= e(i) <= i+1 with at most m-sqrt(m) exceptions. * - All integers in the interval (m/3, m/2] are eigenvalues. * */ case PlasmaMatrixRiemann: { int ii, jj; for (j=0,jj=n0+2; j<N; j++,jj++) { for (i=0,ii=m0+2; i<M; i++,ii++) { if ( jj%ii == 0 ) { A[j*LDA+i] = (PLASMA_Complex32_t)( ii - 1. ); } else { A[j*LDA+i] = (PLASMA_Complex32_t)( -1. ); } } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000049 * * Symmetric positive definite matrix * * Returns the symmetric positive definite n-by-n matrix such that * A(i,j) = i/j for j >= i. * * The Lehmer matrix A has these properties: * - A is totally nonnegative. * - The inverse inv(A) is tridiagonal and explicitly known. * - The order n <= cond(A) <= 4*n*n.Matrix associated with the * Riemann hypothesis * */ case PlasmaMatrixLehmer: { int ii, jj; for (j=0,jj=n0+1; j<N; j++,jj++) { for (i=0,ii=m0+1; i<M; i++,ii++) { if ( jj >= ii ) { A[j*LDA+i] = (PLASMA_Complex32_t)( ii ) / (PLASMA_Complex32_t)( jj ); } else { A[j*LDA+i] = (PLASMA_Complex32_t)( jj ) / (PLASMA_Complex32_t)( ii ); } } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000066 * * Symmetric positive definite matrix * * Returns the n-by-n symmetric positive definite matrix with * A(i,j) = min(i,j). * * The minij matrix has these properties: * - The inverse inv(A) is tridiagonal and equal to -1 times the * second difference matrix, except its (n,n) element is 1. * - Givens' matrix, 2*A-ones(size(A)), has tridiagonal inverse * and eigenvalues 0.5*sec((2*r-1)*pi/(4*n))^2, where r=1:n. * - (n+1)*ones(size(A))-A has elements that are max(i,j) and a * tridiagonal inverse. * */ case PlasmaMatrixMinij: { int ii, jj; for (j=0,jj=n0+1; j<N; j++,jj++) { for (i=0,ii=m0+1; i<M; i++,ii++) { A[j*LDA+i] = (PLASMA_Complex32_t) min( ii, jj ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-999936 * * Diagonally dominant, ill-conditioned, tridiagonal matrix * * Returns the n-by-n matrix, row diagonally dominant, tridiagonal * matrix that is ill-conditioned for small nonnegative values of * theta. The default value of theta is 0.01. The Dorr matrix * itself is the same as gallery('tridiag',c,d,e). * */ case PlasmaMatrixDorr: { PLASMA_Complex32_t theta = 0.01; PLASMA_Complex32_t h = 1. / ( gN + 1. ); PLASMA_Complex32_t term = theta / ( h * h ); int jj; int half = (gN+1) / 2; LAPACKE_claset_work(LAPACK_COL_MAJOR, 'A', M, N, 0., 0., A, LDA); /* First half */ for (j=0, jj=n0; (j<N) && (jj<half); j++, jj++) { i = jj - m0; if ( ( i < -1 ) || (i > M) ) continue; /* Over the diagonal */ if (i > 0) A[j*LDA + i-1] = - term - (0.5 - jj*h)/h; /* Diagonal */ if ( i >= M ) return PLASMA_SUCCESS; if ( i >=0 ) A[j*LDA + i] = 2. * term + (0.5 - (jj+1) * h) / h; /* Below the diagonal */ if (i+1 < M) { if (jj+1 == half) A[j*LDA + i+1] = - term + (0.5 - (jj+2)*h)/h; else A[j*LDA + i+1] = - term; } } /* Second half */ for (; j<N; j++,jj++) { i = jj - m0; if ( ( i < -1 ) || (i > M)) continue; if (i > 0) { if (jj == half) A[j*LDA + i-1] = - term - (0.5 - jj*h)/h; else A[j*LDA + i-1] = - term; } if ((i >=0) && (i < M)) A[j*LDA + i] = 2. * term - (0.5 - (jj+1)*h)/h; if (i+1 < M) A[j*LDA + i+1] = - term + (0.5 - (jj+2)*h)/h; } } break; /* * See [1] J. Demmel, Applied Numerical Linear Algebra, SIAM, * Philadelphia, 1997 * * Returns a matrix defined by: * A = D * ( I + 1e-7* rand(n)), where D = diag(10^{14*(0:n-1)/n}) * */ case PlasmaMatrixDemmel: { PLASMA_Complex32_t dii; int ii, jj; /* Randomize the matrix */ CORE_cplrnt( M, N, A, LDA, gM, m0, n0, seed ); for (j=0,jj=n0; j<N; j++,jj++) { for (i=0,ii=m0; i<M; i++,ii++) { dii = cpowf( 10. , 14. * ii / gM ); A[j*LDA+i] *= dii * ( (jj == ii) ? 1. : 1.e-7 ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000000 * * Inverse of an upper Hessenberg matrix * * A = gallery('invhess',x,y), where x is a length n vector and y * is a length n-1 vector, returns the matrix whose lower triangle * agrees with that of ones(n,1)*x' and whose strict upper * triangle agrees with that of [1 y]*ones(1,n). * * The matrix is nonsingular if x(1) ~= 0 and x(i+1) ~= y(i) for * all i, and its inverse is an upper Hessenberg matrix. Argument * y defaults to -x(1:n-1). * * If x is a scalar, invhess(x) is the same as invhess(1:x). * * Here: gallery('invhess', gM) */ case PlasmaMatrixInvhess: { int ii, jj; for (j=0,jj=n0+1; j<N; j++,jj++) { for (i=0,ii=m0+1; i<M; i++,ii++) { if ( jj <= ii ) { A[j*LDA+i] = (PLASMA_Complex32_t)( jj ); } else { A[j*LDA+i] = (PLASMA_Complex32_t)( -ii ); } } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1019317 * * Cauchy matrix * * Returns an n-by-n matrix C such that, C(i,j) = 1/(i + j). * */ case PlasmaMatrixCauchy: { int ii, jj; for (j=0,jj=n0+1; j<N; j++,jj++) { for (i=0,ii=m0+1; i<M; i++,ii++) { A[j*LDA+i] = (PLASMA_Complex32_t)( 1. ) / (PLASMA_Complex32_t)( ii+jj ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/hilb.html * * Hilbert Matrix * * The Hilbert matrix is a notable example of a poorly conditioned * matrix. The elements of the Hilbert matrices are: * H(i,j) = 1/(i * + j – 1). * */ case PlasmaMatrixHilb: { PLASMA_Complex32_t tmp = (PLASMA_Complex32_t)( m0 + n0 + 1. ); for (j=0; j<N; j++) { for (i=0; i<M; i++) { A[j*LDA+i] = (PLASMA_Complex32_t)1. / (PLASMA_Complex32_t)( tmp + i + j ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000062 * * Lotkin matrix * * Returns the Hilbert matrix with its first row altered to all * ones. The Lotkin matrix A is nonsymmetric, ill-conditioned, and * has many negative eigenvalues of small magnitude. Its inverse * has integer entries and is known explicitly. * */ case PlasmaMatrixLotkin: { PLASMA_Complex32_t tmp = (PLASMA_Complex32_t)( m0 + n0 + 1. ); if (m0 == 0) { for (j=0; j<N; j++) { A[j*LDA] = (PLASMA_Complex32_t)1.; for (i=1; i<M; i++) { A[j*LDA+i] = (PLASMA_Complex32_t)1. / (PLASMA_Complex32_t)( tmp + i + j ); } } } else { for (j=0; j<N; j++) { for (i=0; i<M; i++) { A[j*LDA+i] = (PLASMA_Complex32_t)1. / (PLASMA_Complex32_t)( tmp + i + j ); } } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/gallery.html#f84-1000083 * * Orthogonal and nearly orthogonal matrices * * Returns the matrix Q of order n, such that: * Q(i,j) = sqrt(2/(n+1)) * sin(i*j*pi/(n+1)) * * Symmetric eigenvector matrix for second difference matrix. * */ case PlasmaMatrixOrthog: /* Default: k=1 */ { PLASMA_Complex32_t sqrtn = (PLASMA_Complex32_t) sqrt( 2. / (gN+1.) ); float scale = pi / (float)(gN+1.); int ii, jj; for (j=0,jj=n0+1; j<N; j++,jj++) { for (i=0,ii=m0+1; i<M; i++,ii++) { A[j*LDA+i] = sqrtn * (PLASMA_Complex32_t) sin( (float)ii * (float)jj * scale ); } } } break; /* * See http://www.mathworks.fr/fr/help/matlab/ref/wilkinson.html * * Wilkinson's eigenvalue test matrix * * Returns one of J. H. Wilkinson's eigenvalue test matrices. It * is a symmetric, tridiagonal matrix with pairs of nearly, but * not exactly, equal eigenvalues. * */ case PlasmaMatrixWilkinson: { if (gM != gN) { coreblas_error(6, "Illegal value of gM (Matrix must be square for Wilkinson)"); return -6; } int ii, jj; for (j=0,jj=n0; j<N; j++,jj++) { for (i=0,ii=m0; i<M; i++,ii++) { if (ii == jj) { PLASMA_Complex32_t tmp = (PLASMA_Complex32_t)(( (gN - 1 - ii) < ii ) ? gN - 1 - ii : ii ); A[j*LDA+i] = (PLASMA_Complex32_t)(gN - 2. * tmp - 1.) / 2.; } else if ( (ii == jj+1) || (ii == jj-1) ) { A[j*LDA+i] = (PLASMA_Complex32_t)1.; } else { A[j*LDA+i] = (PLASMA_Complex32_t)0.; } } } } break; /* * See [1] L. V. Foster, Gaussian Elimination with Partial * Pivoting Can Fail in Practice, SIAM J. Matrix * Anal. Appl., 15 (1994), pp. 1354-1362. * * [2] L. V. Foster, The growth factor and efficiency of * Gaussian elimination with rook pivoting, * J. Comput. Appl. Math., 86 (1997), pp. 177-194 * * A pathological case for LU with gaussian elimination. * */ case PlasmaMatrixFoster: /* Default: k=h=c=1 */ { float k=1., h=1., c=1.; int ii, jj; for (j=0,jj=n0; j<N; j++,jj++) { for (i=0,ii=m0; i<M; i++,ii++) { if (ii == jj) { if (jj == 0) A[j*LDA+i] = (PLASMA_Complex32_t)1.; else if (jj == gN-1) A[j*LDA+i] = (PLASMA_Complex32_t)(1. - (1. / c) - (k*h)/2. ); else A[j*LDA+i] = (PLASMA_Complex32_t)(1. - (k*h)/2. ); } else if (jj == 0) { A[j*LDA+i] = (PLASMA_Complex32_t)(-k*h/2.); } else if (jj == gN-1) { A[j*LDA+i] = (PLASMA_Complex32_t)(-1./c); } else if (ii > jj) { A[j*LDA+i] = (PLASMA_Complex32_t)(-k*h); } else { A[j*LDA+i] = (PLASMA_Complex32_t)0.; } } } } break; /* * See [3] S. J. Wright, A collection of problems for which * Gaussian elimination with partial pivoting is unstable, * SIAM J. SCI. STATIST. COMPUT., 14 (1993), pp. 231-238. * * A pathological case for LU with gaussian elimination. * */ /* * Default: h=0.01, M=[-10 -19, 19 30]. Then, * exp(h*M)=[0.9048 0.8270, 1.2092 1.3499] */ case PlasmaMatrixWright: { int ii, jj; for (j=0,jj=n0; j<N; j++,jj++) { for (i=0,ii=m0; i<M; i++,ii++) { if (ii == jj) A[j*LDA+i] = (PLASMA_Complex32_t)1.; else if ((ii == jj + 2) && (jj % 2 == 0)) A[j*LDA+i] = (PLASMA_Complex32_t)(-0.9048); else if ((ii == jj + 3) && (jj % 2 == 0)) A[j*LDA+i] = (PLASMA_Complex32_t)(-1.2092); else if ((ii == jj + 2) && (jj % 2 == 1)) A[j*LDA+i] = (PLASMA_Complex32_t)(-0.8270); else if ((ii == jj + 3) && (jj % 2 == 1)) A[j*LDA+i] = (PLASMA_Complex32_t)(-1.3499); else if ((jj == gM-2) && (ii == 0)) A[j*LDA+i] = (PLASMA_Complex32_t)1.; else if ((jj == gM-1) && (ii == 1)) A[j*LDA+i] = (PLASMA_Complex32_t)1.; else A[j*LDA+i] = (PLASMA_Complex32_t)0.; } } } break; /* * Generates a pathological case for LU with gaussian elimination. * * Returns a random matrix on which, the columns from N/4 to N/2 * are scaled down by eps. * These matrices fails on LU with partial pivoting, but Hybrid * LU-QR algorithms manage to recover the scaled down columns. * */ case PlasmaMatrixLangou: { PLASMA_Complex32_t eps = (PLASMA_Complex32_t) LAPACKE_slamch_work( 'e' ); int ii, jj, mm, minMN; int firstcol, lastcol; /* Create random tile */ CORE_cplrnt( M, N, A, LDA, gM, m0, n0, seed ); /* Scale down the columns gN/4 to gN/2 below the diagonal */ minMN = min( gM, gN ); firstcol = minMN / 4; lastcol = minMN / 2; if ( (m0 >= n0) && ((n0+N) >= firstcol ) && (n0 < lastcol) ) { jj = max( n0, firstcol ); j = jj - n0; for (; j<N && jj < lastcol; j++,jj++) { ii = max( m0, jj ); i = ii - m0; mm = M - i; cblas_cscal( mm, CBLAS_SADDR(eps), A + j*LDA + i, 1); } } } break; default: coreblas_error(1, "Illegal value of mtxtype"); return -1; } return PLASMA_SUCCESS; }
{ "alphanum_fraction": 0.4742868308, "avg_line_length": 30.5369928401, "ext": "c", "hexsha": "e9021a081235b88f13f23169119c023c6c09a4f7", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "zhuangsc/Plasma-ompss1", "max_forks_repo_path": "core_blas/core_cpltmg.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "zhuangsc/Plasma-ompss1", "max_issues_repo_path": "core_blas/core_cpltmg.c", "max_line_length": 110, "max_stars_count": null, "max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "zhuangsc/Plasma-ompss1", "max_stars_repo_path": "core_blas/core_cpltmg.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7819, "size": 25590 }
#ifndef libraries_h #define libraries_h #include <fstream> #include <iostream> #include <iomanip> #include <ctime> #include <math.h> #include <vector> #include <deque> #include <queue> #include <stack> #include <array> #include <algorithm> #include <unordered_map> #include <map> #include <memory> #include <utility> #include <string> #include <gsl/gsl_rng.h> #include <gsl/gsl_statistics.h> #include "types.h" //#include <omp.h> //#include <tbb/tbb.h> #endif
{ "alphanum_fraction": 0.7229437229, "avg_line_length": 17.1111111111, "ext": "h", "hexsha": "f3b6636e6ee6577ac086e36571135c4c220ccc80", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b44d2babe61488bbe4954ad74a8d4e74abe11088", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "kovnerd/cdt2d", "max_forks_repo_path": "include/libraries.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "b44d2babe61488bbe4954ad74a8d4e74abe11088", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "kovnerd/cdt2d", "max_issues_repo_path": "include/libraries.h", "max_line_length": 31, "max_stars_count": 1, "max_stars_repo_head_hexsha": "b44d2babe61488bbe4954ad74a8d4e74abe11088", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "kovnerd/cdt2d", "max_stars_repo_path": "include/libraries.h", "max_stars_repo_stars_event_max_datetime": "2021-07-14T11:44:20.000Z", "max_stars_repo_stars_event_min_datetime": "2021-07-14T11:44:20.000Z", "num_tokens": 114, "size": 462 }
// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #include <gsl/span> namespace onnxruntime { namespace contrib { template <typename T> class IAttentionMechanism { public: virtual ~IAttentionMechanism() = default; virtual void PrepareMemory( const gsl::span<const T>& memory, const gsl::span<const int>& memory_sequence_lengths) = 0; virtual void Compute( const gsl::span<const T>& query, const gsl::span<const T>& prev_alignment, const gsl::span<T>& output, const gsl::span<T>& alignment) const = 0; virtual const gsl::span<const T> Values() const = 0; virtual const gsl::span<const T> Keys() const = 0; virtual int GetMaxMemorySteps() const = 0; virtual bool NeedPrevAlignment() const = 0; }; } }
{ "alphanum_fraction": 0.698019802, "avg_line_length": 21.8378378378, "ext": "h", "hexsha": "c648536f997c578ffd008e8c22410eb5a112296e", "lang": "C", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2021-11-30T13:58:13.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-05T19:52:22.000Z", "max_forks_repo_head_hexsha": "6e4e76414639f50836a64546603c8957227857b0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hqucms/onnxruntime", "max_forks_repo_path": "onnxruntime/contrib_ops/cpu/attnlstm/attention_mechanism.h", "max_issues_count": 8, "max_issues_repo_head_hexsha": "6e4e76414639f50836a64546603c8957227857b0", "max_issues_repo_issues_event_max_datetime": "2021-04-19T16:56:52.000Z", "max_issues_repo_issues_event_min_datetime": "2019-10-08T14:20:49.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hqucms/onnxruntime", "max_issues_repo_path": "onnxruntime/contrib_ops/cpu/attnlstm/attention_mechanism.h", "max_line_length": 61, "max_stars_count": 2, "max_stars_repo_head_hexsha": "6e4e76414639f50836a64546603c8957227857b0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hqucms/onnxruntime", "max_stars_repo_path": "onnxruntime/contrib_ops/cpu/attnlstm/attention_mechanism.h", "max_stars_repo_stars_event_max_datetime": "2019-12-04T12:49:01.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-18T14:04:42.000Z", "num_tokens": 201, "size": 808 }
#pragma once #include <gsl\gsl> #include <winrt\base.h> #include <d3d11.h> #include <DirectXTK\SpriteBatch.h> #include "DrawableGameComponent.h" #include "HeightmapTessellationMaterial.h" #include "RenderStateHelper.h" namespace Rendering { class HeightmapTessellationDemo final : public Library::DrawableGameComponent { public: HeightmapTessellationDemo(Library::Game& game, const std::shared_ptr<Library::Camera>& camera); HeightmapTessellationDemo(const HeightmapTessellationDemo&) = delete; HeightmapTessellationDemo(HeightmapTessellationDemo&&) = default; HeightmapTessellationDemo& operator=(const HeightmapTessellationDemo&) = default; HeightmapTessellationDemo& operator=(HeightmapTessellationDemo&&) = default; ~HeightmapTessellationDemo(); bool AnimationEnabled() const; void SetAnimationEnabled(bool enabled); gsl::span<const float> EdgeFactors() const; gsl::span<const float> InsideFactors() const; void SetUniformFactors(float factor); float DisplacementScale() const; void SetDisplacementScale(float displacementScale); virtual void Initialize() override; virtual void Update(const Library::GameTime& gameTime) override; virtual void Draw(const Library::GameTime& gameTime) override; private: inline static const RECT HeightmapDestinationRectangle = { 0, 512, 256, 768 }; Library::RenderStateHelper mRenderStateHelper; HeightmapTessellationMaterial mMaterial; winrt::com_ptr<ID3D11Buffer> mVertexBuffer; bool mUpdateMaterial{ true }; std::unique_ptr<DirectX::SpriteBatch> mSpriteBatch; std::shared_ptr<Library::Texture2D> mHeightmap; bool mAnimationEnabled{ false }; }; }
{ "alphanum_fraction": 0.7888349515, "avg_line_length": 34.3333333333, "ext": "h", "hexsha": "50b3ab8a1d63e243b2506fc29d01f490e0647c2d", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "05a05c5c26784dafa9a89747276f385252951f2f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ssshammi/real-time-3d-rendering-with-directx-and-hlsl", "max_forks_repo_path": "source/10.3_Heightmap_Tessellation/HeightmapTessellationDemo.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "05a05c5c26784dafa9a89747276f385252951f2f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ssshammi/real-time-3d-rendering-with-directx-and-hlsl", "max_issues_repo_path": "source/10.3_Heightmap_Tessellation/HeightmapTessellationDemo.h", "max_line_length": 97, "max_stars_count": null, "max_stars_repo_head_hexsha": "05a05c5c26784dafa9a89747276f385252951f2f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ssshammi/real-time-3d-rendering-with-directx-and-hlsl", "max_stars_repo_path": "source/10.3_Heightmap_Tessellation/HeightmapTessellationDemo.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 421, "size": 1648 }
#ifndef __COMPLEX_DEF_H__ #define __COMPLEX_DEF_H__ #include <complex> #include <gsl/gsl_math.h> #include <gsl/gsl_sf_gamma.h> #include <gsl/gsl_sf_log.h> #include <gsl/gsl_sf_zeta.h> #include <gsl/gsl_sf_dilog.h> #include <gsl/gsl_sf_result.h> std::complex<long double> operator*(const std::complex<long double>& a, const double& b); std::complex<long double> operator*(const double& a,const std::complex<long double>& b); std::complex<long double> operator/(const std::complex<long double>& a, const double& b); std::complex<long double> operator/(const double& a,const std::complex<long double>& b); std::complex<long double> operator-(const std::complex<long double>& a, const double& b); std::complex<long double> operator-(const double& a,const std::complex<long double>& b); std::complex<long double> operator+(const std::complex<long double>& a, const double& b); std::complex<long double> operator+(const double& a,const std::complex<long double>& b); //Useful Math functions long double log_r(long double x); long double dilog_r(long double x); const std::complex<long double> II(0.0,1.0); std::complex<long double> log_c(std::complex<long double> z); std::complex<long double> dilog_c(std::complex<long double> z); #endif /* __COMPLEX_DEF_H__ */
{ "alphanum_fraction": 0.7413249211, "avg_line_length": 35.2222222222, "ext": "h", "hexsha": "746a327c64cb09f44a10d77353eeb1dc3df96f77", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f320d8f4e2ef27af19cf62bded85afce8e0de7a7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "gvita/RHEHpt", "max_forks_repo_path": "src/complex_def.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "f320d8f4e2ef27af19cf62bded85afce8e0de7a7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "gvita/RHEHpt", "max_issues_repo_path": "src/complex_def.h", "max_line_length": 89, "max_stars_count": null, "max_stars_repo_head_hexsha": "f320d8f4e2ef27af19cf62bded85afce8e0de7a7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "gvita/RHEHpt", "max_stars_repo_path": "src/complex_def.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 333, "size": 1268 }
/* * edges.h -- élek effektív tárolása: lista az id-k szerint rendezve, * ebben gyorsan lehet keresni + binary heap az időpontok szerint, így * a legrégebbit gyorsan ki lehet választani * * Copyright 2013 Kondor Dániel <dani@thinkpad-r9r> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * */ #ifndef EDGES_H #define EDGES_H #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include "idlist.h" #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <ctype.h> #include <sys/mman.h> //~ #include <gsl/gsl_rng.h> #include <limits.h> //~ #include "mt19937.h" //változás: hashmap használata helyett előre beolvassuk az összes lehetséges élt, sorbarendezve (feltétel: // a bemeneti fájlban sorbarendezve kell legyenek, minden él csak egyszer -- ezt egyszerűbb az SQL Serverrel // megcsináltatni), ebben tudunk már gyorsan keresni typedef struct edgehelper_t { const idlist* il; uint64_t* index; uint64_t* outdeg; } edgehelper; //heap struktúra az élek tárolásához (összes él, idő szerint rendezve) typedef struct edge_t { //egy él, heap ezekből, timestamp szerint rendezve uint32_t p1; //első pont -> itt az "igazi" ID-ket tároljuk (a hálózatbeli azonosítókat, ezeknek nem kell szekvenciálisnak lenni) uint32_t p2; //második pont (p1->p2 él) unsigned int offset; //heap-beli offset (heap[i].offset == i mindig) -- vagy: tranzakció ID-k unsigned int timestamp; //legutolsó aktivitás } edge; //méret -- 16 bájt typedef struct edges_t { edge* e; //élek tárolása itt, id-k szerint rendezve uint64_t nedges; uint64_t edges_size; uint64_t edges_grow; edgehelper* h; } edges; /* * egy tömb (unsigned int-ekből), amiben az edge-ekre mutató pointerek vannak, ezek binary heap-ben: * unsigned int* heap; * edges[heap[i]].timestamp < edges[heap[2*i+1 / 2*i+2]].timestamp * és edges[heap[i]].offset == i * */ //hash fv. (két 32-bites id-ből egy 64-bites szám, ezeket talán gyorsabb összehasonlítani static inline uint64_t edgehash(const edge* e, const unsigned int i) { uint64_t r = e[i].p1; r = r << 32; uint64_t r2 = e[i].p2; return r | r2; } //két él összehasonlítása, eredmény: -1, ha eh2-nek e[i] előtt kell lenni, 1 ha utána, 0, ha megegyeznek static inline int cmpedge(const edge* e, uint64_t i, uint64_t eh2) { uint64_t eh1 = edgehash(e,i); if(eh1 < eh2) return 1; if(eh1 > eh2) return -1; return 0; } static inline int cmpedge2(const edge* e, uint64_t i, uint64_t j) { uint64_t eh2 = edgehash(e,j); return cmpedge(e,i,eh2); } //éleket tároló struktúra lefoglalása / növesztése: // ha e == 0, akkor új struktúra lefoglalása // ha e != 0, akkor növesztés (mremap()) //eredmény: 0, ha hiba történt (nem sikerült memóriát lefoglalni) //ha a bemeneti e nem volt 0, akkor azt nem szabadítottuk fel //edges* pointer, ha rendben volt (ha e != 0, akkor e-t adjuk vissza) edges* edges_grow(edges* e); //élek felszabadítása void edges_free(edges* e); //élek beolvasása egy fájlból -- a fájlban már megfelelően rendezve kell lenniük edges* edges_read(FILE* f); //élek beolvasása egy fájlból -- a fájlban már megfelelően rendezve kell lenniük edges* edges_read2(FILE* f); //+ timestamp-ok is meg vannak adva //beolvasás általánosan: //flags értékei: #define EFLAGS_T1 1 //időpontokat is beolvasunk és idő szerint rendezzük az eredményt (ha nincs megadva, akkor csak //éleket olvasunk be és minden élből csak egyet tartunk meg) #define EFLAGS_SELF 2 //megengedünk önmagába mutató éleket (p1->p1) #define EFLAGS_TXID 4 //tranzakció ID-ket is beolvasunk (legutolsó oszlop, az offset tömbbe tároljuk el) #define EFLAGS_ERROR_OVERFLOW 8 // overflow hibát jelent (különben csak kihagyjuk) edges* edges_read0(FILE* f, int flags); //élek átmásolása egy új tömbbe, ha r == 1, akkor fordítva (p2->p1, p1->p2) edges* edges_copy(edges* e1, int r); //részhalmaz átmásolása edges* edges_copy2(edges* e1, uint64_t start, uint64_t end, int r); //él megkeresése, eredmény: a tömbön (e->e) belüli sorszám, ha megtaláltuk, e->nedges, ha nem találtuk uint64_t edges_find(edges* e, uint32_t p1, uint32_t p2); //olyan él keresése, ahol az első ID megegyezik a megadottal uint64_t edges_findfirst(edges* e, uint32_t p1); //élek sorbarendezése az ID-k szerint void edges_sort1(edges* e); //véletlen cserék //a->b, c->d helyett a->d, c->b //N darab csere /* void edges_rand1(edges* e, uint64_t N, gsl_rng* r); //véletlen cserék, a sikertelen próbálkozások is beleszámítanak a cserék számába //a->b, c->d helyett a->d, c->b void edges_rand2(edges* e, uint64_t N, gsl_rng* r); */ // create a "helper" for faster edge lookups: store the starting index for each addr, making it unnecessary to perform binary // search for the whole set, and also return result in O(1) time for addresses with outdeg == 1 int edges_createhelper(edges* e, const idlist* il); //ID-k generálása N db él alapján idlist* ids_gen(const edge* e, unsigned int N); //N db élben az ID-k kicserélése a sorszámukra int ids_replace(const idlist* il, edge* e, uint64_t N); #endif
{ "alphanum_fraction": 0.7319823789, "avg_line_length": 33.1871345029, "ext": "h", "hexsha": "7fddbf401acb057baafdd71d909fbe95469cada7", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ebdb1bae08d32274b16d29fcd07451a7451c8b5b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "dkondor/patest_new", "max_forks_repo_path": "patestgen/edges.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "ebdb1bae08d32274b16d29fcd07451a7451c8b5b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "dkondor/patest_new", "max_issues_repo_path": "patestgen/edges.h", "max_line_length": 129, "max_stars_count": null, "max_stars_repo_head_hexsha": "ebdb1bae08d32274b16d29fcd07451a7451c8b5b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "dkondor/patest_new", "max_stars_repo_path": "patestgen/edges.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1987, "size": 5675 }
#ifndef INCLUDED_TELEPATH_BLAS_1_H #define INCLUDED_TELEPATH_BLAS_1_H #include <complex> #include <cblas.h> namespace telepath{ template< typename T > inline auto asum( std::size_t n, const T* x, std::size_t incX = 1 ); template<> inline auto asum<double>( std::size_t n, const double* x, std::size_t incX ){ return cblas_dasum( n, x, incX ); } template<> inline auto asum<float>( std::size_t n, const float* x, std::size_t incX ){ return cblas_sasum( n, x, incX ); } template<> inline auto asum<std::complex<double> >( std::size_t n, const std::complex<double>* x, std::size_t incX ){ return cblas_dzasum( n, (const double*) x, incX ); } template<> inline auto asum<std::complex<float> >( std::size_t n, const std::complex<float>* x, std::size_t incX ){ return cblas_scasum( n, (const float*) x, incX ); } } //namespace tblas #endif
{ "alphanum_fraction": 0.649122807, "avg_line_length": 35.0769230769, "ext": "h", "hexsha": "1162d66aba971c6ddaf17bb9f6a0d886baa10216", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "636f7345b6479d5c48dbf03cb17343b14c305c7c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "tbepler/telepath", "max_forks_repo_path": "include/telepath/blas/blas_1.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "636f7345b6479d5c48dbf03cb17343b14c305c7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "tbepler/telepath", "max_issues_repo_path": "include/telepath/blas/blas_1.h", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "636f7345b6479d5c48dbf03cb17343b14c305c7c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "tbepler/telepath", "max_stars_repo_path": "include/telepath/blas/blas_1.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 273, "size": 912 }
/* matrix/gsl_matrix_long_double.h * * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __GSL_MATRIX_LONG_DOUBLE_H__ #define __GSL_MATRIX_LONG_DOUBLE_H__ #if !defined( GSL_FUN ) # if !defined( GSL_DLL ) # define GSL_FUN extern # elif defined( BUILD_GSL_DLL ) # define GSL_FUN extern __declspec(dllexport) # else # define GSL_FUN extern __declspec(dllimport) # endif #endif #include <stdlib.h> #include <gsl/gsl_types.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_inline.h> #include <gsl/gsl_check_range.h> #include <gsl/gsl_vector_long_double.h> #undef __BEGIN_DECLS #undef __END_DECLS #ifdef __cplusplus # define __BEGIN_DECLS extern "C" { # define __END_DECLS } #else # define __BEGIN_DECLS /* empty */ # define __END_DECLS /* empty */ #endif __BEGIN_DECLS typedef struct { size_t size1; size_t size2; size_t tda; long double * data; gsl_block_long_double * block; int owner; } gsl_matrix_long_double; typedef struct { gsl_matrix_long_double matrix; } _gsl_matrix_long_double_view; typedef _gsl_matrix_long_double_view gsl_matrix_long_double_view; typedef struct { gsl_matrix_long_double matrix; } _gsl_matrix_long_double_const_view; typedef const _gsl_matrix_long_double_const_view gsl_matrix_long_double_const_view; /* Allocation */ GSL_FUN gsl_matrix_long_double * gsl_matrix_long_double_alloc (const size_t n1, const size_t n2); GSL_FUN gsl_matrix_long_double * gsl_matrix_long_double_calloc (const size_t n1, const size_t n2); GSL_FUN gsl_matrix_long_double * gsl_matrix_long_double_alloc_from_block (gsl_block_long_double * b, const size_t offset, const size_t n1, const size_t n2, const size_t d2); GSL_FUN gsl_matrix_long_double * gsl_matrix_long_double_alloc_from_matrix (gsl_matrix_long_double * m, const size_t k1, const size_t k2, const size_t n1, const size_t n2); GSL_FUN gsl_vector_long_double * gsl_vector_long_double_alloc_row_from_matrix (gsl_matrix_long_double * m, const size_t i); GSL_FUN gsl_vector_long_double * gsl_vector_long_double_alloc_col_from_matrix (gsl_matrix_long_double * m, const size_t j); GSL_FUN void gsl_matrix_long_double_free (gsl_matrix_long_double * m); /* Views */ GSL_FUN _gsl_matrix_long_double_view gsl_matrix_long_double_submatrix (gsl_matrix_long_double * m, const size_t i, const size_t j, const size_t n1, const size_t n2); GSL_FUN _gsl_vector_long_double_view gsl_matrix_long_double_row (gsl_matrix_long_double * m, const size_t i); GSL_FUN _gsl_vector_long_double_view gsl_matrix_long_double_column (gsl_matrix_long_double * m, const size_t j); GSL_FUN _gsl_vector_long_double_view gsl_matrix_long_double_diagonal (gsl_matrix_long_double * m); GSL_FUN _gsl_vector_long_double_view gsl_matrix_long_double_subdiagonal (gsl_matrix_long_double * m, const size_t k); GSL_FUN _gsl_vector_long_double_view gsl_matrix_long_double_superdiagonal (gsl_matrix_long_double * m, const size_t k); GSL_FUN _gsl_vector_long_double_view gsl_matrix_long_double_subrow (gsl_matrix_long_double * m, const size_t i, const size_t offset, const size_t n); GSL_FUN _gsl_vector_long_double_view gsl_matrix_long_double_subcolumn (gsl_matrix_long_double * m, const size_t j, const size_t offset, const size_t n); GSL_FUN _gsl_matrix_long_double_view gsl_matrix_long_double_view_array (long double * base, const size_t n1, const size_t n2); GSL_FUN _gsl_matrix_long_double_view gsl_matrix_long_double_view_array_with_tda (long double * base, const size_t n1, const size_t n2, const size_t tda); GSL_FUN _gsl_matrix_long_double_view gsl_matrix_long_double_view_vector (gsl_vector_long_double * v, const size_t n1, const size_t n2); GSL_FUN _gsl_matrix_long_double_view gsl_matrix_long_double_view_vector_with_tda (gsl_vector_long_double * v, const size_t n1, const size_t n2, const size_t tda); GSL_FUN _gsl_matrix_long_double_const_view gsl_matrix_long_double_const_submatrix (const gsl_matrix_long_double * m, const size_t i, const size_t j, const size_t n1, const size_t n2); GSL_FUN _gsl_vector_long_double_const_view gsl_matrix_long_double_const_row (const gsl_matrix_long_double * m, const size_t i); GSL_FUN _gsl_vector_long_double_const_view gsl_matrix_long_double_const_column (const gsl_matrix_long_double * m, const size_t j); GSL_FUN _gsl_vector_long_double_const_view gsl_matrix_long_double_const_diagonal (const gsl_matrix_long_double * m); GSL_FUN _gsl_vector_long_double_const_view gsl_matrix_long_double_const_subdiagonal (const gsl_matrix_long_double * m, const size_t k); GSL_FUN _gsl_vector_long_double_const_view gsl_matrix_long_double_const_superdiagonal (const gsl_matrix_long_double * m, const size_t k); GSL_FUN _gsl_vector_long_double_const_view gsl_matrix_long_double_const_subrow (const gsl_matrix_long_double * m, const size_t i, const size_t offset, const size_t n); GSL_FUN _gsl_vector_long_double_const_view gsl_matrix_long_double_const_subcolumn (const gsl_matrix_long_double * m, const size_t j, const size_t offset, const size_t n); GSL_FUN _gsl_matrix_long_double_const_view gsl_matrix_long_double_const_view_array (const long double * base, const size_t n1, const size_t n2); GSL_FUN _gsl_matrix_long_double_const_view gsl_matrix_long_double_const_view_array_with_tda (const long double * base, const size_t n1, const size_t n2, const size_t tda); GSL_FUN _gsl_matrix_long_double_const_view gsl_matrix_long_double_const_view_vector (const gsl_vector_long_double * v, const size_t n1, const size_t n2); GSL_FUN _gsl_matrix_long_double_const_view gsl_matrix_long_double_const_view_vector_with_tda (const gsl_vector_long_double * v, const size_t n1, const size_t n2, const size_t tda); /* Operations */ GSL_FUN void gsl_matrix_long_double_set_zero (gsl_matrix_long_double * m); GSL_FUN void gsl_matrix_long_double_set_identity (gsl_matrix_long_double * m); GSL_FUN void gsl_matrix_long_double_set_all (gsl_matrix_long_double * m, long double x); GSL_FUN int gsl_matrix_long_double_fread (FILE * stream, gsl_matrix_long_double * m) ; GSL_FUN int gsl_matrix_long_double_fwrite (FILE * stream, const gsl_matrix_long_double * m) ; GSL_FUN int gsl_matrix_long_double_fscanf (FILE * stream, gsl_matrix_long_double * m); GSL_FUN int gsl_matrix_long_double_fprintf (FILE * stream, const gsl_matrix_long_double * m, const char * format); GSL_FUN int gsl_matrix_long_double_memcpy(gsl_matrix_long_double * dest, const gsl_matrix_long_double * src); GSL_FUN int gsl_matrix_long_double_swap(gsl_matrix_long_double * m1, gsl_matrix_long_double * m2); GSL_FUN int gsl_matrix_long_double_swap_rows(gsl_matrix_long_double * m, const size_t i, const size_t j); GSL_FUN int gsl_matrix_long_double_swap_columns(gsl_matrix_long_double * m, const size_t i, const size_t j); GSL_FUN int gsl_matrix_long_double_swap_rowcol(gsl_matrix_long_double * m, const size_t i, const size_t j); GSL_FUN int gsl_matrix_long_double_transpose (gsl_matrix_long_double * m); GSL_FUN int gsl_matrix_long_double_transpose_memcpy (gsl_matrix_long_double * dest, const gsl_matrix_long_double * src); GSL_FUN long double gsl_matrix_long_double_max (const gsl_matrix_long_double * m); GSL_FUN long double gsl_matrix_long_double_min (const gsl_matrix_long_double * m); GSL_FUN void gsl_matrix_long_double_minmax (const gsl_matrix_long_double * m, long double * min_out, long double * max_out); GSL_FUN void gsl_matrix_long_double_max_index (const gsl_matrix_long_double * m, size_t * imax, size_t *jmax); GSL_FUN void gsl_matrix_long_double_min_index (const gsl_matrix_long_double * m, size_t * imin, size_t *jmin); GSL_FUN void gsl_matrix_long_double_minmax_index (const gsl_matrix_long_double * m, size_t * imin, size_t * jmin, size_t * imax, size_t * jmax); GSL_FUN int gsl_matrix_long_double_isnull (const gsl_matrix_long_double * m); GSL_FUN int gsl_matrix_long_double_ispos (const gsl_matrix_long_double * m); GSL_FUN int gsl_matrix_long_double_isneg (const gsl_matrix_long_double * m); GSL_FUN int gsl_matrix_long_double_isnonneg (const gsl_matrix_long_double * m); GSL_FUN int gsl_matrix_long_double_add (gsl_matrix_long_double * a, const gsl_matrix_long_double * b); GSL_FUN int gsl_matrix_long_double_sub (gsl_matrix_long_double * a, const gsl_matrix_long_double * b); GSL_FUN int gsl_matrix_long_double_mul_elements (gsl_matrix_long_double * a, const gsl_matrix_long_double * b); GSL_FUN int gsl_matrix_long_double_div_elements (gsl_matrix_long_double * a, const gsl_matrix_long_double * b); GSL_FUN int gsl_matrix_long_double_scale (gsl_matrix_long_double * a, const double x); GSL_FUN int gsl_matrix_long_double_add_constant (gsl_matrix_long_double * a, const double x); GSL_FUN int gsl_matrix_long_double_add_diagonal (gsl_matrix_long_double * a, const double x); /***********************************************************************/ /* The functions below are obsolete */ /***********************************************************************/ GSL_FUN int gsl_matrix_long_double_get_row(gsl_vector_long_double * v, const gsl_matrix_long_double * m, const size_t i); GSL_FUN int gsl_matrix_long_double_get_col(gsl_vector_long_double * v, const gsl_matrix_long_double * m, const size_t j); GSL_FUN int gsl_matrix_long_double_set_row(gsl_matrix_long_double * m, const size_t i, const gsl_vector_long_double * v); GSL_FUN int gsl_matrix_long_double_set_col(gsl_matrix_long_double * m, const size_t j, const gsl_vector_long_double * v); /***********************************************************************/ /* inline functions if you are using GCC */ GSL_FUN INLINE_DECL long double gsl_matrix_long_double_get(const gsl_matrix_long_double * m, const size_t i, const size_t j); GSL_FUN INLINE_DECL void gsl_matrix_long_double_set(gsl_matrix_long_double * m, const size_t i, const size_t j, const long double x); GSL_FUN INLINE_DECL long double * gsl_matrix_long_double_ptr(gsl_matrix_long_double * m, const size_t i, const size_t j); GSL_FUN INLINE_DECL const long double * gsl_matrix_long_double_const_ptr(const gsl_matrix_long_double * m, const size_t i, const size_t j); #ifdef HAVE_INLINE INLINE_FUN long double gsl_matrix_long_double_get(const gsl_matrix_long_double * m, const size_t i, const size_t j) { #if GSL_RANGE_CHECK if (GSL_RANGE_COND(1)) { if (i >= m->size1) { GSL_ERROR_VAL("first index out of range", GSL_EINVAL, 0) ; } else if (j >= m->size2) { GSL_ERROR_VAL("second index out of range", GSL_EINVAL, 0) ; } } #endif return m->data[i * m->tda + j] ; } INLINE_FUN void gsl_matrix_long_double_set(gsl_matrix_long_double * m, const size_t i, const size_t j, const long double x) { #if GSL_RANGE_CHECK if (GSL_RANGE_COND(1)) { if (i >= m->size1) { GSL_ERROR_VOID("first index out of range", GSL_EINVAL) ; } else if (j >= m->size2) { GSL_ERROR_VOID("second index out of range", GSL_EINVAL) ; } } #endif m->data[i * m->tda + j] = x ; } INLINE_FUN long double * gsl_matrix_long_double_ptr(gsl_matrix_long_double * m, const size_t i, const size_t j) { #if GSL_RANGE_CHECK if (GSL_RANGE_COND(1)) { if (i >= m->size1) { GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ; } else if (j >= m->size2) { GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ; } } #endif return (long double *) (m->data + (i * m->tda + j)) ; } INLINE_FUN const long double * gsl_matrix_long_double_const_ptr(const gsl_matrix_long_double * m, const size_t i, const size_t j) { #if GSL_RANGE_CHECK if (GSL_RANGE_COND(1)) { if (i >= m->size1) { GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ; } else if (j >= m->size2) { GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ; } } #endif return (const long double *) (m->data + (i * m->tda + j)) ; } #endif __END_DECLS #endif /* __GSL_MATRIX_LONG_DOUBLE_H__ */
{ "alphanum_fraction": 0.6762619372, "avg_line_length": 40.8356545961, "ext": "h", "hexsha": "1d06fe8b1e8a527538c884d15054b684ae236b21", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "099b66cb1285d19955e953f916ec6c12c68f2242", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "berkus/music-cs", "max_forks_repo_path": "deps/include/gsl/gsl_matrix_long_double.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "099b66cb1285d19955e953f916ec6c12c68f2242", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "berkus/music-cs", "max_issues_repo_path": "deps/include/gsl/gsl_matrix_long_double.h", "max_line_length": 145, "max_stars_count": null, "max_stars_repo_head_hexsha": "099b66cb1285d19955e953f916ec6c12c68f2242", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "berkus/music-cs", "max_stars_repo_path": "deps/include/gsl/gsl_matrix_long_double.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3395, "size": 14660 }
/* specfunc/test_hermite.c * * Copyright (C) 2011, 2012, 2013, 2014 Konrad Griessinger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <config.h> #include <gsl/gsl_math.h> #include <gsl/gsl_test.h> #include <gsl/gsl_sf.h> #include "test_sf.h" #define WKB_TOL (1.0e+04 * TEST_SQRT_TOL0) /* * Test the identities: * * Sum_{k=0}^n (n choose k) (2 y)^{n - k} H_k(x) = H_n(x + y) * * and * * Sum_{k=0}^n (n choose k) y^{n-k} He_k(x) = He_n(x + y) * * see: http://mathworld.wolfram.com/HermitePolynomial.html (Eq. 55) */ void test_hermite_id1(const int n, const double x, const double y) { double *a = malloc((n + 1) * sizeof(double)); double *b = malloc((n + 1) * sizeof(double)); double lhs, rhs; int k; a[0] = gsl_pow_int(2.0 * y, n); b[0] = gsl_pow_int(y, n); for (k = 1; k <= n; ++k) { double fac = (n - k + 1.0) / (k * y); a[k] = 0.5 * fac * a[k - 1]; b[k] = fac * b[k - 1]; } lhs = gsl_sf_hermite_series(n, x, a); rhs = gsl_sf_hermite(n, x + y); gsl_test_rel(lhs, rhs, TEST_TOL4, "identity1 phys n=%d x=%g y=%g", n, x, y); lhs = gsl_sf_hermite_prob_series(n, x, b); rhs = gsl_sf_hermite_prob(n, x + y); gsl_test_rel(lhs, rhs, TEST_TOL3, "identity1 prob n=%d x=%g y=%g", n, x, y); free(a); free(b); } int test_hermite(void) { gsl_sf_result r; int s = 0; int m, n, sa; double res[256]; double x; const double aizero1 = -2.3381074104597670384891972524467; /* first zero of the Airy function Ai */ /* test some known identities */ test_hermite_id1(10, 0.75, 0.33); test_hermite_id1(8, -0.75, 1.20); test_hermite_id1(7, 2.88, -3.2); TEST_SF(s, gsl_sf_hermite_prob_e, (0, 0.75, &r), 1., TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_prob_e, (1, 0.75, &r), 0.75, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_prob_e, (25, 0., &r), 0., TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_prob_e, (28, 0., &r), 2.13458046676875e14, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_prob_e, (30, 0., &r), -6.190283353629375e15, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_prob_e, (25, 0.75, &r), -1.08128685847680748265939328423e12, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_prob_e, (28, 0.75, &r), -1.60620252094658918105511125135e14, TEST_TOL0, GSL_SUCCESS); TEST_SF_RETURN(s, gsl_sf_hermite_prob_e, (2800, 0.75, &r), GSL_EOVRFLW); TEST_SF_RETURN(s, gsl_sf_hermite_prob_e, (2800, 1.75, &r), GSL_EOVRFLW); TEST_SF(s, gsl_sf_hermite_prob_deriv_e, (225, 128, 0.75, &r), 0., TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_prob_deriv_e, (5, 128, 0.75, &r), -3.0288278964712702882066404e112, TEST_TOL1, GSL_SUCCESS); x = 0.75; sa = 0; gsl_sf_hermite_prob_array(0, x, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_prob_array(0, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_array(1, x, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); TEST_SF_VAL(sa, res[1], +0.0, x, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_prob_array(1, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_array(100, x, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); TEST_SF_VAL(sa, res[1], +0.0, x, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 823.810509681701660156250, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 1.03749254986255755872498e78, TEST_TOL1); gsl_test(sa, "gsl_sf_hermite_prob_array(100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_array_deriv(0, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 823.810509681701660156250, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 1.03749254986255755872498e78, TEST_TOL1); gsl_test(sa, "gsl_sf_hermite_prob_array_deriv(0, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_array_deriv(1000, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 0.0, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_prob_array_deriv(1000, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_array_deriv(99, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[99], +0.0, 9.332621544394415268169923886e155, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 6.999466158295811451127442914e157, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_prob_array_deriv(99, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_array_deriv(100, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 9.332621544394415268169923886e157, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_prob_array_deriv(100, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_array_deriv(23, 100, 0.75, res); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[23], +0.0, 2.5852016738884976640000000000e22, TEST_TOL0); TEST_SF_VAL(sa, res[24], +0.0, 4.6533630129992957952000000000e23, TEST_TOL0); TEST_SF_VAL(sa, res[37], +0.0, 2.3592417210568968566591219172e37, TEST_TOL0); TEST_SF_VAL(sa, res[60], +0.0, -9.2573208827175536243052086845e59, TEST_TOL0); TEST_SF_VAL(sa, res[61], +0.0, 5.6259625429686219137261735305e59, TEST_TOL1); TEST_SF_VAL(sa, res[100], +0.0, 2.6503570965896336273549197e100, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_prob_array_deriv(23, 37, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_prob_deriv_array(100, 50, x, res); TEST_SF_VAL(sa, res[0], +0.0, -3.88338863813139372375411561e31, TEST_TOL0); TEST_SF_VAL(sa, res[1], +0.0, -4.04757862431646677625108652e32, TEST_TOL1); TEST_SF_VAL(sa, res[10], +0.0, 7.9614368698398116765703194e38, TEST_TOL0); TEST_SF_VAL(sa, res[30], +0.0, -9.1416928183915197188795338e54, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 0.0, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_prob_deriv_array(100, 50, 0.75)"); s += sa; n = 128; res[0] = 1.; for(m=1; m<=n; m++){ res[m] = res[m-1]/2.; } TEST_SF(s, gsl_sf_hermite_prob_series_e, (n, x, res, &r), -4.0451066556993485405907339548e68, TEST_TOL0, GSL_SUCCESS); /* phys */ x = 0.75; TEST_SF(s, gsl_sf_hermite_e, (0, 0.75, &r), 1.0, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_e, (1, 0.75, &r), 1.5, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_e, (25, 0., &r), 0., TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_e, (28, 0., &r), 3.497296636753920000e18, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_e, (30, 0., &r), -2.028432049317273600e20, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_e, (25, 0.75, &r), -9.7029819451106077507781088352e15, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_e, (28, 0.75, &r), 3.7538457078067672096408339776e18, TEST_TOL0, GSL_SUCCESS); TEST_SF_RETURN(s, gsl_sf_hermite_e, (2800, 0.75, &r), GSL_EOVRFLW); TEST_SF_RETURN(s, gsl_sf_hermite_e, (2800, 10.1, &r), GSL_EOVRFLW); TEST_SF(s, gsl_sf_hermite_deriv_e, (225, 128, 0.75, &r), 0., TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_deriv_e, (5, 128, 0.75, &r), 2.89461215568095657569833e132, TEST_TOL0, GSL_SUCCESS); x = 0.75; sa = 0; gsl_sf_hermite_array(0, x, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array(0, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_array(1, x, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); TEST_SF_VAL(sa, res[1], +0.0, 2.*x, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array(1, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_array(100, x, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); TEST_SF_VAL(sa, res[1], +0.0, 2.0*x, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 38740.4384765625, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, -1.4611185395125104593177790757e93, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array(100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_array_deriv(0, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 1.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 38740.4384765625, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, -1.4611185395125104593177790757e93, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array_deriv(0, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_array_deriv(1000, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 0.0, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array_deriv(1000, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_array_deriv(99, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[99], +0.0, 5.915251651227242890408570128e185, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 8.872877476840864335612855192e187, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array_deriv(99, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_array_deriv(100, 100, 0.75, res); TEST_SF_VAL(sa, res[0], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 1.183050330245448578081714026e188, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array_deriv(100, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_array_deriv(23, 100, 0.75, res); TEST_SF_VAL(sa, res[10], +0.0, 0.0, TEST_TOL0); TEST_SF_VAL(sa, res[23], +0.0, 2.168624344319444261221171200e29, TEST_TOL0); TEST_SF_VAL(sa, res[24], +0.0, 7.807047639549999340396216320e30, TEST_TOL0); TEST_SF_VAL(sa, res[37], +0.0, 1.930387357696033719818118732e46, TEST_TOL0); TEST_SF_VAL(sa, res[60], +0.0, 6.775378005383186748501182409e71, TEST_TOL0); TEST_SF_VAL(sa, res[61], +0.0, -4.451215867508936256056845902e73, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 2.957966000491202678467161e118, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_array_deriv(23, 100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_deriv_array(100, 50, x, res); TEST_SF_VAL(sa, res[0], +0.0, -8.26632218305863100726861832e38, TEST_TOL0); TEST_SF_VAL(sa, res[1], +0.0, 2.40954750392844799126151557e40, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 1.52281030265187793605875604e49, TEST_TOL0); TEST_SF_VAL(sa, res[30], +0.0, 9.52199419132990437892101915e65, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, 0.0, TEST_TOL0); gsl_test(sa, "gsl_sf_hermite_deriv_array(100, 50, 0.75)"); s += sa; n = 128; /* arbitrary weights */ res[0] = 1.; for(m=1; m<=n; m++){ res[m] = res[m-1]/2.; } TEST_SF(s, gsl_sf_hermite_series_e, (n, x, res, &r), 1.07772223811696567390619566842e88, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (0, 1.3, &r), 0.322651504564963746879400858624, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (0, 1.3, &r), 0.322651504564963746879400858624, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (1, 1.3, &r), 0.593187573778613235895531272243, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (1, 1.3, &r), 0.593187573778613235895531272243, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (1, -1.3, &r), -0.593187573778613235895531272243, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (1, -1.3, &r), -0.593187573778613235895531272243, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (27, 0, &r), 0.0, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (27, 0, &r), 0.0, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (28, 0, &r), 0.290371943657199641200016132937, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (28, 0, &r), 0.290371943657199641200016132937, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (28, 0.75, &r), 0.23526280808621240649319140441, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (28, 0.75, &r), 0.23526280808621240649319140441, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (200, 0.75, &r), -0.13725356483699291817038427801, TEST_TOL3, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (200, 0.75, &r), -0.13725356483699291817038427801, TEST_TOL3, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (100028, 0.75, &r), -0.02903467369856961147236598086, TEST_TOL4, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (100028, 0.75, &r), -0.02903467369856961147236598086, TEST_TOL5, GSL_SUCCESS); n = 10025; x = ((sqrt(2*n+1.)+aizero1/pow(8.*n,1/6.))/2.5); TEST_SF(s, gsl_sf_hermite_func_e, (n, x, &r), -0.05301278920004176459797680403, TEST_TOL4, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (n, x, &r), -0.05301278920004176459797680403, TEST_TOL4, GSL_SUCCESS); n = 10028; x = ((sqrt(2*n+1.)+aizero1/pow(8.*n,1/6.))/2.5); TEST_SF(s, gsl_sf_hermite_func_e, (n, x, &r), 0.06992968509693993526829596970, TEST_TOL3, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (n, x, &r), 0.06992968509693993526829596970, TEST_TOL3, GSL_SUCCESS); n = 10025; x = (sqrt(2*n+1.)-(aizero1/pow(8.*n,1/6.))/2.5); TEST_SF(s, gsl_sf_hermite_func_e, (n, x, &r), 0.08049000991742150521366671021, TEST_TOL4, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (n, x, &r), 0.08049000991742150521366671021, TEST_TOL4, GSL_SUCCESS); n = 10028; x = (sqrt(2*n+1.)-(aizero1/pow(8.*n,1/6.))/2.5); TEST_SF(s, gsl_sf_hermite_func_e, (n, x, &r), 0.08048800667512084252723933250, TEST_TOL4, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (n, x, &r), 0.08048800667512084252723933250, TEST_TOL4, GSL_SUCCESS); n = 10025; x = (sqrt(2*n+1.)-2.5*(aizero1/pow(8.*n,1/6.))); TEST_SF(s, gsl_sf_hermite_func_e, (n, x, &r), 7.97206830806663013555068100e-6, TEST_TOL4, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (n, x, &r), 7.97206830806663013555068100e-6, 1.0e-9, GSL_SUCCESS); n = 10028; x = (sqrt(2*n+1.)-2.5*(aizero1/pow(8.*n,1/6.))); TEST_SF(s, gsl_sf_hermite_func_e, (n, x, &r), 7.97188517397786729928465829e-6, TEST_TOL4, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (n, x, &r), 7.97188517397786729928465829e-6, 1.0e-8, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_e, (10000, 60.0, &r), 0.03162606955427450540143292572, TEST_TOL3, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_fast_e, (10000, 60.0, &r), 0.03162606955427450540143292572, TEST_TOL4, GSL_SUCCESS); x = 0.75; sa = 0; gsl_sf_hermite_func_array(100, x, res); TEST_SF_VAL(sa, res[0], +0.0, 0.566979307027693616978839335983, TEST_TOL0); TEST_SF_VAL(sa, res[1], +0.0, 0.601372369187597546203014795470, TEST_TOL0); TEST_SF_VAL(sa, res[10], +0.0, 0.360329854170806945032958735574, TEST_TOL0); TEST_SF_VAL(sa, res[100], +0.0, -0.07616422890563462489003733382, TEST_TOL1); gsl_test(sa, "gsl_sf_hermite_func_array(100, 0.75)"); s += sa; sa = 0; gsl_sf_hermite_func_array(250, 20.0, res); TEST_SF_VAL(sa, res[199], +0.0, 0.254621970261340422399150964119, TEST_TOL2); TEST_SF_VAL(sa, res[200], +0.0, 0.288364948026205642290411878357, TEST_TOL2); TEST_SF_VAL(sa, res[210], +0.0, 0.266625427572822255774117774166, TEST_TOL2); TEST_SF_VAL(sa, res[220], +0.0, -0.296028413764592652216845612832, TEST_TOL2); TEST_SF_VAL(sa, res[230], +0.0, 0.229657495510699141971182819560, TEST_TOL2); TEST_SF_VAL(sa, res[240], +0.0, -0.024027870622288819185159269632, TEST_TOL2); TEST_SF_VAL(sa, res[250], +0.0, -0.236101289420398152417654177998, TEST_TOL2); gsl_test(sa, "gsl_sf_hermite_func_array(250, 20.0)"); s += sa; n = 128; /* arbitrary weights */ res[0] = 1.; for(m=1; m<=n; m++){ res[m] = res[m-1]/2.; } TEST_SF(s, gsl_sf_hermite_func_series_e, (n, x, res, &r), 0.81717103529960997134154552556, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (0, 28, 0.75, &r), 0.235262808086212406493191404, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (1, 28, 0.75, &r), 1.289485094958329643927802330, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (2, 28, 0.75, &r), -13.27764473136561269145948989, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (3, 28, 0.75, &r), -72.42242083458141066943555691, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (4, 28, 0.75, &r), 753.6960554274941800190147503, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (5, 28, 0.75, &r), 4035.32788513029308540826835, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (0, 380, 0.75, &r), -0.0400554661321992411631174, TEST_TOL0, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (1, 380, 0.75, &r), -4.0417244263030600591206553, TEST_TOL1, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (2, 380, 0.75, &r), 30.4596785269042604519780923, TEST_TOL2, GSL_SUCCESS); TEST_SF(s, gsl_sf_hermite_func_der_e, (3, 380, 0.75, &r), 3073.4187352276349348458186556, TEST_TOL2, GSL_SUCCESS); { /* positive zeros of the probabilists' Hermite polynomial of order 17 */ double He17z[8] = { 0.751842600703896170737870774614, 1.50988330779674075905491513417, 2.28101944025298889535537879396, 3.07379717532819355851658337833, 3.90006571719800990903311840097, 4.77853158962998382710540812497, 5.74446007865940618125547815768,6.88912243989533223256205432938 }; n = 17; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_prob_zero_e, (n, m, &r), He17z[m-1], TEST_TOL0, GSL_SUCCESS); } } { /* positive zeros of the probabilists' Hermite polynomial of order 18 */ double He18z[9] = { 0.365245755507697595916901619097, 1.09839551809150122773848360538, 1.83977992150864548966395498992, 2.59583368891124032910545091458, 3.37473653577809099529779309480, 4.18802023162940370448450911428, 5.05407268544273984538327527397, 6.00774591135959752029303858752, 7.13946484914647887560975631213 }; n = 18; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_prob_zero_e, (n, m, &r), He18z[m-1], TEST_TOL0, GSL_SUCCESS); } } { /* positive zeros of the probabilists' Hermite polynomial of order 23 */ double He23z[11] = { 0.648471153534495816722576841197, 1.29987646830397886997876116860, 1.95732755293342410739100839243, 2.62432363405918177067330340783, 3.30504002175296456723204112903, 4.00477532173330406712238633738, 4.73072419745147329426707133987, 5.49347398647179412855289367747, 6.31034985444839982842886078177, 7.21465943505186138595859194492, 8.29338602741735258945596770157 }; n = 23; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_prob_zero_e, (n, m, &r), He23z[m-1], TEST_TOL0, GSL_SUCCESS); } } { /* positive zeros of the probabilists' Hermite polynomial of order 24 */ double He24z[12] = { 0.317370096629452319318170455994, 0.953421922932109084904629632351, 1.59348042981642010695074168129, 2.24046785169175236246653790858, 2.89772864322331368932008199475, 3.56930676407356024709649151613, 4.26038360501990548884317727406, 4.97804137463912033462166468006, 5.73274717525120114834341822330, 6.54167500509863444148277523364, 7.43789066602166310850331715501, 8.50780351919525720508386233432 }; n = 24; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_prob_zero_e, (n, m, &r), He24z[m-1], TEST_TOL0, GSL_SUCCESS); } } { /* positive zeros of the physicists' Hermite polynomial of order 17 */ double H17z[8] = { 0.531633001342654731349086553718, 1.06764872574345055363045773799, 1.61292431422123133311288254454, 2.17350282666662081927537907149, 2.75776291570388873092640349574, 3.37893209114149408338327069289, 4.06194667587547430689245559698, 4.87134519367440308834927655662 }; n = 17; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_zero_e, (n, m, &r), H17z[m-1], TEST_TOL0, GSL_SUCCESS); } } { /* positive zeros of the physicists' Hermite polynomial of order 18 */ double H18z[9] = { 0.258267750519096759258116098711, 0.776682919267411661316659462284, 1.30092085838961736566626555439, 1.83553160426162889225383944409, 2.38629908916668600026459301424, 2.96137750553160684477863254906, 3.57376906848626607950067599377, 4.24811787356812646302342016090, 5.04836400887446676837203757885 }; n = 18; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_zero_e, (n, m, &r), H18z[m-1], TEST_TOL0, GSL_SUCCESS); } } { /* positive zeros of the physicists' Hermite polynomial of order 23 */ double H23z[11] = { 0.458538350068104797757887329284, 0.919151465442563765431719239593, 1.38403958568249523732634717118, 1.85567703767137106251504753718, 2.33701621147445578644623502174, 2.83180378712615690144806140734, 3.34512715994122457247439814585, 3.88447270810610186607248760288, 4.46209117374000667673186157071, 5.10153461047667712968749766165, 5.86430949898457256538748413474 }; n = 23; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_zero_e, (n, m, &r), H23z[m-1], TEST_TOL0, GSL_SUCCESS); } } { /* positive zeros of the physicists' Hermite polynomial of order 24 */ double H24z[12] = { 0.224414547472515585151136715527, 0.674171107037212236000245923730, 1.12676081761124507213306126773, 1.58425001096169414850563336202, 2.04900357366169891178708399532, 2.52388101701142697419907602333, 3.01254613756556482565453858421, 3.52000681303452471128987227609, 4.05366440244814950394766297923, 4.62566275642378726504864923776, 5.25938292766804436743072304398, 6.01592556142573971734857350899 }; n = 24; for (m=1; m<=n/2; m++) { TEST_SF(s, gsl_sf_hermite_zero_e, (n, m, &r), H24z[m-1], TEST_TOL0, GSL_SUCCESS); } } n = 2121; x = -1.*n; res[0] = (double) n; sa = 0; for (m=1; m<=n/2; m++) { gsl_sf_hermite_prob_zero_e(n, m, &r); if (x>=r.val) { sa += TEST_SF_INCONS; printf("sanity check failed! (gsl_sf_hermite_prob_zero)\n"); } res[0] = GSL_MIN(res[0],fabs(x-r.val)); x = r.val; } gsl_test(sa, "gsl_sf_hermite_prob_zero(n, m, r)"); n = 2121; x = -1.*n; res[0] = (double) n; sa = 0; for (m=1; m<=n/2; m++) { gsl_sf_hermite_zero_e(n, m, &r); if (x>=r.val) { sa += TEST_SF_INCONS; printf("sanity check failed! (gsl_sf_hermite_zero)\n"); } res[0] = GSL_MIN(res[0],fabs(x-r.val)); x = r.val; } gsl_test(sa, "gsl_sf_hermite_zero(n, m, r)"); return s; }
{ "alphanum_fraction": 0.6816164349, "avg_line_length": 45.3199233716, "ext": "c", "hexsha": "55e00ba12e32ed1f1b660f7867a39666c7016934", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z", "max_forks_repo_head_hexsha": "83fd1fc4cbd053a4f9b673d5cd5841823ddd4d8b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "karanbirsandhu/nu-sense", "max_forks_repo_path": "test/lib/gsl-2.6/specfunc/test_hermite.c", "max_issues_count": 6, "max_issues_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a", "max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z", "max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ielomariala/Hex-Game", "max_issues_repo_path": "gsl-2.6/specfunc/test_hermite.c", "max_line_length": 125, "max_stars_count": 1, "max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ielomariala/Hex-Game", "max_stars_repo_path": "gsl-2.6/specfunc/test_hermite.c", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z", "num_tokens": 9839, "size": 23657 }
/* * mutation.h * * Created on: 17.5.2017 * Author: heine */ #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> #ifndef MUTATION_H_ #define MUTATION_H_ //void set_mutationseed( int id ); void mutation( long N, double *x, int state_dim, gsl_rng * rgen ); #endif /* MUTATION_H_ */
{ "alphanum_fraction": 0.640776699, "avg_line_length": 14.0454545455, "ext": "h", "hexsha": "c42a45aeafab25b111e10a49634fef30854cf6a2", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2b7d74519289d2dac684b483a85ec2696e694c27", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heinekmp/AIRPF", "max_forks_repo_path": "include/mutation.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "2b7d74519289d2dac684b483a85ec2696e694c27", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "heinekmp/AIRPF", "max_issues_repo_path": "include/mutation.h", "max_line_length": 34, "max_stars_count": 1, "max_stars_repo_head_hexsha": "2b7d74519289d2dac684b483a85ec2696e694c27", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heinekmp/AIRPF", "max_stars_repo_path": "include/mutation.h", "max_stars_repo_stars_event_max_datetime": "2020-05-21T06:38:23.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T06:38:23.000Z", "num_tokens": 102, "size": 309 }
/** * * @generated s Tue Jan 7 11:45:26 2014 * **/ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cblas.h> #include <lapacke.h> #include <plasma.h> #include <core_blas.h> #include "auxiliary.h" /*------------------------------------------------------------------- * Check the orthogonality of Q */ int s_check_orthogonality(int M, int N, int LDQ, float *Q) { float alpha, beta; float normQ; int info_ortho; int i; int minMN = min(M, N); float eps; float *work = (float *)malloc(minMN*sizeof(float)); eps = LAPACKE_slamch_work('e'); alpha = 1.0; beta = -1.0; /* Build the idendity matrix USE DLASET?*/ float *Id = (float *) malloc(minMN*minMN*sizeof(float)); memset((void*)Id, 0, minMN*minMN*sizeof(float)); for (i = 0; i < minMN; i++) Id[i*minMN+i] = (float)1.0; /* Perform Id - Q'Q */ if (M >= N) cblas_ssyrk(CblasColMajor, CblasUpper, CblasTrans, N, M, alpha, Q, LDQ, beta, Id, N); else cblas_ssyrk(CblasColMajor, CblasUpper, CblasNoTrans, M, N, alpha, Q, LDQ, beta, Id, M); normQ = LAPACKE_slansy_work(LAPACK_COL_MAJOR, 'i', 'u', minMN, Id, minMN, work); printf("============\n"); printf("Checking the orthogonality of Q \n"); printf("||Id-Q'*Q||_oo / (N*eps) = %e \n",normQ/(minMN*eps)); if ( isnan(normQ / (minMN * eps)) || (normQ / (minMN * eps) > 10.0) ) { printf("-- Orthogonality is suspicious ! \n"); info_ortho=1; } else { printf("-- Orthogonality is CORRECT ! \n"); info_ortho=0; } free(work); free(Id); return info_ortho; } /*------------------------------------------------------------ * Check the factorization QR */ int s_check_QRfactorization(int M, int N, float *A1, float *A2, int LDA, float *Q) { float Anorm, Rnorm; float alpha, beta; int info_factorization; int i,j; float eps; eps = LAPACKE_slamch_work('e'); float *Ql = (float *)malloc(M*N*sizeof(float)); float *Residual = (float *)malloc(M*N*sizeof(float)); float *work = (float *)malloc(max(M,N)*sizeof(float)); alpha=1.0; beta=0.0; if (M >= N) { /* Extract the R */ float *R = (float *)malloc(N*N*sizeof(float)); memset((void*)R, 0, N*N*sizeof(float)); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'u', M, N, A2, LDA, R, N); /* Perform Ql=Q*R */ memset((void*)Ql, 0, M*N*sizeof(float)); cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, N, (alpha), Q, LDA, R, N, (beta), Ql, M); free(R); } else { /* Extract the L */ float *L = (float *)malloc(M*M*sizeof(float)); memset((void*)L, 0, M*M*sizeof(float)); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'l', M, N, A2, LDA, L, M); /* Perform Ql=LQ */ memset((void*)Ql, 0, M*N*sizeof(float)); cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, M, (alpha), L, M, Q, LDA, (beta), Ql, M); free(L); } /* Compute the Residual */ for (i = 0; i < M; i++) for (j = 0 ; j < N; j++) Residual[j*M+i] = A1[j*LDA+i]-Ql[j*M+i]; Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Residual, M, work); Anorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, A2, LDA, work); if (M >= N) { printf("============\n"); printf("Checking the QR Factorization \n"); printf("-- ||A-QR||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); } else { printf("============\n"); printf("Checking the LQ Factorization \n"); printf("-- ||A-LQ||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); } if (isnan(Rnorm / (Anorm * N *eps)) || (Rnorm / (Anorm * N * eps) > 10.0) ) { printf("-- Factorization is suspicious ! \n"); info_factorization = 1; } else { printf("-- Factorization is CORRECT ! \n"); info_factorization = 0; } free(work); free(Ql); free(Residual); return info_factorization; } /*------------------------------------------------------------------------ * Check the factorization of the matrix A2 */ int s_check_LLTfactorization(int N, float *A1, float *A2, int LDA, int uplo) { float Anorm, Rnorm; float alpha; int info_factorization; int i,j; float eps; eps = LAPACKE_slamch_work('e'); float *Residual = (float *)malloc(N*N*sizeof(float)); float *L1 = (float *)malloc(N*N*sizeof(float)); float *L2 = (float *)malloc(N*N*sizeof(float)); float *work = (float *)malloc(N*sizeof(float)); memset((void*)L1, 0, N*N*sizeof(float)); memset((void*)L2, 0, N*N*sizeof(float)); alpha= 1.0; LAPACKE_slacpy_work(LAPACK_COL_MAJOR,' ', N, N, A1, LDA, Residual, N); /* Dealing with L'L or U'U */ if (uplo == PlasmaUpper){ LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'u', N, N, A2, LDA, L1, N); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'u', N, N, A2, LDA, L2, N); cblas_strmm(CblasColMajor, CblasLeft, CblasUpper, CblasTrans, CblasNonUnit, N, N, (alpha), L1, N, L2, N); } else{ LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'l', N, N, A2, LDA, L1, N); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'l', N, N, A2, LDA, L2, N); cblas_strmm(CblasColMajor, CblasRight, CblasLower, CblasTrans, CblasNonUnit, N, N, (alpha), L1, N, L2, N); } /* Compute the Residual || A -L'L|| */ for (i = 0; i < N; i++) for (j = 0; j < N; j++) Residual[j*N+i] = L2[j*N+i] - Residual[j*N+i]; Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, N, Residual, N, work); Anorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, N, A1, LDA, work); printf("============\n"); printf("Checking the Cholesky Factorization \n"); printf("-- ||L'L-A||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); if ( isnan(Rnorm/(Anorm*N*eps)) || (Rnorm/(Anorm*N*eps) > 10.0) ){ printf("-- Factorization is suspicious ! \n"); info_factorization = 1; } else{ printf("-- Factorization is CORRECT ! \n"); info_factorization = 0; } free(Residual); free(L1); free(L2); free(work); return info_factorization; } /*-------------------------------------------------------------- * Check the gemm */ float s_check_gemm(PLASMA_enum transA, PLASMA_enum transB, int M, int N, int K, float alpha, float *A, int LDA, float *B, int LDB, float beta, float *Cplasma, float *Cref, int LDC, float *Cinitnorm, float *Cplasmanorm, float *Clapacknorm ) { float beta_const = -1.0; float Rnorm; float *work = (float *)malloc(max(K,max(M, N))* sizeof(float)); *Cinitnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work); *Cplasmanorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cplasma, LDC, work); cblas_sgemm(CblasColMajor, (CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB, M, N, K, (alpha), A, LDA, B, LDB, (beta), Cref, LDC); *Clapacknorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work); cblas_saxpy(LDC * N, (beta_const), Cplasma, 1, Cref, 1); Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work); free(work); return Rnorm; } /*-------------------------------------------------------------- * Check the trsm */ float s_check_trsm(PLASMA_enum side, PLASMA_enum uplo, PLASMA_enum trans, PLASMA_enum diag, int M, int NRHS, float alpha, float *A, int LDA, float *Bplasma, float *Bref, int LDB, float *Binitnorm, float *Bplasmanorm, float *Blapacknorm ) { float beta_const = -1.0; float Rnorm; float *work = (float *)malloc(max(M, NRHS)* sizeof(float)); /*float eps = LAPACKE_slamch_work('e');*/ *Binitnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, NRHS, Bref, LDB, work); *Bplasmanorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bplasma, LDB, work); cblas_strsm(CblasColMajor, (CBLAS_SIDE)side, (CBLAS_UPLO)uplo, (CBLAS_TRANSPOSE)trans, (CBLAS_DIAG)diag, M, NRHS, (alpha), A, LDA, Bref, LDB); *Blapacknorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bref, LDB, work); cblas_saxpy(LDB * NRHS, (beta_const), Bplasma, 1, Bref, 1); Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bref, LDB, work); Rnorm = Rnorm / *Blapacknorm; /* max(M,NRHS) * eps);*/ free(work); return Rnorm; } /*-------------------------------------------------------------- * Check the solution */ float s_check_solution(int M, int N, int NRHS, float *A, int LDA, float *B, float *X, int LDB, float *anorm, float *bnorm, float *xnorm ) { /* int info_solution; */ float Rnorm = -1.00; float zone = 1.0; float mzone = -1.0; float *work = (float *)malloc(max(M, N)* sizeof(float)); *anorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, A, LDA, work); *xnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, NRHS, X, LDB, work); *bnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, NRHS, B, LDB, work); cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, NRHS, N, (zone), A, LDA, X, LDB, (mzone), B, LDB); Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, NRHS, B, LDB, work); free(work); return Rnorm; }
{ "alphanum_fraction": 0.5517528347, "avg_line_length": 32.2583892617, "ext": "c", "hexsha": "b5a211584cfd2e3fdfa80ecab9f766d5fe3a1f10", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "zhuangsc/Plasma-ompss1", "max_forks_repo_path": "timing/sauxiliary.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "zhuangsc/Plasma-ompss1", "max_issues_repo_path": "timing/sauxiliary.c", "max_line_length": 114, "max_stars_count": null, "max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "zhuangsc/Plasma-ompss1", "max_stars_repo_path": "timing/sauxiliary.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3150, "size": 9613 }
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #pragma once #include "Utils\buffer.h" #include "MageSettings.h" // for CameraIdentity #include "ORBDescriptor.h" #include "Memory\allocators.h" #include "arcana\utils\serialization\serializable.h" #include <opencv2\core\core.hpp> #include <stdint.h> #include <atomic> #include <gsl\span> namespace mage { using ImageAllocator = memory::std_allocator<void*, block_splitting_allocation_strategy>; template<typename AllocT> struct ImageData : mira::serializable<ImageData<AllocT>> { ImageData(CameraIdentity cameraIdentity, size_t maxFeatures, float pyramidScale, size_t numLevels, float imageBorder, const AllocT& allocator) : m_cameraIdentity{ cameraIdentity }, m_featureCount{ 0 }, m_pyramidScale { pyramidScale }, m_numLevels { numLevels }, m_imageBorder { imageBorder }, m_published{ false }, m_maxFeatures{ maxFeatures }, m_keypointBuffer{ maxFeatures, allocator }, m_descriptorBuffer{ maxFeatures, allocator } {} template<typename StreamT, typename = mira::is_stream_t<StreamT>> ImageData(CameraIdentity cameraIdentity, size_t maxFeatures, float pyramidScale, size_t numLevels, float imageBorder, const AllocT& allocator, StreamT& stream) : ImageData{ cameraIdentity, imageWidth, imageHeight, maxFeatures, pyramidScale, allocator } { deserialize(stream); } static constexpr auto members() { return declare_members( &ImageData::m_cameraIdentity, &ImageData::m_featureCount, &ImageData::m_pyramidScale, &ImageData::m_numLevels, &ImageData::m_imageBorder, &ImageData::m_published, &ImageData::m_maxFeatures, &ImageData::m_keypointBuffer, &ImageData::m_descriptorBuffer ); } /* Inserts the keypoints into the image data, and returns how many items it copied. Because we only support a fixed size, we only copy items if we have space. */ size_t Insert(gsl::span<const cv::KeyPoint> keypoints) { auto toCopy = std::min<int>(gsl::narrow_cast<int>(keypoints.size()), gsl::narrow_cast<int>(m_maxFeatures - m_featureCount)); m_featureCount += m_keypointBuffer.copy(keypoints.data(), keypoints.data() + toCopy, m_featureCount); return toCopy; } size_t Insert(const cv::KeyPoint& kp) { if (m_featureCount == m_maxFeatures) return 0; m_keypointBuffer[m_featureCount] = kp; m_featureCount++; return 1; } size_t Insert(const cv::KeyPoint* beg, const cv::KeyPoint* end) { auto toCopy = std::min<int>(gsl::narrow_cast<int>(end - beg), gsl::narrow_cast<int>(m_maxFeatures - m_featureCount)); m_featureCount += m_keypointBuffer.copy(beg, beg + toCopy, m_featureCount); return toCopy; } size_t GetMaxFeatures() const { return m_maxFeatures; } size_t GetFeatureCount() const { return m_featureCount; } float GetPyramidScale() const { return m_pyramidScale; } size_t GetNumLevels() const { return m_numLevels; } float GetImageBorder() const { return m_imageBorder; } CameraIdentity GetCameraIdentity() const { return m_cameraIdentity; } const cv::KeyPoint& GetKeypoint(size_t idx) const { return const_cast<ImageData*>(this)->GetKeypoint(idx); } cv::KeyPoint& GetKeypoint(size_t idx) { assert(0 <= idx && idx < m_featureCount); return m_keypointBuffer[idx]; } gsl::span<const cv::KeyPoint> GetKeypoints() const { return { m_keypointBuffer.begin(), m_keypointBuffer.begin() + m_featureCount }; } gsl::span<cv::KeyPoint> GetKeypoints() { return { m_keypointBuffer.begin(), m_keypointBuffer.begin() + m_featureCount }; } const ORBDescriptor& GetDescriptor(size_t idx) const { return const_cast<ImageData*>(this)->GetDescriptor(idx); } ORBDescriptor& GetDescriptor(size_t idx) { assert(0 <= idx && idx < m_featureCount); return m_descriptorBuffer[idx]; } gsl::span<const ORBDescriptor> GetDescriptors() const { return const_cast<ImageData*>(this)->GetDescriptors(); } gsl::span<ORBDescriptor> GetDescriptors() { return { m_descriptorBuffer.begin(), m_descriptorBuffer.begin() + m_featureCount }; } void SetDescriptors(gsl::span<const ORBDescriptor> values) { assert(m_featureCount == values.size()); m_descriptorBuffer.copy(values.begin(), values.end()); } void ZeroOutDescriptors() { m_descriptorBuffer.fill(0); } /* Returns whether or not this image was ever published to the map */ bool IsPublished() const { return m_published; } void MarkAsPublished() const { m_published = true; } template<typename DerivedT> static size_t AllocationSizeInBytes(size_t maxFeatures) { return sizeof(DerivedT) + maxFeatures * sizeof(cv::KeyPoint) + maxFeatures * sizeof(ORBDescriptor); } private: template<typename T> using rebind_allocator = typename std::allocator_traits<AllocT>::template rebind_alloc<T>; size_t m_featureCount{}; mutable std::atomic<bool> m_published{ false }; const size_t m_maxFeatures{}; const float m_pyramidScale{}; const size_t m_numLevels{}; //TODO: change numlevels to be reasonable with image resolution const float m_imageBorder{}; const CameraIdentity m_cameraIdentity{}; buffer<cv::KeyPoint, rebind_allocator<cv::KeyPoint>> m_keypointBuffer{}; buffer<ORBDescriptor, rebind_allocator<ORBDescriptor>> m_descriptorBuffer{}; }; }
{ "alphanum_fraction": 0.5925531915, "avg_line_length": 31.6346153846, "ext": "h", "hexsha": "6f171ba6c36d32f92a780cdfee56289fd2798045", "lang": "C", "max_forks_count": 16, "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:36:49.000Z", "max_forks_repo_forks_event_min_datetime": "2020-05-07T03:09:13.000Z", "max_forks_repo_head_hexsha": "ba79a4e6315689c072c29749de18d70279a4c5e4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "syntheticmagus/mageslam", "max_forks_repo_path": "Core/MAGESLAM/Source/Image/ImageData.h", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ba79a4e6315689c072c29749de18d70279a4c5e4", "max_issues_repo_issues_event_max_datetime": "2020-10-08T07:43:32.000Z", "max_issues_repo_issues_event_min_datetime": "2020-06-01T00:34:01.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "syntheticmagus/mageslam", "max_issues_repo_path": "Core/MAGESLAM/Source/Image/ImageData.h", "max_line_length": 167, "max_stars_count": 70, "max_stars_repo_head_hexsha": "ba79a4e6315689c072c29749de18d70279a4c5e4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "syntheticmagus/mageslam", "max_stars_repo_path": "Core/MAGESLAM/Source/Image/ImageData.h", "max_stars_repo_stars_event_max_datetime": "2022-02-11T01:04:54.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:09:09.000Z", "num_tokens": 1389, "size": 6580 }
#include <stdio.h> #include <stdlib.h> #include <gsl/gsl_math.h> #include <gsl/gsl_filter.h> #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> #include <gsl/gsl_vector.h> int main(void) { const size_t N = 500; /* length of time series */ const size_t K = 51; /* window size */ const double alpha[3] = { 0.5, 3.0, 10.0 }; /* alpha values */ gsl_vector *x = gsl_vector_alloc(N); /* input vector */ gsl_vector *y1 = gsl_vector_alloc(N); /* filtered output vector for alpha1 */ gsl_vector *y2 = gsl_vector_alloc(N); /* filtered output vector for alpha2 */ gsl_vector *y3 = gsl_vector_alloc(N); /* filtered output vector for alpha3 */ gsl_vector *k1 = gsl_vector_alloc(K); /* Gaussian kernel for alpha1 */ gsl_vector *k2 = gsl_vector_alloc(K); /* Gaussian kernel for alpha2 */ gsl_vector *k3 = gsl_vector_alloc(K); /* Gaussian kernel for alpha3 */ gsl_rng *r = gsl_rng_alloc(gsl_rng_default); gsl_filter_gaussian_workspace *gauss_p = gsl_filter_gaussian_alloc(K); size_t i; double sum = 0.0; /* generate input signal */ for (i = 0; i < N; ++i) { double ui = gsl_ran_gaussian(r, 1.0); sum += ui; gsl_vector_set(x, i, sum); } /* compute kernels without normalization */ gsl_filter_gaussian_kernel(alpha[0], 0, 0, k1); gsl_filter_gaussian_kernel(alpha[1], 0, 0, k2); gsl_filter_gaussian_kernel(alpha[2], 0, 0, k3); /* apply filters */ gsl_filter_gaussian(GSL_FILTER_END_PADVALUE, alpha[0], 0, x, y1, gauss_p); gsl_filter_gaussian(GSL_FILTER_END_PADVALUE, alpha[1], 0, x, y2, gauss_p); gsl_filter_gaussian(GSL_FILTER_END_PADVALUE, alpha[2], 0, x, y3, gauss_p); /* print kernels */ for (i = 0; i < K; ++i) { double k1i = gsl_vector_get(k1, i); double k2i = gsl_vector_get(k2, i); double k3i = gsl_vector_get(k3, i); printf("%e %e %e\n", k1i, k2i, k3i); } printf("\n\n"); /* print filter results */ for (i = 0; i < N; ++i) { double xi = gsl_vector_get(x, i); double y1i = gsl_vector_get(y1, i); double y2i = gsl_vector_get(y2, i); double y3i = gsl_vector_get(y3, i); printf("%.12e %.12e %.12e %.12e\n", xi, y1i, y2i, y3i); } gsl_vector_free(x); gsl_vector_free(y1); gsl_vector_free(y2); gsl_vector_free(y3); gsl_vector_free(k1); gsl_vector_free(k2); gsl_vector_free(k3); gsl_rng_free(r); gsl_filter_gaussian_free(gauss_p); return 0; }
{ "alphanum_fraction": 0.6277866242, "avg_line_length": 31.012345679, "ext": "c", "hexsha": "a4a1a28c257a93a313f574a91b544fdfcd26b1ac", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z", "max_forks_repo_head_hexsha": "83fd1fc4cbd053a4f9b673d5cd5841823ddd4d8b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "karanbirsandhu/nu-sense", "max_forks_repo_path": "test/lib/gsl-2.6/doc/examples/gaussfilt.c", "max_issues_count": 6, "max_issues_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a", "max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z", "max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ielomariala/Hex-Game", "max_issues_repo_path": "gsl-2.6/doc/examples/gaussfilt.c", "max_line_length": 86, "max_stars_count": 1, "max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ielomariala/Hex-Game", "max_stars_repo_path": "gsl-2.6/doc/examples/gaussfilt.c", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z", "num_tokens": 784, "size": 2512 }
#ifndef __COYOTE_H #define __COYOTE_H #include <stdio.h> #include <math.h> #include <stdlib.h> #include <gsl/gsl_integration.h> #include <gsl/gsl_odeiv.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_linalg.h> #include <gsl/gsl_spline.h> #include <gsl/gsl_errno.h> #include "errorlist.h" #include "maths.h" /* Error codes */ #define coyote_base -2200 #define coyote_h -1 + coyote_base #define coyote_flat -2 + coyote_base #define coyote_range -3 + coyote_base /* =============================================== * * From other header files which have been removed * * Constants which are used also outside of Coyote * * (e.g. in cosmo.c) * * =============================================== */ /* Coyote I */ /* Number of k values */ #define nsim 1995 const double ksim[nsim]; /* Coyote II */ #define fr_nsim 582 #define fr_rs 11 const double fr_ksim[fr_nsim]; /* v1: Functions from hubble.c and emu.c */ double getH0fromCMB(double omega_m, double omega_b, double w0_de, int physical); void fill_xstar_wo_z(double omega_m, double omega_b, double n_spec, double sigma_8, double w0_de, double xstar[]); double P_NL_coyote5(double omega_m, double omega_b, double n_spec, double sigma_8, double w0_de, double h_100, double a, double k, error **err); void emu(double *xstar, double *ystar, error **err); /* v2: Functions from fr_emu.c */ double P_NL_coyote6(double omega_m, double omega_b, double n_spec, double sigma_8, double w0_de, double h_100, double a, double k, double **ystar_allz, error **err); void fr_check_range(const double *xstar, error **err); void fr_fill_ystar_allz(double *ystar_allz, const double *xstar, error **err); void fr_emu(const double *xstar, double *ystar, const double *ystar_allz, error **err); void fill_xstar6_wo_z(double omega_m, double omega_b, double n_spec, double sigma_8, double w0_de, double h_100, double xstar[]); #endif
{ "alphanum_fraction": 0.6811145511, "avg_line_length": 28.9253731343, "ext": "h", "hexsha": "6ff6c2427668f0923cf60dbc1dbd93be0e6fec2b", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "722db5bab850bccba3c7c003e0416cefa6d94c62", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "danielgruen/ccv", "max_forks_repo_path": "src/nicaea_2.5/Coyote/include/coyote.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "722db5bab850bccba3c7c003e0416cefa6d94c62", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "danielgruen/ccv", "max_issues_repo_path": "src/nicaea_2.5/Coyote/include/coyote.h", "max_line_length": 114, "max_stars_count": 2, "max_stars_repo_head_hexsha": "722db5bab850bccba3c7c003e0416cefa6d94c62", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "danielgruen/ccv", "max_stars_repo_path": "src/nicaea_2.5/Coyote/include/coyote.h", "max_stars_repo_stars_event_max_datetime": "2021-01-08T03:19:03.000Z", "max_stars_repo_stars_event_min_datetime": "2017-08-11T20:38:17.000Z", "num_tokens": 550, "size": 1938 }
#ifndef ORIENTATION_CONTROLLER_VARIABLE_GAINS_H_ #define ORIENTATION_CONTROLLER_VARIABLE_GAINS_H_ #include <cmath> #include <barrett/units.h> #include <barrett/systems.h> #include <barrett/products/product_manager.h> #include <libconfig.h++> #include <barrett/detail/ca_macro.h> #include <barrett/cdlbt/calgrav.h> #include <barrett/systems/abstract/system.h> #include <barrett/systems/abstract/single_io.h> #include <barrett/systems/kinematics_base.h> #include <barrett/math/kinematics.h> #include <stdio.h> #include <iostream> #include <string> #include <cstdlib> // For std::atexit() #include <barrett/os.h> // For btsleep() #include <barrett/math.h> // For barrett::math::saturate() #include <Eigen/Dense> #include <Eigen/Core> #include <barrett/standard_main_function.h> #include <gsl/gsl_math.h> #include <gsl/gsl_blas.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_linalg.h> #define BARRETT_SMF_VALIDATE_ARGS #include <barrett/standard_main_function.h> using namespace barrett; using namespace systems; using systems::connect; BARRETT_UNITS_FIXED_SIZE_TYPEDEFS; template<size_t DOF> class OrientationControllerVariableGains : public systems::System , public KinematicsInput<DOF> { BARRETT_UNITS_TEMPLATE_TYPEDEFS(DOF); public: Input<Eigen::Quaterniond> ReferenceOrnInput; Input<Eigen::Quaterniond> FeedbackOrnInput; Input<cp_type> KpGains; Input<cp_type> KdGains; public: Output<ct_type> CTOutput; protected: typename Output<ct_type>::Value* ctOutputValue; public: OrientationControllerVariableGains( // const units::CartesianPosition::type& ProportionalGains, // const units::CartesianPosition::type& DerivativeGains, const std::string& sysName = "OrientationControllerVariableGains") : System(sysName), KinematicsInput<DOF>(this), ReferenceOrnInput(this), FeedbackOrnInput(this), KpGains(this) , KdGains(this), CTOutput(this, &ctOutputValue) // , ProportionalGains(ProportionalGains), DerivativeGains(DerivativeGains) { } virtual ~OrientationControllerVariableGains() { this->mandatoryCleanUp(); } protected: cp_type ProportionalGains; cp_type DerivativeGains; Eigen::AngleAxisd error; ct_type ct; cp_type tempVect; cp_type tempVect2; cp_type errorVect; virtual void operate() { ProportionalGains = KpGains.getValue(); DerivativeGains = KdGains.getValue(); // error = this->referenceInput.getValue() * this->feedbackInput.getValue().inverse(); // I think it should be this way error = this->FeedbackOrnInput.getValue() * this->ReferenceOrnInput.getValue().inverse(); // but CD's math (that works, BTW) does it this way double angle = error.angle(); // TODO(dc): I looked into Eigen's implementation and noticed that angle will always be between 0 and 2*pi. We should test for this so if Eigen changes, we notice. if (angle > M_PI) { angle -= 2.0*M_PI; } if (math::abs(angle) > 3.13) { // a little dead-zone near the discontinuity at +/-180 degrees ct.setZero(); } else { tempVect = ProportionalGains ; // copy the ProportiocalGains errorVect = error.axis() * angle ; gsl_vector_mul (tempVect.asGslType() , errorVect.asGslType() ) ; // tempVect <- tempVect * errorVect ct = this->ReferenceOrnInput.getValue().inverse() * ( tempVect ); } tempVect2 = DerivativeGains; gsl_vector_mul ( tempVect2.asGslType() , this->kinInput.getValue().impl->tool_velocity_angular ) ; ct -= tempVect2 ; // ct -= DerivativeGains.dot( this->kinInput.getValue().impl->tool_velocity_angular ) ; // gsl_blas_daxpy( -kd, this->kinInput.getValue().impl->tool_velocity_angular, ct.asGslType()); this->ctOutputValue->setData(&ct); } private: DISALLOW_COPY_AND_ASSIGN(OrientationControllerVariableGains); public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; #endif /*ORIENTATION_CONTROLLER_VARIABLE_GAINS_H_*/
{ "alphanum_fraction": 0.7488986784, "avg_line_length": 30.3858267717, "ext": "h", "hexsha": "8aceb300bb00fb8e935f77f546378bebdf3e42f0", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bcb5cd806ce7c796cfff27f267974c988c5f77ad", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ualberta-robotics/wam_bringup", "max_forks_repo_path": "include/wam_bringup/orientation_controller_variable_gains.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "bcb5cd806ce7c796cfff27f267974c988c5f77ad", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ualberta-robotics/wam_bringup", "max_issues_repo_path": "include/wam_bringup/orientation_controller_variable_gains.h", "max_line_length": 165, "max_stars_count": 1, "max_stars_repo_head_hexsha": "bcb5cd806ce7c796cfff27f267974c988c5f77ad", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ualberta-robotics/wam_bringup", "max_stars_repo_path": "include/wam_bringup/orientation_controller_variable_gains.h", "max_stars_repo_stars_event_max_datetime": "2021-03-13T02:12:58.000Z", "max_stars_repo_stars_event_min_datetime": "2021-03-13T02:12:58.000Z", "num_tokens": 1049, "size": 3859 }
/*Python wrapper module for parameter space sampling; the method used is the same as in http://dan.iel.fm/posts/python-c-extensions/ The module is called _design and it defines the methods below (see docstrings) */ #include <gsl/gsl_matrix.h> #include <Python.h> #include <numpy/arrayobject.h> #include "lenstoolsPy3.h" #include "design.h" #ifndef IS_PY3K static struct module_state _state; #endif //Python module docstrings static char module_docstring[] = "This module provides a python interface for sampling a N-dimensional parameter space"; static char diagonalCost_docstring[] = "Compute the cost function for a diagonal design"; static char cost_docstring[] = "Compute the cost function for a given"; static char sample_docstring[] = "Sample the N-dimensional parameter space and record cost function changes"; //Method declarations static PyObject *_design_diagonalCost(PyObject *self,PyObject *args); static PyObject *_design_cost(PyObject *self,PyObject *args); static PyObject *_design_sample(PyObject *self,PyObject *args); //_design method definitions static PyMethodDef module_methods[] = { {"diagonalCost",_design_diagonalCost,METH_VARARGS,diagonalCost_docstring}, {"cost",_design_cost,METH_VARARGS,cost_docstring}, {"sample",_design_sample,METH_VARARGS,sample_docstring}, {NULL,NULL,0,NULL} } ; //_design constructor #ifdef IS_PY3K static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "_design", module_docstring, sizeof(struct module_state), module_methods, NULL, myextension_trasverse, myextension_clear, NULL }; #define INITERROR return NULL PyMODINIT_FUNC PyInit__design(void) #else #define INITERROR return void init_design(void) #endif { #ifdef IS_PY3K PyObject *m = PyModule_Create(&moduledef); #else PyObject *m = Py_InitModule3("_design",module_methods,module_docstring); #endif if(m==NULL) INITERROR; struct module_state *st = GETSTATE(m); st->error = PyErr_NewException("_design.Error", NULL, NULL); if (st->error == NULL) { Py_DECREF(m); INITERROR; } /*Load numpy functionality*/ import_array(); /*Return*/ #ifdef IS_PY3K return m; #endif } ////////////////////////////////////////////// ////////////////////////////////////////////// ////////////////////////////////////////////// ////////////////////////////////////////////////// /*Function implementations using backend C code*/ ///////////////////////////////////////////////// //diagonalCost() implementation static PyObject *_design_diagonalCost(PyObject *self,PyObject *args){ int Npoints; double lambda,costValue; //Interpret arguments if(!PyArg_ParseTuple(args,"id",&Npoints,&lambda)){ return NULL; } //Compute cost function for a diagonal design costValue = diagonalCost(Npoints,lambda); //Throw error if cost is not positive if(costValue<=0.0){ PyErr_SetString(PyExc_RuntimeError,"Cost function is not positive!"); return NULL; } //Build return value and return PyObject *ret = Py_BuildValue("d",costValue); return ret; } //cost() implementation static PyObject *_design_cost(PyObject *self,PyObject *args){ int i,j; double p,lambda,costValue; PyObject *data_obj; /*Parse the input tuple*/ if(!PyArg_ParseTuple(args,"Odd",&data_obj,&p,&lambda)){ return NULL; } /*Interpret the points in the design as a numpy array*/ PyObject *data_array = PyArray_FROM_OTF(data_obj,NPY_DOUBLE,NPY_IN_ARRAY); if(data_array==NULL){ return NULL; } /*Get a pointer to the array data*/ double *data = (double *)PyArray_DATA(data_array); /*squeeze the dimensions of the parameter space and the number of points*/ int Npoints = (int)PyArray_DIM(data_array,0); int Ndim = (int)PyArray_DIM(data_array,1); /*Wrap a gsl matrix object around the data_array*/ gsl_matrix *m = gsl_matrix_alloc(Npoints,Ndim); /*Copy the elements into it*/ for(i=0;i<Npoints;i++){ for(j=0;j<Ndim;j++){ gsl_matrix_set(m,i,j,data[i*Ndim+j]); } } /*Call the C backend to compute the cost function*/ costValue = cost(m,Npoints,Ndim,p,lambda); /*Release the gsl resources*/ gsl_matrix_free(m); /*Throw error if cost is not positive*/ if(costValue<=0.0){ PyErr_SetString(PyExc_RuntimeError,"Cost function is not positive!"); Py_DECREF(data_array); return NULL; } /*Build the return value and return it*/ PyObject *ret = Py_BuildValue("d",costValue); Py_DECREF(data_array); return ret; } //sampler() implementation static PyObject *_design_sample(PyObject *self,PyObject *args){ int i,j,maxIterations,seed; double p,lambda; PyObject *data_obj,*cost_obj; /*Parse the input tuple*/ if(!PyArg_ParseTuple(args,"OddiiO",&data_obj,&p,&lambda,&maxIterations,&seed,&cost_obj)){ return NULL; } /*Interpret the data_obj as an array*/ PyObject *data_array = PyArray_FROM_OTF(data_obj,NPY_DOUBLE,NPY_IN_ARRAY); PyObject *cost_array = PyArray_FROM_OTF(cost_obj,NPY_DOUBLE,NPY_IN_ARRAY); if(data_array==NULL || cost_array==NULL){ Py_XDECREF(data_array); Py_XDECREF(cost_array); return NULL; } /*Get a pointer to the array data*/ double *data = (double *)PyArray_DATA(data_array); /*Get a pointer to the cost values*/ double *cost_values = (double *)PyArray_DATA(cost_array); /*squeeze the dimensions of the parameter space and the number of points*/ int Npoints = (int)PyArray_DIM(data_array,0); int Ndim = (int)PyArray_DIM(data_array,1); /*Wrap a gsl matrix object around the data_array*/ gsl_matrix *m = gsl_matrix_alloc(Npoints,Ndim); /*Copy the elements into it*/ for(i=0;i<Npoints;i++){ for(j=0;j<Ndim;j++){ gsl_matrix_set(m,i,j,data[i*Ndim+j]); } } /*Spread the points in the parameter space looking for the cost function minimum*/ double deltaPerc = sample(Npoints,Ndim,p,lambda,seed,maxIterations,m,cost_values); /*Copy the points positions from the gsl matrix to the data array*/ for(i=0;i<Npoints;i++){ for(j=0;j<Ndim;j++){ data[i*Ndim+j] = gsl_matrix_get(m,i,j); } } /*Release the gsl resources*/ gsl_matrix_free(m); /*Release the other resources*/ Py_DECREF(data_array); Py_DECREF(cost_array); /*Build the return value*/ PyObject *ret = Py_BuildValue("d",deltaPerc); return ret; }
{ "alphanum_fraction": 0.7076648841, "avg_line_length": 24.2952755906, "ext": "c", "hexsha": "984f0df045eb12de836ce886f538f31a4142d911", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "e155d6d39361e550906cec00dbbc57686a4bca5c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asabyr/LensTools", "max_forks_repo_path": "lenstools/extern/_design.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "e155d6d39361e550906cec00dbbc57686a4bca5c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asabyr/LensTools", "max_issues_repo_path": "lenstools/extern/_design.c", "max_line_length": 120, "max_stars_count": 1, "max_stars_repo_head_hexsha": "e155d6d39361e550906cec00dbbc57686a4bca5c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asabyr/LensTools", "max_stars_repo_path": "lenstools/extern/_design.c", "max_stars_repo_stars_event_max_datetime": "2021-04-27T02:03:11.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-27T02:03:11.000Z", "num_tokens": 1533, "size": 6171 }
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <cblas.h> #include <cuda_runtime_api.h> #include <boost/shared_ptr.hpp> #include <fstream> #include <iostream> #include <map> #include <memory> #include <string> #include <vector> #include "modules/perception/base/blob.h" #include "modules/perception/base/image.h" namespace apollo { namespace perception { namespace inference { bool ResizeGPU(const base::Image8U &src, std::shared_ptr<apollo::perception::base::Blob<float>> dst, int stepwidth, int start_axis); bool ResizeGPU(const apollo::perception::base::Blob<uint8_t> &src_gpu, std::shared_ptr<apollo::perception::base::Blob<float>> dst, int stepwidth, int start_axis, int mean_b, int mean_g, int mean_r, bool channel_axis, float scale); bool ResizeGPU(const base::Image8U &src, std::shared_ptr<apollo::perception::base::Blob<float>> dst, int stepwidth, int start_axis, float mean_b, float mean_g, float mean_r, bool channel_axis, float scale); } // namespace inference } // namespace perception } // namespace apollo
{ "alphanum_fraction": 0.6447368421, "avg_line_length": 35.1851851852, "ext": "h", "hexsha": "43ac5a78d1caf1f690e2c0c8ee24a6a40210c888", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-02-24T06:20:29.000Z", "max_forks_repo_forks_event_min_datetime": "2019-02-24T06:20:29.000Z", "max_forks_repo_head_hexsha": "808f1d20a08efea23b718b4e423d6619c9d4b412", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "thomasgui76/apollo", "max_forks_repo_path": "modules/perception/inference/utils/resize.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "808f1d20a08efea23b718b4e423d6619c9d4b412", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "thomasgui76/apollo", "max_issues_repo_path": "modules/perception/inference/utils/resize.h", "max_line_length": 79, "max_stars_count": 2, "max_stars_repo_head_hexsha": "002eba4a1635d6af7f1ebd2118464bca6f86b106", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ghdawn/apollo", "max_stars_repo_path": "modules/perception/inference/utils/resize.h", "max_stars_repo_stars_event_max_datetime": "2019-03-15T06:31:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-03-15T06:28:38.000Z", "num_tokens": 395, "size": 1900 }
/* integration/integration.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Created: [GJ] Tue Apr 23 21:26:53 EDT 1996 */ #include <config.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <gsl/gsl_errno.h> /* #include "interpolation.h" */ #include <gsl/gsl_integration.h> #if 0 static char * info_string = 0; void set_integ_info(const char * mess) { if(info_string != 0) free(info_string); info_string = 0; if(mess != 0) { info_string = (char *)malloc((strlen(mess)+1) * sizeof(char)); strcpy(info_string, mess); } } /* Integration function for use with open_romberg(). */ #define FUNC(x) ((*func)(x)) static double midpnt(double (*func)(double), double a, double b, int n) { double x,tnm,sum,del,ddel; static double s; static int it; int j; if (n == 1) { it=1; return (s=(b-a)*FUNC(0.5*(a+b))); } else { tnm=it; del=(b-a)/(3.0*tnm); ddel=del+del; x=a+0.5*del; sum=0.0; for (j=1;j<=it;j++) { sum += FUNC(x); x += ddel; sum += FUNC(x); x += del; } it *= 3; s=(s+(b-a)*sum/tnm)/3.0; return s; } } #undef FUNC #define JMAX 10 #define JMAXP JMAX+1 #define K 5 double open_romberg(double(*func)(double), double a, double b, double eps) { int j; double ss,dss,h[JMAXP+1],s[JMAXP+1]; h[1]=1.0; for (j=1;j<=JMAX;j++) { s[j]=midpnt(func,a,b,j); if (j >= K) { /* local_polint(&h[j-K],&s[j-K],K,0.0,&ss,&dss); */ interp_poly(&h[j-K]+1,&s[j-K]+1,K,0.0,&ss,&dss); if (fabs(dss) < eps * fabs(ss)) return ss; } s[j+1]=s[j]; h[j+1]=h[j]/9.0; } push_error("open_romberg: too many steps", Error_ConvFail_); push_generic_error("open_romberg:", info_string); return 0.; } #undef JMAX #undef JMAXP #undef K double gauss_legendre_10(double (*func)(double), double a, double b) { int j; static double x[] = {0., 0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285}; static double w[] = {0., 0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443}; double xm = 0.5 * (b + a); double xr = 0.5 * (b - a); double s = 0.; double dx; double result; for(j=1; j<=5; j++){ dx = xr * x[j]; s += w[j] * ((*func)(xm+dx) + (*func)(xm-dx)); } result = s * xr; return result; } /************************************************************************ * * * Trapezoid rule. * * * * The original trapzd() function from the Numerical Recipes worked * * by side-effects; it tried to remember the value of the integral * * at the current level of refinement. This is REAL BAD, because if * * you try to use it to do a double integral you will get a surprise. * * You cannot tell which "integral" it is remembering. This stems from * * the stupid fact that there was only one, essentially global, * * variable that was doing this memory job. * * * * The solution is simple: pass the current refinement to the function * * so that it can be remembered by an external environment, making it * * easy to avoid confusion. * * * * So the new-method code-fragment for doing an integral looks like: * * * * double answer; * * for(j=1; j<=M+1; j++) * * trapezoid_rule(func, a, b, j, &answer); * * * ************************************************************************/ void trapezoid_rule(double(*f)(double), double a, double b, int n, double *s) { double x, tnm, sum, del; int it, j; if(n==1){ *s = 0.5 * (b-a) * (f(b) + f(a)); } else { for(it=1, j=1; j < n-1; j++) it <<= 1; tnm = (double) it; del = (b-a) / tnm; x = a + 0.5 * del; for(sum=0., j=1; j<=it; j++, x+=del) { sum += f(x); } *s = 0.5 * (*s + del * sum); } } /************************************************************************ * * * Trapezoid rule. * * This version produces a tracing output. * * * ************************************************************************/ #define FUNC(x) ((*func)(x)) void test_trapezoid_rule(double(*func)(double), double a, double b, int n, double *s) { double x, tnm, sum, del; int it, j; if(n==1){ printf("t: a= %g b= %g f(a)= %g f(b)= %g\n", a, b, FUNC(a), FUNC(b)); } if(n==1){ *s = 0.5 * (b-a) * (FUNC(b) + FUNC(a)); printf("s= %g\n", *s); } else { for(it=1, j=1; j < n-1; j++) it <<= 1; tnm = (double) it; del = (b-a) / tnm; x = a + 0.5 * del; for(sum=0., j=1; j<=it; j++, x+=del) sum += FUNC(x); *s = 0.5 * (*s + del * sum); printf("sum= %g tnm= %g del= %g s= %g\n", sum, tnm, del, *s); } } #undef FUNC /* This is fixed to use the non-side-effecting version of the * trapezoidal rule, as implemented in trapezoid_rule() above. * See the discussion there for explanation of the original problem. */ #define JMAX 20 double gsl_integ_simpson(double (*func)(double), double a, double b, double eps) { int j; double s, st, ost, os; ost = os = -1.e50; for(j=1; j<=JMAX; j++){ trapezoid_rule(func, a, b, j, &st); s = (4.*st - ost) / 3.; if(fabs(s-os) < eps * fabs(os)) return s; os = s; ost = st; } GSL_MESSAGE("simpson: too many steps"); return 0.; } #undef JMAX double gsl_integ_simpson_table(const double * x, const double * y, int n) { int i; double result = 0.; for(i=0; i<n-1; i++) { result += 0.5 * (y[i+1] + y[i]) * (x[i+1] - x[i]); } return result; } /* apparatus for lorentzian variable change to remove pole */ static double (*dummy_f)(double); static double dummy_x0; static double dummy_w; static inline double f_y(double y) { return dummy_f(dummy_x0 + dummy_w * tan(dummy_w * y)); } double gsl_integ_lorenz(double (*f)(double), double x0, double w, double a, double b, double eps) { dummy_f = f; dummy_x0 = x0; dummy_w = fabs(w); if(dummy_w < 10.*sqrt(min_double)) { char buff[100]; sprintf(buff,"lorenz_integ: width w= %g too small", dummy_w); GSL_MESSAGE(buff); return 0.; } else { double lower_y = atan((a-x0)/dummy_w) / dummy_w; double upper_y = atan((b-x0)/dummy_w) / dummy_w; return gsl_integ_simpson(f_y, lower_y, upper_y, eps); } } #endif /* 0 */
{ "alphanum_fraction": 0.4835806373, "avg_line_length": 27.5906040268, "ext": "c", "hexsha": "bc68f00c5473e08eb859c114f9770abfaff6b11a", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z", "max_forks_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_forks_repo_path": "Chimera/3rd_Party/GSL_MSVC/integration/integration.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_issues_repo_path": "Chimera/3rd_Party/GSL_MSVC/integration/integration.c", "max_line_length": 81, "max_stars_count": 1, "max_stars_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_stars_repo_path": "Chimera/3rd_Party/GSL_MSVC/integration/integration.c", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z", "num_tokens": 2303, "size": 8222 }
// // Created by Harold on 2020/9/21. // #ifndef M_MATH_M_FILTER_H #define M_MATH_M_FILTER_H #include <gsl/gsl_filter.h> #include <gsl/gsl_vector.h> namespace M_MATH { class GaussianFilter { public: enum EndpointType { NO_PAD, ZERO_PAD, VALUE_PAD }; public: static bool filter(double const* x, size_t length, size_t window_size, double alpha, EndpointType type, size_t n_length, double* n_x, size_t order); private: static gsl_filter_end_t EndpointType2GSL(EndpointType); }; gsl_filter_end_t GaussianFilter::EndpointType2GSL(GaussianFilter::EndpointType type) { switch (type) { case NO_PAD: return GSL_FILTER_END_TRUNCATE; case ZERO_PAD: return GSL_FILTER_END_PADZERO; case VALUE_PAD: return GSL_FILTER_END_PADVALUE; } // default is no pad // no padding is performed, and the windows are simply truncated as the end points are approached return GSL_FILTER_END_TRUNCATE; } // filter with nth order Gaussian filter, default order = 0 bool GaussianFilter::filter(const double *x, size_t length, size_t window_size, double alpha, GaussianFilter::EndpointType type, size_t n_length, double *n_x, size_t order = 0) { // workspace gsl_filter_gaussian_workspace *gauss_p = gsl_filter_gaussian_alloc(window_size); if (gauss_p == nullptr) return false; // xx, yy gsl_vector *xx = gsl_vector_alloc(length); gsl_vector *yy = gsl_vector_alloc(length); for (auto i = 0; i < length; ++i) { gsl_vector_set(xx, i, x[i]); } /* print kernel to debug // kernel gsl_vector *k = gsl_vector_alloc(window_size); // compute kernel without normalization gsl_filter_gaussian_kernel(alpha, 0, 0, k); // print kernel printf("%s", "kernel: "); for (auto i = 0; i < window_size; ++i) printf("%e ", gsl_vector_get(k, i)); printf("\n"); gsl_vector_free(k); */ // apply filter if (gsl_filter_gaussian(EndpointType2GSL(type), alpha, order, xx, yy, gauss_p) != 0) { gsl_vector_free(xx); gsl_vector_free(yy); gsl_filter_gaussian_free(gauss_p); return false; } for (auto i = 0; i < n_length; ++i) { n_x[i] = gsl_vector_get(yy, i); } // clean up gsl_vector_free(xx); gsl_vector_free(yy); gsl_filter_gaussian_free(gauss_p); return true; } } #endif //M_MATH_M_FILTER_H
{ "alphanum_fraction": 0.5475787335, "avg_line_length": 30.7604166667, "ext": "h", "hexsha": "224194b9c3f996351852d9e9a024fc8df0b8b442", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-07-04T12:26:12.000Z", "max_forks_repo_forks_event_min_datetime": "2021-07-04T12:26:12.000Z", "max_forks_repo_head_hexsha": "2815ed395b0c51a6cab2f20754a6edeee44bd495", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Harold2017/m_math", "max_forks_repo_path": "include/m_filter.h", "max_issues_count": 1, "max_issues_repo_head_hexsha": "2815ed395b0c51a6cab2f20754a6edeee44bd495", "max_issues_repo_issues_event_max_datetime": "2021-08-04T06:32:29.000Z", "max_issues_repo_issues_event_min_datetime": "2021-08-03T02:50:20.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Harold2017/m_math", "max_issues_repo_path": "include/m_filter.h", "max_line_length": 105, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2815ed395b0c51a6cab2f20754a6edeee44bd495", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Harold2017/m_math", "max_stars_repo_path": "include/m_filter.h", "max_stars_repo_stars_event_max_datetime": "2021-08-18T08:00:15.000Z", "max_stars_repo_stars_event_min_datetime": "2021-07-04T12:26:11.000Z", "num_tokens": 654, "size": 2953 }
#include <cerrno> #include <cstdio> #include <cstdlib> #include <sys/stat.h> #include <cmath> #include <vector> #include <iostream> #include <fstream> #include <sstream> #include <string> #include <time.h> #include <gsl/gsl_odeiv2.h> #include <gsl/gsl_math.h> #include <math.h> /* pow */ #include <gsl/gsl_sf.h> #include <gsl/gsl_integration.h> #include <gsl/gsl_spline.h> // Common functions to all .cpps /* LCDM Hubble in 1/s */ double hubble(double om, double orad, double a){ double a3 = pow(a,3); double a4 = a*a3; double ol = 1.-om-orad; return h0 * sqrt(om/a3+ orad/a4 + ol); } // Reheating time as a function of temperature --- Trh should be given in Kelvin double timeofrh(double Trh){ return sqrt(5./pow(M_PI,3)/gstar) * pow(10,lgmp)/pow(Trh*keltgev,2) *kgtgev / gevtds ; } /* Critical density in kg/m^3 */ double rhoc(double a){ return 3.*pow(hubble(om, orad, a),2.)/(8.*M_PI*gnewton); } /* Omega_x for LCDM */ double omegalcdm(double ox, double a){ return ox/pow(a,3.) * pow(h0/hubble(om,orad,a),2.); } /* Log10 of Mass spectrum in units 1/kg */ // hi mass - Eq.2.5 of draft // Psi = 10^psihilg as a function of Log10[M] = lgm and omega_pbh double psihilg(double lgm, double opbh){ double fpbh = opbh/oc; return -12.2764 + log10(fpbh) - 3./2. * lgm; } // low mass - Eq.2.2 of draft // Psi = 10^psilowlg as a function of Log10[M] = lgm and peak mass double psilowlg(double lgm, double peakm){ double aofmf = (peakm+2.723)/(-0.6576); double expt = 2.85*(lgm-peakm); return 2.85*(aofmf + lgm) - pow(10,expt)/2.3026; } // full spectrum - polychromatic // Psi = 10^psibroadlg as a function of Log10[M] = lgm and peak mass double psibroadlg(double lgm, double peakm){ // if mass is less than planck mass, set to 0 if(lgmp>lgm){ return -100.; } // if above peak mass, set to hi spectrum else if(lgm>peakm){ return psihilg(lgm,oc); } // if below peak mass, set to low spectrum else{ return psilowlg(lgm,peakm); } } // calculate volume fration given number density double epsilon(double lgni, double lgmass){ double radius = 2. * gnewton * pow(10,lgmass)/pow(sofl,2); printf("%e \n", radius); return pow(10.,lgni) * 4. * M_PI * pow(radius,3) / 3.; } /* Entropy density */ // Temperature given in Kelvin double entropy(double Trh, double a, double arh){ return 2.*pow(M_PI,2)/45 * gstar * pow(Trh*keltgev*arh/a,3.); } // absolute maximum theoretical number density // Some notes: A bh of mass 10^-5.96 kg has a volume of 1.76 x 10^-98 m^3 and so we can have number densities mathematically up to 10^98 x 0.74 where 0.74 is the close packing ratio (max ratio of cube to volume of packed spheres) double maxn0(double lgmass){ double rsch = 2.*gnewton*pow(10.,lgmass)/pow(sofl,2); // schwarzschild radius in m double volume =4./3. * M_PI * pow(rsch,3); return 1./volume * 0.74; }
{ "alphanum_fraction": 0.6746143058, "avg_line_length": 27.6893203883, "ext": "h", "hexsha": "c93752c15fc62b9c0bb40c51983bdcf6275eccc8", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b896bb65d0f204603e26b3579265d4cd613c48e7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nebblu/PBH", "max_forks_repo_path": "gfuncs.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "b896bb65d0f204603e26b3579265d4cd613c48e7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nebblu/PBH", "max_issues_repo_path": "gfuncs.h", "max_line_length": 230, "max_stars_count": null, "max_stars_repo_head_hexsha": "b896bb65d0f204603e26b3579265d4cd613c48e7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nebblu/PBH", "max_stars_repo_path": "gfuncs.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 975, "size": 2852 }
// Copyright (c) 2013-2016 Anton Kozhevnikov, Thomas Schulthess // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, are permitted provided that // the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the // following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions // and the following disclaimer in the documentation and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** \file sirius_internal.h * * \brief Contains basic definitions and declarations. */ #ifndef __SIRIUS_INTERNAL_H__ #define __SIRIUS_INTERNAL_H__ #include <omp.h> #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <gsl/gsl_sf_bessel.h> #include <fftw3.h> #include <vector> #include <complex> #include <iostream> #include <algorithm> #include "config.h" #include "communicator.hpp" #include "runtime.h" #include "sddk.hpp" #include "utils.h" #ifdef __MAGMA #include "GPU/magma.hpp" #endif #include "constants.h" #include "version.h" #include "simulation_context.h" #include "Beta_projectors/beta_projectors_base.h" #ifdef __PLASMA extern "C" void plasma_init(int num_cores); #endif #ifdef __LIBSCI_ACC extern "C" void libsci_acc_init(); extern "C" void libsci_acc_finalize(); #endif /// Namespace of the SIRIUS library. namespace sirius { inline void initialize(bool call_mpi_init__ = true) { if (call_mpi_init__) { Communicator::initialize(); } if (mpi_comm_world().rank() == 0) { printf("SIRIUS %i.%i, git hash: %s\n", major_version, minor_version, git_hash); } #ifdef __GPU if (acc::num_devices()) { acc::create_streams(omp_get_max_threads() + 1); cublas::create_stream_handles(); } #endif #ifdef __MAGMA magma::init(); #endif #ifdef __PLASMA plasma_init(omp_get_max_threads()); #endif #ifdef __LIBSCI_ACC libsci_acc_init(); #endif assert(sizeof(int) == 4); assert(sizeof(double) == 8); } inline void finalize(bool call_mpi_fin__ = true) { #ifdef __MAGMA magma::finalize(); #endif #ifdef __LIBSCI_ACC libsci_acc_finalize(); #endif Beta_projectors_base<1>::cleanup(); Beta_projectors_base<3>::cleanup(); Beta_projectors_base<9>::cleanup(); #ifdef __GPU if (acc::num_devices()) { cublas::destroy_stream_handles(); acc::destroy_streams(); acc::reset(); } #endif fftw_cleanup(); json dict; dict["flat"] = sddk::timer::serialize_timers(); dict["tree"] = sddk::timer::serialize_timers_tree(); if (mpi_comm_world().rank() == 0) { std::ofstream ofs("timers.json", std::ofstream::out | std::ofstream::trunc); ofs << dict.dump(4); } //sddk::timer::print_tree(); if (call_mpi_fin__) { Communicator::finalize(); } } inline void terminate(int err_code__) { MPI_Abort(MPI_COMM_WORLD, err_code__); } }; #endif // __SIRIUS_INTERNAL_H__ /** \mainpage Welcome to SIRIUS \section intro Introduction SIRIUS is a domain-specific library for electronic structure calculations. It supports full-potential linearized augmented plane wave (FP-LAPW) and pseudopotential plane wave (PP-PW) methods and is designed to work with codes such as Exciting, Elk and Quantum ESPRESSO. \section install Installation First, you need to clone the source code: \verbatim git clone https://github.com/electronic-structure/SIRIUS.git \endverbatim Then you need to create a configuration \c json file where you specify your compiliers, compiler flags and libraries. Examples of such configuration files can be found in the <tt>./platforms/</tt> folder. The following variables have to be provided: - \c MPI_CXX -- the MPI wrapper for the C++11 compiler (this is the main compiler for the library) - \c MPI_CXX_OPT -- the C++ compiler options for the library - \c MPI_FC -- the MPI wrapper for the Fortran compiler (used to build ELPA and SIRIUS F90 interface) - \c MPI_FC_OPT -- Fortran compiler options - \c CC -- plain C compilers (used to build the external libraries) - \c CXX -- plain C++ compiler (used to build the external libraries) - \c FC -- plain Fortran compiler (used to build the external libraries) - \c FCCPP -- Fortran preprocessor (usually 'cpp', required by LibXC package) - \c SYSTEM_LIBS -- list of the libraries, necessary for the linking (typically BLAS/LAPACK/ScaLAPACK, libstdc++ and Fortran run-time) - \c install -- list of packages to download, configure and build In addition, the following variables can also be specified: - \c CUDA_ROOT -- path to the CUDA toolkit (if you compile with GPU support) - \c NVCC -- name of the CUDA C++ compiler (usually \c nvcc) - \c NVCC_OPT -- CUDA compiler options - \c MAGMA_ROOT -- location of the compiled MAGMA library (if you compile with MAGMA support) Below is an example of the configurtaion file for the Cray XC50 platform. Cray compiler wrappers for C/C++/Fortran are ftn/cc/CC. The GNU compilers and MKL are used. \verbatim { "comment" : "MPI C++ compiler and options", "MPI_CXX" : "CC", "MPI_CXX_OPT" : "-std=c++11 -Wall -Wconversion -fopenmp -D__SCALAPACK -D__ELPA -D__GPU -D__MAGMA -I$(MKLROOT)/include/fftw/", "comment" : "MPI Fortran compiler and oprions", "MPI_FC" : "ftn", "MPI_FC_OPT" : "-O3 -fopenmp -cpp", "comment" : "plain C compler", "CC" : "cc", "comment" : "plain C++ compiler", "CXX" : "CC", "comment" : "plain Fortran compiler", "FC" : "ftn", "comment" : "Fortran preprocessor", "FCCPP" : "cpp", "comment" : "location of CUDA toolkit", "CUDA_ROOT" : "$(CUDATOOLKIT_HOME)", "comment" : "CUDA compiler and options", "NVCC" : "nvcc", "NVCC_OPT" : "-arch=sm_60 -m64 -DNDEBUG", "comment" : "location of MAGMA library", "MAGMA_ROOT" : "$(HOME)/src/daint/magma-2.2.0", "SYSTEM_LIBS" : "$(MKLROOT)/lib/intel64/libmkl_scalapack_lp64.a -Wl,--start-group $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a $(MKLROOT)/lib/intel64/libmkl_gnu_thread.a $(MKLROOT)/lib/intel64/libmkl_core.a $(MKLROOT)/lib/intel64/libmkl_blacs_intelmpi_lp64.a -Wl,--end-group -lpthread -lstdc++ -ldl", "install" : ["spg", "gsl", "xc"] } \endverbatim FFT library is part of the MKL. The corresponding C++ include directory is passed to the compiler: -I\$(MKLROOT)/include/fftw/. The \c HDF5 library is installed as a module and handeled by the Cray wrappers. The remaining three libraries necessary for SIRIUS (spglib, GSL, libXC) are not available and have to be installed. Once the configuration \c json file is created, you can run \verbatim python configure.py path/to/config.json \endverbatim The Python script will download and configure external packages, specified in the <tt>"install"</tt> list and create Makefile and make.inc files. That's it! The configuration is done and you can run \verbatim make \endverbatim */ //! \page stdvarname Standard variable names //! //! Below is the list of standard names for some of the loop variables: //! //! l - index of orbital quantum number \n //! m - index of azimutal quantum nuber \n //! lm - combined index of (l,m) quantum numbers \n //! ia - index of atom \n //! ic - index of atom class \n //! iat - index of atom type \n //! ir - index of r-point \n //! ig - index of G-vector \n //! idxlo - index of local orbital \n //! idxrf - index of radial function \n //! xi - compbined index of lm and idxrf (product of angular and radial functions) \n //! ik - index of k-point \n //! itp - index of (theta, phi) spherical angles \n //! //! The _loc suffix is often added to the variables to indicate that they represent the local fraction of the elements //! assigned to the given MPI rank. //! //! \page coding Coding style //! //! Below are some basic style rules that we follow: //! - Page width is approximately 120 characters. Screens are wide nowdays and 80 characters is an //! obsolete restriction. Going slightly over 120 characters is allowed if it is requird for the line continuity. //! - Identation: 4 spaces (no tabs) //! - Coments are inserted before the code with slash-star style starting with the lower case: //! \code{.cpp} //! /* call a very important function */ //! do_something(); //! \endcode //! - Spaces between most operators: //! \code{.cpp} //! if (i < 5) { //! j = 5; //! } //! //! for (int k = 0; k < 3; k++) //! //! int lm = l * l + l + m; //! //! double d = std::abs(e); //! //! int k = idx[3]; //! \endcode //! - Spaces between function arguments: //! \code{.cpp} //! double d = some_func(a, b, c); //! \endcode //! but not //! \code{.cpp} //! double d=some_func(a,b,c); //! \endcode //! or //! \code{.cpp} //! double d = some_func( a, b, c ); //! \endcode //! - Spaces between template arguments, but not between <> brackets: //! \code{.cpp} //! std::vector<std::array<int, 2>> vec; //! \endcode //! but not //! \code{.cpp} //! std::vector< std::array< int, 2 > > vec; //! \endcode //! - Curly braces for classes and functions start form the new line: //! \code{.cpp} //! class A //! { //! .... //! }; //! //! inline int num_points() //! { //! return num_points_; //! } //! \endcode //! - Curly braces for if-statements, for-loops, switch-case statements, etc. start at the end of the line: //! \code{.cpp} //! for (int i: {0, 1, 2}) { //! some_func(i); //! } //! //! if (a == 0) { //! printf("a is zero"); //! } else { //! printf("a is not zero"); //! } //! //! switch (i) { //! case 1: { //! do_something(); //! break; //! case 2: { //! do_something_else(); //! break; //! } //! } //! \endcode //! - Even single line 'if' statements and 'for' loops must have the curly brackes: //! \code{.cpp} //! if (i == 4) { //! some_variable = 5; //! } //! //! for (int k = 0; k < 10; k++) { //! do_something(k); //! } //! \endcode //! - Reference and pointer symbols are part of type: //! \code{.cpp} //! std::vector<double>& vec = make_vector(); //! //! double* ptr = &vec[0]; //! //! auto& atom = unit_cell().atom(ia); //! \endcode //! - Const modifier follows the type declaration: //! \code{.cpp} //! std::vector<int> const& idx() const //! { //! return idx_; //! } //! \endcode //! - Names of class members end with underscore: //! \code{.cpp} //! class A //! { //! private: //! int lmax_; //! }; //! \endcode //! - Setter method starts from set_, getter method is a variable name itself: //! \code{.cpp} //! class A //! { //! private: //! int lmax_; //! public: //! int lmax() const //! { //! return lmax_; //! } //! void set_lmax(int lmax__) //! { //! lmax_ = lmax__; //! } //! }; //! \endcode //! - Single-line functions should not be flattened: //! \code{.cpp} //! struct A //! { //! int lmax() const //! { //! return lmax_; //! } //! }; //! \endcode //! but not //! \code{.cpp} //! struct A //! { //! int lmax() const { return lmax_; } //! }; //! \endcode //! - Header guards have a standard name: double underscore + file name in capital letters + double underscore //! \code{.cpp} //! #ifndef __SIRIUS_INTERNAL_H__ //! #define __SIRIUS_INTERNAL_H__ //! ... //! #endif // __SIRIUS_INTERNAL_H__ //! \endcode //! We use clang-format utility to enforce the basic formatting style. Please have a look at .clang-format config file //! in the source root folder for the definitions. //! //! Class naming convention. //! //! Problem: all 'standard' naming conventions are not satisfactory. For example, we have a class //! which does a DFT ground state. Following the common naming conventions it could be named like this: //! DFTGroundState, DftGroundState, dft_ground_state. Last two are bad, because DFT (and not Dft or dft) //! is a well recognized abbreviation. First one is band because capital G adds to DFT and we automaticaly //! read DFTG round state. //! //! Solution: we can propose the following: DFTgroundState or DFT_ground_state. The first variant still //! doens't look very good because one of the words is captalized (State) and one (ground) - is not. So we pick //! the second variant: DFT_ground_state (by the way, this is close to the Bjarne Stroustrup's naiming convention, //! where he uses first capital letter and underscores, for example class Io_obj). //! //! Some other examples: //! - class Ground_state (composed of two words) //! - class FFT_interface (composed of an abbreviation and a word) //! - class Interface_XC (composed of a word and abbreviation) //! - class Spline (single word) //! //! Exceptions are allowed if it makes sense. For example, low level utility classes like 'mdarray' (multi-dimentional //! array) or 'pstdout' (parallel standard output) are named with small letters. //! /** \page fderiv Functional derivatives Definition: \f[ \frac{dF[f+\epsilon \eta ]}{d \epsilon}\Bigg\rvert_{\epsilon = 0} := \int \frac{\delta F[f]}{\delta f(x')} \eta(x') dx' \f] Alternative definition is: \f[ \frac{\delta F[f(x)]}{\delta f(x')} = \lim_{\epsilon \to 0} \frac{F[f(x) + \epsilon \delta(x-x')] - F[f(x)]}{\epsilon} \f] */
{ "alphanum_fraction": 0.5975671889, "avg_line_length": 35.7676537585, "ext": "h", "hexsha": "7b23ef7feb9d7f99b723efaaf038648089a799f6", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ecb7edb4f19577c85b0cec82aa6a0d5374ee1f33", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "ckae95/SIRIUS", "max_forks_repo_path": "src/sirius_internal.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "ecb7edb4f19577c85b0cec82aa6a0d5374ee1f33", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "ckae95/SIRIUS", "max_issues_repo_path": "src/sirius_internal.h", "max_line_length": 303, "max_stars_count": null, "max_stars_repo_head_hexsha": "ecb7edb4f19577c85b0cec82aa6a0d5374ee1f33", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "ckae95/SIRIUS", "max_stars_repo_path": "src/sirius_internal.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3984, "size": 15702 }
// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights // reserved. See files LICENSE and NOTICE for details. // // This file is part of CEED, a collection of benchmarks, miniapps, software // libraries and APIs for efficient high-order finite element and spectral // element discretizations for exascale applications. For more information and // source code availability see http://github.com/ceed. // // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, // a collaborative effort of two U.S. Department of Energy organizations (Office // of Science and the National Nuclear Security Administration) responsible for // the planning and preparation of a capable exascale ecosystem, including // software, applications, hardware, advanced system engineering and early // testbed platforms, in support of the nation's exascale computing imperative. #ifndef setup_h #define setup_h #include <stdbool.h> #include <string.h> #include <petsc.h> #include <petscdmplex.h> #include <petscksp.h> #include <petscfe.h> #include <ceed.h> #if PETSC_VERSION_LT(3,14,0) # define DMAddBoundary(a,b,c,d,e,f,g,h,i,j,k,l) DMAddBoundary(a,b,c,d,e,f,g,h,j,k,l) #endif #ifndef PHYSICS_STRUCT #define PHYSICS_STRUCT typedef struct Physics_private *Physics; struct Physics_private { CeedScalar nu; // Poisson's ratio CeedScalar E; // Young's Modulus }; #endif // ----------------------------------------------------------------------------- // Command Line Options // ----------------------------------------------------------------------------- // Problem options typedef enum { ELAS_LIN = 0, ELAS_HYPER_SS = 1, ELAS_HYPER_FS = 2 } problemType; static const char *const problemTypes[] = {"linElas", "hyperSS", "hyperFS", "problemType","ELAS_",0 }; static const char *const problemTypesForDisp[] = {"Linear elasticity", "Hyper elasticity small strain", "Hyper elasticity finite strain" }; // Forcing function options typedef enum { FORCE_NONE = 0, FORCE_CONST = 1, FORCE_MMS = 2 } forcingType; static const char *const forcingTypes[] = {"none", "constant", "mms", "forcingType","FORCE_",0 }; static const char *const forcingTypesForDisp[] = {"None", "Constant", "Manufactured solution" }; // Multigrid options typedef enum { MULTIGRID_LOGARITHMIC = 0, MULTIGRID_UNIFORM = 1, MULTIGRID_NONE = 2 } multigridType; static const char *const multigridTypes [] = {"logarithmic", "uniform", "none", "multigridType","MULTIGRID",0 }; static const char *const multigridTypesForDisp[] = {"P-multigrid, logarithmic coarsening", "P-multigrind, uniform coarsening", "No multigrid" }; typedef PetscErrorCode BCFunc(PetscInt, PetscReal, const PetscReal *, PetscInt, PetscScalar *, void *); // Note: These variables should be updated if additional boundary conditions // are added to boundary.c. BCFunc BCMMS, BCZero, BCClamp; // MemType Options static const char *const memTypes[] = {"host","device","memType", "CEED_MEM_",0 }; // ----------------------------------------------------------------------------- // Structs // ----------------------------------------------------------------------------- // Units typedef struct Units_private *Units; struct Units_private { // Fundamental units PetscScalar meter; PetscScalar kilogram; PetscScalar second; // Derived unit PetscScalar Pascal; }; // Application context from user command line options typedef struct AppCtx_private *AppCtx; struct AppCtx_private { char ceedResource[PETSC_MAX_PATH_LEN]; // libCEED backend char meshFile[PETSC_MAX_PATH_LEN]; // exodusII mesh file PetscBool testMode; PetscBool viewSoln; PetscBool viewFinalSoln; problemType problemChoice; forcingType forcingChoice; multigridType multigridChoice; PetscScalar nuSmoother; PetscInt degree; PetscInt qextra; PetscInt numLevels; PetscInt *levelDegrees; PetscInt numIncrements; // Number of steps PetscInt bcClampCount; PetscInt bcClampFaces[16]; PetscScalar bcClampMax[16][7]; PetscInt bcTractionCount; PetscInt bcTractionFaces[16]; PetscScalar bcTractionVector[16][3]; PetscScalar forcingVector[3]; PetscBool petscHaveCuda, setMemTypeRequest; CeedMemType memTypeRequested; }; // Problem specific data // *INDENT-OFF* typedef struct { CeedInt qdatasize; CeedQFunctionUser setupgeo, apply, jacob, energy, diagnostic; const char *setupgeofname, *applyfname, *jacobfname, *energyfname, *diagnosticfname; CeedQuadMode qmode; } problemData; // *INDENT-ON* // Data specific to each problem option extern problemData problemOptions[3]; // Forcing function data typedef struct { CeedQFunctionUser setupforcing; const char *setupforcingfname; } forcingData; extern forcingData forcingOptions[3]; // Data for PETSc Matshell typedef struct UserMult_private *UserMult; struct UserMult_private { MPI_Comm comm; DM dm; Vec Xloc, Yloc, NBCs; CeedVector Xceed, Yceed; CeedOperator op; CeedQFunction qf; Ceed ceed; PetscScalar loadIncrement; CeedQFunctionContext ctxPhys, ctxPhysSmoother; CeedMemType memType; int (*VecGetArray)(Vec, PetscScalar **); int (*VecGetArrayRead)(Vec, const PetscScalar **); int (*VecRestoreArray)(Vec, PetscScalar **); int (*VecRestoreArrayRead)(Vec, const PetscScalar **); }; // Data for Jacobian setup routine typedef struct FormJacobCtx_private *FormJacobCtx; struct FormJacobCtx_private { UserMult *jacobCtx; PetscInt numLevels; SNES snesCoarse; Mat *jacobMat, jacobMatCoarse; Vec Ucoarse; }; // Data for PETSc Prolongation/Restriction Matshell typedef struct UserMultProlongRestr_private *UserMultProlongRestr; struct UserMultProlongRestr_private { MPI_Comm comm; DM dmC, dmF; Vec locVecC, locVecF; CeedVector ceedVecC, ceedVecF; CeedOperator opProlong, opRestrict; Ceed ceed; CeedMemType memType; int (*VecGetArray)(Vec, PetscScalar **); int (*VecGetArrayRead)(Vec, const PetscScalar **); int (*VecRestoreArray)(Vec, PetscScalar **); int (*VecRestoreArrayRead)(Vec, const PetscScalar **); }; // libCEED data struct for level typedef struct CeedData_private *CeedData; struct CeedData_private { Ceed ceed; CeedBasis basisx, basisu, basisCtoF, basisEnergy, basisDiagnostic; CeedElemRestriction Erestrictx, Erestrictu, Erestrictqdi, ErestrictGradui, ErestrictEnergy, ErestrictDiagnostic, ErestrictqdDiagnostici; CeedQFunction qfApply, qfJacob, qfEnergy, qfDiagnostic; CeedOperator opApply, opJacob, opRestrict, opProlong, opEnergy, opDiagnostic; CeedVector qdata, qdataDiagnostic, gradu, xceed, yceed, truesoln; }; // ----------------------------------------------------------------------------- // Process command line options // ----------------------------------------------------------------------------- // Process general command line options PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx appCtx); // Process physics options PetscErrorCode ProcessPhysics(MPI_Comm comm, Physics phys, Units units); // ----------------------------------------------------------------------------- // Setup DM // ----------------------------------------------------------------------------- PetscErrorCode CreateBCLabel(DM dm, const char name[]); // Create FE by degree PetscErrorCode PetscFECreateByDegree(DM dm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, const char prefix[], PetscInt order, PetscFE *fem); // Read mesh and distribute DM in parallel PetscErrorCode CreateDistributedDM(MPI_Comm comm, AppCtx appCtx, DM *dm); // Setup DM with FE space of appropriate degree PetscErrorCode SetupDMByDegree(DM dm, AppCtx appCtx, PetscInt order, PetscBool boundary, PetscInt ncompu); // ----------------------------------------------------------------------------- // libCEED Functions // ----------------------------------------------------------------------------- // Destroy libCEED objects PetscErrorCode CeedDataDestroy(CeedInt level, CeedData data); // Utility function - essential BC dofs are encoded in closure indices as -(i+1) PetscInt Involute(PetscInt i); // Utility function to create local CEED restriction from DMPlex PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt P, CeedInt height, DMLabel domainLabel, CeedInt value, CeedElemRestriction *Erestrict); // Utility function to get Ceed Restriction for each domain PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, DMLabel domainLabel, PetscInt value, CeedInt P, CeedInt Q, CeedInt qdatasize, CeedElemRestriction *restrictq, CeedElemRestriction *restrictx, CeedElemRestriction *restrictqdi); // Set up libCEED for a given degree PetscErrorCode SetupLibceedFineLevel(DM dm, DM dmEnergy, DM dmDiagnostic, Ceed ceed, AppCtx appCtx, CeedQFunctionContext physCtx, CeedData *data, PetscInt fineLevel, PetscInt ncompu, PetscInt Ugsz, PetscInt Ulocsz, CeedVector forceCeed, CeedVector neumannCeed); // Set up libCEED multigrid level for a given degree PetscErrorCode SetupLibceedLevel(DM dm, Ceed ceed, AppCtx appCtx, CeedData *data, PetscInt level, PetscInt ncompu, PetscInt Ugsz, PetscInt Ulocsz, CeedVector fineMult); // Setup context data for Jacobian evaluation PetscErrorCode SetupJacobianCtx(MPI_Comm comm, AppCtx appCtx, DM dm, Vec V, Vec Vloc, CeedData ceedData, Ceed ceed, CeedQFunctionContext ctxPhys, CeedQFunctionContext ctxPhysSmoother, UserMult jacobianCtx); // Setup context data for prolongation and restriction operators PetscErrorCode SetupProlongRestrictCtx(MPI_Comm comm, AppCtx appCtx, DM dmC, DM dmF, Vec VF, Vec VlocC, Vec VlocF, CeedData ceedDataC, CeedData ceedDataF, Ceed ceed, UserMultProlongRestr prolongRestrCtx); // ----------------------------------------------------------------------------- // Jacobian setup // ----------------------------------------------------------------------------- PetscErrorCode FormJacobian(SNES snes, Vec U, Mat J, Mat Jpre, void *ctx); // ----------------------------------------------------------------------------- // Solution output // ----------------------------------------------------------------------------- PetscErrorCode ViewSolution(MPI_Comm comm, Vec U, PetscInt increment, PetscScalar loadIncrement); PetscErrorCode ViewDiagnosticQuantities(MPI_Comm comm, DM dmU, UserMult user, Vec U, CeedElemRestriction ErestrictDiagnostic); // ----------------------------------------------------------------------------- // libCEED Operators for MatShell // ----------------------------------------------------------------------------- // This function uses libCEED to compute the local action of an operator PetscErrorCode ApplyLocalCeedOp(Vec X, Vec Y, UserMult user); // This function uses libCEED to compute the non-linear residual PetscErrorCode FormResidual_Ceed(SNES snes, Vec X, Vec Y, void *ctx); // This function uses libCEED to apply the Jacobian for assembly via a SNES PetscErrorCode ApplyJacobianCoarse_Ceed(SNES snes, Vec X, Vec Y, void *ctx); // This function uses libCEED to compute the action of the Jacobian PetscErrorCode ApplyJacobian_Ceed(Mat A, Vec X, Vec Y); // This function uses libCEED to compute the action of the prolongation operator PetscErrorCode Prolong_Ceed(Mat A, Vec X, Vec Y); // This function uses libCEED to compute the action of the restriction operator PetscErrorCode Restrict_Ceed(Mat A, Vec X, Vec Y); // This function returns the computed diagonal of the operator PetscErrorCode GetDiag_Ceed(Mat A, Vec D); // This function calculates the strain energy in the final solution PetscErrorCode ComputeStrainEnergy(DM dmEnergy, UserMult user, CeedOperator opEnergy, Vec X, PetscReal *energy); // ----------------------------------------------------------------------------- // Boundary Functions // ----------------------------------------------------------------------------- // Note: If additional boundary conditions are added, an update is needed in // elasticity.h for the boundaryOptions variable. // BCMMS - boundary function // Values on all points of the mesh is set based on given solution below // for u[0], u[1], u[2] PetscErrorCode BCMMS(PetscInt dim, PetscReal loadIncrement, const PetscReal coords[], PetscInt ncompu, PetscScalar *u, void *ctx); // BCClamp - fix boundary values with affine transformation at fraction of load // increment PetscErrorCode BCClamp(PetscInt dim, PetscReal loadIncrement, const PetscReal coords[], PetscInt ncompu, PetscScalar *u, void *ctx); #endif //setup_h
{ "alphanum_fraction": 0.5674295191, "avg_line_length": 41.7590027701, "ext": "h", "hexsha": "f06355494f7e30fdea4e13c7ba29b5122b08f605", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0983a37fb2a235bf55920dd2b1098e5586f89fb8", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "rscohn2/libCEED", "max_forks_repo_path": "examples/solids/elasticity.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "0983a37fb2a235bf55920dd2b1098e5586f89fb8", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "rscohn2/libCEED", "max_issues_repo_path": "examples/solids/elasticity.h", "max_line_length": 116, "max_stars_count": null, "max_stars_repo_head_hexsha": "0983a37fb2a235bf55920dd2b1098e5586f89fb8", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "rscohn2/libCEED", "max_stars_repo_path": "examples/solids/elasticity.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3124, "size": 15075 }
/* histogram/pdf2d.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007, 2009 Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <config.h> #include <stdlib.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_histogram.h> #include <gsl/gsl_histogram2d.h> #include "find.c" int gsl_histogram2d_pdf_sample (const gsl_histogram2d_pdf * p, double r1, double r2, double *x, double *y) { size_t k; int status; /* Wrap the exclusive top of the bin down to the inclusive bottom of the bin. Since this is a single point it should not affect the distribution. */ if (r2 == 1.0) { r2 = 0.0; } if (r1 == 1.0) { r1 = 0.0; } status = find (p->nx * p->ny, p->sum, r1, &k); if (status) { GSL_ERROR ("cannot find r1 in cumulative pdf", GSL_EDOM); } else { size_t i = k / p->ny; size_t j = k - (i * p->ny); double delta = (r1 - p->sum[k]) / (p->sum[k + 1] - p->sum[k]); *x = p->xrange[i] + delta * (p->xrange[i + 1] - p->xrange[i]); *y = p->yrange[j] + r2 * (p->yrange[j + 1] - p->yrange[j]); return GSL_SUCCESS; } } gsl_histogram2d_pdf * gsl_histogram2d_pdf_alloc (const size_t nx, const size_t ny) { const size_t n = nx * ny; gsl_histogram2d_pdf *p; if (n == 0) { GSL_ERROR_VAL ("histogram2d pdf length n must be positive integer", GSL_EDOM, 0); } p = (gsl_histogram2d_pdf *) malloc (sizeof (gsl_histogram2d_pdf)); if (p == 0) { GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf struct", GSL_ENOMEM, 0); } p->xrange = (double *) malloc ((nx + 1) * sizeof (double)); if (p->xrange == 0) { free (p); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf xranges", GSL_ENOMEM, 0); } p->yrange = (double *) malloc ((ny + 1) * sizeof (double)); if (p->yrange == 0) { free (p->xrange); free (p); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf yranges", GSL_ENOMEM, 0); } p->sum = (double *) malloc ((n + 1) * sizeof (double)); if (p->sum == 0) { free (p->yrange); free (p->xrange); free (p); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf sums", GSL_ENOMEM, 0); } p->nx = nx; p->ny = ny; return p; } int gsl_histogram2d_pdf_init (gsl_histogram2d_pdf * p, const gsl_histogram2d * h) { size_t i; const size_t nx = p->nx; const size_t ny = p->ny; const size_t n = nx * ny; if (nx != h->nx || ny != h->ny) { GSL_ERROR ("histogram2d size must match pdf size", GSL_EDOM); } for (i = 0; i < n; i++) { if (h->bin[i] < 0) { GSL_ERROR ("histogram bins must be non-negative to compute" "a probability distribution", GSL_EDOM); } } for (i = 0; i < nx + 1; i++) { p->xrange[i] = h->xrange[i]; } for (i = 0; i < ny + 1; i++) { p->yrange[i] = h->yrange[i]; } { double mean = 0, sum = 0; for (i = 0; i < n; i++) { mean += (h->bin[i] - mean) / ((double) (i + 1)); } p->sum[0] = 0; for (i = 0; i < n; i++) { sum += (h->bin[i] / mean) / n; p->sum[i + 1] = sum; } } return GSL_SUCCESS; } void gsl_histogram2d_pdf_free (gsl_histogram2d_pdf * p) { RETURN_IF_NULL (p); free (p->xrange); free (p->yrange); free (p->sum); free (p); }
{ "alphanum_fraction": 0.5576750449, "avg_line_length": 23.7021276596, "ext": "c", "hexsha": "07cc24d615fead5e7cd508126da61ca0bbdefcea", "lang": "C", "max_forks_count": 14, "max_forks_repo_forks_event_max_datetime": "2020-03-12T12:31:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T04:47:52.000Z", "max_forks_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "Brian-ning/HMNE", "max_forks_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/histogram/pdf2d.c", "max_issues_count": 6, "max_issues_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z", "max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "Brian-ning/HMNE", "max_issues_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/histogram/pdf2d.c", "max_line_length": 81, "max_stars_count": 14, "max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ielomariala/Hex-Game", "max_stars_repo_path": "gsl-2.6/histogram/pdf2d.c", "max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z", "num_tokens": 1372, "size": 4456 }
#include <stdio.h> #include <gsl/gsl_const_mksa.h> int main (void) { double c = GSL_CONST_MKSA_SPEED_OF_LIGHT; double au = GSL_CONST_MKSA_ASTRONOMICAL_UNIT; double minutes = GSL_CONST_MKSA_MINUTE; /* distance stored in meters */ double r_earth = 1.00 * au; double r_mars = 1.52 * au; double t_min, t_max; t_min = (r_mars - r_earth) / c; t_max = (r_mars + r_earth) / c; printf ("light travel time from Earth to Mars:\n"); printf ("minimum = %.1f minutes\n", t_min / minutes); printf ("maximum = %.1f minutes\n", t_max / minutes); return 0; }
{ "alphanum_fraction": 0.6655112652, "avg_line_length": 22.1923076923, "ext": "c", "hexsha": "47718c51d3cfc27f0f1b29303c8186065b3f7ca5", "lang": "C", "max_forks_count": 40, "max_forks_repo_forks_event_max_datetime": "2022-03-03T23:23:37.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-26T15:31:16.000Z", "max_forks_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "Brian-ning/HMNE", "max_forks_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/doc/examples/const.c", "max_issues_count": 12, "max_issues_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_issues_repo_issues_event_max_datetime": "2022-03-13T03:54:24.000Z", "max_issues_repo_issues_event_min_datetime": "2020-12-15T08:30:19.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "Brian-ning/HMNE", "max_issues_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/doc/examples/const.c", "max_line_length": 55, "max_stars_count": 64, "max_stars_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "manggoguy/parsec-modified", "max_stars_repo_path": "pkgs/libs/gsl/src/doc/examples/const.c", "max_stars_repo_stars_event_max_datetime": "2022-03-24T13:26:53.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-06T00:30:56.000Z", "num_tokens": 192, "size": 577 }
/***************************************************************************** * * * Copyright 2018 Rice University * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * * * *****************************************************************************/ #ifndef LDA_DOC_WORD_TOPIC_JOIN_H #define LDA_DOC_WORD_TOPIC_JOIN_H #include "JoinComp.h" #include "Lambda.h" #include "LDADocWordTopicAssignment.h" #include "LDA/LDATopicWordProb.h" #include "LambdaCreationFunctions.h" #include "LDADocument.h" #include "IntDoubleVectorPair.h" #include "PDBVector.h" #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> #include <random> #include <gsl/gsl_vector.h> #include <algorithm> #include <iostream> #include <math.h> /* This class implements the join between documents, doc-topic probability and word-topic probability */ using namespace pdb; class LDADocWordTopicJoin : public JoinComp<LDADocWordTopicAssignment, LDADocument, IntDoubleVectorPair, LDATopicWordProb> { private: Handle<Vector<char>> myMem; unsigned numWords; public: ENABLE_DEEP_COPY LDADocWordTopicJoin() {} LDADocWordTopicJoin(unsigned numWords) : numWords(numWords) { /* Set up the random number generator */ /* Set up the gsl_rng *src */ gsl_rng* src = gsl_rng_alloc(gsl_rng_mt19937); std::random_device rd; std::mt19937 gen(rd()); gsl_rng_set(src, gen()); /* Allocate space needed for myRand */ int spaceNeeded = sizeof(gsl_rng) + src->type->size; myMem = makeObject<Vector<char>>(spaceNeeded, spaceNeeded); /* Copy src over */ memcpy(myMem->c_ptr(), src, sizeof(gsl_rng)); memcpy(myMem->c_ptr() + sizeof(gsl_rng), src->state, src->type->size); gsl_rng_free(src); } /* Join condition */ Lambda<bool> getSelection(Handle<LDADocument> doc, Handle<IntDoubleVectorPair> DocTopicProb, Handle<LDATopicWordProb> WordTopicProb) override { return (makeLambdaFromMethod(doc, getDoc) == makeLambdaFromMethod(DocTopicProb, getUnsigned)) && (makeLambdaFromMethod(doc, getWord) == makeLambdaFromMethod(WordTopicProb, getKey)); } Lambda<Handle<LDADocWordTopicAssignment>> getProjection( Handle<LDADocument> doc, Handle<IntDoubleVectorPair> DocTopicProb, Handle<LDATopicWordProb> WordTopicProb) override { return makeLambda( doc, DocTopicProb, WordTopicProb, [&](Handle<LDADocument>& doc, Handle<IntDoubleVectorPair>& DocTopicProb, Handle<LDATopicWordProb>& WordTopicProb) { int size = (DocTopicProb->getVector()).size(); /* Compute the posterior probailities of the word coming from each topic */ double* myProb = new double[size]; double* topicProbs = DocTopicProb->getVector().c_ptr(); double* wordProbs = WordTopicProb->getVector().c_ptr(); for (int i = 0; i < size; ++i) { myProb[i] = topicProbs[i] * wordProbs[i]; } unsigned* topics = new unsigned[size]{0}; /* Sample the topics (multinomial sampling) */ gsl_rng* rng = getRng(); unsigned counts = doc->getCount(); double* random_values = new double[counts]; double sum = 0.0; for (int i = 0; i < size; ++i) { sum += myProb[i]; } for (int i = 0; i < counts; ++i) { random_values[i] = gsl_rng_uniform(rng) * sum; } std::sort(random_values, random_values + counts); int j = 0; double accumuProb = 0.0; for (int i = 0; i < size; i++) { accumuProb += myProb[i]; while ((j < counts) && (random_values[j] < accumuProb)) { topics[i]++; j++; } } /* Get the container for the return value */ Handle<LDADocWordTopicAssignment> retVal = makeObject<LDADocWordTopicAssignment>(); retVal->setup(); LDADocWordTopicAssignment& myGuy = *retVal; unsigned myDoc = doc->getDoc(); unsigned myWord = doc->getWord(); /* Create the doc assignment and topic assignment from the sampled topics, and put them in the return value */ for (int i = 0; i < size; ++i) { if (topics[i] != 0) { Handle<DocAssignment> whichDoc = makeObject<DocAssignment>(size, myDoc, i, topics[i]); Handle<TopicAssignment> whichTopic = makeObject<TopicAssignment>(numWords, i, myWord, topics[i]); myGuy.push_back(whichDoc); myGuy.push_back(whichTopic); } } delete[] myProb; delete[] topics; delete[] random_values; return retVal; }); } /* Get the GSL RNG from myMem */ gsl_rng* getRng() { gsl_rng* dst = (gsl_rng*)myMem->c_ptr(); dst->state = (void*)(myMem->c_ptr() + sizeof(gsl_rng)); dst->type = gsl_rng_mt19937; return dst; } }; #endif
{ "alphanum_fraction": 0.4967503693, "avg_line_length": 39.3604651163, "ext": "h", "hexsha": "6a9a1b7b3a7d058d612d4f3413b7e1d87fa5992e", "lang": "C", "max_forks_count": 13, "max_forks_repo_forks_event_max_datetime": "2020-08-03T00:58:24.000Z", "max_forks_repo_forks_event_min_datetime": "2018-06-14T03:39:14.000Z", "max_forks_repo_head_hexsha": "395b5ebd48c2c1b14a56bf24aeea726b36559074", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "dimitrijejankov/pdb", "max_forks_repo_path": "pdb/src/sharedLibraries/headers/LDA/LDADocWordTopicJoin.h", "max_issues_count": 4, "max_issues_repo_head_hexsha": "395b5ebd48c2c1b14a56bf24aeea726b36559074", "max_issues_repo_issues_event_max_datetime": "2018-11-01T15:36:07.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-03T21:50:14.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "dimitrijejankov/pdb", "max_issues_repo_path": "pdb/src/sharedLibraries/headers/LDA/LDADocWordTopicJoin.h", "max_line_length": 126, "max_stars_count": 29, "max_stars_repo_head_hexsha": "395b5ebd48c2c1b14a56bf24aeea726b36559074", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "dimitrijejankov/pdb", "max_stars_repo_path": "pdb/src/sharedLibraries/headers/LDA/LDADocWordTopicJoin.h", "max_stars_repo_stars_event_max_datetime": "2021-04-27T02:45:12.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-14T03:19:32.000Z", "num_tokens": 1364, "size": 6770 }
#pragma once #include <cuda/runtime_api.hpp> #include <gsl-lite/gsl-lite.hpp> #include <cub/cub.cuh> #include <thrustshift/not-a-vector.h> namespace thrustshift { namespace async { template <class ValuesInRange, class ValuesOutRange, class ScanOp, class MemoryResource> void inclusive_scan(cuda::stream_t& stream, ValuesInRange&& values_in, ValuesOutRange&& values_out, ScanOp scan_op, MemoryResource& delayed_memory_resource) { const std::size_t N = values_in.size(); gsl_Expects(values_out.size() == N); size_t tmp_bytes_size = 0; void* tmp_ptr = nullptr; auto exec = [&] { cuda::throw_if_error(cub::DeviceScan::InclusiveScan(tmp_ptr, tmp_bytes_size, values_in.data(), values_out.data(), scan_op, N, stream.handle())); }; exec(); auto tmp = make_not_a_vector<uint8_t>(tmp_bytes_size, delayed_memory_resource); tmp_ptr = tmp.to_span().data(); exec(); } } // namespace async } // namespace thrustshift
{ "alphanum_fraction": 0.5043923865, "avg_line_length": 26.7843137255, "ext": "h", "hexsha": "1f842c15dfc5b7ab9b649436b9a0e2d7bf0a6c6b", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "763805f862e3121374286c927dd6949960bffb84", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pauleonix/thrustshift", "max_forks_repo_path": "include/thrustshift/scan.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "763805f862e3121374286c927dd6949960bffb84", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pauleonix/thrustshift", "max_issues_repo_path": "include/thrustshift/scan.h", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "763805f862e3121374286c927dd6949960bffb84", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pauleonix/thrustshift", "max_stars_repo_path": "include/thrustshift/scan.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 249, "size": 1366 }
/* ** Read input data into array ** ** G.Lohmann, MPI-KYB, 2018 */ #include <viaio/Vlib.h> #include <viaio/VImage.h> #include <viaio/mu.h> #include <viaio/option.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_blas.h> #include <gsl/gsl_math.h> /* ** get global mean regressor */ void GlobalMean(gsl_matrix *Data,gsl_matrix *covariates,int column) { int i=0,j=0; int nt = Data->size2; double sum=0,nx=(double)Data->size1; for (i=0; i<nt; i++) { for (j=0; j<Data->size1; j++) { sum += gsl_matrix_get(Data,j,i); } gsl_matrix_set(covariates,i,column,sum/nx); } /* normalize */ double u=0,s1=0,s2=0,mx=(double)Data->size2; for (i=0; i<nt; i++) { u = gsl_matrix_get(covariates,i,column); s1 += u; s2 += u*u; } double mean = s1/mx; double var = (s2 - mx * mean * mean) / (mx - 1.0); double sd = sqrt(var); for (i=0; i<nt; i++) { u = gsl_matrix_get(covariates,i,column); gsl_matrix_set(covariates,i,column,(u-mean/sd)); } } /* normalize time courses */ void VRowNormalize(gsl_matrix *Data) { size_t i,j; double u=0,s1=0,s2=0,mean=0,sd=0; double nx=(double)Data->size2; for (i=0; i<Data->size1; i++) { s1 = s2 = 0; for (j=0; j<Data->size2; j++) { u = gsl_matrix_get(Data,i,j); s1 += u; s2 += u*u; } mean = s1/nx; sd = sqrt((s2 - nx * mean * mean) / (nx - 1.0)); for (j=0; j<Data->size2; j++) { u = gsl_matrix_get(Data,i,j); gsl_matrix_set(Data,i,j,(u-mean)/sd); } } } /* get timing information */ void VGetTimeInfos(VAttrList *list,int nlists,double *mtr,float *run_duration) { VImage src=NULL; VAttrListPosn posn; int k,ntimesteps=0; VLong itr=0; double tr=-1.0; int ntt=0; for (k=0; k<nlists; k++) { ntt = 0; for (VFirstAttr (list[k], & posn); VAttrExists (& posn); VNextAttr (& posn)) { if (VGetAttrRepn (& posn) != VImageRepn) continue; VGetAttrValue (& posn, NULL,VImageRepn, & src); if (tr < 0) { if (VGetAttr(VImageAttrList(src),"repetition_time",NULL,VLongRepn,&itr) != VAttrFound) VError(" TR info missing in header"); tr = (double) itr / 1000.0; } ntt = VImageNBands(src); run_duration[k] = tr*(float)ntt; } ntimesteps += ntt; } if (tr < 0) VError(" TR info missing"); *mtr = tr; } /* read data block */ gsl_matrix *VReadImageData(VAttrList *list,int nlists) { VAttrListPosn posn; int i=0,k,ntt=0,slice,row,col,nrows=0,ncols=0,ntimesteps=0; double u=0,s1=0,s2=0,nx=0,sd=0,mean=0,tiny=1.0e-8; int nslices = VAttrListNumImages(list[0]); /* alloc src image */ VImage **src = (VImage **) VCalloc(nlists,sizeof(VImage *)); int *nt = (int *) VCalloc(nlists,sizeof(int)); for (k=0; k<nlists; k++) { src[k] = (VImage *) VCalloc(nslices,sizeof(VImage)); i = 0; for (VFirstAttr (list[k], & posn); VAttrExists (& posn); VNextAttr (& posn)) { if (VGetAttrRepn (& posn) != VImageRepn) continue; if (i >= nslices) VError(" inconsistent number of slices, %d %d %d",k,i,nslices); VGetAttrValue (& posn, NULL,VImageRepn, & src[k][i]); i++; } } /* get image dimensions */ nrows = VImageNRows(src[0][0]); ncols = VImageNColumns(src[0][0]); ntimesteps = 0; for (k=0; k<nlists; k++) { ntt = VImageNBands(src[k][0]); ntimesteps += ntt; nt[k] = ntt; if (nrows != VImageNRows(src[k][0])) VError(" inconsistent number of rows "); if (ncols != VImageNColumns(src[k][0])) VError(" inconsistent number of columns "); } /* number of nonzero voxels */ size_t nvox=0; for (slice=0; slice<nslices; slice++) { for (row=0; row<nrows; row++) { for (col=0; col<ncols; col++) { u = VGetPixel(src[0][slice],0,row,col); if (gsl_isnan(u) || gsl_isinf(u)) continue; if (fabs(u) < TINY) continue; nvox++; } } } /* alloc new data struct */ gsl_matrix *Data = gsl_matrix_calloc(nvox,ntimesteps); if (!Data) VError(" error allocating Data"); /* fill map and data */ for (k=0; k<nlists; k++) { ntt = 0; for (i=0; i<k; i++) ntt += nt[i]; nvox=0; for (slice=0; slice<nslices; slice++) { for (row=0; row<nrows; row++) { for (col=0; col<ncols; col++) { u = VGetPixel(src[0][slice],0,row,col); if (gsl_isnan(u) || gsl_isinf(u)) continue; if (fabs(u) < TINY) continue; s1=s2=nx=0; for (i=0; i<nt[k]; i++) { u = VGetPixel(src[k][slice],i,row,col); s1 += u; s2 += u*u; nx++; } mean = s1/nx; sd = sqrt((s2 - nx * mean * mean) / (nx - 1.0)); if (sd < tiny) { u = 0.0; for (i=0; i<nt[k]; i++) { gsl_matrix_set(Data,nvox,ntt+i,u); } } else { for (i=0; i<nt[k]; i++) { u = VGetPixel(src[k][slice],i,row,col); u = (u-mean)/sd; gsl_matrix_set(Data,nvox,ntt+i,u); } } nvox++; } } } } VFree(nt); return Data; } /* get map of voxel addresses */ VImage VoxelMap(VAttrList list) { VAttrListPosn posn; int i=0,slice,row,col,nrows=0,ncols=0; int nslices = VAttrListNumImages(list); /* alloc src image */ i = nrows = ncols = 0; VImage *src = (VImage *) VCalloc(nslices,sizeof(VImage)); i = 0; for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) { if (VGetAttrRepn (& posn) != VImageRepn) continue; if (i >= nslices) VError(" inconsistent number of slices, %d %d",i,nslices); VGetAttrValue (& posn, NULL,VImageRepn, & src[i]); if (VImageNRows(src[i]) > nrows) nrows = VImageNRows(src[i]); if (VImageNColumns(src[i]) > ncols) ncols = VImageNColumns(src[i]); i++; } /* number of nonzero voxels */ double u=0; size_t nvox=0; for (slice=0; slice<nslices; slice++) { for (row=0; row<nrows; row++) { for (col=0; col<ncols; col++) { u = VGetPixel(src[slice],0,row,col); if (fabs(u) < TINY) continue; nvox++; } } } if (nvox < 1) VError(" No non-zero voxels in input image"); /* voxel addresses */ VImage map = VCreateImage(1,4,nvox,VShortRepn); if (map == NULL) VError(" error allocating addr map"); VFillImage(map,VAllBands,0); VCopyImageAttrs (src[0],map); VSetAttr(VImageAttrList(map),"nvoxels",NULL,VLongRepn,(VLong)nvox); VSetAttr(VImageAttrList(map),"nslices",NULL,VLongRepn,(VLong)nslices); VSetAttr(VImageAttrList(map),"nrows",NULL,VLongRepn,(VLong)nrows); VSetAttr(VImageAttrList(map),"ncols",NULL,VLongRepn,(VLong)ncols); VPixel(map,0,3,0,VShort) = nslices; VPixel(map,0,3,1,VShort) = nrows; VPixel(map,0,3,2,VShort) = ncols; /* fill map */ nvox=0; for (slice=0; slice<nslices; slice++) { for (row=0; row<nrows; row++) { for (col=0; col<ncols; col++) { u = VGetPixel(src[slice],0,row,col); if (fabs(u) < TINY) continue; VPixel(map,0,0,nvox,VShort) = slice; VPixel(map,0,1,nvox,VShort) = row; VPixel(map,0,2,nvox,VShort) = col; nvox++; } } } return map; }
{ "alphanum_fraction": 0.587949743, "avg_line_length": 25.1039426523, "ext": "c", "hexsha": "80e285b7e08a1aa5d78a7ecf7c52559acf32f9ed", "lang": "C", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2022-03-22T08:05:46.000Z", "max_forks_repo_forks_event_min_datetime": "2017-09-29T10:33:53.000Z", "max_forks_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "zrajna/lipsia", "max_forks_repo_path": "src/stats/vlisa_prewhitening/ReadData.c", "max_issues_count": 7, "max_issues_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014", "max_issues_repo_issues_event_max_datetime": "2022-02-16T13:42:05.000Z", "max_issues_repo_issues_event_min_datetime": "2019-11-12T15:47:56.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "zrajna/lipsia", "max_issues_repo_path": "src/stats/vlisa_prewhitening/ReadData.c", "max_line_length": 88, "max_stars_count": 17, "max_stars_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "zrajna/lipsia", "max_stars_repo_path": "src/stats/vlisa_prewhitening/ReadData.c", "max_stars_repo_stars_event_max_datetime": "2022-03-18T10:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2017-04-10T16:33:42.000Z", "num_tokens": 2511, "size": 7004 }
#ifndef VKST_PLAT_FS_NOTIFY_LINUX_H #define VKST_PLAT_FS_NOTIFY_LINUX_H #ifndef VKST_PLAT_FS_NOTIFY_H #error "Include fs_notify.h only" #endif #include "fs_notify.h" #include <gsl.h> #include <vector> namespace plat { class fs_notify final : public impl::fs_notify<fs_notify> { public: private: //std::vector<gsl::unique_ptr<watch>> _watches; watch_id do_add(plat::filesystem::path path, impl::fs_notify<fs_notify>::notify_delegate delegate, bool recursive, std::error_code& ec) noexcept; void do_remove(watch_id id) noexcept; void do_tick() noexcept; friend class impl::fs_notify<fs_notify>; }; // class fs_notify } // namespace plat #endif // VKST_PLAT_FS_NOTIFY_LINUX_H
{ "alphanum_fraction": 0.7277701778, "avg_line_length": 20.8857142857, "ext": "h", "hexsha": "306d95f8a7104ae4e77fc02d8b1d4ee58ebccc53", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "5f1210ef8aeecdd2bbc3904b0cc4dd09892f239c", "max_forks_repo_licenses": [ "Zlib" ], "max_forks_repo_name": "wesleygriffin/vkst", "max_forks_repo_path": "src/plat/fs_notify_linux.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "5f1210ef8aeecdd2bbc3904b0cc4dd09892f239c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Zlib" ], "max_issues_repo_name": "wesleygriffin/vkst", "max_issues_repo_path": "src/plat/fs_notify_linux.h", "max_line_length": 71, "max_stars_count": null, "max_stars_repo_head_hexsha": "5f1210ef8aeecdd2bbc3904b0cc4dd09892f239c", "max_stars_repo_licenses": [ "Zlib" ], "max_stars_repo_name": "wesleygriffin/vkst", "max_stars_repo_path": "src/plat/fs_notify_linux.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 184, "size": 731 }
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> /* Adapted from C code from Darren Wilkinson's blog https://darrenjw.wordpress.com/2011/07/16/gibbs-sampler-in-various-languages-revisited/ To build: gcc -O3 gibbs_gsl.c -I/usr/local/include -L/usr/local/lib -lgsl -lgslcblas -lm -o gibbs_gsl To run: time ./gibbs_gsl */ /* Arrays xa and ya are passed by reference */ void gibbs(int N, int thin, double **xa, double **ya) { int i,j; gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937); double x=0; double y=0; for (i=0;i<N;i++) { for (j=0;j<thin;j++) { x=gsl_ran_gamma(r,3.0,1.0/(y*y+4)); y=1.0/(x+1)+gsl_ran_gaussian(r,1.0/sqrt(2*x+2)); } (*xa)[i]=x; /* Note how the arrays are dereferenced */ (*ya)[i]=y; } free(r); } int main() { int N=50000; int thin=1000; double *xa,*ya; xa = (double *)malloc(sizeof(double)*N); ya = (double *)malloc(sizeof(double)*N); gibbs(N,thin,&xa,&ya); return(0); }
{ "alphanum_fraction": 0.634194831, "avg_line_length": 22.8636363636, "ext": "c", "hexsha": "1f4eb5b8453e182d02039ba41b4d25208404b7e9", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-12T00:32:02.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-12T00:32:02.000Z", "max_forks_repo_head_hexsha": "2fc40a1a28eef777c2958b6a58ea3e30c9ac8505", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ruqianl/distributions", "max_forks_repo_path": "examples/gibbs_gsl.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "2fc40a1a28eef777c2958b6a58ea3e30c9ac8505", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ruqianl/distributions", "max_issues_repo_path": "examples/gibbs_gsl.c", "max_line_length": 91, "max_stars_count": 6, "max_stars_repo_head_hexsha": "2fc40a1a28eef777c2958b6a58ea3e30c9ac8505", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ruqianl/distributions", "max_stars_repo_path": "examples/gibbs_gsl.c", "max_stars_repo_stars_event_max_datetime": "2020-11-03T04:58:11.000Z", "max_stars_repo_stars_event_min_datetime": "2016-08-16T15:50:22.000Z", "num_tokens": 363, "size": 1006 }
#include <stdio.h> #include <gsl/gsl_math.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_odeiv2.h> // y' = exp(x) // https://www.wolframalpha.com/input/?i=y%27+%3D+2y+%2B+x%2C+y%280%29+%3D+1%2C+y%281%29 // https://www.wolframalpha.com/input/?i=1%2F4+*+%285+*+e%5E2+-+3%29 int odefunc (double x, const double y[], double f[], void *params) { // f[0] = x+2*y[0]; // pow(): 멱급수(a, b) = a^b (a의 b승) // math.h에 있으며 pow를 활용하기 위해서는 -lm 옵션이 추가로 필요합니다. // GSL 라이브러리를 활용하기 위해선 -lgsl 옵션이 필요합니다. f[0] = pow(M_E, x); return GSL_SUCCESS; } int * jac; int main(void) { int dim = 1; // 미방을 풀기 위한 데이터 타입 gsl_odeiv2_system sys = {odefunc, NULL, dim, NULL}; // 드라이버는 미방을 쉽게 풀 수 있도록 시간에 따른 변화, 제어, 스텝에 대한 래퍼 // gsl_odeiv2_step_rkf45는 룬게쿠타 4-5차를 의미함 // 다음 인자는 미분방정식의 시작지점 // 절대적인 에러 바운드와 상대적인 에러 바운드 gsl_odeiv2_driver * d = gsl_odeiv2_driver_alloc_y_new (&sys, gsl_odeiv2_step_rkf45, 1e-6, 1e-6, 0.0); int i; double x0 = 0.0, xf = 10.0; /* start and end of integration interval */ double x = x0; double y[1] = { 1 }; /* initial value */ double tmp = 0.0; for (i = 0; tmp <= xf; tmp += 0.1) { // for문을 포함하여 아래 한 줄을 통해 상황에 따라 // 간소화된 형태로 결과를 출력할 수도 있고 // 시간이 좀 더 오래걸리더라도 더 정확한 데이터를 산출할 수도 있음 double xi = x0 + tmp * (xf-x0) / xf; int status = gsl_odeiv2_driver_apply (d, &x, xi, y); if (status != GSL_SUCCESS) { printf ("error, return value=%d\n", status); break; } printf ("%.8e %.8e\n", x, y[0]); } gsl_odeiv2_driver_free (d); return 0; }
{ "alphanum_fraction": 0.5815115553, "avg_line_length": 26.6833333333, "ext": "c", "hexsha": "072a2d9a14265b879ac74dd230ba149b986e6d18", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-19T01:22:06.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-19T01:22:06.000Z", "max_forks_repo_head_hexsha": "245385b79807c25081dfe2014c72843226716f92", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "EDDI-RobotAcademy/E4DS-DSP-Basic-Mathematics", "max_forks_repo_path": "ch4/src/main/detail_yprime_exp_x.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "245385b79807c25081dfe2014c72843226716f92", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "EDDI-RobotAcademy/E4DS-DSP-Basic-Mathematics", "max_issues_repo_path": "ch4/src/main/detail_yprime_exp_x.c", "max_line_length": 105, "max_stars_count": 1, "max_stars_repo_head_hexsha": "245385b79807c25081dfe2014c72843226716f92", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "EDDI-RobotAcademy/E4DS-DSP-Basic-Mathematics", "max_stars_repo_path": "ch4/src/main/detail_yprime_exp_x.c", "max_stars_repo_stars_event_max_datetime": "2021-10-22T00:39:04.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-22T00:39:04.000Z", "num_tokens": 770, "size": 1601 }
/** * Subroutines for fitting functions to data. * Most of the functions are used for the * background determination. */ #include <gsl/gsl_sort.h> #include <gsl/gsl_statistics.h> #include <gsl/gsl_fit.h> #include <gsl/gsl_multifit.h> #include "spce_fitting.h" /** * Function: det_vector_polyN * A function using GSL fitting functions to fit a set x,y,w of n elements * such that an Nth degree polynomial is fitted to the x and y vectors * using the weights w. This function avoids NaN values in ys AND elements * with an associated weight that is zero. * * Parameters: * @param m - order of the fit * @param xs - double vector containing the x values * @param ys - double vector containing the y values * @param ws - double vector containing the weights associated with ys * @param n - number of points in xs,ys, and ws (must be greater than m!) * @param c - the vector with the fitted coefficients * @param cov - the covariance matrix * * Returns: * @return interp - vector with additional fitting information */ gsl_vector * det_vector_polyN (int m, const double *const xs, double *const ys, double *const ws, const int n, gsl_vector *c, gsl_matrix *cov) { int i, j, nn, ii; double chisq; gsl_matrix *X; gsl_vector *y, *w; double *tmp, *xmp; double median, xean; gsl_vector *interp; // allocate the return vector interp = gsl_vector_alloc(5); // allocate temporary vectors tmp = (double *) malloc (n * sizeof (double)); xmp = (double *) malloc (n * sizeof (double)); // fill weights and independent values // for the background pixels into the arrays nn = 0; for (i = 0; i < n; i++) { if (ws[i] > 0.0) { // tmp[nn] = ws[i]; tmp[nn] = 1.0/(ws[i]*ws[i]); xmp[nn] = xs[i]; nn++; } } // compute the median weight // to be used for all pixels gsl_sort( tmp, 1, m); median = gsl_stats_median_from_sorted_data(tmp, 1, nn); // determine the anchor point in the // independent variable xean = gsl_stats_mean (xmp, 1, nn); // check whether the desired // intepolation degree is feasible if (nn < m) { aXe_message (aXe_M_WARN4, __FILE__, __LINE__, "Not enough points (%d) found to perform the %d order fit. Doing %d order instead.\n", nn, m, nn); m = nn; } // allocate more temporary space X = gsl_matrix_alloc (nn, m); y = gsl_vector_alloc (nn); w = gsl_vector_alloc (nn); // c = gsl_vector_alloc (m); // cov = gsl_matrix_alloc (m, m); // transfer independent/dependent and weight // values from the background pixels to the // temporary arrays ii = 0; for (i = 0; i < n; i++) { if (ws[i] > 0.0) { // shift the x-values // and store them in the matrix for (j = 0; j < m; j++) { gsl_matrix_set (X, ii, j, pow (xs[i] - xean, j)); } gsl_vector_set (y, ii, ys[i]); gsl_vector_set (w, ii, median); ii++; } } // allocate space and do the fit; release the space gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (nn, m); gsl_multifit_wlinear (X, w, y, c, cov, &chisq, work); gsl_multifit_linear_free (work); // release memory gsl_matrix_free (X); gsl_vector_free (y); gsl_vector_free (w); // free the tmp-arrays free(tmp); free(xmp); // fill the mean x-value // and the order into the return vector gsl_vector_set(interp, 0, xean); gsl_vector_set(interp, 1, (double)m); return interp; } /** * Function: fill_polyN_interp * Evaluates a polynomial of any order and fills the * result plus the error, compute using the covariance * matrix, in vectors. * * Parameters: * @param xs - double vector containing the x values * @param ys - double vector containing the y values * @param yi - double vector containing the intermediate y-values * @param ws - double vector containing the weights associated with ys * @param n - number of points in xs,ys, and ws (must be greater than m!) * @param c - the vector with the fitted coefficients * @param cov - the covariance matrix * @param interp - additional fitting ifnormation * @param final - flagg to indicate final fit and * therefore a replacement */ void fill_polyN_interp(const double *const xs, double *const ys, double *const ws, double *yi, const int n, gsl_vector *coeffs, gsl_matrix *cov, gsl_vector *interp, const int final) { int i, j, m; double xf, yf, sq_yf_err, yf_err; double xean; // get the mean x-value and // polynomial order from the vector xean = gsl_vector_get(interp, 0); m = (int)gsl_vector_get(interp, 1); // put the interpolated values // for object pixels back into the // inut arrays for (i = 0; i < n; i++) { // compute and store interpolated // values an corresponding error xf = xs[i]-xean; yf = 0.0; yf_err = 0.0; sq_yf_err = 0.0; // compute the polynimials for (j = 0; j < m; j++) { // first compute the y-value yf += gsl_vector_get(coeffs,j)*pow (xf, j); // compute the associated error sq_yf_err += gsl_matrix_get(cov,j,j) * pow (xf, j) * pow (xf, j); } // put the intepolated value in the intermediate vector yi[i] = yf; // if requested, fill the interpolated values // into the origina; arrays if (final && ws[i] == 0.0) { ys[i] = yf; ws[i] = sqrt(sq_yf_err); } } } /** * Function: comp_vector_average * The function provides the computation of the average of * the y-values and store that average in temporary * or the original y-vector. * * @param xs - absissa * @param ys - value at xs[] * @param ws - weight in ys[] * @param yi - temprary y-values * @param n - number of points in xs, ys, ws * @param final - flagg to store to temp (0) or final (1) vectors */ void comp_vector_average (const double *xs, double *ys, double *ws, double *yi, const int n, const int final) { double ave, std; //int i, m; det_vector_average (xs, ys, ws, n, &ave, &std); fill_const_value(ys, ws, yi, n, ave, std, final); } /** * Function: comp_vector_median * The function provides the computation of the median of * the y-values and store that median in temporary * or the original y-vector * * @param xs - absissa * @param ys - value at xs[] * @param ws - weight in ys[] * @param yi - temprary y-values * @param n - number of points in xs, ys, ws * @param final - flagg to store to temp (0) or final (1) vectors */ void comp_vector_median (const double *xs, double *ys, double *ws, double *yi, const int n, const int final) { double med, std; det_vector_median (xs, ys, ws, n, &med, &std); fill_const_value(ys, ws, yi, n, med, std, final); } /** * Function: comp_vector_linear * The function fits a linear function to the y-values * and fills the linear inteprolated values in a temporary * vector and, if requested, in the original vector as well. * * @param xs - absissa * @param ys - value at xs[] * @param ws - weight in ys[] * @param yi - temprary y-values * @param n - number of points in xs, ys, ws * @param final - flagg to store to temp (0) or final (1) vectors */ void comp_vector_linear (const double *xs, double *ys, double *ws, double *yi, const int n, const int final) { gsl_vector *interp; // make a weighted linear fit interp = det_vector_linear(xs, ys, ws, n, 1); // make the interpolations, // using the linear fit fill_linear_interp(xs, ys, ws, yi, n, interp, final); gsl_vector_free(interp); } /** * Function: comp_vector_polyN * The function fits a polynomial function to the y-values * and fills the evaluated polynomial values in a temporary * vector and, if requested, in the original vector as well. * * @param xs - absissa * @param ys - value at xs[] * @param ws - weight in ys[] * @param yi - temprary y-values * @param n - number of points in xs, ys, ws * @param final - flagg to store to temp (0) or final (1) vectors */ void comp_vector_polyN (const int m, const double *xs, double *ys, double *ws, double *yi, const int n, const int final) { gsl_vector *interp, *coeffs; gsl_matrix *cov; coeffs = gsl_vector_alloc(m); cov = gsl_matrix_alloc(m,m); interp = det_vector_polyN (m, xs, ys, ws, n, coeffs, cov); fill_polyN_interp(xs, ys, ws, yi, n, coeffs, cov, interp, final); gsl_vector_free(interp); gsl_vector_free(coeffs); gsl_matrix_free(cov); } /** * Function: det_vector_linear * Performs a linear fit of the xs, ys, and ws arrays. * Ignores NaN values. Fitted values are returned in * ys and errors in ws. * * Parameters: * @param xs - absissa * @param ys - value at xs[] * @param ws - error in ys[] * @param n - number of points in xs, ys, ws * @param weight - make weighted fit (=1) or not (=0) * * Returns: * @return ret - the covariance values */ gsl_vector * det_vector_linear(const double *xs, double *ys, double *ws, const int n, const int weight) { int i, m; double c0, c1, cov00, cov01, cov11, chisq; double *xx, *yy, *ww, *tmp, *xmp; double median, xean; //double xf, yf, yf_err; gsl_vector *ret; ret = gsl_vector_alloc(10); // allocate space for temporary vectors tmp = (double *) malloc (n * sizeof (double)); xmp = (double *) malloc (n * sizeof (double)); // fill the temporary vectors // with background values and weights m = 0; for (i = 0; i < n; i++) { if (ws[i] > 0.0) { // tmp[m] = ws[i]; tmp[m] = 1.0/(ws[i]*ws[i]); xmp[m] = xs[i]; m++; } } // determine the median weight which // is used for all data gsl_sort( tmp, 1, m); median = gsl_stats_median_from_sorted_data(tmp, 1, m); // determine the mean in the independent variable xean = gsl_stats_mean (xmp, 1, m); // allocate more temporary vectors xx = (double *) malloc (m * sizeof (double)); yy = (double *) malloc (m * sizeof (double)); ww = (double *) malloc (m * sizeof (double)); // fill the temporary vectors with // background independent/dependent variables // plus the weight m = 0; for (i = 0; i < n; i++) { if (ws[i] > 0.0) { xx[m] = xs[i]-xean; yy[m] = ys[i]; ww[m] = median; m++; } } // check for weighted fit if (weight) // doe the linear fit gsl_fit_wlinear (xx, 1, ww, 1, yy, 1, m, &c0, &c1, &cov00, &cov01, &cov11, &chisq); else // does the linear fit gsl_fit_linear (xx, 1, yy, 1, m, &c0, &c1, &cov00, &cov01, &cov11, &chisq); gsl_vector_set(ret, 0, xean); gsl_vector_set(ret, 1, c0); gsl_vector_set(ret, 2, c1); gsl_vector_set(ret, 3, cov00); gsl_vector_set(ret, 4, cov01); gsl_vector_set(ret, 5, cov11); gsl_vector_set(ret, 6, chisq); // free the arrays free(tmp); free(xmp); free(xx); free(yy); free(ww); return ret; } /** * Function: fill_linear_interp * The function computes and stores linear interpolated values * in one or several output vectors. * * Parameters: * @param xs - double vector containing the x values * @param ys - double vector containing the y values * @param ws - double vector containing the weights associated with ys * @param yi - double vector containing the intermediate y-values * @param n - number of points in xs,ys, and ws (must be greater than m!) * @param interp - vector with the fitted values * @param final - flagg to indicate final fit and * therefore a replacement */ void fill_linear_interp(const double *const xs, double *const ys, double *const ws, double *yi, const int n, gsl_vector *interp, const int final) { double c0, c1, cov00, cov01, cov11, xean; double xf, yf, yf_err; int i; xean = gsl_vector_get(interp, 0); c0 = gsl_vector_get(interp, 1); c1 = gsl_vector_get(interp, 2); cov00 = gsl_vector_get(interp, 3); cov01 = gsl_vector_get(interp, 4); cov11 = gsl_vector_get(interp, 5); // determine the interpolated values // and store them in the input arrays for (i = 0; i < n; i++) { xf = xs[i]-xean; gsl_fit_linear_est (xf, c0, c1, cov00, cov01, cov11, &yf, &yf_err); yi[i] = yf; // for object pixels, // fill in the interpolated values if (final && ws[i] == 0.0) { ys[i] = yf; ws[i] = yf_err; } } } /** * Function: det_vector_average * The function computes the average and the standard * deviation from the values in a vector * * @param xs - absissa * @param ys - value at xs[] * @param ws - weight in ys[] * @param n - number of points in xs, ys, ws * @param avg - the average * @param std - the standard deviation */ void det_vector_average (const double *xs, double *ys, double *ws, const int n, double *avg, double *std) { double *tmp, sum = 0.0; int nn = 0; int j; // count the number of // interpolation points nn = 0; for (j = 0; j < n; j++) { if (ws[j] != 0.0) nn++; } // allocate a tmp-array tmp = malloc (nn * sizeof (double)); // sum up all values in the // interpolation points, // and transfer the values to the // tmp-array nn = 0; for (j = 0; j < n; j++) { if (ws[j] != 0.0) { sum += ys[j]; tmp[nn] = ys[j]; nn++; } } // compute the average if (nn > 0) *avg = sum / (double)nn; // compute the standard deviation *std = gsl_stats_sd (tmp, 1, nn); } /** * Function: det_vector_median * The function computes the median and the standard * deviation from the values in a vector * * @param xs - absissa * @param ys - value at xs[] * @param ws - weight in ys[] * @param n - number of points in xs, ys, ws * @param med - the median * @param std - the standard deviation */ void det_vector_median (const double *xs, double *ys, double *ws, const int n, double *med, double *std) { double *tmp; int nn = 0; int j; // count the number of // interpolation points for (j = 0; j < n; j++) { if (ws[j] != 0.0) nn++; } // allocate a tmp-array tmp = malloc (nn * sizeof (double)); // transfer the values of the interpolation // points to the tmp-array nn = 0; for (j = 0; j < n; j++) { if (ws[j] != 0.0) { tmp[nn] = ys[j]; nn++; } } // sort the tmp array gsl_sort (tmp, 1, nn); // compute the median *med = gsl_stats_median_from_sorted_data (tmp, 1, nn); // compute the standard deviation *std = gsl_stats_sd (tmp, 1, nn); } /** * Function:fill_const_value * The function fills two constant values into * up to three vectors. * * @param ys - value at xs[] * @param ws - weight in ys[] * @param yi - value at xs[] * @param n - number of points in xs, ys, ws * @param cval - number of points in xs, ys, ws * @param stdev - number of points in xs, ys, ws * @param final - flagg which indicates which vectors to fill */ void fill_const_value(double *ys, double *ws, double *yi, const int n, double cval, double stdev, const int final) { int j; int m=0; // fill the constant value and the stdev // in the whole value and error // arrays, respectively for (j = 0; j < n; j++) { yi[j] = cval; if (final && ws[j] == 0.0) { ys[j] = cval; ws[j] = stdev; m++; } } }
{ "alphanum_fraction": 0.6230649148, "avg_line_length": 24.5984, "ext": "c", "hexsha": "3bc7c0812ccb66083ccd37836574c0ab4b200880", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f57de55daf77de21d5868ace08b69090778d5975", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "sosey/pyaxe", "max_forks_repo_path": "cextern/src/spce_fitting.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "f57de55daf77de21d5868ace08b69090778d5975", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "sosey/pyaxe", "max_issues_repo_path": "cextern/src/spce_fitting.c", "max_line_length": 92, "max_stars_count": null, "max_stars_repo_head_hexsha": "f57de55daf77de21d5868ace08b69090778d5975", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "sosey/pyaxe", "max_stars_repo_path": "cextern/src/spce_fitting.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4658, "size": 15374 }
/* specfunc/elementary.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Author: G. Jungman */ #include <config.h> #include <gsl/gsl_math.h> #include <gsl/gsl_errno.h> #include "gsl_sf_elementary.h" #include "error.h" #include "check.h" int gsl_sf_multiply_e(const double x, const double y, gsl_sf_result * result) { const double ax = fabs(x); const double ay = fabs(y); if(x == 0.0 || y == 0.0) { /* It is necessary to eliminate this immediately. */ result->val = 0.0; result->err = 0.0; return GSL_SUCCESS; } else if((ax <= 1.0 && ay >= 1.0) || (ay <= 1.0 && ax >= 1.0)) { /* Straddling 1.0 is always safe. */ result->val = x*y; result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val); return GSL_SUCCESS; } else { const double f = 1.0 - 2.0 * GSL_DBL_EPSILON; const double min = GSL_MIN_DBL(fabs(x), fabs(y)); const double max = GSL_MAX_DBL(fabs(x), fabs(y)); if(max < 0.9 * GSL_SQRT_DBL_MAX || min < (f * DBL_MAX)/max) { result->val = GSL_COERCE_DBL(x*y); result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val); CHECK_UNDERFLOW(result); return GSL_SUCCESS; } else { OVERFLOW_ERROR(result); } } } int gsl_sf_multiply_err_e(const double x, const double dx, const double y, const double dy, gsl_sf_result * result) { int status = gsl_sf_multiply_e(x, y, result); result->err += fabs(dx*y) + fabs(dy*x); return status; } /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/ #include "eval.h" double gsl_sf_multiply(const double x, const double y) { EVAL_RESULT(gsl_sf_multiply_e(x, y, &result)); }
{ "alphanum_fraction": 0.6379310345, "avg_line_length": 28, "ext": "c", "hexsha": "6491ce14fbb0d9513e80e4e30ceb705663d70a22", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ICML14MoMCompare/spectral-learn", "max_forks_repo_path": "code/em/treba/gsl-1.0/specfunc/elementary.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ICML14MoMCompare/spectral-learn", "max_issues_repo_path": "code/em/treba/gsl-1.0/specfunc/elementary.c", "max_line_length": 75, "max_stars_count": 14, "max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ICML14MoMCompare/spectral-learn", "max_stars_repo_path": "code/em/treba/gsl-1.0/specfunc/elementary.c", "max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z", "num_tokens": 702, "size": 2436 }
/** * \author Sylvain Marsat, University of Maryland - NASA GSFC * * \brief C header for functions windowing and computing FFT/IFFT of time/frequency series. * */ #ifndef __GENERATETDIFD_H__ #define __GENERATETDIFD_H__ 1 #ifdef __GNUC__ #define UNUSED __attribute__ ((unused)) #else #define UNUSED #endif #define _XOPEN_SOURCE 500 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <complex.h> #include <time.h> #include <unistd.h> #include <getopt.h> #include <stdbool.h> #include <string.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_bspline.h> #include <gsl/gsl_blas.h> #include <gsl/gsl_min.h> #include <gsl/gsl_spline.h> #include <gsl/gsl_complex.h> #include "constants.h" #include "struct.h" #include "waveform.h" #include "fft.h" #include "LISAgeometry.h" #include "LISAFDresponse.h" #include "LISAnoise.h" /********************************** Structures ******************************************/ typedef enum GenTDIFDtag { TDIhlm, TDIFD, TDIFFT, h22FFT, yslrFFT } GenTDIFDtag; /* Parameters for the generation of a LISA waveform (in the form of a list of modes) */ typedef struct tagGenTDIFDparams { double tRef; /* reference time (s) - GPS time at the frequency representing coalescence */ double torb; /* reference orbital time entering orbital response (s) */ double phiRef; /* reference phase (rad) - phase at the frequency representing coalescence (or at fRef if specified) */ double fRef; /* reference frequency at which phiRef is set (Hz, default 0 which is interpreted as Mf=0.14) */ double m1; /* mass of companion 1 (solar masses, default 2e6) */ double m2; /* mass of companion 2 (solar masses, default 1e6) */ double distance; /* distance of source (Mpc, default 1e3) */ double inclination; /* inclination of source (rad, default pi/3) */ double lambda; /* first angle for the position in the sky (rad, default 0) */ double beta; /* second angle for the position in the sky (rad, default 0) */ double polarization; /* polarization angle (rad, default 0) */ int nbmode; /* number of modes to generate (starting with 22) - defaults to 5 (all modes) */ double minf; /* Minimal frequency (Hz, default=0) - when set to 0, use the lowest frequency where the detector noise model is trusted __LISASimFD_Noise_fLow (set somewhat arbitrarily)*/ double maxf; /* Maximal frequency (Hz, default=0) - when set to 0, use the highest frequency where the detector noise model is trusted __LISASimFD_Noise_fHigh (set somewhat arbitrarily)*/ double deltatobs; /* Observation duration (years, default=2) */ int tagextpn; /* Tag to allow PN extension of the waveform at low frequencies (default=1) */ double Mfmatch; /* When PN extension allowed, geometric matching frequency: will use ROM above this value. If <=0, use ROM down to the lowest covered frequency (default=0.) */ int setphiRefatfRef; /* Flag for adjusting the FD phase at phiRef at the given fRef, which depends also on tRef - if false, treat phiRef simply as an orbital phase shift (minus an observer phase shift) (default=1) */ double deltaf; /* When generating frequency series from the mode contributions, deltaf for the output (0 to set automatically at 1/2*1/(2T)) */ double twindowbeg; /* When generating frequency series from file by FFT, twindowbeg (0 to set automatically at 0.05*duration) */ double twindowend; /* When generating frequency series from file by FFT, twindowend (0 to set automatically at 0.01*duration) */ int tagh22fromfile; /* Tag choosing wether to load h22 FD downsampled Amp/Phase from file (default 0) */ int tagtdi; /* Tag selecting the desired output format */ int frozenLISA; /* Freeze the orbital configuration to the time of peak of the injection (default 0) */ ResponseApproxtag responseapprox; /* Approximation in the GAB and orb response - choices are full (full response, default), lowfL (keep orbital delay frequency-dependence but simplify constellation response) and lowf (simplify constellation and orbital response) - WARNING : at the moment noises are not consistent, and TDI combinations from the GAB are unchanged */ int taggenwave; /* Tag selecting the desired output format */ int restorescaledfactor; /* If 1, restore the factors that were scaled out of TDI observables */ int FFTfromtdfile; /* Option for loading time series and FFTing (default: false) */ int nsamplesinfile; /* Number of lines of input file */ int binaryin; /* Tag for loading the data in gsl binary form instead of text (default false) */ int binaryout; /* Tag for outputting the data in gsl binary form instead of text (default false) */ char indir[256]; /* Path for the input directory */ char infile[256]; /* Path for the input file */ char outdir[256]; /* Path for the output directory */ char outfileprefix[256]; /* Path for the output file */ } GenTDIFDparams; #if 0 { /* so that editors will match succeeding brace */ #elif defined(__cplusplus) } #endif #endif /* _GENERATETDIFD_H */
{ "alphanum_fraction": 0.6755646817, "avg_line_length": 52.5196078431, "ext": "h", "hexsha": "86c4f77b03fc7e84abdbfb3226054020f0d5f787", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-07-20T02:56:30.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-20T14:19:13.000Z", "max_forks_repo_head_hexsha": "a58d2e6c2b36c0f17b310b305b45d447afc04dec", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "JohnGBaker/flare", "max_forks_repo_path": "LISAsim/GenerateTDIFD.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "a58d2e6c2b36c0f17b310b305b45d447afc04dec", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "JohnGBaker/flare", "max_issues_repo_path": "LISAsim/GenerateTDIFD.h", "max_line_length": 371, "max_stars_count": 3, "max_stars_repo_head_hexsha": "a58d2e6c2b36c0f17b310b305b45d447afc04dec", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "JohnGBaker/flare", "max_stars_repo_path": "LISAsim/GenerateTDIFD.h", "max_stars_repo_stars_event_max_datetime": "2020-07-20T02:56:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-26T15:21:13.000Z", "num_tokens": 1318, "size": 5357 }
#pragma once #include <Babylon/JsRuntime.h> #include <napi/env.h> #include <gsl/gsl> #include <cassert> namespace Babylon { class NativeDataStream final : public Napi::ObjectWrap<NativeDataStream> { static constexpr auto JS_CLASS_NAME = "_NativeDataStream"; static constexpr auto JS_ENGINE_CONSTRUCTOR_NAME = "NativeDataStream"; static constexpr auto VALIDATION_ENABLED = false; enum class ValidationType : uint32_t { Uint32, Int32, Float32, Uint32Array, Int32Array, Float32Array, NativeData, Boolean, }; template<ValidationType T, typename ReaderT> static inline void Validate(ReaderT& reader) { if constexpr (VALIDATION_ENABLED) { uint32_t value{reader.template Read<uint32_t>()}; if (value != static_cast<uint32_t>(T)) { throw std::runtime_error{"Data stream validation error: data type mismatch."}; } } } public: class Reader final { public: Reader(const Reader&) = delete; Reader(Reader&&) = delete; Reader operator=(const Reader&) = delete; Reader operator=(const Reader&&) = delete; bool CanRead() const { assert(m_position <= static_cast<size_t>(m_buffer.size())); return m_position < static_cast<size_t>(m_buffer.size()); } uint32_t ReadUint32() { Validate<ValidationType::Uint32>(*this); return Read<uint32_t>(); } int32_t ReadInt32() { Validate<ValidationType::Int32>(*this); return Read<int32_t>(); } float ReadFloat32() { Validate<ValidationType::Float32>(*this); return Read<float>(); } gsl::span<uint32_t> ReadUint32Array() { Validate<ValidationType::Uint32Array>(*this); return ReadArray<uint32_t>(); } gsl::span<int32_t> ReadInt32Array() { Validate<ValidationType::Int32Array>(*this); return ReadArray<int32_t>(); } gsl::span<float> ReadFloat32Array() { Validate<ValidationType::Float32Array>(*this); return ReadArray<float>(); } template<typename T> T ReadNativeData() { Validate<ValidationType::NativeData>(*this); static_assert(sizeof(T) % 4 == 0); auto span = gsl::make_span(reinterpret_cast<uint32_t*>(m_buffer.data() + m_position), sizeof(T) / 4); m_position += sizeof(T) / 4; return *reinterpret_cast<T*>(span.data()); } template<typename T, class = typename std::enable_if<!std::is_pointer<T>::value>::type> auto ReadPointer() { return ReadNativeData<typename std::conditional<std::is_member_pointer<T>::value, T, T*>::type>(); } private: gsl::span<uint32_t> m_buffer{}; size_t m_position{0}; const gsl::final_action<std::function<void()>> m_scopeGuard; friend class NativeDataStream; template<typename CallableT> Reader(gsl::span<uint32_t> buffer, CallableT&& callable) : m_buffer{buffer} , m_scopeGuard{std::forward<CallableT>(callable)} { } template<typename T> T Read() { static_assert(sizeof(T) % 4 == 0); T t{*reinterpret_cast<T*>(m_buffer.data() + m_position)}; m_position += sizeof(T) / 4; return t; } template<typename T> gsl::span<T> ReadArray() { static_assert(sizeof(T) % 4 == 0); // The first 32 bit number is a length uint32_t length = Read<uint32_t>(); auto span = gsl::make_span<T>(reinterpret_cast<T*>(m_buffer.data() + m_position), length * (sizeof(T) / 4)); m_position += length; return span; } }; static void Initialize(Napi::Env env) { Napi::HandleScope scope{env}; if constexpr (VALIDATION_ENABLED) { Napi::Function func = DefineClass( env, JS_CLASS_NAME, { InstanceMethod("writeBuffer", &NativeDataStream::WriteBuffer), StaticValue("VALIDATION_ENABLED", Napi::Boolean::From(env, VALIDATION_ENABLED)), StaticValue("VALIDATION_UINT_32", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::Uint32))), StaticValue("VALIDATION_INT_32", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::Int32))), StaticValue("VALIDATION_FLOAT_32", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::Float32))), StaticValue("VALIDATION_UINT_32_ARRAY", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::Uint32Array))), StaticValue("VALIDATION_INT_32_ARRAY", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::Int32Array))), StaticValue("VALIDATION_FLOAT_32_ARRAY", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::Float32Array))), StaticValue("VALIDATION_NATIVE_DATA", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::NativeData))), StaticValue("VALIDATION_BOOLEAN", Napi::Number::From(env, static_cast<uint32_t>(ValidationType::Boolean))), }); JsRuntime::NativeObject::GetFromJavaScript(env).Set(JS_ENGINE_CONSTRUCTOR_NAME, func); } else { Napi::Function func = DefineClass( env, JS_CLASS_NAME, { InstanceMethod("writeBuffer", &NativeDataStream::WriteBuffer) }); JsRuntime::NativeObject::GetFromJavaScript(env).Set(JS_ENGINE_CONSTRUCTOR_NAME, func); } } NativeDataStream(const Napi::CallbackInfo& info) : Napi::ObjectWrap<NativeDataStream>(info) , m_requestFlushCallback{Napi::Persistent(info[0].As<Napi::Function>())} { } void WriteBuffer(const Napi::CallbackInfo& info) { assert(!m_locked); // Cannot write bytes while the stream is locked for reading. const auto& buffer = info[0].As<Napi::ArrayBuffer>(); const auto& length = info[1].ToNumber().Uint32Value(); auto span = gsl::make_span(reinterpret_cast<uint32_t*>(buffer.Data()), static_cast<ptrdiff_t>(length)); m_buffer.insert(m_buffer.end(), span.begin(), span.end()); } Reader GetReader() { assert(!m_locked); m_requestFlushCallback.Call({}); m_locked = true; return {m_buffer, [this]() { m_buffer.clear(); m_locked = false; }}; } private: std::vector<uint32_t> m_buffer{}; Napi::FunctionReference m_requestFlushCallback{}; bool m_locked{false}; }; }
{ "alphanum_fraction": 0.5281780751, "avg_line_length": 36.1488372093, "ext": "h", "hexsha": "da8010bed82cf02a62ce28d62733568bb56f8a76", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "18ea83ee51e4e5d8b1763cf8d9ef5b48b2f9bb0a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "SergioRZMasson/BabylonNative", "max_forks_repo_path": "Plugins/NativeEngine/Source/NativeDataStream.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "18ea83ee51e4e5d8b1763cf8d9ef5b48b2f9bb0a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "SergioRZMasson/BabylonNative", "max_issues_repo_path": "Plugins/NativeEngine/Source/NativeDataStream.h", "max_line_length": 143, "max_stars_count": null, "max_stars_repo_head_hexsha": "18ea83ee51e4e5d8b1763cf8d9ef5b48b2f9bb0a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "SergioRZMasson/BabylonNative", "max_stars_repo_path": "Plugins/NativeEngine/Source/NativeDataStream.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1564, "size": 7772 }
/* this program is in the public domain */ #include "bench-user.h" #include <math.h> #ifdef HAVE_GSL_GSL_VERSION_H #include <gsl/gsl_version.h> #endif static const char *mkvers(void) { #ifdef HAVE_GSL_GSL_VERSION_H return gsl_version; #else return "unknown" #endif } BEGIN_BENCH_DOC BENCH_DOC("name", "gsl-mixed-radix") BENCH_DOC("package", "GNU Scientific Library (GSL)") BENCH_DOC("author", "Brian Gough") BENCH_DOC("year", "2002") BENCH_DOC("url", "http://sources.redhat.com/gsl") BENCH_DOC("url-was-valid-on", "Thu Jul 26 07:48:45 EDT 2001") BENCH_DOC("copyright", "Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough\n" "\n" "This program is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" "the Free Software Foundation; either version 2 of the License, or (at\n" "your option) any later version.\n") BENCH_DOC("language", "C") BENCH_DOCF("version", mkvers) END_BENCH_DOC #ifdef BENCHFFT_SINGLE #include <gsl/gsl_fft_complex_float.h> #include <gsl/gsl_fft_real_float.h> #include <gsl/gsl_fft_halfcomplex_float.h> #define C(x) gsl_fft_complex_float_##x #define CWv(x) gsl_fft_complex_wavetable_float_##x #define CWk(x) gsl_fft_complex_workspace_float_##x #define R(x) gsl_fft_real_float_##x #define RWv(x) gsl_fft_real_wavetable_float_##x #define RWk(x) gsl_fft_real_workspace_float_##x #define H(x) gsl_fft_halfcomplex_float_##x #define HWv(x) gsl_fft_halfcomplex_wavetable_float_##x #else #include <gsl/gsl_fft_complex.h> #include <gsl/gsl_fft_real.h> #include <gsl/gsl_fft_halfcomplex.h> #define C(x) gsl_fft_complex_##x #define CWv(x) gsl_fft_complex_wavetable_##x #define CWk(x) gsl_fft_complex_workspace_##x #define R(x) gsl_fft_real_##x #define RWv(x) gsl_fft_real_wavetable_##x #define RWk(x) gsl_fft_real_workspace_##x #define H(x) gsl_fft_halfcomplex_##x #define HWv(x) gsl_fft_halfcomplex_wavetable_##x #endif int can_do(struct problem *p) { return (p->rank == 1 && problem_in_place(p)); } /* fftpack-style real transforms */ void copy_h2c(struct problem *p, bench_complex *out) { copy_h2c_1d_fftpack(p, out, -1.0); } void copy_c2h(struct problem *p, bench_complex *in) { copy_c2h_1d_fftpack(p, in, -1.0); } static void *Wv = 0, *Wk = 0; void setup(struct problem *p) { int n; BENCH_ASSERT(can_do(p)); n = p->n[0]; if (p->kind == PROBLEM_COMPLEX) { Wv = CWv(alloc)(n); Wk = CWk(alloc)(n); } else { if (p->sign == -1) Wv = RWv(alloc)(n); else Wv = HWv(alloc)(n); Wk = RWk(alloc)(n); } } void doit(int iter, struct problem *p) { int i; int n = p->n[0]; void *in = p->in; void *wv = Wv, *wk = Wk; if (p->kind == PROBLEM_COMPLEX) { if (p->sign == -1) { for (i = 0; i < iter; ++i) C(forward)(in, 1, n, wv, wk); } else { for (i = 0; i < iter; ++i) C(backward)(in, 1, n, wv, wk); } } else { if (p->sign == -1) { for (i = 0; i < iter; ++i) R(transform)(in, 1, n, wv, wk); } else { for (i = 0; i < iter; ++i) H(transform)(in, 1, n, wv, wk); } } } void done(struct problem *p) { UNUSED(p); if (p->kind == PROBLEM_COMPLEX) { CWv(free)(Wv); } else { if (p->sign == -1) RWv(free)(Wv); else HWv(free)(Wv); RWk(free)(Wk); } }
{ "alphanum_fraction": 0.6483353151, "avg_line_length": 24.0285714286, "ext": "c", "hexsha": "8f0f070b690b334c848c0f3a2e77f121d53c9141", "lang": "C", "max_forks_count": 9, "max_forks_repo_forks_event_max_datetime": "2022-01-26T11:50:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-06-02T08:44:13.000Z", "max_forks_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_forks_repo_licenses": [ "ImageMagick" ], "max_forks_repo_name": "mreineck/benchfft", "max_forks_repo_path": "benchees/gsl/doit.c", "max_issues_count": 5, "max_issues_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_issues_repo_issues_event_max_datetime": "2022-01-21T21:39:55.000Z", "max_issues_repo_issues_event_min_datetime": "2020-12-01T18:15:43.000Z", "max_issues_repo_licenses": [ "ImageMagick" ], "max_issues_repo_name": "mreineck/benchfft", "max_issues_repo_path": "benchees/gsl/doit.c", "max_line_length": 75, "max_stars_count": 11, "max_stars_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_stars_repo_licenses": [ "ImageMagick" ], "max_stars_repo_name": "mreineck/benchfft", "max_stars_repo_path": "benchees/gsl/doit.c", "max_stars_repo_stars_event_max_datetime": "2022-02-18T01:31:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-11T02:13:09.000Z", "num_tokens": 1130, "size": 3364 }
/* sys/test.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <config.h> #include <stdlib.h> #include <stdio.h> #include <gsl/gsl_math.h> #include <gsl/gsl_test.h> #include <gsl/gsl_ieee_utils.h> int main (void) { double y, y_expected; gsl_ieee_env_setup (); /* Test for expm1 */ y = gsl_expm1 (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.0)"); y = gsl_expm1 (1e-10); y_expected = 1.000000000050000000002e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(1e-10)"); y = gsl_expm1 (-1e-10); y_expected = -9.999999999500000000017e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-1e-10)"); y = gsl_expm1 (0.1); y_expected = 0.1051709180756476248117078264902; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.1)"); y = gsl_expm1 (-0.1); y_expected = -0.09516258196404042683575094055356; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-0.1)"); y = gsl_expm1 (10.0); y_expected = 22025.465794806716516957900645284; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(10.0)"); y = gsl_expm1 (-10.0); y_expected = -0.99995460007023751514846440848444; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-10.0)"); /* Test for log1p */ y = gsl_log1p (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.0)"); y = gsl_log1p (1e-10); y_expected = 9.9999999995000000000333333333308e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(1e-10)"); y = gsl_log1p (0.1); y_expected = 0.095310179804324860043952123280765; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.1)"); y = gsl_log1p (10.0); y_expected = 2.3978952727983705440619435779651; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(10.0)"); /* Test for gsl_hypot */ y = gsl_hypot (0.0, 0.0) ; y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(0.0, 0.0)"); y = gsl_hypot (1e-10, 1e-10) ; y_expected = 1.414213562373095048801688e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, 1e-10)"); y = gsl_hypot (1e-38, 1e-38) ; y_expected = 1.414213562373095048801688e-38; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-38, 1e-38)"); y = gsl_hypot (1e-10, -1.0) ; y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, -1)"); y = gsl_hypot (-1.0, 1e-10) ; y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(-1, 1e-10)"); y = gsl_hypot (1e307, 1e301) ; y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e301)"); y = gsl_hypot (1e301, 1e307) ; y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e301, 1e307)"); y = gsl_hypot (1e307, 1e307) ; y_expected = 1.414213562373095048801688e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e307)"); /* Test for acosh */ y = gsl_acosh (1.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.0)"); y = gsl_acosh (1.1); y_expected = 4.435682543851151891329110663525e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.1)"); y = gsl_acosh (10.0); y_expected = 2.9932228461263808979126677137742e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(10.0)"); y = gsl_acosh (1e10); y_expected = 2.3718998110500402149594646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1e10)"); /* Test for asinh */ y = gsl_asinh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.0)"); y = gsl_asinh (1e-10); y_expected = 9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (-1e-10); y_expected = -9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (0.1); y_expected = 9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.1)"); y = gsl_asinh (-0.1); y_expected = -9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-0.1)"); y = gsl_asinh (1.0); y_expected = 8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1.0)"); y = gsl_asinh (-1.0); y_expected = -8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1.0)"); y = gsl_asinh (10.0); y_expected = 2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(10)"); y = gsl_asinh (-10.0); y_expected = -2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-10)"); y = gsl_asinh (1e10); y_expected = 2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e10)"); y = gsl_asinh (-1e10); y_expected = -2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1e10)"); /* Test for atanh */ y = gsl_atanh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.0)"); y = gsl_atanh (1e-20); y_expected = 1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(1e-20)"); y = gsl_atanh (-1e-20); y_expected = -1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-1e-20)"); y = gsl_atanh (0.1); y_expected = 1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.1)"); y = gsl_atanh (-0.1); y_expected = -1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-0.1)"); y = gsl_atanh (0.9); y_expected = 1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); y = gsl_atanh (-0.9); y_expected = -1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); /* Test for pow_int */ y = gsl_pow_2 (-3.14); y_expected = pow(-3.14, 2.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_2(-3.14)"); y = gsl_pow_3 (-3.14); y_expected = pow(-3.14, 3.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_3(-3.14)"); y = gsl_pow_4 (-3.14); y_expected = pow(-3.14, 4.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_4(-3.14)"); y = gsl_pow_5 (-3.14); y_expected = pow(-3.14, 5.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_5(-3.14)"); y = gsl_pow_6 (-3.14); y_expected = pow(-3.14, 6.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_6(-3.14)"); y = gsl_pow_7 (-3.14); y_expected = pow(-3.14, 7.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_7(-3.14)"); y = gsl_pow_8 (-3.14); y_expected = pow(-3.14, 8.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_8(-3.14)"); y = gsl_pow_9 (-3.14); y_expected = pow(-3.14, 9.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_9(-3.14)"); { int n; for (n = -9; n < 10; n++) { y = gsl_pow_int (-3.14, n); y_expected = pow(-3.14, n); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_n(-3.14,%d)", n); } } /* Test for isinf, isnan, finite*/ { double zero, one, inf, nan; int s; zero = 0.0; one = 1.0; inf = exp(1.0e10); nan = inf / inf; s = gsl_isinf(zero); gsl_test_int (s, 0, "gsl_isinf(0)"); s = gsl_isinf(one); gsl_test_int (s, 0, "gsl_isinf(1)"); s = gsl_isinf(inf); gsl_test_int (s, 1, "gsl_isinf(inf)"); s = gsl_isinf(-inf); gsl_test_int (s, -1, "gsl_isinf(-inf)"); s = gsl_isinf(nan); gsl_test_int (s, 0, "gsl_isinf(nan)"); s = gsl_isnan(zero); gsl_test_int (s, 0, "gsl_isnan(0)"); s = gsl_isnan(one); gsl_test_int (s, 0, "gsl_isnan(1)"); s = gsl_isnan(inf); gsl_test_int (s, 0, "gsl_isnan(inf)"); s = gsl_isnan(nan); gsl_test_int (s, 1, "gsl_isnan(nan)"); s = gsl_finite(zero); gsl_test_int (s, 1, "gsl_finite(0)"); s = gsl_finite(one); gsl_test_int (s, 1, "gsl_finite(1)"); s = gsl_finite(inf); gsl_test_int (s, 0, "gsl_finite(inf)"); s = gsl_finite(nan); gsl_test_int (s, 0, "gsl_finite(nan)"); } { double x = gsl_fdiv (2.0, 3.0); gsl_test_rel (x, 2.0/3.0, 4*GSL_DBL_EPSILON, "gsl_fdiv(2,3)"); } exit (gsl_test_summary ()); }
{ "alphanum_fraction": 0.6587418951, "avg_line_length": 32.925093633, "ext": "c", "hexsha": "df30fe4ea48d93efcc2bef0a3035cd458f245651", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ICML14MoMCompare/spectral-learn", "max_forks_repo_path": "code/em/treba/gsl-1.0/sys/test.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ICML14MoMCompare/spectral-learn", "max_issues_repo_path": "code/em/treba/gsl-1.0/sys/test.c", "max_line_length": 78, "max_stars_count": 14, "max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ICML14MoMCompare/spectral-learn", "max_stars_repo_path": "code/em/treba/gsl-1.0/sys/test.c", "max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z", "num_tokens": 3661, "size": 8791 }
#ifndef _OPTIMIZE_STATE_RECONSTRUCTOR_GSL_H_ #define _OPTIMIZE_STATE_RECONSTRUCTOR_GSL_H_ using namespace std; #include <armadillo> using namespace arma; #include "rate_model.h" #include "state_reconstructor.h" #include <gsl/gsl_vector.h> class OptimizeStateReconstructor{ private: RateModel * rm; StateReconstructor * sr; mat * free_variables; int nfree_variables; int maxiterations; double stoppingprecision; double GetLikelihoodWithOptimized(const gsl_vector * variables); static double GetLikelihoodWithOptimized_gsl(const gsl_vector * variables, void *obj); public: OptimizeStateReconstructor(RateModel *,StateReconstructor *, mat *, int); mat optimize(); }; #endif /* _OPTIMIZE_STATE_RECONSTRUCTOR_GSL_H_ */
{ "alphanum_fraction": 0.7732634338, "avg_line_length": 23.1212121212, "ext": "h", "hexsha": "2a23531a8e8964b65a327aa358aafb144329e5c9", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-31T18:23:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-07-18T05:20:26.000Z", "max_forks_repo_head_hexsha": "08070c6d4a6fbd9320265e1e698c95ba80f81123", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jlanga/smsk_orthofinder", "max_forks_repo_path": "src/phyx-1.01/src/optimize_state_reconstructor_gsl.h", "max_issues_count": 1, "max_issues_repo_head_hexsha": "08070c6d4a6fbd9320265e1e698c95ba80f81123", "max_issues_repo_issues_event_max_datetime": "2018-11-08T13:59:48.000Z", "max_issues_repo_issues_event_min_datetime": "2017-08-21T07:26:13.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jlanga/smsk_selection", "max_issues_repo_path": "src/phyx-1.01/src/optimize_state_reconstructor_gsl.h", "max_line_length": 90, "max_stars_count": 4, "max_stars_repo_head_hexsha": "08070c6d4a6fbd9320265e1e698c95ba80f81123", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jlanga/smsk_selection", "max_stars_repo_path": "src/phyx-1.01/src/optimize_state_reconstructor_gsl.h", "max_stars_repo_stars_event_max_datetime": "2022-01-03T10:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2021-07-18T05:20:20.000Z", "num_tokens": 179, "size": 763 }
/***************************************************************************** * * Rokko: Integrated Interface for libraries of eigenvalue decomposition * * Copyright (C) 2015 by Rokko Developers https://github.com/t-sakashita/rokko * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * *****************************************************************************/ #ifndef ROKKO_LAPACK_H #define ROKKO_LAPACK_H #include <rokko/mangling.h> #include <lapacke.h> #ifdef __cplusplus #include <boost/numeric/ublas/traits.hpp> #define LAPACKE_GEQRF_DECL(NAME, TYPE) \ lapack_int LAPACKE_geqrf(int matrix_order, lapack_int m, lapack_int n, TYPE * a, lapack_int lda, TYPE * tau); LAPACKE_GEQRF_DECL(sgeqrf, float); LAPACKE_GEQRF_DECL(dgeqrf, double); LAPACKE_GEQRF_DECL(cgeqrf, lapack_complex_float); LAPACKE_GEQRF_DECL(zgeqrf, lapack_complex_double); #undef LAPACKE_GEQRF_DECL #define LAPACKE_GESVD_DECL(NAME, TYPE) \ lapack_int LAPACKE_gesvd(int matrix_order, char jobu, char jobvt, lapack_int m, lapack_int n, TYPE * a, lapack_int lda, boost::numeric::ublas::type_traits<TYPE>::real_type * s, TYPE * u, lapack_int ldu, TYPE * vt, lapack_int ldvt, boost::numeric::ublas::type_traits<TYPE>::real_type * superb); LAPACKE_GESVD_DECL(sgesvd, float); LAPACKE_GESVD_DECL(dgesvd, double); LAPACKE_GESVD_DECL(cgesvd, lapack_complex_float); LAPACKE_GESVD_DECL(zgesvd, lapack_complex_double); #undef LAPACKE_GESVD_DECL #define LAPACKE_HEEV_DECL(NAME, TYPE) \ lapack_int LAPACKE_heev(int matrix_order, char jobz, char uplo, lapack_int n, TYPE * a, lapack_int lda, boost::numeric::ublas::type_traits<TYPE>::real_type * w); LAPACKE_HEEV_DECL(cheev, lapack_complex_float); LAPACKE_HEEV_DECL(zheev, lapack_complex_double); #undef LAPACKE_HEEV_DECL #define LAPACKE_ORGQR_DECL(NAME, TYPE) \ lapack_int LAPACKE_orgqr(int matrix_order, lapack_int m, lapack_int n, lapack_int k, TYPE * a, lapack_int lda, const TYPE * tau); \ lapack_int LAPACKE_ungqr(int matrix_order, lapack_int m, lapack_int n, lapack_int k, TYPE * a, lapack_int lda, const TYPE * tau); LAPACKE_ORGQR_DECL(sorgqr, float); LAPACKE_ORGQR_DECL(dorgqr, double); #undef LAPACKE_ORGQR_DECL #define LAPACKE_SYEV_DECL(NAME, TYPE) \ lapack_int LAPACKE_syev(int matrix_order, char jobz, char uplo, lapack_int n, TYPE * a, lapack_int lda, TYPE * w ); \ lapack_int LAPACKE_heev(int matrix_order, char jobz, char uplo, lapack_int n, TYPE * a, lapack_int lda, TYPE * w ); LAPACKE_SYEV_DECL(ssyev, float); LAPACKE_SYEV_DECL(dsyev, double); #undef LAPACKE_SYEV_DECL #define LAPACKE_UNGQR_DECL(NAME, TYPE) \ lapack_int LAPACKE_ungqr(int matrix_order, lapack_int m, lapack_int n, lapack_int k, TYPE * a, lapack_int lda, const TYPE * tau); LAPACKE_UNGQR_DECL(cungqr, lapack_complex_float); LAPACKE_UNGQR_DECL(zungqr, lapack_complex_double); #undef LAPACKE_UNGQR_DECL #define LAPACKE_SYGV_DECL(NAME, TYPE) \ lapack_int LAPACKE_sygv(int matrix_order, lapack_int itype, char jobz, char uplo, lapack_int n, TYPE * a, lapack_int lda, TYPE * b, lapack_int ldb, TYPE * w ); \ lapack_int LAPACKE_heev(int matrix_order, lapack_int itype, char jobz, char uplo, lapack_int n, TYPE * a, lapack_int lda, TYPE * b, lapack_int ldb, TYPE * w ); LAPACKE_SYGV_DECL(ssygv, float); LAPACKE_SYGV_DECL(dsygv, double); #undef LAPACKE_SYGV_DECL #endif // __cplusplus #endif // ROKKO_LAPACK_H
{ "alphanum_fraction": 0.7528617552, "avg_line_length": 46.0405405405, "ext": "h", "hexsha": "b8544bc30b8a408e595b290069a407344268a562", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7cd9d5155e82f038039a46c1dc8f382b3fe7e2b7", "max_forks_repo_licenses": [ "BSL-1.0" ], "max_forks_repo_name": "wistaria/rokko", "max_forks_repo_path": "rokko/lapack.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cd9d5155e82f038039a46c1dc8f382b3fe7e2b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSL-1.0" ], "max_issues_repo_name": "wistaria/rokko", "max_issues_repo_path": "rokko/lapack.h", "max_line_length": 293, "max_stars_count": null, "max_stars_repo_head_hexsha": "7cd9d5155e82f038039a46c1dc8f382b3fe7e2b7", "max_stars_repo_licenses": [ "BSL-1.0" ], "max_stars_repo_name": "wistaria/rokko", "max_stars_repo_path": "rokko/lapack.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1064, "size": 3407 }
#include <gsl/gsl_test.h> #include <gsl/gsl_ieee_utils.h> #include <gsl/gsl_math.h> #include "gsl_cblas.h" #include "tests.h" void test_tbmv (void) { const double flteps = 1e-4, dbleps = 1e-6; { int order = 101; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { 0.017088f, 0.315595f, 0.243875f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 894)"); } }; }; { int order = 101; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { -0.089f, -0.721909f, 0.129992f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 895)"); } }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { 0.156927f, -0.159004f, 0.098252f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 896)"); } }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { 0.043096f, -0.584876f, -0.203f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 897)"); } }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { 0.024831f, -0.24504f, 0.447756f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 898)"); } }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { -0.089f, -0.670912f, 0.146504f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 899)"); } }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { -0.24504f, 0.447756f, -0.089117f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 900)"); } }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.439f, -0.484f, -0.952f, -0.508f, 0.381f, -0.889f, -0.192f, -0.279f, -0.155f }; float X[] = { -0.089f, -0.688f, -0.203f }; int incX = -1; float x_expected[] = { -0.351128f, -0.589748f, -0.203f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 901)"); } }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { 0.156047f, 0.189418f, -0.52828f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 902)"); } }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { 0.194342f, -0.449858f, -0.562f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 903)"); } }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { -0.0046f, 0.156047f, 0.189418f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 904)"); } }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { 0.023f, -0.516295f, -0.423724f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 905)"); } }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { 0.328565f, 0.326454f, 0.051142f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 906)"); } }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { 0.356165f, -0.345888f, -0.562f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 907)"); } }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { -0.015295f, 0.13041f, -0.482689f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 908)"); } }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.94f, -0.091f, 0.984f, -0.276f, -0.342f, -0.484f, -0.665f, -0.2f, 0.349f }; float X[] = { 0.023f, -0.501f, -0.562f }; int incX = -1; float x_expected[] = { 0.023f, -0.508866f, -0.516409f }; cblas_stbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], flteps, "stbmv(case 909)"); } }; }; { int order = 101; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { 0.50204, 0.563918, -0.590448 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 910)"); } }; }; { int order = 101; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { -0.77, -0.95429, -0.44419 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 911)"); } }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { 1.214016, -0.433258, 0.321835 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 912)"); } }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { -0.236664, -1.106472, 0.337 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 913)"); } }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { 0.68068, 0.357254, 1.022043 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 914)"); } }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { -0.77, -0.31596, 1.037208 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 915)"); } }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { 0.357254, 1.022043, 0.190742 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 916)"); } }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.566, 0.955, -0.086, -0.856, 0.177, 0.974, -0.652, -0.884, 0.77 }; double X[] = { -0.77, -0.818, 0.337 }; int incX = -1; double x_expected[] = { -0.914786, -0.496165, 0.337 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 917)"); } }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { 0.610833, -0.293243, 0.02914 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 918)"); } }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { -0.635031, 0.574, 0.155 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 919)"); } }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { 0.024679, 0.610833, -0.293243 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 920)"); } }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { -0.851, 0.875864, -0.231243 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 921)"); } }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { -0.198505, 0.091504, 0.093 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 922)"); } }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { -1.074184, 0.356535, 0.155 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 923)"); } }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { 0.394864, -0.768342, 0.31774 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 924)"); } }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.188, 0.6, -0.743, -0.803, 0.449, -0.681, -0.464, -0.029, 0.553 }; double X[] = { -0.851, 0.481, 0.155 }; int incX = -1; double x_expected[] = { -0.851, 0.098901, 0.4436 }; cblas_dtbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[i], x_expected[i], dbleps, "dtbmv(case 925)"); } }; }; { int order = 101; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { -0.113114f, -0.051704f, -0.403567f, -0.288349f, -0.223936f, 0.841145f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 926) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 926) imag"); }; }; }; { int order = 101; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { -0.46f, 0.069f, -0.14027f, -0.23208f, -0.537722f, 0.841425f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 927) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 927) imag"); }; }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { -0.099689f, 0.487805f, 0.353793f, 0.325411f, -0.225658f, -0.776023f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 928) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 928) imag"); }; }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { -0.39057f, 0.113296f, 0.388863f, 0.131011f, -0.236f, 0.605f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 929) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 929) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { -0.169119f, 0.443509f, 0.159816f, 0.139696f, -0.180955f, -0.835292f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 930) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 930) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { -0.46f, 0.069f, 0.194886f, -0.054704f, -0.191297f, 0.545731f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 931) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 931) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { 0.159816f, 0.139696f, -0.180955f, -0.835292f, 0.077786f, 0.60472f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 932) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 932) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { 0.824f, -0.45f, -0.987f, 0.758f, 0.42f, -0.357f, 0.147f, -0.191f, 0.88f, 0.63f, 0.155f, -0.573f, 0.224f, 0.146f, 0.501f, -0.889f, 0.456f, 0.796f }; float X[] = { -0.46f, 0.069f, 0.308f, -0.003f, -0.236f, 0.605f }; int incX = -1; float x_expected[] = { -0.18707f, 0.2604f, 0.082342f, -0.779023f, -0.236f, 0.605f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 933) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 933) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { 0.647885f, 0.621535f, -0.104407f, 0.05309f, 0.732704f, 0.055982f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 934) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 934) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { 1.2955f, 0.190774f, -0.247934f, 0.982616f, -0.894f, -0.116f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 935) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 935) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { 0.096482f, -0.071661f, 0.647885f, 0.621535f, -0.104407f, 0.05309f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 936) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 936) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { 0.411f, -0.308f, -1.14861f, 0.933761f, -1.66247f, -0.234526f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 937) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 937) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { 0.632361f, -0.409373f, 0.578489f, 0.012724f, 0.664066f, 0.171616f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 938) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 938) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { 0.946879f, -0.645712f, -1.21801f, 0.32495f, -0.894f, -0.116f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 939) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 939) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { -0.236612f, 0.122761f, -1.12184f, -0.358823f, 1.4975f, -0.470595f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 940) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 940) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.814f, 0.043f, -0.755f, -0.094f, 0.876f, 0.257f, 0.406f, 0.491f, -0.27f, -0.787f, 0.545f, 0.732f, -0.512f, -0.085f, 0.234f, 0.001f, -0.225f, -0.002f }; float X[] = { 0.411f, -0.308f, -0.912f, 0.811f, -0.894f, -0.116f }; int incX = -1; float x_expected[] = { 0.411f, -0.308f, -1.26537f, 0.570703f, -0.129206f, -0.642577f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 941) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 941) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { 0.413357f, 0.178267f, -0.114618f, -1.35595f, -0.513288f, 0.611332f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 942) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 942) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { 0.368428f, 0.071217f, -0.954366f, -0.390486f, 0.694f, -0.954f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 943) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 943) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { -0.084786f, -0.059464f, 0.413357f, 0.178267f, -0.114618f, -1.35595f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 944) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 944) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { 0.065f, -0.082f, -0.636071f, 0.80005f, 0.787748f, -1.14446f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 945) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 945) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { -1.18498f, -0.424201f, 0.230196f, 0.374209f, -0.208366f, -1.16549f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 946) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 946) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { -1.03519f, -0.446737f, -0.819232f, 0.995992f, 0.694f, -0.954f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 947) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 947) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { 0.109929f, 0.02505f, 0.062939f, -0.202464f, -0.470658f, 1.69006f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 948) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 948) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; float A[] = { -0.675f, 0.047f, 0.695f, 0.724f, -0.438f, 0.991f, -0.188f, -0.06f, -0.093f, 0.302f, 0.842f, -0.753f, 0.465f, -0.972f, -0.058f, 0.988f, 0.093f, 0.164f }; float X[] = { 0.065f, -0.082f, -0.746f, 0.775f, 0.694f, -0.954f }; int incX = -1; float x_expected[] = { 0.065f, -0.082f, -0.776809f, 0.762996f, 0.73663f, 0.124729f }; cblas_ctbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctbmv(case 949) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctbmv(case 949) imag"); }; }; }; { int order = 101; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { -0.010019, -0.1678, -0.042017, -1.112094, 0.010004, -0.480427 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 950) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 950) imag"); }; }; }; { int order = 101; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { 0.064, 0.169, -0.80842, -0.715637, -0.829924, -0.212971 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 951) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 951) imag"); }; }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { 0.634014, 0.796937, -0.585538, -0.895375, -0.125887, 0.010019 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 952) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 952) imag"); }; }; }; { int order = 101; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { 0.567497, 1.085122, -1.217792, -1.322566, -0.641, -0.103 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 953) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 953) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { 0.130517, -0.119185, -0.187765, -0.519609, -0.169484, -1.165438 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 954) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 954) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { 0.064, 0.169, -0.820019, -0.9468, -0.684597, -1.278457 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 955) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 955) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { -0.187765, -0.519609, -0.169484, -1.165438, 0.198928, -0.370456 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 956) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 956) imag"); }; }; }; { int order = 102; int trans = 111; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.212, 0.612, 0.189, -0.046, -0.124, 0.82, 0.753, 0.727, 0.331, 0.116, 0.504, -0.673, -0.888, -0.277, -0.361, -0.909, 0.982, -0.124 }; double X[] = { 0.064, 0.169, -0.81, -0.779, -0.641, -0.103 }; int incX = -1; double x_expected[] = { -0.113746, -0.182809, -0.935887, -0.768981, -0.641, -0.103 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 957) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 957) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { -0.436746, 0.963714, -1.087615, -0.018695, 0.30063, 0.12958 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 958) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 958) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { 0.895682, 1.407174, 0.2408, -0.14282, -0.649, 0.188 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 959) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 959) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { 0.785744, -0.3966, -0.436746, 0.963714, -1.087615, -0.018695 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 960) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 960) imag"); }; }; }; { int order = 101; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { 0.884, 0.636, 0.472572, 0.47454, -1.056415, 0.594125 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 961) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 961) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { 0.464705, -0.108078, 0.094975, 0.376323, -0.6802, -0.42482 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 962) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 962) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { 0.562961, 0.924522, 1.004293, -0.112851, -0.649, 0.188 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 963) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 963) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { -0.448428, 0.19254, -0.674583, 1.236189, 0.780774, 1.167088 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 964) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 964) imag"); }; }; }; { int order = 102; int trans = 112; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { -0.374, -0.308, 0.792, 0.884, -0.794, -0.055, -0.281, 0.527, 0.246, 0.762, 0.853, 0.891, -0.231, 0.384, 0.373, -0.717, -0.957, -0.338 }; double X[] = { 0.884, 0.636, 0.921, 0.282, -0.649, 0.188 }; int incX = -1; double x_expected[] = { 0.884, 0.636, 0.653832, 1.112064, -0.168856, 1.225508 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 965) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 965) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { -0.59515, 0.077106, -0.27658, -0.637356, 0.407252, -0.308844 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 966) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 966) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { -1.46131, 0.537642, 0.624614, 0.762252, 0.326, 0.428 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 967) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 967) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { -0.536274, 0.421806, -0.59515, 0.077106, -0.27658, -0.637356 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 968) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 968) imag"); }; }; }; { int order = 101; int trans = 113; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { -0.591, -0.084, 0.98216, 0.400464, 0.131806, -0.026608 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 969) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 969) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 121; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { -1.68293, 0.796222, -0.96062, 0.415172, -0.082386, -0.182748 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 970) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 970) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 121; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { -1.737656, 0.290416, 0.61669, 0.73853, 0.326, 0.428 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 971) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 971) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 122; int diag = 131; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { 0.27516, -0.544536, -0.10627, -0.988374, 0.229991, -0.711267 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 972) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 972) imag"); }; }; }; { int order = 102; int trans = 113; int uplo = 122; int diag = 132; int N = 3; int K = 1; int lda = 3; double A[] = { 0.002, 0.95, -0.363, 0.084, -0.646, 0.816, -0.407, 0.099, -0.02, -0.906, -0.874, 0.191, -0.328, -0.968, 0.79, 0.826, -0.795, 0.277 }; double X[] = { -0.591, -0.084, 0.707, 0.945, 0.326, 0.428 }; int incX = -1; double x_expected[] = { -0.591, -0.084, 0.794924, 0.411234, 0.148739, 0.025577 }; cblas_ztbmv(order, uplo, trans, diag, N, K, A, lda, X, incX); { int i; for (i = 0; i < 3; i++) { gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztbmv(case 973) real"); gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztbmv(case 973) imag"); }; }; }; }
{ "alphanum_fraction": 0.5108851252, "avg_line_length": 29.5543956044, "ext": "c", "hexsha": "861a529cab46c73d74d514d14e737aa730bfde53", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ICML14MoMCompare/spectral-learn", "max_forks_repo_path": "code/em/treba/gsl-1.0/cblas/test_tbmv.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ICML14MoMCompare/spectral-learn", "max_issues_repo_path": "code/em/treba/gsl-1.0/cblas/test_tbmv.c", "max_line_length": 170, "max_stars_count": 14, "max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ICML14MoMCompare/spectral-learn", "max_stars_repo_path": "code/em/treba/gsl-1.0/cblas/test_tbmv.c", "max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z", "num_tokens": 25464, "size": 53789 }
#include <stdlib.h> #include <stdio.h> #include <gsl/gsl_math.h> #include <gsl/gsl_sf_expint.h> #include "cosmocalc.h" #include "haloprofs.h" double fourierTransformNFW(double k, double m, double rvir, double c) { double rs,rhos; double ukm; rs = rvir/c; rhos = m/4.0/M_PI/rs/rs/rs/(log(1.0+c) - c/(1.0+c)); if(k > 0) ukm = 4.0*M_PI*rhos*rs*rs*rs/m *(sin(k*rs)*(gsl_sf_Si((1.0+c)*k*rs) - gsl_sf_Si(k*rs)) - sin(c*k*rs)/(1.0+c)/k/rs + cos(k*rs)*(gsl_sf_Ci((1.0+c)*k*rs) - gsl_sf_Ci(k*rs))); else ukm = 1.0; return ukm; } double NFWprof(double r, double m, double rvir, double c) { double rs,rhos; rs = rvir/c; rhos = m/4.0/M_PI/rs/rs/rs/(log(1.0+c) - c/(1.0+c)); return rhos/(r/rs)/(1+r/rs)/(1+r/rs); } double NFWprof_menc(double r, double m, double rvir, double c) { double mc = log(1+c) - c/(1.0+c); double mr = c*r/rvir; mr = log(1.0 + mr) - mr/(1.0+mr); return mr/mc*m; } inline double _duffy2008_concNFW(double m, double a) { return 6.71/pow(1.0/a,0.44)*pow(m/2e12,-0.091); } double concNFW(double m, double a) { return _duffy2008_concNFW(m,a); } double duffy2008_concNFW(double m, double a) { return _duffy2008_concNFW(m,a); } /* double bh2012_concNFW(double m, double a) { double nu = DELTAC/sigmaMtophat(m,a); } double prada2011_concNFW(double m, double a) { } */
{ "alphanum_fraction": 0.6200294551, "avg_line_length": 17.8684210526, "ext": "c", "hexsha": "5a6efae920394e27870e647fabce371ed8230a4c", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2017-08-11T17:31:51.000Z", "max_forks_repo_forks_event_min_datetime": "2017-07-14T12:17:31.000Z", "max_forks_repo_head_hexsha": "aa7d7cb58f05a36d446e02b45a9117d93eb16556", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "beckermr/cosmocalc", "max_forks_repo_path": "src/haloprofs.c", "max_issues_count": 1, "max_issues_repo_head_hexsha": "aa7d7cb58f05a36d446e02b45a9117d93eb16556", "max_issues_repo_issues_event_max_datetime": "2016-04-05T19:36:21.000Z", "max_issues_repo_issues_event_min_datetime": "2016-04-05T19:10:45.000Z", "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "beckermr/cosmocalc", "max_issues_repo_path": "src/haloprofs.c", "max_line_length": 146, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa7d7cb58f05a36d446e02b45a9117d93eb16556", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "beckermr/cosmocalc", "max_stars_repo_path": "src/haloprofs.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 550, "size": 1358 }
/** * \copyright * Copyright (c) 2015, OpenGeoSys Community (http://www.opengeosys.org) * Distributed under a Modified BSD License. * See accompanying file LICENSE.txt or * http://www.opengeosys.org/project/license * */ /**************************************************************************/ /* ROCKFLOW - Modul: makros.h */ /* Aufgabe: Diese Datei wird von allen ROCKFLOW-Modulen (*.c - Dateien !!!) importiert. Sie enthaelt globale Preprozessor-Definitionen und importiert weitere, (fast) ueberall benoetigte Header. */ /**************************************************************************/ #ifndef makros_INC #define makros_INC /* Global benoetigte Header */ //#include <stdlib.h> /* Speicherverwaltung */ //#include <string.h> #include <string> /* Zeichenketten */ //#include <float.h> /* Floating-Point */ /* ROCKFLOW-Version */ // LB: renamed ROCKFLOW_VERSION to OGS_VERSION and moved the #define to // Base/Configure.h.in. Please set the version in the top-level CMakeLists.txt!! // (see sources/CMakeLists.txt) /* Definitionen von Makros zur Steuerung der bedingten Compilierung */ #define SWITCHES /* Ausgabe der Schalterstellungen zu Beginn des Programms */ #ifdef MSVCPP6 #pragma warning(disable : 4786) #endif /* Laufzeitausgaben */ #define TESTTIME #ifdef TESTTIME #define TIMER_ROCKFLOW 0 #endif /**********************************************************************/ /* Speicher */ #ifndef NO_ERROR_CONTROL /* Wird ggf. im Makefile gesetzt */ #define ERROR_CONTROL /* Fehlertests (Feldgrenzen, Existenz o.ae.), die bei sauberen Netzen und einwandfrei funktionierendem Programm nichts bringen und nur Laufzeit kosten */ #endif #define MEMORY_MANAGEMENT_NOT_ANSI_COMPLIANT /* Bei einigen Compilern werden malloc(0) realloc(NULL,xxx) realloc(xxx,0) free(NULL) nicht ANSI-gerecht gehandhabt. Mit diesem Schalter wird ANSI-Verhalten gewaehrleistet. */ #define noMEMORY_ALLOCATION_TEST_SUCCESS /* Prueft, ob eine Speicheranforderung erfolgreich absolviert wurde */ #define noMEMORY_TEST_IN_TIME /* fuer Versions-Speichertest */ /* Erstellt waehrend der Laufzeit eine Bilanz des allockierten und wieder freigegebenen Speichers. Sehr Zeitintensiv !!! */ #define noMEMORY_STR /* fuer Versions-Speichertest */ /* Gibt Informationen bei Memory-Funktionen zur Aufrufstellenlokalisation. Funktioniert nur zusammen mit MEMORY_TEST_IN_TIME. Sehr Speicherintensiv!!! */ #define noMEMORY_SHOW_USAGE /* Gibt bei MEMORY_TEST_IN_TIME Informationen ueber jeden Malloc/Realloc/Free-Vorgang aus. */ #define noMEMORY_REALLOC /* Ersetzt Realloc durch Malloc und Free und speichert um */ #ifndef MEMORY_TEST_IN_TIME #ifdef MEMORY_SHOW_USAGE #undef MEMORY_SHOW_USAGE #endif #ifndef MEMORY_ALLOCATION_TEST_SUCCESS #ifdef MEMORY_STR #undef MEMORY_STR #endif #endif #endif #ifdef MEMORY_STR #define Malloc(a) MAlloc(a, __FILE__, __LINE__) #define Free(a) FRee(a, __FILE__, __LINE__) #define Realloc(a, b) REalloc(a, b, __FILE__, __LINE__) /* Ersetzt Malloc, Free und Realloc in allen *.c-Dateien durch den erweiterten Aufruf mit Dateiname und Zeilennummer */ #endif /**********************************************************************/ /* Daten */ #define noENABLE_ADT /* Listen, Baeumen, etc sind dann moeglich */ /* Definitionen der Feldgroessen */ #define ELEM_START_SIZE 200l /* Minimale Groesse des Elementverzeichnisses */ #define ELEM_INC_SIZE 1000l /* Bei Erreichen von ELEM_START_SIZE wird das Elementverzeichnis automatisch um ELEM_INC_SIZE vergroessert */ #define NODE_START_SIZE 200l /* Minimale Groesse des Knotenverzeichnisses */ #define NODE_INC_SIZE 1000l /* Bei Erreichen von NODE_START_SIZE wird das Knotenverzeichnis automatisch um NODE_INC_SIZE vergroessert */ #define EDGE_START_SIZE 0l /* Minimale Groesse des Kantenverzeichnisses */ #define EDGE_INC_SIZE 1000l /* Bei Erreichen von EDGE_START_SIZE wird das Kantenverzeichnis automatisch um EDGE_INC_SIZE vergroessert */ #define PLAIN_START_SIZE 0l /* Minimale Groesse des Flaechenverzeichnisses */ #define PLAIN_INC_SIZE 1000l /* Bei Erreichen von PLAIN_START_SIZE wird das Flaechenverzeichnis automatisch um PLAIN_INC_SIZE vergroessert */ /**********************************************************************/ /* Protokolle */ /* Definitionen der Dateinamen-Erweiterungen */ #define TEXT_EXTENSION ".rfd" /* Dateinamen-Erweiterung fuer Text-Eingabedatei */ #define PROTOCOL_EXTENSION ".rfe" /* Dateinamen-Erweiterung fuer Text-Protokolldatei */ #define RF_INPUT_EXTENSION ".rfi" /* Dateinamen-Erweiterung fuer RF-Input-Dateien */ #define RF_OUTPUT_EXTENSION ".rfo" /* Dateinamen-Erweiterung fuer RF-Output-Dateien */ #define RF_MESSAGE_EXTENSION ".msg" /* Dateinamen-Erweiterung fuer RF-Output-Dateien */ #define RF_SAVE_EXTENSION1 ".sv1" /* Dateinamen-Erweiterung fuer RF-Sicherheitskopien */ #define RF_SAVE_EXTENSION2 ".sv2" /* Dateinamen-Erweiterung fuer RF-Sicherheitskopien */ #define MESH_GENERATOR_EXTENSION ".rfm" /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Netzgenerator) */ #define MESH_GENERATOR_PROTOCOL_EXTENSION ".rfg" /* Dateinamen-Erweiterung fuer Text-Protokolldatei (Netzgenerator) */ #define INVERSE_EXTENSION ".rfv" /* ah inv */ /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Inverses Modellieren) */ #define INVERSE_PROTOCOL_EXTENSION ".rfp" /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Inverses Modellieren) */ #define CHEM_REACTION_EXTENSION ".pqc" /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Chemical reaction) */ #define CHEMAPP_REACTION_EXTENSION ".chm" #define REACTION_EXTENSION_CHEMAPP ".cap" // DL/SB 11.2008 #define TEC_FILE_EXTENSION ".tec" #define VTK_FILE_EXTENSION ".vtk" // GK #define CSV_FILE_EXTENSION ".csv" #define noTESTFILES /* RFD-File Datenbank testen */ #define noEXT_RFD /* Eingabeprotokoll ausfuehrlich kommentieren */ #define EXT_RFD_MIN /* Eingabeprotokoll kommentieren, nur gefundene Schluesselworte */ #ifdef EXT_RFD #undef EXT_RFD_MIN #endif /* Format der Double-Ausgabe ueber FilePrintDouble --> txtinout */ #define FORMAT_DOUBLE #define FPD_GESAMT 4 #define FPD_NACHKOMMA 14 /**********************************************************************/ /* C1.2 Numerik */ #define noTESTTAYLOR /* nur zu Testzwecken: Taylor-Galerkin-Verfahren nach Donea (1D) */ /**********************************************************************/ /* C1.4 Loeser */ #define noNULLE_ERGEBNIS /* Nullt den Ergebnisvektor vor Aufruf des Loesers; ansonsten wird er mit den Ergebniswerten des letzten Zeitschritts vorbelegt. */ #define noSOLVER_SHOW_ERROR /* Anzeigen des Iterationsfehlers */ #define noSOLVER_SHOW_RESULTS /* Anzeigen der Iterationswerte */ #define RELATIVE_EPS /* Abbruchkriterium bei CG-Loesern wird nicht als absolute Schranke benutzt, sondern mit der Norm der rechten Seite multipliziert */ /* Benutzte Normen bei Abbruchkriterien der CG-Loeser mit Speichertechnik: MVekNorm1 : Spaltensummennorm MVekNorm2 : euklidische Norm MVekNormMax : Maximumnorm Diese Normen muessen hier fuer die verschiedenen Loeser eingetragen werden !!! */ #define VEKNORM_BICG MVekNorm2 /* Norm fuer SpBICG-Loeser */ #define VEKNORM_BICGSTAB MVekNorm2 /* Norm fuer SpBICGSTAB-Loeser */ #define VEKNORM_QMRCGSTAB MVekNorm2 /* Norm fuer SpQMRCGSTAB-Loeser */ /*ahb*/ #define VEKNORM_CG MVekNorm2 /* Norm fuer SpCG-Loeser */ #define NORM 2 /* Norm fuer alle Objekte */ #if NORM == 0 #define VEKNORM MVekNormMax #elif NORM == 1 #define VEKNORM MVekNorm1 #else #define VEKNORM MVekNorm2 #endif /*ahe*/ /**********************************************************************/ /* C1.9 Adaption */ #define noTEST_ADAPTIV /* nur zu Testzwecken */ #define noREF_STATIC /* erlaubt an ungefaehrlichen Stellen statische Variablen in Rekursionen. --> refine.c */ /**********************************************************************/ /* C1.10 Grafik */ #define no__RFGRAF /* Bindet zur Zeit die Grafik-Funktionen unter X11 */ /**********************************************************************/ /* PCS / C++ */ #define PCS_OBJECTS #define PCS_NUMBER_MAX 30 #define DOF_NUMBER_MAX 6 // JT: max # dof's per process #define MAX_FLUID_PHASES 2 // JT: max # fluid phases #define noPCS_NOD //#define GLI // KR #define noWINDOWS /**********************************************************************/ /* Parallelization */ #define noPARALLEL #define noCHEMAPP // MX #define noREACTION_ELEMENT #define noSX #define noMPI #define noOPEN_MP /* Definitionen von Konstanten, die bei manchen Compilern benoetigt werden */ #ifndef NULL #define NULL ((void*)0) #endif #ifndef TRUE #define TRUE (0 == 0) #endif #ifndef FALSE #define FALSE (1 == 0) #endif #ifndef PI #define PI 3.14159265358979323846 #endif /* Feste Zahlen fuer Genauigkeitspruefungen etc. */ #define Mdrittel (1.0 / 3.0) #define MKleinsteZahl DBL_EPSILON #define MFastNull DBL_MIN #define MSqrt2Over3 sqrt(2.0 / 3.0) /* CBLAS oder MKL_CBLAS verwenden? Wenn ja, wo? */ #define noCBLAS #define noMKL_CBLAS /* Includes fuer CBLAS oder MKL */ #ifdef MKL_CBLAS #include <mkl_cblas.h> #define CBLAS #else #ifdef CBLAS #include <cblas.h> #endif #endif /* Wo verwenden? */ #ifdef CBLAS #define CBLAS_M2MatVek #define CBLAS_MSkalarprodukt #define CBLAS_MMultMatMat #endif /* UMF-Pack-Loeser verwenden? */ #ifdef UMFPACK31 #define UMFPACK #endif #ifdef UMFPACK40 #define UMFPACK #endif // min und max #define Max(A, B) ((A) > (B) ? (A) : (B)) /* #ifndef min #define min(A,B) ((A) < (B) ? (A) : (B)) #endif #ifndef max #define max(A,B) ((A) > (B) ? (A) : (B)) #endif */ #define MAX_ZEILE 2048 /* max. Laenge einer UCD-Zeile; bei Leseproblemen vergroessern */ // enum DIS_TYPES {CONSTANT,LINEAR}; extern std::string FileName; extern std::string FilePath; // WW #define RESET_4410 // H2_ELE test //---- MPI Parallel -------------- #if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ || defined(USE_MPI_BRNS) || defined(USE_MPI_KRC) || defined(USE_PETSC) extern int mysize; // WW extern int myrank; #endif //---- MPI Parallel -------------- #endif
{ "alphanum_fraction": 0.6928522269, "avg_line_length": 29.8269794721, "ext": "h", "hexsha": "8a8131207f86a1be560b909c3686556a06dc51b7", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-06-15T08:30:31.000Z", "max_forks_repo_forks_event_min_datetime": "2016-06-27T15:30:02.000Z", "max_forks_repo_head_hexsha": "3ebcbbc209e2306e0721d408a699ecaea52b89d1", "max_forks_repo_licenses": [ "BSD-4-Clause" ], "max_forks_repo_name": "yingtaohu/ogs5", "max_forks_repo_path": "Base/makros.h", "max_issues_count": 1, "max_issues_repo_head_hexsha": "3ebcbbc209e2306e0721d408a699ecaea52b89d1", "max_issues_repo_issues_event_max_datetime": "2016-08-03T14:13:54.000Z", "max_issues_repo_issues_event_min_datetime": "2016-08-03T14:13:54.000Z", "max_issues_repo_licenses": [ "BSD-4-Clause" ], "max_issues_repo_name": "yingtaohu/ogs5", "max_issues_repo_path": "Base/makros.h", "max_line_length": 103, "max_stars_count": 1, "max_stars_repo_head_hexsha": "3ebcbbc209e2306e0721d408a699ecaea52b89d1", "max_stars_repo_licenses": [ "BSD-4-Clause" ], "max_stars_repo_name": "yingtaohu/ogs5", "max_stars_repo_path": "Base/makros.h", "max_stars_repo_stars_event_max_datetime": "2018-07-28T01:46:45.000Z", "max_stars_repo_stars_event_min_datetime": "2018-07-28T01:46:45.000Z", "num_tokens": 2801, "size": 10171 }
/* Author: G. Jungman (+modifications from O. Teytaud olivier.teytaud@inria.fr) */ #include <config.h> #include <stdlib.h> #include <gsl/gsl_ieee_utils.h> #include <gsl/gsl_qrng.h> #include <gsl/gsl_test.h> #include <math.h> void test_sobol(void) { int status = 0; double v[3]; /* int i; */ /* test in dimension 2 */ gsl_qrng * g = gsl_qrng_alloc(gsl_qrng_sobol, 2); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.25 || v[1] != 0.75 ); gsl_qrng_get(g, v); status += ( v[0] != 0.375 || v[1] != 0.375 ); gsl_qrng_free(g); gsl_test (status, "Sobol d=2"); status = 0; /* test in dimension 3 */ g = gsl_qrng_alloc(gsl_qrng_sobol, 3); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.25 ); gsl_qrng_get(g, v); status += ( v[0] != 0.375 || v[1] != 0.375 || v[2] != 0.625 ); gsl_test (status, "Sobol d=3"); status = 0; gsl_qrng_init(g); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.25 ); gsl_qrng_get(g, v); status += ( v[0] != 0.375 || v[1] != 0.375 || v[2] != 0.625 ); gsl_qrng_free(g); gsl_test (status, "Sobol d=3 (reinitialized)"); } void test_halton(void) { int status = 0; double v[1229]; unsigned int i; /* test in dimension 1229 */ gsl_qrng * g = gsl_qrng_alloc(gsl_qrng_halton, 1229); for (i=0;i<30;i++) gsl_qrng_get(g, v); gsl_qrng_free(g); gsl_test (status, "Halton d=1229"); status = 0; /* test in dimension 2 */ /*should be * 0.5 0.333333 * 0.25 0.666667 * 0.75 0.111111 * 0.125 0.444444*/ g = gsl_qrng_alloc(gsl_qrng_halton, 2); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_test_rel (v[0], 3.0/4.0, 1e-3, "halton(2) k=2 v[0]"); gsl_test_rel (v[1], 1.0/9.0, 1e-3, "halton(2) k=2 v[1]"); gsl_qrng_get(g, v); gsl_test_rel (v[0], 1.0/8.0, 1e-3, "halton(2) k=3 v[0]"); gsl_test_rel (v[1], 4.0/9.0, 1e-3, "halton(2) k=3 v[1]"); gsl_qrng_free(g); /* test in dimension 3 */ g = gsl_qrng_alloc(gsl_qrng_halton, 3); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.75, 1e-3, "halton(3) k=3 v[0]"); gsl_test_rel (v[1], 1.0/9.0, 1e-3, "halton(3) k=3 v[1]"); gsl_test_rel (v[2], 0.6, 1e-3, "halton(3) k=3 v[2]"); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.125, 1e-3, "halton(3) k=4 v[0]"); gsl_test_rel (v[1], 4.0/9.0, 1e-3, "halton(3) k=4 v[1]"); gsl_test_rel (v[2], 0.8, 1e-3, "halton(3) k=4 v[2]"); gsl_qrng_init(g); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.75, 1e-3, "halton(3) reinitialized k=3 v[0]"); gsl_test_rel (v[1], 1.0/9.0, 1e-3, "halton(3) reinitialized k=3 v[1]"); gsl_test_rel (v[2], 0.6, 1e-3, "halton(3) reinitialized k=3 v[2]"); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.125, 1e-3, "halton(3) reinitialized k=4 v[0]"); gsl_test_rel (v[1], 4.0/9.0, 1e-3, "halton(3) reinitialized k=4 v[1]"); gsl_test_rel (v[2], 0.8, 1e-3, "halton(3) reinitialized k=4 v[2]"); gsl_qrng_free(g); } void test_reversehalton(void) { int status = 0; double v[3]; /* test in dimension 2 */ gsl_qrng * g = gsl_qrng_alloc(gsl_qrng_reversehalton, 2); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); /* should be * 0.5 0.666667 * 0.25 0.333333 * 0.75 0.222222 * 0.125 0.888889*/ gsl_test_rel (v[0], 3.0/4.0, 1e-3, "reversehalton(2) k=2 v[0]"); gsl_test_rel (v[1], 2.0/9.0, 1e-3, "reversehalton(2) k=2 v[1]"); gsl_qrng_get(g, v); gsl_test_rel (v[0], 1.0/8.0, 1e-3, "reversehalton(2) k=2 v[0]"); gsl_test_rel (v[1], 8.0/9.0, 1e-3, "reversehalton(2) k=2 v[1]"); gsl_qrng_free(g); /* test in dimension 3 */ g = gsl_qrng_alloc(gsl_qrng_reversehalton, 3); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.75, 1e-3, "reversehalton(3) k=3 v[0]"); gsl_test_rel (v[1], 2.0/9.0, 1e-3, "reversehalton(3) k=3 v[1]"); gsl_test_rel (v[2], 0.4, 1e-3, "reversehalton(3) k=3 v[2]"); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.125, 1e-3, "reversehalton(3) k=3 v[0]"); gsl_test_rel (v[1], 8.0/9.0, 1e-3, "reversehalton(3) k=3 v[1]"); gsl_test_rel (v[2], 0.2, 1e-3, "reversehalton(3) k=3 v[2]"); status = 0; gsl_qrng_init(g); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.75, 1e-3, "reversehalton(3) reinitialized k=3 v[0]"); gsl_test_rel (v[1], 2.0/9.0, 1e-3, "reversehalton(3) reinitialized k=3 v[1]"); gsl_test_rel (v[2], 0.4, 1e-3, "reversehalton(3) reinitialized k=3 v[2]"); gsl_qrng_get(g, v); gsl_test_rel (v[0], 0.125, 1e-3, "reversehalton(3) reinitialized k=3 v[0]"); gsl_test_rel (v[1], 8.0/9.0, 1e-3, "reversehalton(3) reinitialized k=3 v[1]"); gsl_test_rel (v[2], 0.2, 1e-3, "reversehalton(3) reinitialized k=3 v[2]"); gsl_qrng_free(g); } void test_nied2(void) { int status = 0; double v[3]; /* int i; */ /* test in dimension 2 */ gsl_qrng * g = gsl_qrng_alloc(gsl_qrng_niederreiter_2, 2); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.75 || v[1] != 0.25 ); gsl_qrng_get(g, v); status += ( v[0] != 0.25 || v[1] != 0.75 ); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.625 || v[1] != 0.125 ); gsl_qrng_free(g); gsl_test (status, "Niederreiter d=2"); status = 0; /* test in dimension 3 */ g = gsl_qrng_alloc(gsl_qrng_niederreiter_2, 3); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.75 || v[1] != 0.25 || v[2] != 0.3125 ); gsl_qrng_get(g, v); status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.5625 ); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.625 || v[1] != 0.125 || v[2] != 0.6875 ); gsl_test (status, "Niederreiter d=3"); status = 0; gsl_qrng_init(g); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.75 || v[1] != 0.25 || v[2] != 0.3125 ); gsl_qrng_get(g, v); status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.5625 ); gsl_qrng_get(g, v); gsl_qrng_get(g, v); gsl_qrng_get(g, v); status += ( v[0] != 0.625 || v[1] != 0.125 || v[2] != 0.6875 ); gsl_qrng_free(g); gsl_test (status, "Niederreiter d=3 (reinitialized)"); } int main() { gsl_ieee_env_setup (); test_sobol(); test_halton(); test_reversehalton(); test_nied2(); exit (gsl_test_summary ()); }
{ "alphanum_fraction": 0.574734956, "avg_line_length": 27.0040322581, "ext": "c", "hexsha": "c5ab7cde102851ffeaf3b433fed0dcbc5708cd99", "lang": "C", "max_forks_count": 224, "max_forks_repo_forks_event_max_datetime": "2022-03-30T00:57:48.000Z", "max_forks_repo_forks_event_min_datetime": "2015-11-12T21:17:03.000Z", "max_forks_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "utdsimmons/ohpc", "max_forks_repo_path": "tests/libs/gsl/tests/qrng/test.c", "max_issues_count": 1096, "max_issues_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:48:41.000Z", "max_issues_repo_issues_event_min_datetime": "2015-11-12T09:08:22.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "utdsimmons/ohpc", "max_issues_repo_path": "tests/libs/gsl/tests/qrng/test.c", "max_line_length": 86, "max_stars_count": 692, "max_stars_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "utdsimmons/ohpc", "max_stars_repo_path": "tests/libs/gsl/tests/qrng/test.c", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:45:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-11-12T13:56:43.000Z", "num_tokens": 2978, "size": 6697 }
// // Created by pedram pakseresht on 2/18/21. // // #include <petsc.h> #include <printf.h> #include <stdlib.h> void setNumber(double *zxy); int main( int argc, char *argv[] ) { double *x = NULL; x = malloc( sizeof(double )); *x =2.0; printf("hello world %g\n", *x); setNumber(x); printf("hello world %g\n", *x); printf("size of %lu", sizeof(double *)); free(x); x=NULL; } void setNumber(double *z){ printf("hello world %g\n", *z); *z =1; printf("hello world %g\n", *z); }
{ "alphanum_fraction": 0.5730994152, "avg_line_length": 13.8648648649, "ext": "c", "hexsha": "a566cd6748e05b77494cc5381eb7b935327089ae", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c7bb7cf4a4ec706170efd7c06bf8589e30ece47b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pakserep/ablateClient", "max_forks_repo_path": "pointerExp.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "c7bb7cf4a4ec706170efd7c06bf8589e30ece47b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pakserep/ablateClient", "max_issues_repo_path": "pointerExp.c", "max_line_length": 43, "max_stars_count": null, "max_stars_repo_head_hexsha": "c7bb7cf4a4ec706170efd7c06bf8589e30ece47b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pakserep/ablateClient", "max_stars_repo_path": "pointerExp.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 162, "size": 513 }
#include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <err.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include <gsl/gsl_histogram.h> #include <gsl/gsl_errno.h> #include "my_signal.h" #include "my_socket.h" #include "set_timer.h" #include "get_num.h" int debug = 0; gsl_histogram *histo; unsigned long histo_overflow = 0; unsigned long total_bytes = 0; unsigned long read_count = 0; struct timeval start, stop; int bufsize = 2*1024*1024; int usage() { //char msg[] = "Usage: ./read-sock-histo [-b bufsize] [-w bin_width] [-B n_bin] [-t TIMEOUT] ip_address:port x_min x_max n_bin\n" char msg[] = "Usage: ./read-sock-histo [-b bufsize] [-t TIMEOUT] ip_address:port x_min x_max n_bin\n" "example of ip_address:port\n" "remote_host:1234\n" "192.168.10.16:24\n" "default port: 1234\n" " Options:\n" " -b bufsize: suffix k for kilo (1024), m for mega(1024*1024) (default 2MB)\n" " -t TIMEOUT: seconds. (default: 10 seconds)\n"; fprintf(stderr, "%s\n", msg); return 0; } void sig_int(int signo) { struct timeval elapse; gettimeofday(&stop, NULL); timersub(&stop, &start, &elapse); fprintf(stderr, "bufsize: %.3f kB\n", bufsize/1024.0); fprintf(stderr, "total bytes: %ld bytes\n", total_bytes); fprintf(stderr, "read count : %ld\n", read_count); fprintf(stderr, "running %ld.%06ld sec\n", elapse.tv_sec, elapse.tv_usec); double elapsed_time = elapse.tv_sec + 0.000001*elapse.tv_usec; double transfer_rate_MB_s = (double)total_bytes / elapsed_time / 1024.0 / 1024.0; double transfer_rate_Gbps = (double)total_bytes * 8 / elapsed_time / 1000000000.0; double read_bytes_per_read = (double)total_bytes / (double)read_count / 1024.0; fprintf(stderr, "transfer_rate: %.3f MB/s %.3f Gbps\n", transfer_rate_MB_s, transfer_rate_Gbps); fprintf(stderr, "read_bytes_per_read: %.3f kB/read\n", read_bytes_per_read); gsl_histogram_fprintf(stdout, histo, "%g", "%g"); gsl_histogram_free(histo); //if (histo_overflow > 0) { printf("# overflow: %ld\n", histo_overflow); //} exit(0); } int main(int argc, char *argv[]) { int c; int period = 10; /* default run time (10 seconds) */ while ( (c = getopt(argc, argv, "b:dht:w:B:")) != -1) { switch (c) { case 'b': bufsize = get_num(optarg); break; case 'h': usage(); exit(0); break; /* NOTREACHED */ case 'd': debug = 1; break; case 't': period = strtol(optarg, NULL, 0); break; default: break; } } argc -= optind; argv += optind; if (argc != 4) { usage(); exit(1); } int port = 1234; char *remote_host_info = argv[0]; char *tmp = strdup(remote_host_info); char *remote_host = strsep(&tmp, ":"); if (tmp != NULL) { port = strtol(tmp, NULL, 0); } double x_min = (double) get_num(argv[1]); double x_max = (double) get_num(argv[2]); int n_bin = strtol(argv[3], NULL, 0); my_signal(SIGINT, sig_int); my_signal(SIGTERM, sig_int); my_signal(SIGALRM, sig_int); histo = gsl_histogram_alloc(n_bin); gsl_histogram_set_ranges_uniform(histo, x_min, x_max); int sockfd = tcp_socket(); if (sockfd < 0) { errx(1, "tcp_socket"); } if (connect_tcp(sockfd, remote_host, port) < 0) { errx(1, "connect_tcp"); } set_timer(period, 0, period, 0); gettimeofday(&start, NULL); char *buf = malloc(bufsize); if (buf == NULL) { err(1, "malloc for buf"); } for ( ; ; ) { int n, m; n = read(sockfd, buf, bufsize); total_bytes += n; read_count ++; m = gsl_histogram_increment(histo, n); if (m == GSL_EDOM) { histo_overflow += 1; } } }
{ "alphanum_fraction": 0.5668576886, "avg_line_length": 27.7350993377, "ext": "c", "hexsha": "3d57dba7293324fa99c1d1fddd7e8c295c9e8550", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bc212c555ae044eb5b96d80c9f204fee63be3e8e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "h-sendai/read-sock-histo", "max_forks_repo_path": "read-sock-histo.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc212c555ae044eb5b96d80c9f204fee63be3e8e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "h-sendai/read-sock-histo", "max_issues_repo_path": "read-sock-histo.c", "max_line_length": 133, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc212c555ae044eb5b96d80c9f204fee63be3e8e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "h-sendai/read-sock-histo", "max_stars_repo_path": "read-sock-histo.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1180, "size": 4188 }
/* * ----------------------------------------------------------------- * ode_lib.h * ODE Solver Library * Version: 2.0 * Last Update: Oct 3, 2019 * * This is the header file for computational library with * routines to deal with Ordinary Differential Equations (ODE). * ----------------------------------------------------------------- * Programmer: Americo Barbosa da Cunha Junior * americo.cunhajr@gmail.com * ----------------------------------------------------------------- * Copyright (c) 2019 by Americo Barbosa da Cunha Junior * ----------------------------------------------------------------- */ #ifndef __ODESOLVER_LIB_H__ #define __ODESOLVER_LIB_H__ #include <gsl/gsl_vector.h> #include <gsl/gsl_matrix.h> #include <cvode/cvode.h> /* *------------------------------------------------------------ * function prototypes *------------------------------------------------------------ */ double uround(void); double wnorm(int n, double *v1, double *v2); void ewtset(int n, double *v, double atol, double rtol, double *ewt); int jacobian(CVRhsFn f, void *f_data, gsl_vector *Fx, gsl_vector *x, double t, double atol, double rtol, gsl_matrix *J); int gradient(void *cvode_mem, double t0, double delta_t, gsl_vector *phi, gsl_vector *Rphi, gsl_matrix *A); void linear_approx(gsl_vector *x, gsl_vector *x0, gsl_vector *Fx0, gsl_matrix *DFx0, gsl_vector *Fx); int odesolver_init(CVRhsFn f, void *data, double t0, int mxsteps, double atol, double rtol, gsl_vector *x, void *cvode_mem); int odesolver_reinit(double t0, gsl_vector *x, void *cvode_mem); int odesolver(void *cvode_mem, double tf, gsl_vector *Fx); #endif /* __ODESOLVER_LIB_H__ */
{ "alphanum_fraction": 0.4283113336, "avg_line_length": 24.1428571429, "ext": "h", "hexsha": "01d11e0cb8e1b942a6b719a5e36e9862327cf96e", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-12-30T01:44:13.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-15T03:57:44.000Z", "max_forks_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "americocunhajr/CRFlowLib", "max_forks_repo_path": "CRFlowLib-2.0/include/ode_lib.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "americocunhajr/CRFlowLib", "max_issues_repo_path": "CRFlowLib-2.0/include/ode_lib.h", "max_line_length": 68, "max_stars_count": 1, "max_stars_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "americocunhajr/CRFlowLib", "max_stars_repo_path": "CRFlowLib-2.0/include/ode_lib.h", "max_stars_repo_stars_event_max_datetime": "2020-12-29T12:56:14.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-29T12:56:14.000Z", "num_tokens": 455, "size": 2197 }
/** * * @file testing_zgecfi.c * * PLASMA testings module * PLASMA is a software package provided by Univ. of Tennessee, * Univ. of California Berkeley and Univ. of Colorado Denver * * This program tests the implementation of the inplace format * conversion based on the GKK algorithm by Gustavson, Karlsson, * Kagstrom. * * @version 2.6.0 * @author Mathieu Faverge * @date 2010-11-15 * * @precisions normal z -> c d s * * Purpose : * Test all the possibilities of matrix conversion (6*6) **/ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <lapacke.h> #include <plasma.h> #include "testing_zmain.h" static int conversions[36][2] = { /* No conversion */ { PlasmaCM, PlasmaCM }, { PlasmaCCRB, PlasmaCCRB }, { PlasmaCRRB, PlasmaCRRB }, { PlasmaRCRB, PlasmaRCRB }, { PlasmaRRRB, PlasmaRRRB }, { PlasmaRM, PlasmaRM }, /* One Conversion */ { PlasmaCM, PlasmaCCRB }, { PlasmaCCRB, PlasmaCM }, { PlasmaRM, PlasmaRRRB }, { PlasmaRRRB, PlasmaRM }, { PlasmaCCRB, PlasmaCRRB }, { PlasmaCRRB, PlasmaCCRB }, { PlasmaRCRB, PlasmaRRRB }, { PlasmaRRRB, PlasmaRCRB }, { PlasmaCCRB, PlasmaRCRB }, { PlasmaRCRB, PlasmaCCRB }, { PlasmaCRRB, PlasmaRRRB }, { PlasmaRRRB, PlasmaCRRB }, /* Two Conversions */ { PlasmaRM, PlasmaCRRB }, { PlasmaCRRB, PlasmaRM }, { PlasmaCM, PlasmaRCRB }, { PlasmaRCRB, PlasmaCM }, { PlasmaCCRB, PlasmaRRRB }, { PlasmaRRRB, PlasmaCCRB }, { PlasmaCRRB, PlasmaRCRB }, { PlasmaRCRB, PlasmaCRRB }, { PlasmaCM, PlasmaCRRB }, { PlasmaCRRB, PlasmaCM }, { PlasmaRCRB, PlasmaRM }, { PlasmaRM, PlasmaRCRB }, /* Three Conversions */ { PlasmaCM, PlasmaRRRB }, { PlasmaRRRB, PlasmaCM }, { PlasmaCCRB, PlasmaRM }, { PlasmaRM, PlasmaCCRB }, /* Three Conversions */ { PlasmaCM, PlasmaRM }, { PlasmaRM, PlasmaCM }, }; static int check_solution(int m, int n, int mba, int nba, int mbb, int nbb, PLASMA_Complex64_t *A, PLASMA_Complex64_t *B, int (*mapA)(int, int, int, int, int, int), int (*mapB)(int, int, int, int, int, int)) { int i, j; for( j=0; j<n; j++) { for (i=0; i<m; i++) { if (A[ mapA(m, n, mba, nba, i, j) ] != B[ mapB(m, n, mbb, nbb, i, j) ] ) { return -1; } } } return 0; } int testing_zgecfi(int argc, char **argv){ PLASMA_Complex64_t *A, *B; int m, n, mb, nb, mb2, nb2; int i, ret, size; int f1, f2; /* Check for number of arguments*/ if (argc != 6){ USAGE("GECFI", "M N MB NB with \n", " - M : the number of rows of the matrix \n" " - N : the number of columns of the matrix \n" " - MB : the number of rows of each block \n" " - NB : the number of columns of each block \n" " - MB2 : the number of rows of each block \n" " - NB2 : the number of columns of each block \n"); return -1; } m = atoi(argv[0]); n = atoi(argv[1]); mb = atoi(argv[2]); nb = atoi(argv[3]); mb2 = atoi(argv[4]); nb2 = atoi(argv[5]); /* Initialize Plasma */ size = m*n*sizeof(PLASMA_Complex64_t); A = (PLASMA_Complex64_t *)malloc(size); B = (PLASMA_Complex64_t *)malloc(size); LAPACKE_zlarnv_work(1, ISEED, m*n, A); for(i=0; i<36; i++) { memcpy(B, A, size); f1 = conversions[i][0]-PlasmaRM; f2 = conversions[i][1]-PlasmaRM; printf(" - TESTING ZGECFI (%4s => %4s) ...", formatstr[f1], formatstr[f2] ); ret = PLASMA_zgecfi(m, n, B, conversions[i][0], mb, nb, conversions[i][1], mb2, nb2); if (ret != PLASMA_SUCCESS) { printf("Failed\n"); continue; } if ( check_solution(m, n, mb, nb, mb2, nb2, A, B, (int (*)(int, int, int, int, int, int))formatmap[f1], (int (*)(int, int, int, int, int, int))formatmap[f2] ) == 0 ) printf("............ PASSED !\n"); else printf("... FAILED !\n"); #if 0 { char cmd[256]; PLASMA_Finalize(); sprintf(cmd, "mv $PWD/dot_dag_file.dot $PWD/zgecfi_%s_%s.dot", formatstr[f1], formatstr[f2]); system(cmd); PLASMA_Init(0); PLASMA_Set( PLASMA_SCHEDULING_MODE, PLASMA_DYNAMIC_SCHEDULING ); } #endif } free( A ); free( B ); return 0; }
{ "alphanum_fraction": 0.5361315448, "avg_line_length": 28.7080745342, "ext": "c", "hexsha": "d6bb98e9b1e808118072f52d18e7021eeb5e0189", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "zhuangsc/Plasma-ompss1", "max_forks_repo_path": "testing/testing_zgecfi.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "zhuangsc/Plasma-ompss1", "max_issues_repo_path": "testing/testing_zgecfi.c", "max_line_length": 113, "max_stars_count": null, "max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "zhuangsc/Plasma-ompss1", "max_stars_repo_path": "testing/testing_zgecfi.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1448, "size": 4622 }
// -------------------------------------------------------------------------- // OpenMS -- Open-Source Mass Spectrometry // -------------------------------------------------------------------------- // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, // ETH Zurich, and Freie Universitaet Berlin 2002-2013. // // This software is released under a three-clause BSD license: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of any author or any participating institution // may be used to endorse or promote products derived from this software // without specific prior written permission. // For a full list of authors, refer to the file AUTHORS. // -------------------------------------------------------------------------- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // -------------------------------------------------------------------------- // $Maintainer: Andreas Bertsch $ // $Authors: $ // -------------------------------------------------------------------------- // #ifndef OPENMS_MATH_STATISTICS_GAUSSFITTER_H #define OPENMS_MATH_STATISTICS_GAUSSFITTER_H #include <OpenMS/DATASTRUCTURES/String.h> #include <OpenMS/DATASTRUCTURES/DPosition.h> #include <vector> // gsl includes #include <gsl/gsl_rng.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_multifit_nlin.h> namespace OpenMS { namespace Math { /** @brief Implements a fitter for gaussian functions This class fits a gaussian distribution to a number of data points. The results as well as the initial guess are specified using the struct GaussFitResult. The complete gaussian formula with the fitted parameters can be transformed into a gnuplot formula using getGnuplotFormula after fitting. The fitting is implemented using GSL fitting algorithms. @ingroup Math */ class OPENMS_DLLAPI GaussFitter { public: /// struct of parameters of a gaussian distribution struct GaussFitResult { public: /// parameter A of gaussian distribution (amplitude) double A; /// parameter x0 of gaussian distribution (left/right shift) double x0; /// parameter sigma of gaussian distribution (width) double sigma; }; /// Default constructor GaussFitter(); /// Destructor virtual ~GaussFitter(); /// sets the initial parameters used by the fit method as initial guess for the gaussian void setInitialParameters(const GaussFitResult & result); /** @brief Fits a gaussian distribution to the given data points @param points the data points used for the gaussian fitting @exception Exception::UnableToFit is thrown if fitting cannot be performed */ GaussFitResult fit(std::vector<DPosition<2> > & points); /// return the gnuplot formula of the gaussian const String & getGnuplotFormula() const; protected: static int gaussFitterf_(const gsl_vector * x, void * params, gsl_vector * f); static int gaussFitterdf_(const gsl_vector * x, void * params, gsl_matrix * J); static int gaussFitterfdf_(const gsl_vector * x, void * params, gsl_vector * f, gsl_matrix * J); void printState_(size_t iter, gsl_multifit_fdfsolver * s); GaussFitResult init_param_; String gnuplot_formula_; private: /// Copy constructor (not implemented) GaussFitter(const GaussFitter & rhs); /// Assignment operator (not implemented) GaussFitter & operator=(const GaussFitter & rhs); }; } } #endif
{ "alphanum_fraction": 0.6542893726, "avg_line_length": 35.5, "ext": "h", "hexsha": "9d40eba88953079c77c6a0542792bd96f4f21cc1", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "45455356482ce5ab35e32e445609b291ec78a6d6", "max_forks_repo_licenses": [ "Zlib", "Apache-2.0" ], "max_forks_repo_name": "kreinert/OpenMS", "max_forks_repo_path": "src/openms/include/OpenMS/MATH/STATISTICS/GaussFitter.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "45455356482ce5ab35e32e445609b291ec78a6d6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Zlib", "Apache-2.0" ], "max_issues_repo_name": "kreinert/OpenMS", "max_issues_repo_path": "src/openms/include/OpenMS/MATH/STATISTICS/GaussFitter.h", "max_line_length": 102, "max_stars_count": 1, "max_stars_repo_head_hexsha": "b182ba576e0cbfbe420b8edb0dd1c42bb6c973f3", "max_stars_repo_licenses": [ "Zlib", "Apache-2.0" ], "max_stars_repo_name": "open-ms/all-svn-branches", "max_stars_repo_path": "include/OpenMS/MATH/STATISTICS/GaussFitter.h", "max_stars_repo_stars_event_max_datetime": "2018-05-23T03:43:10.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-23T03:43:10.000Z", "num_tokens": 941, "size": 4686 }
/* rng/ran2.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <config.h> #include <stdlib.h> #include <gsl/gsl_rng.h> /* This is an implementation of the algorithm used in Numerical Recipe's ran2 generator. It is a L'Ecuyer combined recursive generator with a 32-element shuffle-box. As far as I can tell, in general the effects of adding a shuffle box cannot be proven theoretically, so the period of this generator is unknown. The period of the underlying combined generator is O(2^60). */ static inline unsigned long int ran2_get (void *vstate); static double ran2_get_double (void *vstate); static void ran2_set (void *state, unsigned long int s); static const long int m1 = 2147483563, a1 = 40014, q1 = 53668, r1 = 12211; static const long int m2 = 2147483399, a2 = 40692, q2 = 52774, r2 = 3791; #define N_SHUFFLE 32 #define N_DIV (1 + 2147483562/N_SHUFFLE) typedef struct { unsigned long int x; unsigned long int y; unsigned long int n; unsigned long int shuffle[N_SHUFFLE]; } ran2_state_t; static inline unsigned long int ran2_get (void *vstate) { ran2_state_t *state = (ran2_state_t *) vstate; const unsigned long int x = state->x; const unsigned long int y = state->y; long int h1 = x / q1; long int t1 = a1 * (x - h1 * q1) - h1 * r1; long int h2 = y / q2; long int t2 = a2 * (y - h2 * q2) - h2 * r2; if (t1 < 0) t1 += m1; if (t2 < 0) t2 += m2; state->x = t1; state->y = t2; { unsigned long int j = state->n / N_DIV; long int delta = state->shuffle[j] - t2; if (delta < 1) delta += m1 - 1; state->n = delta; state->shuffle[j] = t1; } return state->n; } static double ran2_get_double (void *vstate) { float x_max = 1 - 1.2e-7f ; /* Numerical Recipes version of 1-FLT_EPS */ float x = ran2_get (vstate) / 2147483563.0f ; if (x > x_max) return x_max ; return x ; } static void ran2_set (void *vstate, unsigned long int s) { ran2_state_t *state = (ran2_state_t *) vstate; int i; if (s == 0) s = 1; /* default seed is 1 */ state->y = s; for (i = 0; i < 8; i++) { long int h = s / q1; long int t = a1 * (s - h * q1) - h * r1; if (t < 0) t += m1; s = t; } for (i = N_SHUFFLE - 1; i >= 0; i--) { long int h = s / q1; long int t = a1 * (s - h * q1) - h * r1; if (t < 0) t += m1; s = t; state->shuffle[i] = s; } state->x = s; state->n = s; return; } static const gsl_rng_type ran2_type = {"ran2", /* name */ 2147483562, /* RAND_MAX */ 1, /* RAND_MIN */ sizeof (ran2_state_t), &ran2_set, &ran2_get, &ran2_get_double}; const gsl_rng_type *gsl_rng_ran2 = &ran2_type;
{ "alphanum_fraction": 0.6312445856, "avg_line_length": 23.5578231293, "ext": "c", "hexsha": "d6555ec624638777bbfc246830993c68e953f56f", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ICML14MoMCompare/spectral-learn", "max_forks_repo_path": "code/em/treba/gsl-1.0/rng/ran2.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ICML14MoMCompare/spectral-learn", "max_issues_repo_path": "code/em/treba/gsl-1.0/rng/ran2.c", "max_line_length": 74, "max_stars_count": 14, "max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ICML14MoMCompare/spectral-learn", "max_stars_repo_path": "code/em/treba/gsl-1.0/rng/ran2.c", "max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z", "num_tokens": 1137, "size": 3463 }
#include <gsl/gsl_math.h> #include "gsl_cblas.h" #include "cblas.h" void cblas_csscal (const int N, const float alpha, void *X, const int incX) { #define BASE float #include "source_scal_c_s.h" #undef BASE }
{ "alphanum_fraction": 0.7320574163, "avg_line_length": 17.4166666667, "ext": "c", "hexsha": "bd2b2b52659f3c3dfb472b094a680b9b1d86105f", "lang": "C", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z", "max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ICML14MoMCompare/spectral-learn", "max_forks_repo_path": "code/em/treba/gsl-1.0/cblas/csscal.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ICML14MoMCompare/spectral-learn", "max_issues_repo_path": "code/em/treba/gsl-1.0/cblas/csscal.c", "max_line_length": 70, "max_stars_count": 14, "max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ICML14MoMCompare/spectral-learn", "max_stars_repo_path": "code/em/treba/gsl-1.0/cblas/csscal.c", "max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z", "num_tokens": 64, "size": 209 }
#include <math.h> #include <stdlib.h> #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> extern void getTimeSeries(int points, double* times, int from, int nAgents, double eBirth, double eDeath, int rng_seed, int* output);
{ "alphanum_fraction": 0.7488986784, "avg_line_length": 32.4285714286, "ext": "h", "hexsha": "221b511b73cc9d308f7e2a71af893a65c1207ae6", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "471fcf1bbc7cbf3865144e4b1c1bbfcd7be182f6", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "akononovicius/anomalous-diffusion-in-nonlinear-transformations-of-the-noisy-voter-model", "max_forks_repo_path": "crun/mu-zero/nvm.h", "max_issues_count": null, "max_issues_repo_head_hexsha": "471fcf1bbc7cbf3865144e4b1c1bbfcd7be182f6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "akononovicius/anomalous-diffusion-in-nonlinear-transformations-of-the-noisy-voter-model", "max_issues_repo_path": "crun/mu-zero/nvm.h", "max_line_length": 133, "max_stars_count": null, "max_stars_repo_head_hexsha": "471fcf1bbc7cbf3865144e4b1c1bbfcd7be182f6", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "akononovicius/anomalous-diffusion-in-nonlinear-transformations-of-the-noisy-voter-model", "max_stars_repo_path": "crun/mu-zero/nvm.h", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 63, "size": 227 }
#include <stdio.h> #include <string.h> #include <gsl/gsl_statistics_double.h> #include "tz_error.h" #include "tz_constant.h" #include "tz_image_lib.h" #include "tz_objdetect.h" #include "tz_imatrix.h" #include "tz_stack_math.h" #include "tz_stack_draw.h" #include "tz_pixel_array.h" #include "tz_stack_bwmorph.h" #include "tz_dimage_lib.h" #include "tz_stack_objmask.h" #include "tz_dmatrix.h" INIT_EXCEPTION_MAIN(e) int main(int argc, char* argv[]) { char neuron_name[100]; if (argc == 1) { strcpy(neuron_name, "fly_neuron"); } else { strcpy(neuron_name, argv[1]); } char file_path[100]; sprintf(file_path, "../data/%s/mask.tif", neuron_name); Stack *stack2 = Read_Stack(file_path); Stack *stack3 = Copy_Stack(stack2); sprintf(file_path, "../data/%s/blobmask.tif", neuron_name); Stack *stack1 = Read_Stack(file_path); Object_3d_List *objs = Stack_Find_Object_N(stack1, NULL, 1, 7, 26); sprintf(file_path, "../data/%s/holeimg.tif", neuron_name); Stack *hole_stack = Read_Stack(file_path); int value; int label = 2; char id_file_path[100]; sprintf(id_file_path, "../data/%s/region_id.txt", neuron_name); FILE *id_fp = fopen(id_file_path, "w"); while (objs != NULL) { int hole_area = Stack_Foreground_Area_O(hole_stack, objs->data); printf("%d / %lu\n", hole_area, objs->data->size); //if (hole_area > (int) ((double) (objs->data->size) * 0.01)) { if (hole_area > 100) { value = 3; } else { value = 2; } if (objs->data->size + hole_area < TZ_PI * 10.0 * 10.0) { TRACE("small object labeled"); } fprintf(id_fp, "%d %d\n", label, value); Stack_Draw_Object_Bw(stack3, objs->data, label++); Stack_Draw_Object_Bw(stack2, objs->data, value); objs = objs->next; } fprintf(id_fp, "-1 -1\n"); fclose(id_fp); sprintf(file_path, "../data/%s/soma.tif", neuron_name); Write_Stack(file_path, stack2); printf("%s (2: arbor, 3: soma) created.\n", file_path); sprintf(file_path, "../data/%s/region_label.tif", neuron_name); Write_Stack(file_path, stack3); printf("%s (one unique label for one region) created.\n", file_path); Kill_Stack(stack1); Kill_Stack(stack2); Kill_Stack(stack3); Kill_Stack(hole_stack); return 0; }
{ "alphanum_fraction": 0.6609498681, "avg_line_length": 25.2666666667, "ext": "c", "hexsha": "b915b14f1a56c6c358b0c6a6cfcaabeaba8bb1e5", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "zzhmark/vaa3d_tools", "max_forks_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/fly_neuron_soma.c", "max_issues_count": 1, "max_issues_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d", "max_issues_repo_issues_event_max_datetime": "2016-12-03T05:33:13.000Z", "max_issues_repo_issues_event_min_datetime": "2016-12-03T05:33:13.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "zzhmark/vaa3d_tools", "max_issues_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/fly_neuron_soma.c", "max_line_length": 71, "max_stars_count": 1, "max_stars_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "zzhmark/vaa3d_tools", "max_stars_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/fly_neuron_soma.c", "max_stars_repo_stars_event_max_datetime": "2021-12-27T19:14:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-12-27T19:14:03.000Z", "num_tokens": 685, "size": 2274 }
#include <stdio.h> #include <gsl/gsl_matrix.h> int main(void) { int i, j; gsl_matrix * m = gsl_matrix_alloc (10,3); for (i=0; i<10; i++) for (j=0; j<3; j++) gsl_matrix_set (m, i, j, 0.23 + 100*i + j); for (i=0; i< 10; i++) /* OUT OF RANGE ERROR */ for (j=0; j<3; j++) printf("m(%d,%d) = %g\n", i, j, gsl_matrix_get (m, i, j)); gsl_matrix_free(m); return 0; }
{ "alphanum_fraction": 0.5048780488, "avg_line_length": 18.6363636364, "ext": "c", "hexsha": "dceb620f3e56dc14badb20161dc021d9106b8e4d", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bdb5cd965e862ba5cc21bee75d5c8620e106c0cc", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "tcrundall/chronostar", "max_forks_repo_path": "playground/matrices.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "bdb5cd965e862ba5cc21bee75d5c8620e106c0cc", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "tcrundall/chronostar", "max_issues_repo_path": "playground/matrices.c", "max_line_length": 49, "max_stars_count": null, "max_stars_repo_head_hexsha": "bdb5cd965e862ba5cc21bee75d5c8620e106c0cc", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "tcrundall/chronostar", "max_stars_repo_path": "playground/matrices.c", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 161, "size": 410 }
#include <stdlib.h> #include <stdio.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_blas.h> #include <gsl/gsl_multifit_nlinear.h> /* parameters to model */ struct model_params { double a1; double a2; double a3; double a4; double a5; }; /* Branin function */ int func_f (const gsl_vector * x, void *params, gsl_vector * f) { struct model_params *par = (struct model_params *) params; double x1 = gsl_vector_get(x, 0); double x2 = gsl_vector_get(x, 1); double f1 = x2 + par->a1 * x1 * x1 + par->a2 * x1 + par->a3; double f2 = sqrt(par->a4) * sqrt(1.0 + (1.0 - par->a5) * cos(x1)); gsl_vector_set(f, 0, f1); gsl_vector_set(f, 1, f2); return GSL_SUCCESS; } int func_df (const gsl_vector * x, void *params, gsl_matrix * J) { struct model_params *par = (struct model_params *) params; double x1 = gsl_vector_get(x, 0); double f2 = sqrt(par->a4) * sqrt(1.0 + (1.0 - par->a5) * cos(x1)); gsl_matrix_set(J, 0, 0, 2.0 * par->a1 * x1 + par->a2); gsl_matrix_set(J, 0, 1, 1.0); gsl_matrix_set(J, 1, 0, -0.5 * par->a4 / f2 * (1.0 - par->a5) * sin(x1)); gsl_matrix_set(J, 1, 1, 0.0); return GSL_SUCCESS; } int func_fvv (const gsl_vector * x, const gsl_vector * v, void *params, gsl_vector * fvv) { struct model_params *par = (struct model_params *) params; double x1 = gsl_vector_get(x, 0); double v1 = gsl_vector_get(v, 0); double c = cos(x1); double s = sin(x1); double f2 = sqrt(par->a4) * sqrt(1.0 + (1.0 - par->a5) * c); double t = 0.5 * par->a4 * (1.0 - par->a5) / f2; gsl_vector_set(fvv, 0, 2.0 * par->a1 * v1 * v1); gsl_vector_set(fvv, 1, -t * (c + s*s/f2) * v1 * v1); return GSL_SUCCESS; } void callback(const size_t iter, void *params, const gsl_multifit_nlinear_workspace *w) { gsl_vector * x = gsl_multifit_nlinear_position(w); double x1 = gsl_vector_get(x, 0); double x2 = gsl_vector_get(x, 1); /* print out current location */ printf("%f %f\n", x1, x2); } void solve_system(gsl_vector *x0, gsl_multifit_nlinear_fdf *fdf, gsl_multifit_nlinear_parameters *params) { const gsl_multifit_nlinear_type *T = gsl_multifit_nlinear_trust; const size_t max_iter = 200; const double xtol = 1.0e-8; const double gtol = 1.0e-8; const double ftol = 1.0e-8; const size_t n = fdf->n; const size_t p = fdf->p; gsl_multifit_nlinear_workspace *work = gsl_multifit_nlinear_alloc(T, params, n, p); gsl_vector * f = gsl_multifit_nlinear_residual(work); gsl_vector * x = gsl_multifit_nlinear_position(work); int info; double chisq0, chisq, rcond; printf("# %s/%s\n", gsl_multifit_nlinear_name(work), gsl_multifit_nlinear_trs_name(work)); /* initialize solver */ gsl_multifit_nlinear_init(x0, fdf, work); /* store initial cost */ gsl_blas_ddot(f, f, &chisq0); /* iterate until convergence */ gsl_multifit_nlinear_driver(max_iter, xtol, gtol, ftol, callback, NULL, &info, work); /* store final cost */ gsl_blas_ddot(f, f, &chisq); /* store cond(J(x)) */ gsl_multifit_nlinear_rcond(&rcond, work); /* print summary */ fprintf(stderr, "%-25s %-6zu %-5zu %-5zu %-13.4e %-12.4e %-13.4e (%.2e, %.2e)\n", gsl_multifit_nlinear_trs_name(work), gsl_multifit_nlinear_niter(work), fdf->nevalf, fdf->nevaldf, chisq0, chisq, 1.0 / rcond, gsl_vector_get(x, 0), gsl_vector_get(x, 1)); printf("\n\n"); gsl_multifit_nlinear_free(work); } int main (void) { const size_t n = 2; const size_t p = 2; gsl_vector *f = gsl_vector_alloc(n); gsl_vector *x = gsl_vector_alloc(p); gsl_multifit_nlinear_fdf fdf; gsl_multifit_nlinear_parameters fdf_params = gsl_multifit_nlinear_default_parameters(); struct model_params params; params.a1 = -5.1 / (4.0 * M_PI * M_PI); params.a2 = 5.0 / M_PI; params.a3 = -6.0; params.a4 = 10.0; params.a5 = 1.0 / (8.0 * M_PI); /* print map of Phi(x1, x2) */ { double x1, x2, chisq; for (x1 = -5.0; x1 < 15.0; x1 += 0.1) { for (x2 = -5.0; x2 < 15.0; x2 += 0.1) { gsl_vector_set(x, 0, x1); gsl_vector_set(x, 1, x2); func_f(x, &params, f); gsl_blas_ddot(f, f, &chisq); printf("%f %f %f\n", x1, x2, chisq); } printf("\n"); } printf("\n\n"); } /* define function to be minimized */ fdf.f = func_f; fdf.df = func_df; fdf.fvv = func_fvv; fdf.n = n; fdf.p = p; fdf.params = &params; /* starting point */ gsl_vector_set(x, 0, 6.0); gsl_vector_set(x, 1, 14.5); fprintf(stderr, "%-25s %-6s %-5s %-5s %-13s %-12s %-13s %-15s\n", "Method", "NITER", "NFEV", "NJEV", "Initial Cost", "Final cost", "Final cond(J)", "Final x"); fdf_params.trs = gsl_multifit_nlinear_trs_lm; solve_system(x, &fdf, &fdf_params); fdf_params.trs = gsl_multifit_nlinear_trs_lmaccel; solve_system(x, &fdf, &fdf_params); fdf_params.trs = gsl_multifit_nlinear_trs_dogleg; solve_system(x, &fdf, &fdf_params); fdf_params.trs = gsl_multifit_nlinear_trs_ddogleg; solve_system(x, &fdf, &fdf_params); fdf_params.trs = gsl_multifit_nlinear_trs_subspace2D; solve_system(x, &fdf, &fdf_params); gsl_vector_free(f); gsl_vector_free(x); return 0; }
{ "alphanum_fraction": 0.6207346634, "avg_line_length": 25.5380952381, "ext": "c", "hexsha": "9dbf278372d284108daf4e2b3dbd6ec068f5fdcc", "lang": "C", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z", "max_forks_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "Brian-ning/HMNE", "max_forks_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/doc/examples/nlfit3.c", "max_issues_count": 6, "max_issues_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z", "max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "Brian-ning/HMNE", "max_issues_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/doc/examples/nlfit3.c", "max_line_length": 83, "max_stars_count": 1, "max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ielomariala/Hex-Game", "max_stars_repo_path": "gsl-2.6/doc/examples/nlfit3.c", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z", "num_tokens": 1891, "size": 5363 }
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <gsl/gsl_bspline.h> #include <gsl/gsl_spline.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_linalg.h> /* number of data points to fit */ #define N 6 /* number of fit coefficients */ #define NCOEFFS 6 /* Spline order */ #define K 3 /* nbreak = ncoeffs + 2 - k */ #define NBREAK (NCOEFFS + 2 - K) void gsl_solve( gsl_matrix *A, const size_t n, double xmax, double xmin, double *B ) { printf("\n *** Solve with GSL *** \n"); gsl_vector *d; d = gsl_vector_alloc(n); gsl_vector *e; e = gsl_vector_alloc(n-1); gsl_vector *f; f = gsl_vector_alloc(n-1); gsl_vector *b; b = gsl_vector_alloc(n); gsl_vector *x; x = gsl_vector_alloc(n); for (int i = 0; i < n; i++) { gsl_vector_set(d, i, gsl_matrix_get(A,i,i)); if (i>0) gsl_vector_set(f, i-1, gsl_matrix_get(A,i,i-1)); if (i<n-1) gsl_vector_set(e, i, gsl_matrix_get(A,i,i+1)); } for (int i=0; i<n; i++) gsl_vector_set(b,i,B[i]); gsl_linalg_solve_tridiag ( d, e, f, b, x); for (int i=0; i<n; i++) printf ("x[%d] = %f \n", i, gsl_vector_get(x,i)); gsl_vector_free(e); e = gsl_vector_alloc(n); gsl_vector_free(f); f = gsl_vector_alloc(n); double alpha = 0.5; double beta = 0.5; printf("\n *** A Matrix *** \n"); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf ("%6.3f", gsl_matrix_get (A, i, j)); } printf("\n"); } for (int i = 0; i < n; i++) { gsl_vector_set(d, i, gsl_matrix_get(A,i,i)); if (i>0) gsl_vector_set(f, i-1, gsl_matrix_get(A,i,i-1)); if (i<n-1) gsl_vector_set(e, i, gsl_matrix_get(A,i,i+1)); } gsl_vector_set(e,n-1,alpha); gsl_vector_set(f,n-1,beta); for (int i=0; i<n; i++) gsl_vector_set(b,i,B[i]); // A = ( d_0 e_0 0 f_3 ) // ( f_0 d_1 e_1 0 ) // ( 0 f_1 d_2 e_2 ) // ( e_3 0 f_2 d_3 ) for (int i=0; i<n; i++) printf ("%d = %f %f %f \n", i, gsl_vector_get(d,i) , gsl_vector_get(e,i) , gsl_vector_get(f,i)); gsl_linalg_solve_cyc_tridiag (d, e, f, b, x); printf("\n cyclic \n\n"); for (int i=0; i<n; i++) printf ("x[%d] = %f \n", i, gsl_vector_get(x,i)); } void tridag(double a[], double b[], double c[], double r[], double u[], int n) { double bet; double *gam; gam = (double *) malloc(n*sizeof(double)); if (b[0] == 0.0) printf("Error 1 in tridag"); u[0]=r[0]/(bet=b[0]); for (int j=1;j<n;j++) { gam[j]= c[j-1]/bet; bet=b[j]-a[j]*gam[j]; if (bet == 0.0) printf("Error 2 in tridag"); u[j]=(r[j]-a[j]*u[j-1])/bet; } for (int j=(n-2);j>=0;j--) u[j] -= gam[j+1]*u[j+1]; free(gam); } void cyclic(double a[], double b[], double c[], double alpha, double beta, double r[], double x[], int n) { double fact,gamma; double *bb; double *u; double *z; if (n <= 2) printf("n too small in cyclic"); bb = (double *) malloc(n*sizeof(double)); u = (double *) malloc(n*sizeof(double)); z = (double *) malloc(n*sizeof(double)); gamma = -b[0]; bb[0] = b[0]-gamma; bb[n-1] = b[n-1]-alpha*beta/gamma; for (int i=1;i<n-1;i++) bb[i]=b[i]; tridag(a,bb,c,r,x,n); u[0] =gamma; u[n-1]=alpha; for (int i=1;i<n-1;i++) u[i]=0.0; tridag(a,bb,c,u,z,n); fact=(x[0]+beta*x[n-1]/gamma)/(1.0+z[0]+beta*z[n-1]/gamma); for (int i=0;i<n;i++) x[i] -= fact*z[i]; free(z); free(u); free(bb); } void nr_solve( gsl_matrix *A, int n, double xmax, double xmin, double *B ) { printf("\n *** Solve with Numerical Recipes *** \n"); double *a; a = (double *) malloc(n*sizeof(double)); double *b; b = (double *) malloc(n*sizeof(double)); double *c; c = (double *) malloc(n*sizeof(double)); double *r; r = (double *) malloc(n*sizeof(double)); double *u; u = (double *) malloc(n*sizeof(double)); for (int i = 0; i < n; i++) { if (i>0) a[i] = gsl_matrix_get (A, i, i-1); b[i] = gsl_matrix_get (A, i, i); if (i<n-1) c[i] = gsl_matrix_get (A, i, i+1); r[i] = B[i]; } for (int i=0; i<n; i++) printf ("%d = %f %f %f \n", i, a[i], b[i], c[i]); tridag ( a, b, c, r, u, n); for (int i=0; i<n; i++) printf ("u[%d] = %f \n", i, u[i]); double alpha = 0.5; double beta = 0.5; cyclic( a, b, c, alpha, beta, r, u, n); printf("\n cyclic \n\n"); for (int i=0; i<n; i++) printf ("u[%d] = %f \n", i, u[i]); } int main (void) { const size_t n = N; const size_t ncoeffs = NCOEFFS; const size_t nbreak = NBREAK; size_t i, j; gsl_bspline_workspace *bw; gsl_vector *B; double xmin=0.0, xmax=2.0; const size_t k = K; gsl_vector *tau; gsl_matrix *A; double *y; double dx = (xmax-xmin)/(n-1); double xc = (xmax+xmin)*0.5; y = (double *) malloc(ncoeffs*sizeof(double)); tau = gsl_vector_alloc(n); /* allocate a cubic bspline workspace */ bw = gsl_bspline_alloc(k, nbreak); B = gsl_vector_alloc(ncoeffs); A = gsl_matrix_alloc(n, ncoeffs); /* gsl_bspline_knots(breakpts, bw) Compute the knots from the given breakpoints: knots(1:k) = breakpts(1) knots(k+1:k+l-1) = breakpts(i), i = 2 .. l knots(n+1:n+k) = breakpts(l + 1) */ /* use uniform breakpoints on [xmin, xmax] */ gsl_bspline_knots_uniform(xmin, xmax, bw); //knots(1:k) = xmin //knots(k+1:k+l-1) = xmin + i*delta, i = 1 .. l - 1 //knots(n+1:n+k) = xmax /* construct the fit matrix X */ for (i = 0; i < n; ++i) { double taui = i * dx; double ti = gsl_vector_get(bw->knots, i); gsl_vector_set(tau, i, taui); /* compute B_j(xi) for all j */ gsl_bspline_eval(taui, B, bw); printf("%f %f\n", taui, ti); /* fill in row i of X */ for (j = 0; j < ncoeffs; ++j) { double Bj = gsl_vector_get(B, j); gsl_matrix_set(A, i, j, Bj); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf ("%6.3f", gsl_matrix_get (A, i, j)); } printf("\n"); } for (int i=0; i<n;i++) y[i] = fabs(i*dx-xc); nr_solve( A, ncoeffs, xmax, xmin, y); gsl_solve( A, ncoeffs, xmax, xmin, y); gsl_bspline_free(bw); gsl_vector_free(B); gsl_matrix_free(A); return 0; }
{ "alphanum_fraction": 0.5107608366, "avg_line_length": 22.2905405405, "ext": "c", "hexsha": "1aa9581c45d554596b82e6787e68816ee266f7c0", "lang": "C", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_forks_repo_licenses": [ "CECILL-B" ], "max_forks_repo_name": "utastudents/selalib", "max_forks_repo_path": "external/pppack/testing/test_gsl_bsplines.c", "max_issues_count": 8, "max_issues_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_licenses": [ "CECILL-B" ], "max_issues_repo_name": "utastudents/selalib", "max_issues_repo_path": "external/pppack/testing/test_gsl_bsplines.c", "max_line_length": 61, "max_stars_count": 8, "max_stars_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_stars_repo_licenses": [ "CECILL-B" ], "max_stars_repo_name": "utastudents/selalib", "max_stars_repo_path": "external/pppack/testing/test_gsl_bsplines.c", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "num_tokens": 2374, "size": 6598 }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include "compearth.h" #include "cmopad.h" #ifdef COMPEARTH_USE_MKL #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreserved-id-macro" #pragma clang diagnostic ignored "-Wstrict-prototypes" #endif #include <mkl_cblas.h> #ifdef __clang__ #pragma clang diagnostic pop #endif #else #include <cblas.h> #endif struct mt_struct { double mt[6]; double tax[3]; double bax[3]; double pax[3]; double sdr1[3]; //strike dip rake; fault plane 2 double sdr2[3]; //strike dip rake; fault plane 1 double mag; double exp; }; /* int compearth_standardDecomposition(const int nmt, const double *__restrict__ M, enum compearthCoordSystem_enum basis, double *__restrict__ M0, double *__restrict__ Mw, double *__restrict__ fp1, double *__restrict__ fp2, double *__restrict__ pAxis, double *__restrict__ bAxis, double *__restrict__ tAxis, double *__restrict__ isoPct, double *__restrict__ devPct, double *__restrict__ dcPct, double *__restrict__ clvdPct); */ int decompose(const int nmt, const double mtUSE[6]); int decompose(const int nmt, const double mtUSE[6]) { //double K[3], N[3], S[3], lam[3], U[9], Uuse[9], b[3], p[3], t[3], //double gamma, delta, M0, kappa, theta, sigma, thetadc, // k2, d2, s2; struct cmopad_struct src; const char *fcnm = "decompose\0"; enum cmopad_basis_enum cin, cloc; double M[3][3], pax[3], bax[3], tax[3]; int i, ierr; const int iverb = 0; /* //------------------------------------------------------------------------// // Do the cMoPaD decomposition // //------------------------------------------------------------------------// // Copy moment tensor M[0][0] = mtUSE[0]; //Mrr M[1][1] = mtUSE[1]; //Mtt M[2][2] = mtUSE[2]; //Mpp M[0][1] = M[1][0] = mtUSE[3]; //Mrt M[0][2] = M[2][0] = mtUSE[4]; //Mrp M[1][2] = M[2][1] = mtUSE[5]; //Mtp // Mopad works in North, East, Down frame but inversion is Up, South, East cin = USE; cloc = NED; cmopad_basis_transformMatrixM33(M, cin, cloc); //USE -> NED // Compute the isotropic, CLVD, DC decomposition ierr = cmopad_standardDecomposition(M, &src); if (ierr != 0) { printf("%s: Error in decomposition!\n", fcnm); return EXIT_FAILURE; } // Compute the princple axes with corresponding strikes, dips, and rakes ierr = cmopad_MT2PrincipalAxisSystem(iverb, &src); if (ierr != 0) { printf("%s: Error computing principal axis\n",fcnm); return EXIT_FAILURE; } // Compute the pressure, null, and, tension principal axes as len,az,plunge cin = NED; //MoPaD is in north, east, down ierr = cmopad_Eigenvector2PrincipalAxis(cin, src.eig_pnt[0], src.p_axis, pax); if (ierr != 0) { printf("%s: Error converting pax\n",fcnm); return EXIT_FAILURE; } ierr = cmopad_Eigenvector2PrincipalAxis(cin, src.eig_pnt[1], src.null_axis, bax); if (ierr != 0){ printf("%s: Error converting bax\n",fcnm); return EXIT_FAILURE; } ierr = cmopad_Eigenvector2PrincipalAxis(cin, src.eig_pnt[2], src.t_axis, tax); if (ierr != 0) { printf("%s: Error converting tax\n",fcnm); return EXIT_FAILURE; } */ //printf("%f %f %f %f %f %f\n", // mtUSE[0], mtUSE[1], mtUSE[2], mtUSE[3], mtUSE[4], mtUSE[5]); //ierr = compearth_CMT2TT(1, mtUSE, false, // &gamma, &delta, &M0, // &kappa, &theta, &sigma, // K, N, S, &thetadc, // lam, U); //if (ierr != 0) //{ // fprintf(stderr, "%s: CMT2TT failed\n", __func__); // return EXIT_FAILURE; //} /* // Need to switch from SEU to USE. This requires computing // R U inv(R) where: // R = [0 0 1 // 1 0 0 // 0 1 0] // Carrying through the multiplication yields the permutation // U_{use} = [U_{33} U_{31} U_{32} // U_{13} U_{11} U_{12} // U_{23} U_{21} U_{22}] // // Permute the column major matrix Uuse[0] = U[8]; Uuse[1] = U[6]; Uuse[2] = U[7]; Uuse[3] = U[2]; Uuse[4] = U[0]; Uuse[5] = U[1]; Uuse[6] = U[5]; Uuse[7] = U[3]; Uuse[8] = U[4]; printf("%f %f %f\n%f %f %f\n%f %f %f\n", U[0], U[3], U[6], U[1], U[4], U[7], U[2], U[5], U[8]); */ //ierr = compearth_U2pa(1, U, // &p[2], &p[1], &b[2], &b[1], &t[2], &t[1]); //if (ierr != 0) //{ // fprintf(stderr, "%s: Error converting u to plunge/azimuth\n", // __func__); // return EXIT_FAILURE; //} //// Fill in the eigenvalues //p[0] = lam[0]; //b[0] = lam[1]; //t[0] = lam[2]; //printf("p: %e %f %f\n", p[0], p[1], p[2]); //printf("b: %e %f %f\n", b[0], b[1], b[2]); //printf("t: %e %f %f\n", t[0] ,t[1], t[2]); // Compute the auxiliary fault plane //ierr = compearth_auxiliaryPlane(1, &kappa, &theta, &sigma, // &k2, &d2, &s2); // Just define some convention where smaller strike goes first //printf("%e %f %f %f\n", M0, kappa, theta, sigma); //printf("%f %f %f\n", k2, d2, s2); //------------------------------------------------------------------------// // do the standard decomposition // //------------------------------------------------------------------------// //double pAxis[3], bAxis[3], tAxis[3], fp1[3], fp2[3], isoPct, dcPct, devPct, clvdPct, Mw; double *pAxis, *bAxis, *tAxis, *fp1, *fp2, *isoPct, *dcPct, *devPct, *clvdPct, *Mw, *M0; M0 = (double *) calloc((size_t) nmt, sizeof(double)); Mw = (double *) calloc((size_t) nmt, sizeof(double)); fp1 = (double *) calloc((size_t) (3*nmt), sizeof(double)); fp2 = (double *) calloc((size_t) (3*nmt), sizeof(double)); pAxis = (double *) calloc((size_t) (3*nmt), sizeof(double)); bAxis = (double *) calloc((size_t) (3*nmt), sizeof(double)); tAxis = (double *) calloc((size_t) (3*nmt), sizeof(double)); isoPct = (double *) calloc((size_t) nmt, sizeof(double)); devPct = (double *) calloc((size_t) nmt, sizeof(double)); dcPct = (double *) calloc((size_t) nmt, sizeof(double)); clvdPct = (double *) calloc((size_t) nmt, sizeof(double)); ierr = compearth_standardDecomposition(nmt, mtUSE, CE_USE, M0, Mw, fp1, fp2, pAxis, bAxis, tAxis, isoPct, devPct, dcPct, clvdPct); if (ierr != 0) { fprintf(stderr, "Failed to compute standard decomposition\n"); return EXIT_FAILURE; } for (i=0; i<nmt; i++) { //--------------------------------------------------------------------// // Do the cMoPaD decomposition // //--------------------------------------------------------------------// // Copy moment tensor M[0][0] = mtUSE[6*i+0]; //Mrr M[1][1] = mtUSE[6*i+1]; //Mtt M[2][2] = mtUSE[6*i+2]; //Mpp M[0][1] = M[1][0] = mtUSE[6*i+3]; //Mrt M[0][2] = M[2][0] = mtUSE[6*i+4]; //Mrp M[1][2] = M[2][1] = mtUSE[6*i+5]; //Mtp // Mopad works in North, East, Down cin = USE; cloc = NED; cmopad_basis_transformMatrixM33(M, cin, cloc); //USE -> NED // Compute the isotropic, CLVD, DC decomposition ierr = cmopad_standardDecomposition(M, &src); if (ierr != 0) { printf("%s: Error in decomposition!\n", fcnm); return EXIT_FAILURE; } // Compute the princple axes and strikes, dips, and rakes ierr = cmopad_MT2PrincipalAxisSystem(iverb, &src); if (ierr != 0) { printf("%s: Error computing principal axis\n",fcnm); return EXIT_FAILURE; } // Compute the pressure, null, and, tension principal axes as // len,az,plunge cin = NED; //MoPaD is in north, east, down ierr = cmopad_Eigenvector2PrincipalAxis(cin, src.eig_pnt[0], src.p_axis, pax); if (ierr != 0) { printf("%s: Error converting pax\n",fcnm); return EXIT_FAILURE; } ierr = cmopad_Eigenvector2PrincipalAxis(cin, src.eig_pnt[1], src.null_axis, bax); if (ierr != 0) { printf("%s: Error converting bax\n",fcnm); return EXIT_FAILURE; } ierr = cmopad_Eigenvector2PrincipalAxis(cin, src.eig_pnt[2], src.t_axis, tax); if (ierr != 0) { printf("%s: Error converting tax\n",fcnm); return EXIT_FAILURE; } // Check it //printf("%d %d %e\n", i, i%9, Mw[i]); if (fabs(M0[i] - src.seismic_moment)/src.seismic_moment > 1.e-10) { fprintf(stderr, "failed M0 %f %f %e %d\n", M0[i], src.seismic_moment, fabs(M0[i] - src.seismic_moment)/src.seismic_moment, i); return EXIT_FAILURE; } if (fabs(Mw[i] - src.moment_magnitude) > 1.e-10) { fprintf(stderr, "failed Mw %f %f %d\n", Mw[i], src.moment_magnitude, i); return EXIT_FAILURE; } if (fabs(isoPct[i] - src.ISO_percentage) > 1.e-10) { fprintf(stderr, "Failed iso pct %f %f\n", isoPct[i], src.ISO_percentage); return EXIT_FAILURE; } if (fabs(dcPct[i] - src.DC_percentage) > 1.e-10) { fprintf(stderr, "Failed DC pct %f %f %d\n", dcPct[i], src.DC_percentage, i); return EXIT_FAILURE; } if (fabs(devPct[i] - src.DEV_percentage) > 1.e-10) { fprintf(stderr, "Failed dev pct %f %f\n", devPct[i], src.DEV_percentage); return EXIT_FAILURE; } if (fabs(clvdPct[i] - src.CLVD_percentage) > 1.e-10) { fprintf(stderr, "Failed clvd pct %f %f\n", devPct[i], src.CLVD_percentage); return EXIT_FAILURE; } // Swap fault planes if (fabs(fp1[3*i+0] - src.fp1[0]) > 1.e-10) { if (fabs(fp1[3*i+0] - src.fp2[0]) > 1.e-10) { fprintf(stderr, "Failed strike 1 %f %f\n", fp1[3*i+0], src.fp2[0]); return EXIT_FAILURE; } if (fabs(fp1[3*i+1] - src.fp2[1]) > 1.e-10) { fprintf(stderr, "Failed dip 1 %f %f\n", fp1[3*i+1], src.fp2[1]); return EXIT_FAILURE; } if (fabs(fp1[3*i+2] - src.fp2[2]) > 1.e-10) { fprintf(stderr, "Failed rake 1 %f %f\n", fp1[3*i+2], src.fp2[2]); return EXIT_FAILURE; } if (fabs(fp2[3*i+0] - src.fp1[0]) > 1.e-10) { fprintf(stderr, "Failed strike 2 %f %f\n", fp2[3*i+0], src.fp1[0]); return EXIT_FAILURE; } if (fabs(fp2[3*i+1] - src.fp1[1]) > 1.e-10) { fprintf(stderr, "Failed dip 2 %f %f\n", fp2[3*i+1], src.fp1[1]); return EXIT_FAILURE; } if (fabs(fp2[3*i+2] - src.fp1[2]) > 1.e-10) { fprintf(stderr, "Failed rake 2 %f %f\n", fp2[3*i+2], src.fp1[2]); return EXIT_FAILURE; } } else { if (fabs(fp1[3*i+0] - src.fp1[0]) > 1.e-10) { fprintf(stderr, "Failed strike 1 %f %f\n", fp1[3*i+0], src.fp1[0]); return EXIT_FAILURE; } if (fabs(fp1[3*i+1] - src.fp1[1]) > 1.e-10) { fprintf(stderr, "Failed dip 1 %f %f\n", fp1[3*i+1], src.fp1[1]); return EXIT_FAILURE; } if (fabs(fp1[3*i+2] - src.fp1[2]) > 1.e-10) { fprintf(stderr, "Failed rake 1 %f %f\n", fp1[3*i+2], src.fp1[2]); return EXIT_FAILURE; } if (fabs(fp2[3*i+0] - src.fp2[0]) > 1.e-10) { fprintf(stderr, "Failed strike 2 %f %f\n", fp2[3*i+0], src.fp2[0]); return EXIT_FAILURE; } if (fabs(fp2[3*i+1] - src.fp2[1]) > 1.e-10) { fprintf(stderr, "Failed dip 2 %f %f\n", fp2[3*i+1], src.fp2[1]); return EXIT_FAILURE; } if (fabs(fp2[3*i+2] - src.fp2[2]) > 1.e-10) { fprintf(stderr, "Failed rake 2 %f %f\n", fp2[3*i+2], src.fp2[2]); return EXIT_FAILURE; } } if (fabs(pAxis[3*i+0] - pax[0]) > 1.e-10 || fabs(pAxis[3*i+1] - pax[1]) > 1.e-10 || fabs((pAxis[3*i+2] - pax[2])/pax[2]) > 1.e-10) { fprintf(stderr, "failed pressure axix: %f %f %f %f %f %f\n", pAxis[0], pAxis[1], pAxis[2], pax[0], pax[1], pax[2]); return EXIT_FAILURE; } if (fabs(bAxis[3*i+0] - bax[0]) > 1.e-10 || fabs(bAxis[3*i+1] - bax[1]) > 1.e-10 || fabs((bAxis[3*i+2] - bax[2])/bax[2]) > 1.e-10) { fprintf(stderr, "Failed null axis: %f %f %f %f %f %f\n", bAxis[0], bAxis[1], bAxis[2], bax[0], bax[1], bax[2]); return EXIT_FAILURE; } if (fabs(tAxis[3*i+0] - tax[0]) > 1.e-10 || fabs(tAxis[3*i+1] - tax[1]) > 1.e-10 || fabs((tAxis[3*i+2] - tax[2])/tax[2]) > 1.e-10) { fprintf(stderr, "Failed tension axis %f %f %f %f %f %f\n", tAxis[0], tAxis[1], tAxis[2], tax[0], tax[1], tax[2]); return EXIT_FAILURE; } if (nmt == 1) { printf("Summary:\n"); printf("Mw: %f\n", Mw[i]); printf("(strike,dip,rake): (%f,%f,%f)\n", fp1[3*i+0], fp1[3*i+1], fp1[3*i+2]); printf("(strike,dip,rake): (%f,%f,%f)\n", fp2[3*i+0], fp2[3*i+1], fp2[3*i+2]); printf("iso pct: %f\n", isoPct[i]); printf("dc pct: %f\n", dcPct[i]); printf("dev pct: %f\n", devPct[i]); printf("clvd pct: %f\n", clvdPct[i]); printf("\n"); } } free(M0); free(Mw); free(fp1); free(fp2); free(pAxis); free(bAxis); free(tAxis); free(isoPct); free(devPct); free(dcPct); free(clvdPct); return EXIT_SUCCESS; } int main() { struct mt_struct mt; const int nmt = 21*CE_CHUNKSIZE - 1; double *mtTest = (double *) calloc((size_t) (6*nmt), sizeof(double)); //mtTest[2*6*CE_CHUNKSIZE]; double xscal; int ierr, jmt; const int n6 = 6; const int incx = 1; //-----------------------------------1------------------------------------// mt.exp = 23.0 - 7.0; mt.mag = 5.1; mt.mt[0] =-4.360; mt.mt[1] = 3.200; mt.mt[2] = 1.170; mt.mt[3] =-0.794; mt.mt[4] = 1.650; mt.mt[5] = 2.060; mt.sdr1[0] = 77.0; mt.sdr1[1] = 47.0; mt.sdr1[2] =-62.0; mt.sdr2[0] = 219.0; mt.sdr2[1] = 50.0; mt.sdr2[2] =-117.0; mt.tax[0] = 4.49; mt.tax[1] = 1.0; mt.tax[2] = 328.0; mt.bax[0] = 0.56; mt.bax[1] = 20.0; mt.bax[2] = 237.0; mt.pax[0] =-5.04; mt.pax[1] = 70.0; mt.pax[2] = 61.0; xscal = pow(10.0, mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[0], 1); // Perform decomposition ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decomposiing 1\n"); return EXIT_FAILURE; } //--------------------------------------2----------------------------------// mt.exp = 23.0 - 7.0; mt.mag = 5.0; mt.mt[0] =-4.480; mt.mt[1] = 1.440; mt.mt[2] = 3.040; mt.mt[3] = 0.603; mt.mt[4] = 0.722; mt.mt[5] =-1.870; mt.sdr1[0] =316.0; mt.sdr1[1] = 44.0; mt.sdr1[2] =-105.0; mt.sdr2[0] = 157.0; mt.sdr2[1] = 48.0; mt.sdr2[2] =-76.0; mt.tax[0] = 4.28; mt.tax[1] = 2.0; mt.tax[2] = 237.0; mt.bax[0] = 0.37; mt.bax[1] = 10.0; mt.bax[2] = 327.0; mt.pax[0] =-4.66; mt.pax[1] = 79.0; mt.pax[2] =137.0; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[6], 1); // Perform decomposition ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decomposiing 1\n"); return EXIT_FAILURE; } //------------------------------------3-----------------------------------// mt.exp = 23.0 - 7.0; mt.mag = 4.9; mt.mt[0] =-2.460; mt.mt[1] = 0.207; mt.mt[2] = 2.250; mt.mt[3] = 0.793; mt.mt[4] = 0.267; mt.mt[5] =-0.363; mt.sdr1[0] =335.0; mt.sdr1[1] = 46.0; mt.sdr1[2] =-113.0; mt.sdr2[0] = 186.0; mt.sdr2[1] = 49.0; mt.sdr2[2] =-68.0; mt.tax[0] = 2.32; mt.tax[1] = 2.0; mt.tax[2] = 261.0; mt.bax[0] = 0.38; mt.bax[1] = 16.0; mt.bax[2] = 351.0; mt.pax[0] =-2.70; mt.pax[1] = 74.0; mt.pax[2] =165.0; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[12], 1); ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decomposing 3\n"); return EXIT_FAILURE; } //-----------------------------------4------------------------------------// mt.exp = 23.0 - 7.0; mt.mag = 4.9; mt.mt[0] =-2.270; mt.mt[1] = 0.058; mt.mt[2] = 2.210; mt.mt[3] = 0.079; mt.mt[4] =-0.737; mt.mt[5] = 0.246; mt.sdr1[0] =190.0; mt.sdr1[1] = 36.0; mt.sdr1[2] =-84.0; mt.sdr2[0] = 3.0; mt.sdr2[1] = 54.0; mt.sdr2[2] =-94.0; mt.tax[0] = 2.35; mt.tax[1] = 9.0; mt.tax[2] = 96.0; mt.bax[0] = 0.04; mt.bax[1] = 4.0; mt.bax[2] = 5.0; mt.pax[0] =-2.39; mt.pax[1] = 80.0; mt.pax[2] =253.0; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[18], 1); ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error dcomposing 4\n"); return EXIT_FAILURE; } //-----------------------------------5------------------------------------// mt.exp = 26.0 - 7.0; mt.mag = 6.5; mt.mt[0] = 0.745; mt.mt[1] =-0.036; mt.mt[2] =-0.709; mt.mt[3] =-0.242; mt.mt[4] =-0.048; mt.mt[5] = 0.208; mt.sdr1[0] =181.0; mt.sdr1[1] = 47.0; mt.sdr1[2] =114.0; mt.sdr2[0] = 328.0; mt.sdr2[1] = 48.0; mt.sdr2[2] = 67.0; mt.tax[0] = 0.82; mt.tax[1] = 73.0; mt.tax[2] = 166.0; mt.bax[0] =-0.05; mt.bax[1] = 17.0; mt.bax[2] = 344.0; mt.pax[0] =-0.77; mt.pax[1] = 1.0; mt.pax[2] = 74.0; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[24], 1); ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decomposing 5\n"); return EXIT_FAILURE; } //-----------------------------------6------------------------------------// mt.exp = 24.0 - 7.0; mt.mag = 5.3; mt.mt[0] = 0.700; mt.mt[1] =-0.883; mt.mt[2] = 0.183; mt.mt[3] = 0.260; mt.mt[4] = 0.289; mt.mt[5] = 0.712; mt.sdr1[0] =329.0; mt.sdr1[1] = 54.0; mt.sdr1[2] =141.0; mt.sdr2[0] = 85.0; mt.sdr2[1] = 59.0; mt.sdr2[2] = 43.0; mt.tax[0] = 1.01; mt.tax[1] = 51.0; mt.tax[2] = 300.0; mt.bax[0] = 0.24; mt.bax[1] = 39.0; mt.bax[2] = 113.0; mt.pax[0] =-1.25; mt.pax[1] = 3.0; mt.pax[2] = 206.; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[30], 1); ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decomposing 6\n"); return EXIT_FAILURE; } //-----------------------------------7------------------------------------// mt.exp = 23.0 - 7.0; mt.mag = 5.0; mt.mt[0] = 3.150; mt.mt[1] =-2.470; mt.mt[2] =-0.676; mt.mt[3] = 1.650; mt.mt[4] = 1.880; mt.mt[5] =-1.470; mt.sdr1[0] =252.0; mt.sdr1[1] = 28.0; mt.sdr1[2] =111.0; mt.sdr2[0] = 49.0; mt.sdr2[1] = 64.0; mt.sdr2[2] = 79.0; mt.tax[0] = 4.08; mt.tax[1] = 69.0; mt.tax[2] = 297.0; mt.bax[0] = 0.01; mt.bax[1] = 10.0; mt.bax[2] = 54.0; mt.pax[0] =-4.08; mt.pax[1] = 18.0; mt.pax[2] = 147.0; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[36], 1); ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decomposing 7\n"); return EXIT_FAILURE; } //-----------------------------------8------------------------------------// mt.exp = 23.0 - 7.0; mt.mag = 4.8; mt.mt[0] =-1.870; mt.mt[1] = 0.488; mt.mt[2] = 1.380; mt.mt[3] =-0.057; mt.mt[4] = 0.600; mt.mt[5] = 0.664; mt.sdr1[0] = 36.0; mt.sdr1[1] = 38.0; mt.sdr1[2] =-76.0; mt.sdr2[0] = 199.0; mt.sdr2[1] = 53.0; mt.sdr2[2] =-101.0; mt.tax[0] = 1.80; mt.tax[1] = 8.0; mt.tax[2] = 296.0; mt.bax[0] = 0.18; mt.bax[1] = 9.0; mt.bax[2] = 205.0; mt.pax[0] =-1.99; mt.pax[1] = 78.0; mt.pax[2] = 69.0; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[42], 1); ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decomposing 8\n"); return EXIT_FAILURE; } //-----------------------------------9------------------------------------// mt.exp = 23.0 - 7.0; mt.mag = 5.0; mt.mt[0] =-3.540; mt.mt[1] = 1.040; mt.mt[2] = 2.510; mt.mt[3] =-0.474; mt.mt[4] = 1.640; mt.mt[5] = 1.530; mt.sdr1[0] = 47.0; mt.sdr1[1] = 38.0; mt.sdr1[2] =-63.0; mt.sdr2[0] = 195.0; mt.sdr2[1] = 56.0; mt.sdr2[2] =-109.0; mt.tax[0] = 3.66; mt.tax[1] = 10.0; mt.tax[2] = 299.0; mt.bax[0] = 0.45; mt.bax[1] = 16.0; mt.bax[2] =206.0; mt.pax[0] =-4.10; mt.pax[1] = 71.0; mt.pax[2] = 58.0; xscal = pow(10.0,mt.exp); cblas_dscal(n6, xscal, mt.mt, incx); cblas_dcopy(n6, mt.mt, 1, &mtTest[48], 1); // now copy this for (jmt=9; jmt<nmt; jmt++) { cblas_dcopy(n6, &mtTest[6*((jmt-9)%9)], 1, &mtTest[6*jmt], 1); } ierr = decompose(1, mt.mt); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error decompsoing 9\n"); return EXIT_FAILURE; } //-----------------------------Test 'em all-------------------------------// ierr = decompose(nmt, mtTest); if (ierr != EXIT_SUCCESS) { fprintf(stderr, "Error in bulk decomposition\n"); return EXIT_FAILURE; } fprintf(stdout, "Success!\n"); free(mtTest); return EXIT_SUCCESS; }
{ "alphanum_fraction": 0.4428805909, "avg_line_length": 32.7553763441, "ext": "c", "hexsha": "f06edc92fc8cabc7dfcab5ca62ec03f09636711e", "lang": "C", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-02-28T13:42:40.000Z", "max_forks_repo_forks_event_min_datetime": "2021-07-08T00:13:50.000Z", "max_forks_repo_head_hexsha": "188058083602cebf1471ea88939b07999c90b655", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "carltape/mtbeach", "max_forks_repo_path": "c_src/unit_tests/decompose.c", "max_issues_count": 1, "max_issues_repo_head_hexsha": "188058083602cebf1471ea88939b07999c90b655", "max_issues_repo_issues_event_max_datetime": "2017-11-02T17:30:53.000Z", "max_issues_repo_issues_event_min_datetime": "2017-11-02T17:30:53.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "carltape/mtbeach", "max_issues_repo_path": "c_src/unit_tests/decompose.c", "max_line_length": 94, "max_stars_count": 9, "max_stars_repo_head_hexsha": "188058083602cebf1471ea88939b07999c90b655", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "OUCyf/mtbeach", "max_stars_repo_path": "c_src/unit_tests/decompose.c", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:55:36.000Z", "max_stars_repo_stars_event_min_datetime": "2021-03-13T01:18:12.000Z", "num_tokens": 8584, "size": 24370 }
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <pthread.h> #include <gsl/gsl_sf.h> #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> #include <gsl/gsl_statistics.h> #include <gsl/gsl_integration.h> #include <gsl/gsl_errno.h> #include "SIShift.h" static int verbose = FALSE; static int nLines = 10; static char *usage[] = {"SIShift - \n", "Required parameters:\n", " -a abundance data\n", " -in filename parameter file \n", "Optional:\n", " -b integer length of sample file to ignore\n", " -s integer sampling frequency\n", " -seed long seed random number generator\n", " -v verbose\n"}; void updateExpectations(double* adExpect, int nMax, double dAlpha, double dBeta, double dGamma, int nS, t_Data *ptData) { int i = 0; for(i = 1; i <= nMax; i++){ int nA = i; double dLog = 0.0, dP = 0.0; dLog = logLikelihood(nA, dAlpha, dBeta, dGamma); dP = exp(dLog); adExpect[i - 1] += dP*nS; } } int main(int argc, char* argv[]){ t_Params tParams; t_SIParams* atSIParams; int i = 0, nSamples = 0, nMax = 0; t_Data tData; double* adExpect = NULL; double dShift = 0.0; gsl_set_error_handler_off(); getCommandLineParams(&tParams, argc, argv); /*allocate memory for samples*/ atSIParams = (t_SIParams *) malloc(MAX_SAMPLES*sizeof(t_SIParams)); if(!atSIParams) goto memoryError; /*read in Monte-Carlo samples*/ readSamples(&tParams, atSIParams, &nSamples); readAbundanceData(tParams.szAbundFile, &tData); nMax = 1000;//tData.aanAbund[tData.nNA - 1][0]; nMax = floor(pow(2.0,ceil(log((double) nMax)/log(2.0)) + 2.0) + 1.0e-7); adExpect = (double *) malloc(sizeof(double)*nMax); for(i = 0; i < nMax; i++){ adExpect[i] = 0.0; } dShift = 5.0e5/(double) tData.nJ; for(i = 0; i < nSamples; i++){ updateExpectations(adExpect, nMax, atSIParams[i].dAlpha*sqrt(dShift), atSIParams[i].dBeta*dShift, atSIParams[i].dGamma, atSIParams[i].nS, &tData); } for(i = 1; i <= nMax; i++){ printf("%d %f\n",i,adExpect[i - 1]/((double) nSamples)); } free(adExpect); exit(EXIT_SUCCESS); memoryError: fprintf(stderr, "Failed to allocate memory in main aborting ...\n"); fflush(stderr); exit(EXIT_FAILURE); } int intCompare(const void *pvA, const void *pvB) { int* pnA = (int *) pvA, *pnB = (int *) pvB; if(*pnA < *pnB) return +1; else if(*pnA == *pnB){ return 0; } else{ return -1; } } int doubleCompare(const void *pvA, const void *pvB) { double* pnA = (double *) pvA, *pnB = (double *) pvB; if(*pnA < *pnB) return +1; else if(*pnA == *pnB){ return 0; } else{ return -1; } } void writeUsage(FILE* ofp) { int i = 0; char *line; for(i = 0; i < nLines; i++){ line = usage[i]; fputs(line,ofp); } } char *extractParameter(int argc, char **argv, char *param,int when) { int i = 0; while((i < argc) && (strcmp(param,argv[i]))){ i++; } if(i < argc - 1){ return(argv[i + 1]); } if((i == argc - 1) && (when == OPTION)){ return ""; } if(when == ALWAYS){ fprintf(stdout,"Can't find asked option %s\n",param); } return (char *) NULL; } void getCommandLineParams(t_Params *ptParams,int argc,char *argv[]) { char *szTemp = NULL; char *cError = NULL; /*get parameter file name*/ ptParams->szInputFile = extractParameter(argc,argv, INPUT_FILE,ALWAYS); if(ptParams->szInputFile == NULL) goto error; /*get abundance file name*/ ptParams->szAbundFile = extractParameter(argc,argv, ABUND_FILE,ALWAYS); if(ptParams->szAbundFile == NULL) goto error; /*get long seed*/ szTemp = extractParameter(argc,argv,SEED,OPTION); if(szTemp != NULL){ ptParams->lSeed = strtol(szTemp,&cError,10); if(*cError != '\0'){ goto error; } } else{ ptParams->lSeed = 0; } /*get burn*/ szTemp = extractParameter(argc, argv, BURN, OPTION); if(szTemp != NULL){ ptParams->nBurn = strtol(szTemp,&cError,10); if(*cError != '\0'){ goto error; } } else{ ptParams->nBurn = DEF_BURN; } /*get long seed*/ szTemp = extractParameter(argc, argv, SAMPLE, OPTION); if(szTemp != NULL){ ptParams->nSample = strtol(szTemp,&cError,10); if(*cError != '\0'){ goto error; } } else{ ptParams->nSample = DEF_SAMPLE; } /*verbosity*/ szTemp = extractParameter(argc, argv, VERBOSE, OPTION); if(szTemp != NULL){ verbose = TRUE; } return; error: writeUsage(stdout); exit(EXIT_FAILURE); } void readSamples(t_Params *ptParams, t_SIParams *atSIParams, int *pnSamples) { int nSamples = 0; char *szInputFile = ptParams->szInputFile; char szLine[MAX_LINE_LENGTH]; FILE *ifp = NULL; ifp = fopen(szInputFile, "r"); if(ifp){ while(fgets(szLine, MAX_LINE_LENGTH, ifp)){ char *szTok = NULL, *szBrk = NULL, *pcError = NULL; int nTime = 0; /*remove trailing new line*/ szBrk = strpbrk(szLine, "\n"); (*szBrk) = '\0'; szTok = strtok(szLine, DELIM); nTime = strtol(szTok, &pcError, 10); if(*pcError != '\0') goto fileFormatError; if(nTime > ptParams->nBurn && nTime % ptParams->nSample == 0){ szTok = strtok(NULL,DELIM); atSIParams[nSamples].dAlpha = strtod(szTok, &pcError); if(*pcError != '\0') goto fileFormatError; szTok = strtok(NULL,DELIM); atSIParams[nSamples].dBeta = strtod(szTok, &pcError); if(*pcError != '\0') goto fileFormatError; szTok = strtok(NULL,DELIM); atSIParams[nSamples].dGamma = strtod(szTok, &pcError); if(*pcError != '\0') goto fileFormatError; szTok = strtok(NULL,DELIM); atSIParams[nSamples].nS = strtol(szTok, &pcError, 10); if(*pcError != '\0') goto fileFormatError; nSamples++; } } fclose(ifp); } else{ fprintf(stderr, "Failed to open file %s aborting\n", szInputFile); fflush(stderr); exit(EXIT_FAILURE); } (*pnSamples) = nSamples; return; fileFormatError: fprintf(stderr, "Incorrectly formatted input file aborting\n"); fflush(stderr); exit(EXIT_FAILURE); } void readAbundanceData(const char *szFile, t_Data *ptData) { int **aanAbund = NULL; int i = 0, nNA = 0, nA = 0, nC = 0; int nL = 0, nJ = 0; char szLine[MAX_LINE_LENGTH]; FILE* ifp = NULL; ifp = fopen(szFile, "r"); if(ifp){ char* szTok = NULL; char* pcError = NULL; fgets(szLine, MAX_LINE_LENGTH, ifp); szTok = strtok(szLine, DELIM2); nNA = strtol(szTok,&pcError,10); if(*pcError != '\0'){ goto formatError; } aanAbund = (int **) malloc(nNA*sizeof(int*)); for(i = 0; i < nNA; i++){ aanAbund[i] = (int *) malloc(sizeof(int)*2); fgets(szLine, MAX_LINE_LENGTH, ifp); szTok = strtok(szLine, DELIM2); nA = strtol(szTok,&pcError,10); if(*pcError != '\0'){ goto formatError; } szTok = strtok(NULL, DELIM2); nC = strtol(szTok,&pcError,10); if(*pcError != '\0'){ goto formatError; } nL += nC; nJ += nC*nA; aanAbund[i][0] = nA; aanAbund[i][1] = nC; } } else{ fprintf(stderr, "Failed to open abundance data file %s aborting\n", szFile); fflush(stderr); exit(EXIT_FAILURE); } ptData->nJ = nJ; ptData->nL = nL; ptData->aanAbund = aanAbund; ptData->nNA = nNA; return; formatError: fprintf(stderr, "Incorrectly formatted abundance data file\n"); fflush(stderr); exit(EXIT_FAILURE); } double fX(double x, double dA, double dB, double dNDash) { double dTemp1 = (dA*(x - dB)*(x - dB))/x; return log(x) - (1.0/dNDash)*(x + dTemp1); } double f2X(double x, double dA, double dB, double dNDash) { double dRet = 0.0, dTemp = 2.0*dA*dB*dB; dRet = (1.0/(x*x))*(1.0 + (1.0/dNDash)*(dTemp/x)); return -dRet; } double sd(int n, double dAlpha, double dBeta, double dGamma) { double dA = 0.5*(-1.0 + sqrt(1.0 + (dAlpha*dAlpha)/(dBeta*dBeta))); double dN = (double) n, dNDash = dN + dGamma - 1.0, dRN = 1.0/dN; double dTemp1 = (0.5*dN)/(1.0 + dA), dTemp2 = 4.0*dRN*dRN*(1.0 + dA)*dA*dBeta*dBeta; double dXStar = dTemp1*(1.0 + sqrt(1.0 + dTemp2)); double dFX = fX(dXStar, dA, dBeta, dNDash); double d2FX = -dNDash*f2X(dXStar, dA, dBeta, dNDash); double dLogK = 0.0, dGamma1 = dGamma; if(dGamma1 < 0.0){ dGamma1 *= -1.0; } dLogK = gsl_sf_bessel_lnKnu(dGamma1,2.0*dA*dBeta); return -2.0*dA*dBeta -log(2.0) -dLogK -dGamma*log(dBeta) + dNDash*dFX + 0.5*log(2.0*M_PI) - 0.5*log(d2FX); } int bessel(double* pdResult, int n, double dAlpha, double dBeta, double dGamma) { double dResult = 0.0; double dOmega = 0.0, dGamma2 = 0.0; double dLogK1 = 0.0, dLogK2 = 0.0; double dN = (double) n, dNu = dGamma + dN; double dTemp1 = 0.0; if(dNu < 0.0){ dNu = -dNu; } if(dGamma < 0.0){ dGamma2 = -dGamma; } else{ dGamma2 = dGamma; } dOmega = sqrt(dBeta*dBeta + dAlpha*dAlpha) - dBeta; dLogK2 = gsl_sf_bessel_lnKnu(dNu, dAlpha); if(!gsl_finite(dLogK2)){ if(dAlpha < 0.1*sqrt(dNu + 1.0)){ //printf("l "); dLogK2 = gsl_sf_lngamma(dNu) + (dNu - 1.0)*log(2.0) - dNu*log(dAlpha); } else{ //printf("sd "); (*pdResult) = dResult; return FALSE; } } dLogK1 = dGamma*log(dOmega/dAlpha) -gsl_sf_bessel_lnKnu(dGamma2,dOmega); dTemp1 = log((dBeta*dOmega)/dAlpha); dResult = dN*dTemp1 + dLogK2 + dLogK1; (*pdResult) = dResult; return TRUE; } double logLikelihood(int n, double dAlpha, double dBeta, double dGamma) { double dLogFacN = 0.0; int status = 0; double dRet = 0.0; if(n < 50){ dLogFacN = gsl_sf_fact(n); dLogFacN = log(dLogFacN); } else{ dLogFacN = gsl_sf_lngamma(((double) n) + 1.0); } status = bessel(&dRet,n, dAlpha,dBeta,dGamma); if(status == FALSE){ dRet = sd(n, dAlpha,dBeta,dGamma); } return dRet - dLogFacN; }
{ "alphanum_fraction": 0.5927467301, "avg_line_length": 21.9869281046, "ext": "c", "hexsha": "036f1eb74c42dbfdd19f8493b88011af301a6953", "lang": "C", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f8ce1a8afd10311420227a6259739c7938695b79", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "chrisquince/DiversityEstimates", "max_forks_repo_path": "SIShift/SIShift.c", "max_issues_count": null, "max_issues_repo_head_hexsha": "f8ce1a8afd10311420227a6259739c7938695b79", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "chrisquince/DiversityEstimates", "max_issues_repo_path": "SIShift/SIShift.c", "max_line_length": 119, "max_stars_count": 2, "max_stars_repo_head_hexsha": "f8ce1a8afd10311420227a6259739c7938695b79", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "chrisquince/DiversityEstimates", "max_stars_repo_path": "SIShift/SIShift.c", "max_stars_repo_stars_event_max_datetime": "2019-03-19T13:22:59.000Z", "max_stars_repo_stars_event_min_datetime": "2019-03-18T17:56:16.000Z", "num_tokens": 3464, "size": 10092 }