@@ -50,12 +50,8 @@ trait ArrayOps extends Variables {
50
50
}
51
51
52
52
trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp {
53
- case class ArrayNew [T : Manifest ](n : Exp [Int ]) extends Def [Array [T ]] {
54
- val m = manifest[T ]
55
- }
56
- case class ArrayFromSeq [T : Manifest ](xs : Seq [Exp [T ]]) extends Def [Array [T ]] {
57
- val m = manifest[T ]
58
- }
53
+ case class ArrayNew [T ](n : Exp [Int ], m : Manifest [T ]) extends Def [Array [T ]]
54
+ case class ArrayFromSeq [T ](xs : Seq [Exp [T ]], m : Manifest [T ]) extends Def [Array [T ]]
59
55
case class ArrayApply [T : Manifest ](a : Exp [Array [T ]], n : Exp [Int ]) extends Def [T ]
60
56
case class ArrayUpdate [T : Manifest ](a : Exp [Array [T ]], n : Exp [Int ], y : Exp [T ]) extends Def [Unit ]
61
57
case class ArrayLength [T : Manifest ](a : Exp [Array [T ]]) extends Def [Int ] {
@@ -74,8 +70,8 @@ trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp {
74
70
case class ArrayToSeq [A : Manifest ](x : Exp [Array [A ]]) extends Def [Seq [A ]]
75
71
case class ArraySlice [A : Manifest ](a : Exp [Array [A ]], s: Exp [Int ], e: Exp [Int ]) extends Def [Array [A ]]
76
72
77
- def array_obj_new [T : Manifest ](n : Exp [Int ]) = reflectMutable(ArrayNew (n))
78
- def array_obj_fromseq [T : Manifest ](xs : Seq [Exp [T ]]) = /* reflectMutable(*/ ArrayFromSeq (xs) /* )*/
73
+ def array_obj_new [T : Manifest ](n : Exp [Int ]) = reflectMutable(ArrayNew (n, manifest[ T ] ))
74
+ def array_obj_fromseq [T : Manifest ](xs : Seq [Exp [T ]]) = /* reflectMutable(*/ ArrayFromSeq (xs, manifest[ T ] ) /* )*/
79
75
def array_apply [T : Manifest ](x : Exp [Array [T ]], n : Exp [Int ])(implicit pos : SourceContext ): Exp [T ] = ArrayApply (x, n)
80
76
def array_update [T : Manifest ](x : Exp [Array [T ]], n : Exp [Int ], y : Exp [T ])(implicit pos : SourceContext ) = reflectWrite(x)(ArrayUpdate (x,n,y))
81
77
def array_unsafe_update [T : Manifest ](x : Rep [Array [T ]], n : Rep [Int ], y : Rep [T ])(implicit pos : SourceContext ) = ArrayUpdate (x,n,y)
@@ -104,7 +100,7 @@ trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp {
104
100
case ArrayLength (x) => array_length(f(x))
105
101
case e@ ArraySort (x) => array_sort(f(x))(e.m,pos)
106
102
case e@ ArrayCopy (a,ap,d,dp,l) => toAtom(ArrayCopy (f(a),f(ap),f(d),f(dp),f(l))(e.m))(mtype(manifest[A ]),pos)
107
- case Reflect (e @ ArrayNew (n), u, es) => reflectMirrored(Reflect (ArrayNew (f(n))(e. m), mapOver(f,u), f(es)))(mtype(manifest[A ]), pos)
103
+ case Reflect (ArrayNew (n, m ), u, es) => reflectMirrored(Reflect (ArrayNew (f(n), m), mapOver(f,u), f(es)))(mtype(manifest[A ]), pos)
108
104
case Reflect (e@ ArrayLength (x), u, es) => reflectMirrored(Reflect (ArrayLength (f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A ]), pos)
109
105
case Reflect (ArrayApply (l,r), u, es) => reflectMirrored(Reflect (ArrayApply (f(l),f(r))(mtype(manifest[A ])), mapOver(f,u), f(es)))(mtype(manifest[A ]), pos)
110
106
case Reflect (e@ ArraySort (x), u, es) => reflectMirrored(Reflect (ArraySort (f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A ]), pos)
@@ -139,12 +135,12 @@ trait ArrayOpsExpOpt extends ArrayOpsExp {
139
135
* @author Alen Stojanov ([email protected] )
140
136
*/
141
137
override def array_length [T : Manifest ](a : Exp [Array [T ]])(implicit pos : SourceContext ) : Rep [Int ] = a match {
142
- case Def (ArrayNew (n : Exp [ Int ] )) => n
143
- case Def (ArrayFromSeq (xs)) => Const (xs.size)
138
+ case Def (ArrayNew (n, _ )) => n
139
+ case Def (ArrayFromSeq (xs, _ )) => Const (xs.size)
144
140
case Def (ArraySort (x)) => array_length(x)
145
141
case Def (ArrayMap (x, _, _)) => array_length(x)
146
- case Def (Reflect (ArrayNew (n : Exp [ Int ] ), _, _)) => n
147
- case Def (Reflect (ArrayFromSeq (xs), _, _)) => Const (xs.size)
142
+ case Def (Reflect (ArrayNew (n, _ ), _, _)) => n
143
+ case Def (Reflect (ArrayFromSeq (xs, _ ), _, _)) => Const (xs.size)
148
144
case Def (Reflect (ArraySort (x), _, _)) => array_length(x)
149
145
case Def (Reflect (ArrayMap (x, _, _), _, _)) => array_length(x)
150
146
case _ => super .array_length(a)
@@ -158,7 +154,7 @@ trait ArrayOpsExpOpt extends ArrayOpsExp {
158
154
// TODO: could use calculateDependencies?
159
155
160
156
val rhs = context.reverse.collectFirst {
161
- // case w @ Def(Reflect(ArrayNew(sz: Exp[T] ), _, _)) if w == x => Some(Const(0)) // FIXME: bounds check!
157
+ // case w @ Def(Reflect(ArrayNew(sz, _ ), _, _)) if w == x => Some(Const(0)) // FIXME: bounds check!
162
158
case Def (Reflect (ArrayUpdate (`x`, `n`, rhs : Exp [T ]), _, _)) => Some (rhs)
163
159
case Def (Reflect (_, u, _)) if mayWrite(u, List (vs)) => None // not a simple assignment
164
160
}
@@ -176,7 +172,7 @@ trait ArrayOpsExpOpt extends ArrayOpsExp {
176
172
// TODO: could use calculateDependencies?
177
173
178
174
val rhs = context.reverse.collectFirst {
179
- // case w @ Def(Reflect(ArrayNew(sz: Exp[T] ), _, _)) if w == x => Some(Const(())) // FIXME: bounds check!
175
+ // case w @ Def(Reflect(ArrayNew(sz, _ ), _, _)) if w == x => Some(Const(())) // FIXME: bounds check!
180
176
case Def (Reflect (ArrayUpdate (`x`, `n`, `y`), _, _)) => Some (Const (()))
181
177
case Def (Reflect (_, u, _)) if mayWrite(u, List (vs)) => None // not a simple assignment
182
178
}
@@ -204,8 +200,8 @@ trait ScalaGenArrayOps extends BaseGenArrayOps with ScalaGenBase {
204
200
val ARRAY_LITERAL_MAX_SIZE = 1000
205
201
206
202
override def emitNode (sym : Sym [Any ], rhs : Def [Any ]) = rhs match {
207
- case a @ ArrayNew (n) => emitValDef(sym, src " new Array[ ${remap(a. m)}]( $n) " )
208
- case e @ ArrayFromSeq (xs) => {
203
+ case ArrayNew (n, m ) => emitValDef(sym, src " new Array[ ${remap(m)}]( $n) " )
204
+ case ArrayFromSeq (xs, m ) => {
209
205
emitData(sym, xs)
210
206
emitValDef(sym,
211
207
if (xs.size > ARRAY_LITERAL_MAX_SIZE ) {
@@ -217,10 +213,17 @@ trait ScalaGenArrayOps extends BaseGenArrayOps with ScalaGenBase {
217
213
}
218
214
val numBlocks = Math.ceil(xs.size / ARRAY_LITERAL_MAX_SIZE).intValue
219
215
"{val buf=new Array[" + remap(e.mt) + "](" + xs.size + ")\n" + ((0 until numBlocks).map(append)).mkString("\n") + "buf}" */
220
- " {import scala.io.Source;(Source.fromFile(\" " + symDataPath(sym) + " \" ).getLines.map{Integer.parseInt(_)}).toArray}"
216
+ val parsingMethod = m.asInstanceOf [Manifest [_]] match {
217
+ case Manifest .Int => " Integer.parseInt"
218
+ case Manifest .Long => " java.lang.Long.parseLong"
219
+ case Manifest .Float => " java.lang.Float.parseFloat"
220
+ case Manifest .Double => " java.lang.Double.parseDouble"
221
+ case _ if m.runtimeClass == classOf [String ] => " x => x"
222
+ }
223
+ s """ scala.io.Source.fromFile(" ${symDataPath(sym)}").getLines.map( $parsingMethod).toArray} """
221
224
}
222
225
else {
223
- " Array(" + (xs map quote).mkString(" ," ) + " )"
226
+ s " Array[ ${remap(m)} ] (" + (xs map quote).mkString(" ," ) + " )"
224
227
}
225
228
)
226
229
}
0 commit comments