/usr/lib/ats-anairiats-0.2.5/prelude/SATS/matrix.sats is in ats-lang-anairiats 0.2.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | (***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(* Hongwei Xi *)
(* *)
(***********************************************************************)
(*
** ATS - Unleashing the Potential of Types!
**
** Copyright (C) 2002-2008 Hongwei Xi, Boston University
**
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the
** Free Software Foundation; either version 2.1, or (at your option) any
** later version.
**
** ATS 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 ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
(* author: Hongwei Xi (hwxi AT cs DOT bu DOT edu) *)
(* ****** ****** *)
#include "prelude/params.hats"
(* ****** ****** *)
#if VERBOSE_PRELUDE #then
#print "Loading [matrix.sats] starts!\n"
#endif // end of [VERBOSE_PRELUDE]
(* ****** ****** *)
//
// HX: [mtrxt] is row-major
//
absviewt@ype
mtrxt // flat matrix type
(a:viewt@ype+, row:int, col:int) = @[@[a][col]][row]
// end of [mtrxt]
viewdef matrix_v
(a:viewt@ype, m:int, n:int, l:addr) = mtrxt (a, m, n) @ l
// end of [matrix_v]
(* ****** ****** *)
prfun array_v_of_matrix_v
{a:viewt@ype} {m,n:nat} {l:addr} (
pf_mat: matrix_v (a, m, n, l)
) :<> [mn:nat] (MUL (m, n, mn), array_v (a, mn, l))
prfun matrix_v_of_array_v
{a:viewt@ype} {m,n:nat} {mn:int} {l:addr} (
pf_mul: MUL (m, n, mn), pf_arr: array_v (a, mn, l)
) :<> matrix_v (a, m, n, l)
(* ****** ****** *)
fun{a:viewt@ype}
matrix_ptr_takeout_row
{m,n:int} {i:int | i < m} {l0:addr} (
pf_mat: matrix_v (a, m, n, l0)
| base: ptr l0, i: size_t i, n: size_t n
) :<> [l:addr] (
array_v (a, n, l)
, array_v (a, n, l) -<lin,prf> matrix_v (a, m, n, l0)
| ptr l
) // end of [matrix_ptr_takeout_row]
fun matrix_ptr_takeout_row_tsz
{a:viewt@ype}
{m,n:int} {i:int | i < m} {l0:addr} (
pf_mat: matrix_v (a, m, n, l0)
| base: ptr l0, i: size_t i, n: size_t n, tsz: sizeof_t a
) :<> [l:addr] (
array_v (a, n, l)
, array_v (a, n, l) -<lin,prf> matrix_v (a, m, n, l0)
| ptr l
) = "atspre_matrix_ptr_takeout_row_tsz"
(*
//
// HX: this is not a completely safe version, but ...
//
fun{a:viewt@ype}
matrix_ptr_vtakeout_row
{m,n:int}
{i:nat | i < m}
{l0:addr} (
pf_mat: matrix_v (a, m, n, l0)
| base: ptr l0
, i: size_t i
, n: size_t n
) : [l:addr] (
array_v (a, n, l)
, array_v (a, n, l) -<> void
| ptr l // l = l0 + i*n*sizeof<a>
) // end of [matrix_ptr_vtakeout_row]
*)
(* ****** ****** *)
fun{a:viewt@ype}
matrix_ptr_takeout_elt
{m,n:int} {i,j:nat | i < m; j < n} {l0:addr} (
pf_mat: matrix_v (a, m, n, l0)
| base: ptr l0, i: size_t i, n: size_t n, j: size_t j
) :<> [l:addr] (
a @ l
, a @ l -<lin,prf> matrix_v (a, m, n, l0)
| ptr l
) // end of [matrix_ptr_takeout_elt]
fun matrix_ptr_takeout_elt_tsz
{a:viewt@ype}
{m,n:int} {i,j:nat | i < m; j < n} {l0:addr} (
pf_mat: matrix_v (a, m, n, l0)
| base: ptr l0, i: size_t i, n: size_t n, j: size_t j, tsz: sizeof_t a
) :<> [l:addr] (
a @ l
, a @ l -<lin,prf> matrix_v (a, m, n, l0)
| ptr l
) = "atspre_matrix_ptr_takeout_elt_tsz"
(* ****** ****** *)
(*
**
** persistent matrices
**
*)
(* ****** ****** *)
exception MatrixSubscriptException of ()
(* ****** ****** *)
fun matrix_make_arrsz
{a:viewt@ype} {m,n:nat} (
m: size_t m, n: size_t n, arrsz: arraysize (a, m*n)
) :<> matrix (a, m, n) // end of [matrix_make_arrsz]
macdef matrix (m, n) (asz) =
matrix_make_arrsz (,(m), ,(n), ,(asz))
// end of [macdef]
//
// HX: implemented in [prelude/DATS/matrix.dats]
//
fun matrix_make_arrsz__main
{a:viewt@ype} {m,n:nat} {mn:int}
(pf: MUL (m, n, mn) | m: size_t m, n: size_t n, arrsz: arraysize (a, mn))
:<> matrix (a, m, n)
= "atspre_matrix_make_arrsz__main"
// end of [matrix_make_arrsz__main]
(* ****** ****** *)
fun{a:t@ype}
matrix_make_elt {m,n:pos}
(row: size_t m, col: size_t n, elt: a):<> matrix (a, m, n)
// end of [matrix_make_elt]
(* ****** ****** *)
//
// HX: implemented in [prelude/DATS/matrix.dats]
//
fun matrix_make_funenv_tsz
{a:viewt@ype}
{v:view} {vt:viewtype}
{m,n:pos} {f:eff} (
pf: !v
| row: size_t m, col: size_t n
, f: (!v | sizeLt m, sizeLt n, &(a?) >> a, !vt) -<fun,f> void
, tsz: sizeof_t a
, env: !vt
) :<f> matrix (a, m, n)
= "atspre_matrix_make_funenv_tsz"
// end of [fun]
fun{a:viewt@ype}
matrix_make_fun
{m,n:pos} {f:eff} (
row: size_t m, col: size_t n
, f: (sizeLt m, sizeLt n, &(a?) >> a) -<fun,f> void
) :<f> matrix (a, m, n) // end of [matrix_make_fun_tsz]
fun{a:viewt@ype}
matrix_make_vclo
{v:view}
{m,n:pos} {f:eff} (
pfv: !v
| row: size_t m, col: size_t n
, f: &(!v | sizeLt m, sizeLt n, &(a?) >> a) -<clo,f> void
) :<f> matrix (a, m, n) // end of [matrix_make_vclo]
(* ****** ****** *)
fun{a:t@ype}
matrix_get_elt_at {m,n:int} {i,j:nat | i < m; j < n}
(A: matrix (a, m, n), i: size_t i, n: size_t n, j: size_t j):<!ref> a
overload [] with matrix_get_elt_at
fun{a:t@ype}
matrix_set_elt_at {m,n:int} {i,j:nat | i < m; j < n}
(A: matrix (a, m, n), i: size_t i, n: size_t n, j: size_t j, x: a):<!ref> void
overload [] with matrix_set_elt_at
(* ****** ****** *)
fun{a:t@ype}
matrix_get_elt_at__intsz {m,n:int} {i,j:nat | i < m; j < n}
(A: matrix (a, m, n), i: int i, n: int n, j: int j):<!ref> a
overload [] with matrix_get_elt_at__intsz
fun{a:t@ype}
matrix_set_elt_at__intsz {m,n:int} {i,j:nat | i < m; j < n}
(A: matrix (a, m, n), i: int i, n: int n, j: int j, x: a):<!ref> void
overload [] with matrix_set_elt_at__intsz
(* ****** ****** *)
//
// HX:
// these foreach-functions are just as easy to be
// implemented on the spot
//
(* ****** ****** *)
(*
** HX: implemented in ATS (prelude/DATS/matrix.dats)
*)
fun{a:viewt@ype}
matrix_foreach_funenv
{v:view} {vt:viewtype} {m,n:nat} (
pf: !v
| M: matrix (a, m, n)
, f: (!v | &a, !vt) -<fun> void, m: size_t m, n: size_t n
, env: !vt
) :<!ref> void
// end of [matrix_foreach_funenv]
fun{a:viewt@ype}
matrix_foreach_fun {m,n:nat} (
M: matrix (a, m, n)
, f: (&a) -<fun> void, m: size_t m, n: size_t n
) :<!ref> void // end of [matrix_foreach_fun]
fun{a:viewt@ype}
matrix_foreach_vclo {v:view} {m,n:nat} (
pf: !v
| M: matrix (a, m, n)
, f: &(!v | &a) -<clo> void, m: size_t m, n: size_t n
) :<!ref> void // end of [matrix_foreach_vclo]
fun{a:viewt@ype}
matrix_foreach_cloref {m,n:nat} (
M: matrix (a, m, n), f: (&a) -<cloref> void, m: size_t m, n: size_t n
) :<!ref> void // end of [matrix_foreach_cloref]
(* ****** ****** *)
//
// HX:
// these iforeach-functions are just as easy to be
// implemented on the spot
//
(* ****** ****** *)
(*
** HX: implemented in ATS (prelude/DATS/matrix.dats)
*)
fun{a:viewt@ype}
matrix_iforeach_funenv
{v:view} {vt:viewtype} {m,n:nat} (
pf: !v
| M: matrix (a, m, n)
, f: (!v | sizeLt m, sizeLt n, &a, !vt) -<fun> void, m: size_t m, n: size_t n
, env: !vt
) :<!ref> void // end of [matrix_iforeach_funenv]
fun{a:viewt@ype}
matrix_iforeach_fun {m,n:nat} (
M: matrix (a, m, n)
, f: (sizeLt m, sizeLt n, &a) -<fun> void, m: size_t m, n: size_t n
) :<!ref> void // end of [matrix_iforeach_fun]
fun{a:viewt@ype}
matrix_iforeach_vclo {v:view} {m,n:nat} (
pf: !v
| M: matrix (a, m, n)
, f: &(!v | sizeLt m, sizeLt n, &a) -<clo> void, m: size_t m, n: size_t n
) :<!ref> void // end of [matrix_iforeach_vclo]
fun{a:viewt@ype}
matrix_iforeach_cloref {m,n:nat} (
M: matrix (a, m, n)
, f: (sizeLt m, sizeLt n, &a) -<cloref1> void, m: size_t m, n: size_t n
) :<fun1> void // end of [matrix_iforeach_cloref]
(* ****** ****** *)
#if VERBOSE_PRELUDE #then
#print "Loading [matrix.sats] finishes!\n"
#endif // end of [VERBOSE_PRELUDE]
(* end of [matrix.sats] *)
|