1 ! Copyright (C) 2008 Slava Pestov.
\r
2 ! See http://factorcode.org/license.txt for BSD license.
\r
3 USING: arrays kernel kernel.private math sequences
\r
4 sequences.private growable float-arrays prettyprint.backend
\r
8 TUPLE: float-vector underlying fill ;
\r
10 M: float-vector underlying underlying>> { float-array } declare ;
\r
12 M: float-vector set-underlying (>>underlying) ;
\r
14 M: float-vector length fill>> { array-capacity } declare ;
\r
16 M: float-vector set-fill (>>fill) ;
\r
20 : float-array>vector ( float-array length -- float-vector )
\r
21 float-vector boa ; inline
\r
25 : <float-vector> ( n -- float-vector )
\r
26 0.0 <float-array> 0 float-array>vector ; inline
\r
28 : >float-vector ( seq -- float-vector )
\r
29 T{ float-vector f F{ } 0 } clone-like ;
\r
31 M: float-vector like
\r
32 drop dup float-vector? [
\r
34 [ dup length float-array>vector ] [ >float-vector ] if
\r
37 M: float-vector new-sequence
\r
38 drop [ 0.0 <float-array> ] keep >fixnum float-array>vector ;
\r
40 M: float-vector equal?
\r
41 over float-vector? [ sequence= ] [ 2drop f ] if ;
\r
43 M: float-array new-resizable drop <float-vector> ;
\r
45 INSTANCE: float-vector growable
\r
47 : FV{ \ } [ >float-vector ] parse-literal ; parsing
\r
49 M: float-vector >pprint-sequence ;
\r
51 M: float-vector pprint-delims drop \ FV{ \ } ;
\r