Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/vec1/test/vec1_common.tcl # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / vec1 / test / vec1_common.tcl` 125 lines ยท 3146 bytes Raw Blame History 1 2 if {![info exists testdir]} { 3 set testdir [file join [file dirname [info script]] .. .. .. test] 4 } 5 source $testdir/tester.tcl 6 7 set dir [file dirname [info nameofexecutable]] 8 set vec1_shlib [file join $dir vec1] 9 10 11 proc vec1_load_only {db} { 12 if {[catch {$db one {SELECT vec1_info()}}]} { 13 global vec1_shlib 14 $db enable_load_extension 1 15 if {[catch { sqlite3_load_extension $db $vec1_shlib }]} { 16 $db eval { SELECT load_extension($vec1_shlib) } 17 } 18 $db enable_load_extension 0 19 } 20 } 21 22 sqlite3 db_test_vec1 "" 23 set res [catch { vec1_load_only db_test_vec1 }] 24 db_test_vec1 close 25 if {$res} { 26 finish_test 27 return -code return 28 } 29 30 proc vec1_load {db} { 31 if {[catch {$db one {SELECT vec1_info()}}]} { 32 global vec1_shlib 33 $db enable_load_extension 1 34 $db eval { SELECT load_extension($vec1_shlib) } 35 $db enable_load_extension 0 36 } 37 $db func random_vector random_vector 38 $db func random_vector2 random_vector2 39 $db func rvec rvec 40 } 41 42 proc vec1_load_scalar {db} { 43 global vec1_shlib 44 $db enable_load_extension 1 45 set scalar "${vec1_shlib}testscalar" 46 sqlite3_load_extension $db $scalar 47 $db enable_load_extension 0 48 } 49 50 proc random_vector {n {scale 1.0}} { 51 set v [list] 52 for {set i 0} {$i < $n} {incr i} { 53 lappend v [expr {((rand() * 2.0) - 1.0) * $scale}] 54 } 55 binary format f$n $v 56 } 57 58 proc random_vector2 {n} { 59 set v [list] 60 for {set i 0} {$i < $n} {incr i} { 61 lappend v [expr {abs(rand() * 10.0)}] 62 } 63 binary format f$n $v 64 } 65 66 proc rvec {n i} { 67 set lPrime { 68 23 29 31 37 41 43 47 53 69 59 61 67 71 73 79 83 89 70 97 101 103 107 109 113 127 131 71 137 139 149 151 157 163 167 173 72 179 181 191 193 197 199 211 223 73 227 229 233 239 241 251 257 263 74 269 271 277 281 283 293 307 311 75 313 317 331 337 347 349 353 359 76 367 373 379 383 389 397 401 409 77 419 421 431 433 439 443 449 457 78 461 463 467 479 487 491 499 503 79 509 521 523 541 547 557 563 569 80 571 577 587 593 599 601 607 613 81 617 619 631 641 643 647 653 659 82 661 673 677 683 691 701 709 719 83 727 733 739 743 751 757 761 769 84 } 85 86 if {$n>[llength $lPrime]} { 87 error "n value too large ($n)" 88 } 89 90 set i [expr $i * 769] 91 92 set lDim [list] 93 for {set iDim 0} {$iDim<$n} {incr iDim} { 94 set x [lindex $lPrime $iDim] 95 lappend lDim [expr ($i % $x) - $x/2] 96 } 97 98 binary format r* $lDim 99 } 100 db func rvec rvec 101 102 proc model2tbl {nm vec1tbl} { 103 set model [db one "SELECT val FROM ${vec1tbl}_model WHERE id=1"] 104 105 binary scan $model IIIIII iVersion flags nElem nCodebook nBucket eDistance 106 107 set nBytePerVector [expr $nElem*4] 108 set iOff [expr 4 * 6] 109 if {($flags & 0x08)==0 && $nCodebook>0} { 110 incr iOff [expr 4 * $nElem * 256] 111 } 112 #puts "nBytePerVector=$nBytePerVector" 113 #puts "nBucket=$nBucket" 114 #puts "sz=[string length $model]" 115 #puts "iOff=$iOff" 116 117 db eval "CREATE TABLE $nm (ibucket INTEGER PRIMARY KEY, coarse BLOB)" 118 for {set iBucket 0} {$iBucket<$nBucket} {incr iBucket} { 119 set vec [string range $model $iOff [expr $iOff+$nBytePerVector-1]] 120 db eval "INSERT INTO $nm VALUES(\$iBucket, \$vec)" 121 incr iOff $nBytePerVector 122 } 123 } 124 125