BaseVector
The `BaseVector` class in the SOFA framework provides a generic vector API that allows for filling and using vectors independently of the linear algebra library being used. It is part of the Sofa.linearalgebra module and is defined in the `sofa/linearalgebra/BaseVector.h` header file. This class acts as an abstract interface with pure virtual methods, ensuring that any derived classes must implement operations such as size retrieval, element access, resizing, clearing, setting values, and addition to existing elements. **Role in SOFA**: - `BaseVector` serves as a fundamental abstraction for vector operations within the framework. It facilitates genericity by providing an interface that can be implemented with different underlying storage mechanisms (e.g., full or sparse vectors) without changing the rest of the codebase. **Interactions with Other Components**: - Derived classes implementing `BaseVector` provide concrete vector implementations. These implementations are used throughout SOFA for tasks requiring linear algebra operations, such as solving systems of equations in solvers and managing degrees of freedom. **Practical Usage Guidance**: - Users should be aware that using the generic methods provided by `BaseVector` can be slower compared to direct access due to the abstraction layer. The class is recommended for scenarios where genericity across different linear algebra libraries is necessary. - Key data fields and methods include size retrieval (`size`), element access (`element`), resizing (`resize`), clearing values (`clear`), setting elements (`set`), adding to elements (`add`), getting element types, and determining if the vector is full or sparse. These operations are performed through virtual methods that must be implemented by derived classes.
- abstract
- `BaseVector` defines an abstract interface for vector operations in SOFA, allowing generic manipulation of vectors independently of the linear algebra library used.
- sheet
- # BaseVector ## Overview The `BaseVector` class provides a generic API for vector operations within the SOFA framework. It acts as an abstract base class with pure virtual methods that must be implemented by derived classes to support specific storage mechanisms (e.g., full or sparse vectors). This abstraction ensures consistent vector manipulation across different linear algebra libraries. ## Parameters and Data The `BaseVector` class does not expose any significant data fields. Its functionality is entirely defined through its public interface, which includes methods for size retrieval (`size`), element access (`element`), resizing (`resize`), clearing values (`clear`), setting elements (`set`), adding to elements (`add`), and determining the vector's type and sparsity. ## Practical Notes Using `BaseVector` can be slower compared to direct access due to its abstraction layer. It is recommended for scenarios where genericity across different linear algebra libraries is necessary.
- description
- The `BaseVector` class in the SOFA framework provides a generic vector API that allows for filling and using vectors independently of the linear algebra library being used. It is part of the Sofa.linearalgebra module and is defined in the `sofa/linearalgebra/BaseVector.h` header file. This class acts as an abstract interface with pure virtual methods, ensuring that any derived classes must implement operations such as size retrieval, element access, resizing, clearing, setting values, and addition to existing elements. **Role in SOFA**: - `BaseVector` serves as a fundamental abstraction for vector operations within the framework. It facilitates genericity by providing an interface that can be implemented with different underlying storage mechanisms (e.g., full or sparse vectors) without changing the rest of the codebase. **Interactions with Other Components**: - Derived classes implementing `BaseVector` provide concrete vector implementations. These implementations are used throughout SOFA for tasks requiring linear algebra operations, such as solving systems of equations in solvers and managing degrees of freedom. **Practical Usage Guidance**: - Users should be aware that using the generic methods provided by `BaseVector` can be slower compared to direct access due to the abstraction layer. The class is recommended for scenarios where genericity across different linear algebra libraries is necessary. - Key data fields and methods include size retrieval (`size`), element access (`element`), resizing (`resize`), clearing values (`clear`), setting elements (`set`), adding to elements (`add`), getting element types, and determining if the vector is full or sparse. These operations are performed through virtual methods that must be implemented by derived classes.
- maths
- ### Mathematical Description The `BaseVector` class in the SOFA framework is designed to provide an abstract interface for a vector, which can be represented mathematically as $\vec{v} = [v_0, v_1, ..., v_{n-1}]$, where each $v_i$ represents an element of the vector and $n$ denotes the size (number of elements) in the vector. #### Basic Operations: 1. **Size** ($size$): - *Operation*: Returns the number of elements, $n$, in the vector. - *Mathematical Representation*: $n = |\vec{v}|$ 2. **Element Access** ($element(i)$): - *Operation*: Retrieves the value at a specific index $i$ from the vector. - *Mathematical Representation*: $v_i = \vec{v}[i]$, where $0 leq i < n$ 3. **Resize** ($resize(dim)$): - *Operation*: Changes the size of the vector to a new dimension $dim$ and resets all values to 0. - *Mathematical Representation*: If $\vec{v}$ is resized to have $m$ elements, then $\vec{v} = [0, 0, ..., 0]$ with $|\vec{v}| = m$ 4. **Clear** ($clear()$): - *Operation*: Resets all values in the vector to 0. - *Mathematical Representation*: $\forall i: v_i \rightarrow 0$, where $0 leq i < n$ 5. **Set** ($set(i, v)$): - *Operation*: Sets the value at index $i$ in the vector to a new value $v$. - *Mathematical Representation*: $\vec{v}[i] \rightarrow v$, where $0 leq i < n$ 6. **Add** ($add(i, v)$): - *Operation*: Adds a value $v$ to the existing value at index $i$ in the vector. - *Mathematical Representation*: $\vec{v}[i] \rightarrow (\vec{v}[i] + v)$, where $0 leq i < n$ #### Advanced Operations: 1. **Element Type** ($getElementType()$): - *Operation*: Determines the type of elements stored in the vector. - *Mathematical Representation*: Returns an enumeration value (e.g., `ELEMENT_FLOAT` or `ELEMENT_INT`) indicating the type of $v_i$ 2. **Get Elements** ($elements(i0, n, src)$): - *Operation*: Retrieves a contiguous block of elements from index $i_0$ to $i_0 + n$ and stores them in an array `$src`. - *Mathematical Representation*: If `src` is provided as storage, then for each $j$, where $0 leq j < n$: $\text{src}[j] \leftarrow \vec{v}[i_0 + j]$; otherwise returns a pointer to the internal data if compatible. 3. **Set Elements** ($set(i0, n, src)$): - *Operation*: Sets a contiguous block of elements from index $i_0$ to $i_0 + n$ using values provided in an array `$src`. - *Mathematical Representation*: For each $j$, where $0 leq j < n$: $\vec{v}[i_0 + j] \leftarrow \text{src}[j]$ 4. **Add to Elements** ($add(i0, n, src)$): - *Operation*: Adds a contiguous block of elements from index $i_0$ to $i_0 + n$ using values provided in an array `$src`. - *Mathematical Representation*: For each $j$, where $0 leq j < n$: $\vec{v}[i_0 + j] \leftarrow (\vec{v}[i_0 + j] + \text{src}[j])$ 5. **Clear Element** ($clear(i)$): - *Operation*: Resets the value of a specific element at index $i$ to 0. - *Mathematical Representation*: $\vec{v}[i] \rightarrow 0$, where $0 leq i < n$ ### Physical Description In a physical context, vectors are often used to represent quantities such as forces, displacements, and velocities in simulations. The `BaseVector` class provides the necessary abstraction for these operations across different types of storage mechanisms (e.g., dense or sparse). This allows the SOFA framework to be flexible and performant with various linear algebra libraries while maintaining a consistent interface. The vector $\vec{v}$ can represent physical quantities in simulations. For example, if $\vec{f} = [f_0, f_1, ..., f_{n-1}]$ is a force vector applied to points in space, each component $f_i$ could correspond to the magnitude of force at point $i$. Operations such as setting and adding values allow for modifying these forces according to physical interactions within the simulation. In summary, `BaseVector` ensures that all derived classes implementing this interface follow a consistent set of mathematical operations necessary for effective vector manipulation in physics-based simulations.
{
"name": "BaseVector",
"main": {
"name": "BaseVector",
"namespace": "sofa::linearalgebra",
"module": "Sofa.framework.LinearAlgebra",
"include": "sofa/linearalgebra/BaseVector.h",
"doc": "Generic vector API, allowing to fill and use a vector independently of the linear algebra library in use.\nNote that accessing values using this class is rather slow and should only be used in codes where the\nprovided genericity is necessary.",
"inherits": [],
"templates": [],
"data_fields": [],
"links": [],
"methods": [
{
"name": "size",
"return_type": "Index",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "element",
"return_type": "SReal",
"params": [
{
"name": "i",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "resize",
"return_type": "void",
"params": [
{
"name": "dim",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "clear",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "set",
"return_type": "void",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "v",
"type": "SReal"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "add",
"return_type": "void",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "v",
"type": "SReal"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "getElementType",
"return_type": "ElementType",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getElementSize",
"return_type": "int",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "isFull",
"return_type": "bool",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "isSparse",
"return_type": "bool",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "elementsDefaultImpl",
"return_type": "const T *",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "buffer",
"type": "T *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "setDefaultImpl",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const T *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "addDefaultImpl",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const T *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "elements",
"return_type": "const float *",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "float *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "elements",
"return_type": "const double *",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "double *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "elements",
"return_type": "const int *",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "int *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "set",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const float *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "set",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const double *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "set",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const int *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "add",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const float *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "add",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const double *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "add",
"return_type": "void",
"params": [
{
"name": "i0",
"type": "Index"
},
{
"name": "n",
"type": "Index"
},
{
"name": "src",
"type": "const int *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "clear",
"return_type": "void",
"params": [
{
"name": "i",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
}
]
},
"desc": {
"description": "The `BaseVector` class in the SOFA framework provides a generic vector API that allows for filling and using vectors independently of the linear algebra library being used. It is part of the Sofa.linearalgebra module and is defined in the `sofa/linearalgebra/BaseVector.h` header file. This class acts as an abstract interface with pure virtual methods, ensuring that any derived classes must implement operations such as size retrieval, element access, resizing, clearing, setting values, and addition to existing elements.\n\n**Role in SOFA**: \n- `BaseVector` serves as a fundamental abstraction for vector operations within the framework. It facilitates genericity by providing an interface that can be implemented with different underlying storage mechanisms (e.g., full or sparse vectors) without changing the rest of the codebase.\n\n**Interactions with Other Components**:\n- Derived classes implementing `BaseVector` provide concrete vector implementations. These implementations are used throughout SOFA for tasks requiring linear algebra operations, such as solving systems of equations in solvers and managing degrees of freedom.\n\n**Practical Usage Guidance**:\n- Users should be aware that using the generic methods provided by `BaseVector` can be slower compared to direct access due to the abstraction layer. The class is recommended for scenarios where genericity across different linear algebra libraries is necessary.\n- Key data fields and methods include size retrieval (`size`), element access (`element`), resizing (`resize`), clearing values (`clear`), setting elements (`set`), adding to elements (`add`), getting element types, and determining if the vector is full or sparse. These operations are performed through virtual methods that must be implemented by derived classes."
},
"maths": {
"maths": "### Mathematical Description\n\nThe `BaseVector` class in the SOFA framework is designed to provide an abstract interface for a vector, which can be represented mathematically as $\\vec{v} = [v_0, v_1, ..., v_{n-1}]$, where each $v_i$ represents an element of the vector and $n$ denotes the size (number of elements) in the vector.\n\n#### Basic Operations:\n\n1. **Size** ($size$):\n - *Operation*: Returns the number of elements, $n$, in the vector.\n - *Mathematical Representation*: $n = |\\vec{v}|$\n\n2. **Element Access** ($element(i)$):\n - *Operation*: Retrieves the value at a specific index $i$ from the vector.\n - *Mathematical Representation*: $v_i = \\vec{v}[i]$, where $0 \tleq i < n$\n\n3. **Resize** ($resize(dim)$):\n - *Operation*: Changes the size of the vector to a new dimension $dim$ and resets all values to 0.\n - *Mathematical Representation*: If $\\vec{v}$ is resized to have $m$ elements, then $\\vec{v} = [0, 0, ..., 0]$ with $|\\vec{v}| = m$\n\n4. **Clear** ($clear()$):\n - *Operation*: Resets all values in the vector to 0.\n - *Mathematical Representation*: $\\forall i: v_i \\rightarrow 0$, where $0 \tleq i < n$\n\n5. **Set** ($set(i, v)$):\n - *Operation*: Sets the value at index $i$ in the vector to a new value $v$.\n - *Mathematical Representation*: $\\vec{v}[i] \\rightarrow v$, where $0 \tleq i < n$\n\n6. **Add** ($add(i, v)$):\n - *Operation*: Adds a value $v$ to the existing value at index $i$ in the vector.\n - *Mathematical Representation*: $\\vec{v}[i] \\rightarrow (\\vec{v}[i] + v)$, where $0 \tleq i < n$\n\n#### Advanced Operations:\n\n1. **Element Type** ($getElementType()$):\n - *Operation*: Determines the type of elements stored in the vector.\n - *Mathematical Representation*: Returns an enumeration value (e.g., `ELEMENT_FLOAT` or `ELEMENT_INT`) indicating the type of $v_i$\n\n2. **Get Elements** ($elements(i0, n, src)$):\n - *Operation*: Retrieves a contiguous block of elements from index $i_0$ to $i_0 + n$ and stores them in an array `$src`.\n - *Mathematical Representation*: If `src` is provided as storage, then for each $j$, where $0 \tleq j < n$: $\\text{src}[j] \\leftarrow \\vec{v}[i_0 + j]$; otherwise returns a pointer to the internal data if compatible.\n\n3. **Set Elements** ($set(i0, n, src)$):\n - *Operation*: Sets a contiguous block of elements from index $i_0$ to $i_0 + n$ using values provided in an array `$src`.\n - *Mathematical Representation*: For each $j$, where $0 \tleq j < n$: $\\vec{v}[i_0 + j] \\leftarrow \\text{src}[j]$\n\n4. **Add to Elements** ($add(i0, n, src)$):\n - *Operation*: Adds a contiguous block of elements from index $i_0$ to $i_0 + n$ using values provided in an array `$src`.\n - *Mathematical Representation*: For each $j$, where $0 \tleq j < n$: $\\vec{v}[i_0 + j] \\leftarrow (\\vec{v}[i_0 + j] + \\text{src}[j])$\n\n5. **Clear Element** ($clear(i)$):\n - *Operation*: Resets the value of a specific element at index $i$ to 0.\n - *Mathematical Representation*: $\\vec{v}[i] \\rightarrow 0$, where $0 \tleq i < n$\n\n### Physical Description\n\nIn a physical context, vectors are often used to represent quantities such as forces, displacements, and velocities in simulations. The `BaseVector` class provides the necessary abstraction for these operations across different types of storage mechanisms (e.g., dense or sparse). This allows the SOFA framework to be flexible and performant with various linear algebra libraries while maintaining a consistent interface.\n\nThe vector $\\vec{v}$ can represent physical quantities in simulations. For example, if $\\vec{f} = [f_0, f_1, ..., f_{n-1}]$ is a force vector applied to points in space, each component $f_i$ could correspond to the magnitude of force at point $i$. Operations such as setting and adding values allow for modifying these forces according to physical interactions within the simulation.\n\nIn summary, `BaseVector` ensures that all derived classes implementing this interface follow a consistent set of mathematical operations necessary for effective vector manipulation in physics-based simulations."
},
"summary": {
"abstract": "`BaseVector` defines an abstract interface for vector operations in SOFA, allowing generic manipulation of vectors independently of the linear algebra library used.",
"sheet": "# BaseVector\n\n## Overview\nThe `BaseVector` class provides a generic API for vector operations within the SOFA framework. It acts as an abstract base class with pure virtual methods that must be implemented by derived classes to support specific storage mechanisms (e.g., full or sparse vectors). This abstraction ensures consistent vector manipulation across different linear algebra libraries.\n\n## Parameters and Data\nThe `BaseVector` class does not expose any significant data fields. Its functionality is entirely defined through its public interface, which includes methods for size retrieval (`size`), element access (`element`), resizing (`resize`), clearing values (`clear`), setting elements (`set`), adding to elements (`add`), and determining the vector's type and sparsity.\n\n## Practical Notes\nUsing `BaseVector` can be slower compared to direct access due to its abstraction layer. It is recommended for scenarios where genericity across different linear algebra libraries is necessary."
}
}