Move columns, bit-vectors, byte-vectors, float-vectors to extra
parent
435e24f3b7
commit
18c2f11d06
|
@ -1,11 +1,10 @@
|
|||
! Copyright (C) 2003, 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays byte-arrays byte-vectors bit-arrays bit-vectors
|
||||
generic hashtables io assocs kernel math namespaces sequences
|
||||
strings sbufs io.styles vectors words prettyprint.config
|
||||
prettyprint.sections quotations io io.files math.parser effects
|
||||
classes.tuple classes.tuple.private classes float-arrays
|
||||
float-vectors ;
|
||||
USING: arrays byte-arrays bit-arrays generic hashtables io
|
||||
assocs kernel math namespaces sequences strings sbufs io.styles
|
||||
vectors words prettyprint.config prettyprint.sections quotations
|
||||
io io.files math.parser effects classes.tuple
|
||||
classes.tuple.private classes float-arrays ;
|
||||
IN: prettyprint.backend
|
||||
|
||||
GENERIC: pprint* ( obj -- )
|
||||
|
@ -140,11 +139,8 @@ M: curry pprint-delims drop \ [ \ ] ;
|
|||
M: compose pprint-delims drop \ [ \ ] ;
|
||||
M: array pprint-delims drop \ { \ } ;
|
||||
M: byte-array pprint-delims drop \ B{ \ } ;
|
||||
M: byte-vector pprint-delims drop \ BV{ \ } ;
|
||||
M: bit-array pprint-delims drop \ ?{ \ } ;
|
||||
M: bit-vector pprint-delims drop \ ?V{ \ } ;
|
||||
M: float-array pprint-delims drop \ F{ \ } ;
|
||||
M: float-vector pprint-delims drop \ FV{ \ } ;
|
||||
M: vector pprint-delims drop \ V{ \ } ;
|
||||
M: hashtable pprint-delims drop \ H{ \ } ;
|
||||
M: tuple pprint-delims drop \ T{ \ } ;
|
||||
|
|
|
@ -76,10 +76,7 @@ ARTICLE: "sequences-reshape" "Reshaping sequences"
|
|||
{ $subsection reversed }
|
||||
{ $subsection <reversed> }
|
||||
"Transposing a matrix:"
|
||||
{ $subsection flip }
|
||||
"A " { $emphasis "column" } " presents a column of a matrix represented as a sequence of rows:"
|
||||
{ $subsection column }
|
||||
{ $subsection <column> } ;
|
||||
{ $subsection flip } ;
|
||||
|
||||
ARTICLE: "sequences-appending" "Appending sequences"
|
||||
{ $subsection append }
|
||||
|
@ -785,23 +782,6 @@ HELP: <slice>
|
|||
|
||||
{ <slice> subseq } related-words
|
||||
|
||||
HELP: column
|
||||
{ $class-description "A virtual sequence which presents a fixed column of a matrix represented as a sequence of rows. New instances can be created by calling " { $link <column> } "." } ;
|
||||
|
||||
HELP: <column> ( seq n -- column )
|
||||
{ $values { "seq" sequence } { "n" "a non-negative integer" } { "column" column } }
|
||||
{ $description "Outputs a new virtual sequence which presents a fixed column of a matrix represented as a sequence of rows." "The " { $snippet "i" } "th element of a column is the " { $snippet "n" } "th element of the " { $snippet "i" } "th element of" { $snippet "seq" } ". Every element of " { $snippet "seq" } " must be a sequence, and all sequences must have equal length." }
|
||||
{ $examples
|
||||
{ $example
|
||||
"USING: arrays prettyprint sequences ;"
|
||||
"{ { 1 2 3 } { 4 5 6 } { 7 8 9 } } 0 <column> >array ."
|
||||
"{ 1 4 7 }"
|
||||
}
|
||||
}
|
||||
{ $notes
|
||||
"In the same sense that " { $link <reversed> } " is a virtual variant of " { $link reverse } ", " { $link <column> } " is a virtual variant of " { $snippet "swap [ nth ] curry map" } "."
|
||||
} ;
|
||||
|
||||
HELP: repetition
|
||||
{ $class-description "A virtual sequence consisting of " { $link repetition-elt } " repeated " { $link repetition-len } " times. Repetitions are created by calling " { $link <repetition> } "." } ;
|
||||
|
||||
|
|
|
@ -224,13 +224,6 @@ unit-test
|
|||
[ V{ 1 2 3 } ]
|
||||
[ 3 V{ 1 3 2 } clone [ push-new ] keep ] unit-test
|
||||
|
||||
! Columns
|
||||
{ { 1 2 3 } { 4 5 6 } { 7 8 9 } } [ clone ] map "seq" set
|
||||
|
||||
[ { 1 4 7 } ] [ "seq" get 0 <column> >array ] unit-test
|
||||
[ ] [ "seq" get 1 <column> [ sq ] change-each ] unit-test
|
||||
[ { 4 25 64 } ] [ "seq" get 1 <column> >array ] unit-test
|
||||
|
||||
! erg's random tester found this one
|
||||
[ SBUF" 12341234" ] [
|
||||
9 <sbuf> dup "1234" swap push-all dup dup swap push-all
|
||||
|
|
|
@ -215,18 +215,6 @@ M: slice length dup slice-to swap slice-from - ;
|
|||
|
||||
INSTANCE: slice virtual-sequence
|
||||
|
||||
! A column of a matrix
|
||||
TUPLE: column seq col ;
|
||||
|
||||
C: <column> column
|
||||
|
||||
M: column virtual-seq column-seq ;
|
||||
M: column virtual@
|
||||
dup column-col -rot column-seq nth bounds-check ;
|
||||
M: column length column-seq length ;
|
||||
|
||||
INSTANCE: column virtual-sequence
|
||||
|
||||
! One element repeated many times
|
||||
TUPLE: repetition len elt ;
|
||||
|
||||
|
@ -703,5 +691,5 @@ PRIVATE>
|
|||
: flip ( matrix -- newmatrix )
|
||||
dup empty? [
|
||||
dup [ length ] map infimum
|
||||
[ <column> dup like ] with map
|
||||
swap [ [ nth-unsafe ] with { } map-as ] curry { } map-as
|
||||
] unless ;
|
||||
|
|
|
@ -150,18 +150,6 @@ ARTICLE: "syntax-byte-arrays" "Byte array syntax"
|
|||
{ $subsection POSTPONE: B{ }
|
||||
"Byte arrays are documented in " { $link "byte-arrays" } "." ;
|
||||
|
||||
ARTICLE: "syntax-bit-vectors" "Bit vector syntax"
|
||||
{ $subsection POSTPONE: ?V{ }
|
||||
"Bit vectors are documented in " { $link "bit-vectors" } "." ;
|
||||
|
||||
ARTICLE: "syntax-float-vectors" "Float vector syntax"
|
||||
{ $subsection POSTPONE: FV{ }
|
||||
"Float vectors are documented in " { $link "float-vectors" } "." ;
|
||||
|
||||
ARTICLE: "syntax-byte-vectors" "Byte vector syntax"
|
||||
{ $subsection POSTPONE: BV{ }
|
||||
"Byte vectors are documented in " { $link "byte-vectors" } "." ;
|
||||
|
||||
ARTICLE: "syntax-pathnames" "Pathname syntax"
|
||||
{ $subsection POSTPONE: P" }
|
||||
"Pathnames are documented in " { $link "pathnames" } "." ;
|
||||
|
@ -182,9 +170,6 @@ $nl
|
|||
{ $subsection "syntax-float-arrays" }
|
||||
{ $subsection "syntax-vectors" }
|
||||
{ $subsection "syntax-sbufs" }
|
||||
{ $subsection "syntax-bit-vectors" }
|
||||
{ $subsection "syntax-byte-vectors" }
|
||||
{ $subsection "syntax-float-vectors" }
|
||||
{ $subsection "syntax-hashtables" }
|
||||
{ $subsection "syntax-tuples" }
|
||||
{ $subsection "syntax-pathnames" } ;
|
||||
|
@ -291,30 +276,12 @@ HELP: B{
|
|||
{ $description "Marks the beginning of a literal byte array. Literal byte arrays are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "B{ 1 2 3 }" } } ;
|
||||
|
||||
HELP: BV{
|
||||
{ $syntax "BV{ elements... }" }
|
||||
{ $values { "elements" "a list of bytes" } }
|
||||
{ $description "Marks the beginning of a literal byte vector. Literal byte vectors are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "BV{ 1 2 3 12 }" } } ;
|
||||
|
||||
HELP: ?{
|
||||
{ $syntax "?{ elements... }" }
|
||||
{ $values { "elements" "a list of booleans" } }
|
||||
{ $description "Marks the beginning of a literal bit array. Literal bit arrays are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "?{ t f t }" } } ;
|
||||
|
||||
HELP: ?V{
|
||||
{ $syntax "?V{ elements... }" }
|
||||
{ $values { "elements" "a list of booleans" } }
|
||||
{ $description "Marks the beginning of a literal bit vector. Literal bit vectors are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "?V{ t f t }" } } ;
|
||||
|
||||
HELP: FV{
|
||||
{ $syntax "FV{ elements... }" }
|
||||
{ $values { "elements" "a list of real numbers" } }
|
||||
{ $description "Marks the beginning of a literal float vector. Literal float vectors are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "FV{ 1.0 2.0 3.0 }" } } ;
|
||||
|
||||
HELP: F{
|
||||
{ $syntax "F{ elements... }" }
|
||||
{ $values { "elements" "a list of real numbers" } }
|
||||
|
|
|
@ -79,11 +79,8 @@ IN: bootstrap.syntax
|
|||
"{" [ \ } [ >array ] parse-literal ] define-syntax
|
||||
"V{" [ \ } [ >vector ] parse-literal ] define-syntax
|
||||
"B{" [ \ } [ >byte-array ] parse-literal ] define-syntax
|
||||
"BV{" [ \ } [ >byte-vector ] parse-literal ] define-syntax
|
||||
"?{" [ \ } [ >bit-array ] parse-literal ] define-syntax
|
||||
"?V{" [ \ } [ >bit-vector ] parse-literal ] define-syntax
|
||||
"F{" [ \ } [ >float-array ] parse-literal ] define-syntax
|
||||
"FV{" [ \ } [ >float-vector ] parse-literal ] define-syntax
|
||||
"H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
|
||||
"T{" [ \ } [ >tuple ] parse-literal ] define-syntax
|
||||
"W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USING: namespaces math sequences splitting kernel ;
|
||||
USING: namespaces math sequences splitting kernel columns ;
|
||||
IN: benchmark.dispatch2
|
||||
|
||||
: sequences
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
USING: sequences math mirrors splitting kernel namespaces
|
||||
assocs alien.syntax ;
|
||||
assocs alien.syntax columns ;
|
||||
IN: benchmark.dispatch3
|
||||
|
||||
GENERIC: g ( obj -- str )
|
||||
|
|
|
@ -19,7 +19,7 @@ IN: benchmark.spectral-norm
|
|||
pick 0.0 [
|
||||
swap >r >r 2dup r> (eval-A-times-u) r> +
|
||||
] reduce nip
|
||||
] F{ } map-as 2nip ; inline
|
||||
] F{ } map-as { float-array } declare 2nip ; inline
|
||||
|
||||
: (eval-At-times-u) ( u i j -- x )
|
||||
tuck swap eval-A >r swap nth-unsafe r> * ; inline
|
||||
|
@ -29,7 +29,7 @@ IN: benchmark.spectral-norm
|
|||
pick 0.0 [
|
||||
swap >r >r 2dup r> (eval-At-times-u) r> +
|
||||
] reduce nip
|
||||
] F{ } map-as 2nip ; inline
|
||||
] F{ } map-as { float-array } declare 2nip ; inline
|
||||
|
||||
: eval-AtA-times-u ( n u -- seq )
|
||||
dupd eval-A-times-u eval-At-times-u ; inline
|
||||
|
|
|
@ -11,6 +11,8 @@ $nl
|
|||
"Creating bit vectors:"
|
||||
{ $subsection >bit-vector }
|
||||
{ $subsection <bit-vector> }
|
||||
"Literal syntax:"
|
||||
{ $subsection POSTPONE: ?V{ }
|
||||
"If you don't care about initial capacity, a more elegant way to create a new bit vector is to write:"
|
||||
{ $code "?V{ } clone" } ;
|
||||
|
||||
|
@ -31,3 +33,10 @@ HELP: bit-array>vector
|
|||
{ $values { "bit-array" "an array" } { "length" "a non-negative integer" } { "bit-vector" bit-vector } }
|
||||
{ $description "Creates a new bit vector using the array for underlying storage with the specified initial length." }
|
||||
{ $warning "This word is in the " { $vocab-link "bit-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >bit-vector } " instead." } ;
|
||||
|
||||
HELP: ?V{
|
||||
{ $syntax "?V{ elements... }" }
|
||||
{ $values { "elements" "a list of booleans" } }
|
||||
{ $description "Marks the beginning of a literal bit vector. Literal bit vectors are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "?V{ t f t }" } } ;
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays kernel kernel.private math sequences
|
||||
sequences.private growable bit-arrays ;
|
||||
sequences.private growable bit-arrays prettyprint.backend
|
||||
parser ;
|
||||
IN: bit-vectors
|
||||
|
||||
<PRIVATE
|
||||
|
@ -31,3 +32,7 @@ M: bit-vector equal?
|
|||
M: bit-array new-resizable drop <bit-vector> ;
|
||||
|
||||
INSTANCE: bit-vector growable
|
||||
|
||||
: ?V \ } [ >bit-vector ] parse-literal ; parsing
|
||||
|
||||
M: bit-vector pprint-delims drop \ ?V{ \ } ;
|
|
@ -3,7 +3,7 @@ byte-vectors.private combinators ;
|
|||
IN: byte-vectors
|
||||
|
||||
ARTICLE: "byte-vectors" "Byte vectors"
|
||||
"A byte vector is a resizable mutable sequence of unsigned bytes. The literal syntax is covered in " { $link "syntax-byte-vectors" } ". Byte vector words are found in the " { $vocab-link "byte-vectors" } " vocabulary."
|
||||
"A byte vector is a resizable mutable sequence of unsigned bytes. Byte vector words are found in the " { $vocab-link "byte-vectors" } " vocabulary."
|
||||
$nl
|
||||
"Byte vectors form a class:"
|
||||
{ $subsection byte-vector }
|
||||
|
@ -11,6 +11,8 @@ $nl
|
|||
"Creating byte vectors:"
|
||||
{ $subsection >byte-vector }
|
||||
{ $subsection <byte-vector> }
|
||||
"Literal syntax:"
|
||||
{ $subsection POSTPONE: BV{ }
|
||||
"If you don't care about initial capacity, a more elegant way to create a new byte vector is to write:"
|
||||
{ $code "BV{ } clone" } ;
|
||||
|
||||
|
@ -32,3 +34,9 @@ HELP: byte-array>vector
|
|||
{ $values { "byte-array" "an array" } { "length" "a non-negative integer" } { "byte-vector" byte-vector } }
|
||||
{ $description "Creates a new byte vector using the array for underlying storage with the specified initial length." }
|
||||
{ $warning "This word is in the " { $vocab-link "byte-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >byte-vector } " instead." } ;
|
||||
|
||||
HELP: BV{
|
||||
{ $syntax "BV{ elements... }" }
|
||||
{ $values { "elements" "a list of bytes" } }
|
||||
{ $description "Marks the beginning of a literal byte vector. Literal byte vectors are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "BV{ 1 2 3 12 }" } } ;
|
|
@ -1,7 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays kernel kernel.private math sequences
|
||||
sequences.private growable byte-arrays ;
|
||||
sequences.private growable byte-arrays prettyprint.backend
|
||||
parser ;
|
||||
IN: byte-vectors
|
||||
|
||||
<PRIVATE
|
||||
|
@ -31,3 +32,7 @@ M: byte-vector equal?
|
|||
M: byte-array new-resizable drop <byte-vector> ;
|
||||
|
||||
INSTANCE: byte-vector growable
|
||||
|
||||
: BV{ \ } [ >byte-vector ] parse-literal ; parsing
|
||||
|
||||
M: byte-vector pprint-delims drop \ BV{ \ } ;
|
|
@ -11,6 +11,8 @@ $nl
|
|||
"Creating float vectors:"
|
||||
{ $subsection >float-vector }
|
||||
{ $subsection <float-vector> }
|
||||
"Literal syntax:"
|
||||
{ $subsection POSTPONE: FV{ }
|
||||
"If you don't care about initial capacity, a more elegant way to create a new float vector is to write:"
|
||||
{ $code "FV{ } clone" } ;
|
||||
|
||||
|
@ -32,3 +34,9 @@ HELP: float-array>vector
|
|||
{ $values { "float-array" "an array" } { "length" "a non-negative integer" } { "float-vector" float-vector } }
|
||||
{ $description "Creates a new float vector using the array for underlying storage with the specified initial length." }
|
||||
{ $warning "This word is in the " { $vocab-link "float-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >float-vector } " instead." } ;
|
||||
|
||||
HELP: FV{
|
||||
{ $syntax "FV{ elements... }" }
|
||||
{ $values { "elements" "a list of real numbers" } }
|
||||
{ $description "Marks the beginning of a literal float vector. Literal float vectors are terminated by " { $link POSTPONE: } } "." }
|
||||
{ $examples { $code "FV{ 1.0 2.0 3.0 }" } } ;
|
|
@ -1,7 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays kernel kernel.private math sequences
|
||||
sequences.private growable float-arrays ;
|
||||
sequences.private growable float-arrays prettyprint.backend
|
||||
parser ;
|
||||
IN: float-vectors
|
||||
|
||||
<PRIVATE
|
||||
|
@ -31,3 +32,7 @@ M: float-vector equal?
|
|||
M: float-array new-resizable drop <float-vector> ;
|
||||
|
||||
INSTANCE: float-vector growable
|
||||
|
||||
: FV{ \ } [ >float-vector ] parse-literal ; parsing
|
||||
|
||||
M: float-vector pprint-delims drop \ FV{ \ } ;
|
|
@ -145,9 +145,9 @@ ARTICLE: "collections" "Collections"
|
|||
{ $subsection "vectors" }
|
||||
"Resizable specialized sequences:"
|
||||
{ $subsection "sbufs" }
|
||||
{ $subsection "bit-vectors" }
|
||||
{ $subsection "byte-vectors" }
|
||||
{ $subsection "float-vectors" }
|
||||
{ $vocab-subsection "Bit vectors" "bit-vectors" }
|
||||
{ $vocab-subsection "Byte vectors" "byte-vectors" }
|
||||
{ $vocab-subsection "Float vectors" "float-vectors" }
|
||||
{ $heading "Associative mappings" }
|
||||
{ $subsection "assocs" }
|
||||
{ $subsection "namespaces" }
|
||||
|
|
|
@ -38,7 +38,7 @@ M: predicate word-help* drop \ $predicate ;
|
|||
\ $error-description swap word-help elements empty? not ;
|
||||
|
||||
: sort-articles ( seq -- newseq )
|
||||
[ dup article-title ] { } map>assoc sort-values 0 <column> ;
|
||||
[ dup article-title ] { } map>assoc sort-values keys ;
|
||||
|
||||
: all-errors ( -- seq )
|
||||
all-words [ error? ] subset sort-articles ;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Fast Fourier Transform, copyright (C) 2007 Hans Schmid
|
||||
! http://dressguardmeister.blogspot.com/2007/01/fft.html
|
||||
USING: arrays sequences math math.vectors math.constants
|
||||
math.functions kernel splitting ;
|
||||
math.functions kernel splitting columns ;
|
||||
IN: math.fft
|
||||
|
||||
: n^v ( n v -- w ) [ ^ ] with map ;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
! Haar wavelet transform -- http://dmr.ath.cx/gfx/haar/
|
||||
USING: sequences math kernel splitting ;
|
||||
USING: sequences math kernel splitting columns ;
|
||||
IN: math.haar
|
||||
|
||||
: averages ( seq -- seq )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! Based on http://www.ffconsultancy.com/ocaml/sudoku/index.html
|
||||
USING: sequences namespaces kernel math math.parser io
|
||||
io.styles combinators ;
|
||||
io.styles combinators columns ;
|
||||
IN: sudoku
|
||||
|
||||
SYMBOL: solutions
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2006 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays kernel math namespaces sequences words io
|
||||
io.streams.string math.vectors ui.gadgets ;
|
||||
io.streams.string math.vectors ui.gadgets columns ;
|
||||
IN: ui.gadgets.grids
|
||||
|
||||
TUPLE: grid children gap fill? ;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
USING: arrays assocs kernel math models namespaces
|
||||
sequences words strings system hashtables math.parser
|
||||
math.vectors classes.tuple classes ui.gadgets boxes
|
||||
calendar alarms symbols combinators sets ;
|
||||
calendar alarms symbols combinators sets columns ;
|
||||
IN: ui.gestures
|
||||
|
||||
: set-gestures ( class hash -- ) "gestures" set-word-prop ;
|
||||
|
|
Loading…
Reference in New Issue