Implements the Math S4groupGeneric functions
for dbMatrix objects. This includes various mathematical operations such as
logarithms, exponentials, trigonometric functions, and other transformations.
Arguments
- x
A
dbMatrixobject.
Value
A dbMatrix object with the mathematical operation applied to each element.
Details
This method provides implementations for the following Math functions:
Arithmetic and rounding:
Cumulative operations:
Logarithmic:
DuckDB Log Function Mappings:
| R Function | DuckDB Function | Notes |
log(x) | LN(x) | Natural logarithm |
log10(x) | LOG10(x) | Base-10 logarithm |
log2(x) | LOG2(x) | Base-2 logarithm |
log1p(x) | LN(x + 1) | log(1+x), computed as LN |
Sparsity-Preserving Log:
For dbSparseMatrix with pending operations, log(x + 1) operations preserve sparsity
since log(0 + 1) = 0. The multiplicative component is applied first,
then the log transformation is applied to sparse values only.
Trigonometric:
Exponential:
Special functions:
Note:
digamma()trigamma()are not supported
The function applies the specified mathematical operation to each element
of the dbMatrix object.
Examples
mat <- matrix(1, nrow = 3, ncol = 3)
dbmat <- as.dbMatrix(mat)
log(dbmat)
#> 3 x 3 dbMatrix of class "dbDenseMatrix"
#> [[ Colnames: 'col1', 'col2', 'col3' ]]
#>
#> row1 0.0000000 0.0000000 0.0000000
#> row2 0.0000000 0.0000000 0.0000000
#> row3 0.0000000 0.0000000 0.0000000
sqrt(dbmat)
#> 3 x 3 dbMatrix of class "dbDenseMatrix"
#> [[ Colnames: 'col1', 'col2', 'col3' ]]
#>
#> row1 1.0000000 1.0000000 1.0000000
#> row2 1.0000000 1.0000000 1.0000000
#> row3 1.0000000 1.0000000 1.0000000
sin(dbmat)
#> 3 x 3 dbMatrix of class "dbDenseMatrix"
#> [[ Colnames: 'col1', 'col2', 'col3' ]]
#>
#> row1 0.8414710 0.8414710 0.8414710
#> row2 0.8414710 0.8414710 0.8414710
#> row3 0.8414710 0.8414710 0.8414710