class staticla. BoolVector
Source: ladoc.
The boolean vector representation. Wraps a C++ array.
Property
new BoolVector([arg])
Vector - array of boolean.
Example
var la = require('qminer').la;
// create a new empty vector
var vec = new la.BoolVector();
// create a new vector
var vec2 = new la.BoolVector([true, true, false]);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
arg |
(Array of boolean or module:la.BoolVector) |
Yes |
Constructor arguments. There are two ways of constructing:
|
Property
length
Gives the length of vector. Type number
.
Example
var la = require('qminer').la;
// create a new vector
var x = new la.BoolVector([true, true, false]);
// get the length of the vector
var len = x.length; // returns 3
Methods
at(index) → boolean
Returns element at index.
Example
// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// get the element at index 1
var el = vec[1];
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
Element index (zero-based). |
- Returns
-
boolean
Vector element.
load(fin) → module:la.BoolVector
Loads the vector from input stream (binary deserialization).
Example
// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create an empty vector
var vec = new la.BoolVector();
// open a read stream
var fin = fs.openRead('vec.dat');
// load the vector
vec.load(fin);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fin |
|
Input stream. |
- Returns
-
module:la.BoolVector
Self. The vector is filled using the input streamfin
.
loadascii(fin) → module:la.BoolVector
Loads the vector from input stream (ascii deserialization).
Example
// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create an empty vector
var vec = new la.BoolVector();
// open a read stream
var fin = fs.openRead('vec.dat');
// load the matrix
vec.loadascii(fin);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fin |
|
Input stream. |
- Returns
-
module:la.BoolVector
Self. The vector is filled using the input streamfin
.
push(val) → number
Adds an element to the end of the vector.
Example
// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// push an element to the vector
vec.push(false);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
val |
boolean |
|
The element added to the vector. |
- Returns
-
number
The new length property of the object upon which the method was called.
pushV(vec) → number
Appends a second vector to the first one.
Example
// import la module
var la = require('qminer').la;
// create two new vectors
var vec = new la.BoolVector([true, true, false]);
var vec2 = new la.BoolVector([false, true]);
// append the two vectors
vec.pushV(vec2);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
vec |
|
The appended vector. |
- Returns
-
number
The new length property of the vectors.
put(idx, val) → module:la.BoolVector
Sets an element in vector.
Example
// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// set the first element to false
vec.put(0, false);
Parameters
Name | Type | Optional | Description |
---|---|---|---|
idx |
number |
|
Index (zero based). |
val |
boolean |
|
Element value. |
- Returns
-
module:la.BoolVector
Self. The values at indexidx
has been changed toval
.
save(fout) → module:fs.FOut
Saves the vector as output stream (binary serialization).
Example
// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// open write stream
var fout = fs.openWrite('vec.dat');
// save vector and close write stream
vec.save(fout).close();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fout |
|
Output stream. |
- Returns
-
module:fs.FOut
The output streamfout
.
saveascii(fout) → module:fs.FOut
Saves the vector as output stream (ascii serialization).
Example
// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// open write stream
var fout = fs.openWrite('vec.dat');
// save matrix and close write stream
vec.saveascii(fout).close();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fout |
|
Output stream. |
- Returns
-
module:fs.FOut
The output streamfout
.
shuffle() → module:la.BoolVector
Randomly reorders the elements of the vector (inplace).
Example
// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, false, false]);
// shuffle the elements
vec.shuffle();
- Returns
-
module:la.BoolVector
Self. The elements are randomly reordered.
splice(start, deleteCount[, ...itemN]) → module:la.BoolVector
Changes the vector by removing and adding elements.
Example
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// splice the vector by removing the last two elements and adding false, true
vec.splice(1, 2, false, true)// returns vector [true, false, true]
Parameters
Name | Type | Optional | Description |
---|---|---|---|
start |
number |
|
Index at which to start changing the array. |
deleteCount |
number |
|
Number of elements to be removed. |
itemN |
number |
Yes |
The element(s) to be add to the array. If no elements are given, splice() will only remove elements from the array. Value can be repeated. |
- Returns
-
module:la.BoolVector
Self. The selected elements are removed/replaced.
toArray() → Array of boolean
Copies the vector into a JavaScript array of booleans.
Example
// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, false, true]);
// create a JavaScript array out of vec
var arr = vec.toArray(); // returns an array [true, false, true]
- Returns
-
Array of boolean
A JavaScript array of booleans.
toString() → string
Returns the vector as string.
Example
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// create vector as string
vec.toString(); // returns 'true, true, false'
- Returns
-
string
String representation.
trunc(idx) → module:la.BoolVector
Deletes elements with sprecific index or more.
Example
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// trunc all elements with index 1 or more
vec.trunc(1); // returns vector [true]
Parameter
Name | Type | Optional | Description |
---|---|---|---|
idx |
boolean |
|
Index (zero based). |
- Returns
-
module:la.BoolVector
Self after truncating.
unshift(...args) → number
Adds elements to the beginning of the vector.
Example
// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// add two elements to the beggining of the vector
var len = vec.unshift(false, true); // returns 5
Parameter
Name | Type | Optional | Description |
---|---|---|---|
args |
boolean |
|
One or more elements to be added to the vector. Value can be repeated. |
- Returns
-
number
The new length of vector.