module Music.Theory.Array where
import Data.List
import qualified Data.Array as A
import qualified Music.Theory.List as T
larray_bounds :: Ord k => [(k,v)] -> (k,k)
larray_bounds :: forall k v. Ord k => [(k, v)] -> (k, k)
larray_bounds = forall t. Ord t => [t] -> (t, t)
T.minmax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst
larray :: A.Ix k => [(k,v)] -> A.Array k v
larray :: forall k v. Ix k => [(k, v)] -> Array k v
larray [(k, v)]
a = forall i e. Ix i => (i, i) -> [(i, e)] -> Array i e
A.array (forall k v. Ord k => [(k, v)] -> (k, k)
larray_bounds [(k, v)]
a) [(k, v)]
a
type Table a = [[a]]
tbl_rows :: Table t -> Int
tbl_rows :: forall t. Table t -> Int
tbl_rows = forall (t :: * -> *) a. Foldable t => t a -> Int
length
tbl_columns :: Table t -> Int
tbl_columns :: forall t. Table t -> Int
tbl_columns Table t
tbl =
case Table t
tbl of
[] -> Int
0
[t]
r0:Table t
_ -> forall (t :: * -> *) a. Foldable t => t a -> Int
length [t]
r0
tbl_is_regular :: Table t -> Bool
tbl_is_regular :: forall t. Table t -> Bool
tbl_is_regular = (forall a. Eq a => a -> a -> Bool
== Int
1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> [a]
nub forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (t :: * -> *) a. Foldable t => t a -> Int
length
tbl_make_regular :: (t -> u,u) -> Table t -> Table u
tbl_make_regular :: forall t u. (t -> u, u) -> Table t -> Table u
tbl_make_regular (t -> u
f,u
k) Table t
tbl =
let z :: Int
z = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum (forall a b. (a -> b) -> [a] -> [b]
map forall (t :: * -> *) a. Foldable t => t a -> Int
length Table t
tbl)
in forall a b. (a -> b) -> [a] -> [b]
map (forall a. a -> Int -> [a] -> [a]
T.pad_right u
k Int
z forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map t -> u
f) Table t
tbl
tbl_make_regular_nil :: t -> Table t -> Table t
tbl_make_regular_nil :: forall t. t -> Table t -> Table t
tbl_make_regular_nil t
k = forall t u. (t -> u, u) -> Table t -> Table u
tbl_make_regular (forall a. a -> a
id,t
k)
type Dimensions i = (i,i)
type Ix i = (i,i)
ix_translate :: Num t => (t,t) -> Ix t -> Ix t
ix_translate :: forall t. Num t => (t, t) -> (t, t) -> (t, t)
ix_translate (t
dr,t
dc) (t
r,t
c) = (t
r forall a. Num a => a -> a -> a
+ t
dr,t
c forall a. Num a => a -> a -> a
+ t
dc)
ix_modulo :: Integral t => Dimensions t -> Ix t -> Ix t
ix_modulo :: forall t.
Integral t =>
Dimensions t -> Dimensions t -> Dimensions t
ix_modulo (t
nr,t
nc) (t
r,t
c) = (t
r forall a. Integral a => a -> a -> a
`mod` t
nr,t
c forall a. Integral a => a -> a -> a
`mod` t
nc)
row_indices :: (Enum t, Num t) => t -> t -> [Ix t]
row_indices :: forall t. (Enum t, Num t) => t -> t -> [Ix t]
row_indices t
nc t
r = forall a b. (a -> b) -> [a] -> [b]
map (\t
c -> (t
r,t
c)) [t
0 .. t
nc forall a. Num a => a -> a -> a
- t
1]
column_indices_at :: (Enum t, Num t) => t -> t -> [Ix t]
column_indices_at :: forall t. (Enum t, Num t) => t -> t -> [Ix t]
column_indices_at t
nr t
c = forall a b. (a -> b) -> [a] -> [b]
map (\t
r -> (t
r,t
c)) [t
0 .. t
nr forall a. Num a => a -> a -> a
- t
1]
matrix_indices :: (Enum t, Num t) => Dimensions t -> [Ix t]
matrix_indices :: forall t. (Enum t, Num t) => Dimensions t -> [Dimensions t]
matrix_indices (t
nr,t
nc) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall t. (Enum t, Num t) => t -> t -> [Ix t]
row_indices t
nc) [t
0 .. t
nr forall a. Num a => a -> a -> a
- t
1 ]
matrix_corner_indices :: Num t => Dimensions t -> [Ix t]
matrix_corner_indices :: forall t. Num t => Dimensions t -> [Dimensions t]
matrix_corner_indices (t
nr,t
nc) = [(t
0,t
0),(t
0,t
nc forall a. Num a => a -> a -> a
- t
1),(t
nr forall a. Num a => a -> a -> a
- t
1,t
0),(t
nr forall a. Num a => a -> a -> a
- t
1,t
nc forall a. Num a => a -> a -> a
- t
1)]
parallelogram_corner_indices :: Num t => (Dimensions t,t) -> [Ix t]
parallelogram_corner_indices :: forall t. Num t => (Dimensions t, t) -> [Dimensions t]
parallelogram_corner_indices ((t
nr,t
nc),t
o) = [(t
0,t
0),(t
0,t
nc forall a. Num a => a -> a -> a
- t
1),(t
nr forall a. Num a => a -> a -> a
- t
1,t
o),(t
nr forall a. Num a => a -> a -> a
- t
1,t
nc forall a. Num a => a -> a -> a
+ t
o forall a. Num a => a -> a -> a
- t
1)]
all_ix_translations :: Integral t => Dimensions t -> [Ix t] -> [[Ix t]]
all_ix_translations :: forall t.
Integral t =>
Dimensions t -> [Dimensions t] -> [[Dimensions t]]
all_ix_translations Dimensions t
dm [Dimensions t]
ix =
let f :: Dimensions t -> Dimensions t -> Dimensions t
f Dimensions t
z = forall t.
Integral t =>
Dimensions t -> Dimensions t -> Dimensions t
ix_modulo Dimensions t
dm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Num t => (t, t) -> (t, t) -> (t, t)
ix_translate Dimensions t
z
in forall a b. (a -> b) -> [a] -> [b]
map (\Dimensions t
dx -> forall a b. (a -> b) -> [a] -> [b]
map (Dimensions t -> Dimensions t -> Dimensions t
f Dimensions t
dx) [Dimensions t]
ix) (forall t. (Enum t, Num t) => Dimensions t -> [Dimensions t]
matrix_indices Dimensions t
dm)
all_ix_translations_uniq :: Integral t => Dimensions t -> [Ix t] -> [[Ix t]]
all_ix_translations_uniq :: forall t.
Integral t =>
Dimensions t -> [Dimensions t] -> [[Dimensions t]]
all_ix_translations_uniq Ix t
dm = forall a. Eq a => [a] -> [a]
nub forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
Integral t =>
Dimensions t -> [Dimensions t] -> [[Dimensions t]]
all_ix_translations Ix t
dm