Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellga committed Jun 21, 2024
1 parent d8e0828 commit e3944b8
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 50 deletions.
3 changes: 1 addition & 2 deletions r-harmonium/.testtest.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pkgbuild::clean_dll()
devtools::load_all(".", export_all = FALSE)
devtools::test()
devtools::check(document = FALSE, cran = FALSE, args = c("--no-manual", "--no-build-vignettes", "--no-codoc", "--no-examples", "--no-tests"))

devtools::check(document = FALSE, cran = FALSE, args = c("--no-manual", "--no-build-vignettes", "--no-codoc", "--no-examples", "--no-tests"))
106 changes: 63 additions & 43 deletions r-harmonium/R/000-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ HArray_mem_adress <- function(self) {
}
}

HArray_is_standard_layout <- function(self) {
function() {
.Call(savvy_HArray_is_standard_layout__impl, self)
}
}

HArray_invalidate <- function(self) {
function() {
invisible(.Call(savvy_HArray_invalidate__impl, self))
Expand All @@ -121,6 +127,7 @@ HArray_invalidate <- function(self) {
e$dtype <- HArray_dtype(ptr)
e$is_shared <- HArray_is_shared(ptr)
e$mem_adress <- HArray_mem_adress(ptr)
e$is_standard_layout <- HArray_is_standard_layout(ptr)
e$invalidate <- HArray_invalidate(ptr)

class(e) <- "HArray"
Expand All @@ -129,7 +136,7 @@ HArray_invalidate <- function(self) {


#' HArray
#' An array representation. \
#' An array representation.
#'
#' # Methods
#'
Expand Down Expand Up @@ -157,7 +164,7 @@ HArray$new_from_values <- function(arr, dtype) {


#' HAudioOp
#' A collection of methods that can be applied to float 1D or 2D `HArray`s which represents audio data. \
#' A collection of methods that can be applied to float 1D or 2D `HArray`s which represents audio data.
#'
#' # Methods
#'
Expand Down Expand Up @@ -311,7 +318,7 @@ HAudioSink_volume <- function(self) {


#' HAudioSink
#' Handle to a device that outputs sounds. \
#' Handle to a device that outputs sounds.
#'
#' # Methods
#'
Expand Down Expand Up @@ -371,8 +378,9 @@ HDataType_ne <- function(self) {


#' HDataType
#' A type representation. \
#' Supports `Float32`, `Float64`, `Complex32` and `Complex64` types. \
#' A type representation.
#'
#' Supports `Float32`, `Float64`, `Complex32` and `Complex64` types.
#'
#' # Methods
#'
Expand Down Expand Up @@ -459,7 +467,7 @@ HDecoderStream_stream <- function(self) {


#' HDecoderStream
#' An iterator that decodes audio in streams. \
#' An iterator that decodes audio in streams.
#'
#' # Methods
#'
Expand Down Expand Up @@ -511,7 +519,7 @@ HFftPlanner_print <- function(self) {


#' HFftPlanner
#' A planner is used to create FFTs. It caches results internally, so when making more than one FFT it is advisable to reuse the same planner. \
#' A planner is used to create FFTs. It caches results internally, so when making more than one FFT it is advisable to reuse the same planner.
#'
#' # Methods
#'
Expand Down Expand Up @@ -539,7 +547,7 @@ HFftPlanner$new <- function(dtype) {


#' HFile
#' A collection of methods designed to streamline input and output operations. \
#' A collection of methods designed to streamline input and output operations.
#'
#' # Methods
#'
Expand Down Expand Up @@ -606,8 +614,9 @@ HInterpolationType_ne <- function(self) {


#' HInterpolationType
#' A interpolation type representation. \
#' Supports `Cubic`, `Linear`, `Quadratic` and `Nearest`. \
#' A interpolation type representation.
#'
#' Supports `Cubic`, `Linear`, `Quadratic` and `Nearest` types.
#'
#' # Methods
#'
Expand Down Expand Up @@ -667,8 +676,9 @@ HMetadataType_ne <- function(self) {


#' HMetadataType
#' A metadata type representation. \
#' Supports `All`, `Text` and `Visual` types. \
#' A metadata type representation.
#'
#' Supports `All`, `Text` and `Visual` types.
#'
#' # Methods
#'
Expand Down Expand Up @@ -727,22 +737,27 @@ HPolynomialDegree_ne <- function(self) {


#' HPolynomialDegree
#' Degree of the polynomial used for interpolation. A higher degree gives a higher quality result, while taking longer to compute. \
#' Degree of the polynomial used for interpolation. A higher degree gives a higher quality result, while taking longer to compute.
#'
#' - `Septic`
#'
#' Septic polynomial, fitted using 8 sample points.
#'
#' * `Septic` \
#' Septic polynomial, fitted using 8 sample points. \
#' - `Quintic`.
#'
#' * `Quintic`. \
#' Quintic polynomial, fitted using 6 sample points. \
#' Quintic polynomial, fitted using 6 sample points.
#'
#' * `Cubic`. \
#' Cubic polynomial, fitted using 4 sample points. \
#' - `Cubic`.
#'
#' * `Linear`. \
#' Linear polynomial, fitted using 2 sample points. \
#' Cubic polynomial, fitted using 4 sample points.
#'
#' * `Nearest`. \
#' Nearest, uses the nearest sample point without any fitting. \
#' - `Linear`.
#'
#' Linear polynomial, fitted using 2 sample points.
#'
#' - `Nearest`.
#'
#' Nearest, uses the nearest sample point without any fitting.
#'
#' # Methods
#'
Expand Down Expand Up @@ -810,8 +825,9 @@ HRealFftPlanner_print <- function(self) {


#' HRealFftPlanner
#' A planner is used to create FFTs. It caches results internally, so when making more than one FFT it is advisable to reuse the same planner. \
#' This planner is used to calculate FFTs of real valued inputs and its inverse operation. \
#' A planner is used to create FFTs. It caches results internally, so when making more than one FFT it is advisable to reuse the same planner.
#'
#' This planner is used to calculate FFTs of real valued inputs and its inverse operation.
#'
#' # Methods
#'
Expand Down Expand Up @@ -887,32 +903,34 @@ HResampler_print <- function(self) {


#' HResampler
#' A resampler. \
#' A resampler.
#'
#' #### Asynchronous Resamplers
#'
#' The resampling is based on band-limited interpolation using sinc interpolation filters. The sinc interpolation upsamples by an adjustable factor, \
#' and then the new sample points are calculated by interpolating between these points. \
#' The resampling ratio can be updated at any time. \
#' The resampling is based on band-limited interpolation using sinc interpolation filters. The sinc interpolation upsamples by an adjustable factor,
#' and then the new sample points are calculated by interpolating between these points.
#'
#' * `SincFixedIn` \
#' The resampling ratio can be updated at any time.
#'
#' * `SincFixedOut` \
#' - `SincFixedIn`
#'
#' * `FastFixedIn` \
#' - `SincFixedOut`
#'
#' * `FastFixedOut` \
#' - `FastFixedIn`
#'
#' - `FastFixedOut`
#'
#' #### Synchronous Resamplers
#'
#' Is implemented via FFT. The data is FFTed, the spectrum modified, and then inverse FFTed to get the resampled data. \
#' This type of resampler is considerably faster but doesn’t support changing the resampling ratio. \
#' Is implemented via FFT. The data is FFTed, the spectrum modified, and then inverse FFTed to get the resampled data.
#'
#' This type of resampler is considerably faster but doesn’t support changing the resampling ratio.
#'
#' * `FftFixedIn` \
#' - `FftFixedIn`
#'
#' * `FftFixedInOut` \
#' - `FftFixedInOut`
#'
#' * `FftFixedOut` \
#' - `FftFixedOut`
#'
#' # Methods
#'
Expand Down Expand Up @@ -976,9 +994,10 @@ HResamplerType_ne <- function(self) {


#' HResamplerType
#' A resampler type representation. \
#' A resampler type representation.
#'
#' Supports `FftFixedIn`, `FftFixedInOut`, `FftFixedOut`, `SincFixedIn`, `SincFixedOut`,
#' `FastFixedIn` and `FastFixedOut` types. \
#' `FastFixedIn` and `FastFixedOut` types.
#'
#' # Methods
#'
Expand Down Expand Up @@ -1025,7 +1044,7 @@ HSincInterpolationParameters_print <- function(self) {


#' HSincInterpolationParameters
#' Parameters to be used for sinc interpolation. \
#' Parameters to be used for sinc interpolation.
#'
#' # Methods
#'
Expand Down Expand Up @@ -1134,8 +1153,9 @@ HWindowType_ne <- function(self) {


#' HWindowType
#' A window type representation. \
#' Supports `Blackman`, `Blackman2`, `BlackmanHarris`, `BlackmanHarris2`, `Hann` and `Hann2` types. \
#' A window type representation.
#'
#' Supports `Blackman`, `Blackman2`, `BlackmanHarris`, `BlackmanHarris2`, `Hann` and `Hann2` types.
#'
#' # Methods
#'
Expand Down
6 changes: 6 additions & 0 deletions r-harmonium/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ SEXP savvy_HArray_mem_adress__impl(SEXP self__) {
return handle_result(res);
}

SEXP savvy_HArray_is_standard_layout__impl(SEXP self__) {
SEXP res = savvy_HArray_is_standard_layout__ffi(self__);
return handle_result(res);
}

SEXP savvy_HArray_invalidate__impl(SEXP self__) {
SEXP res = savvy_HArray_invalidate__ffi(self__);
return handle_result(res);
Expand Down Expand Up @@ -526,6 +531,7 @@ static const R_CallMethodDef CallEntries[] = {
{"savvy_HArray_dtype__impl", (DL_FUNC) &savvy_HArray_dtype__impl, 1},
{"savvy_HArray_is_shared__impl", (DL_FUNC) &savvy_HArray_is_shared__impl, 1},
{"savvy_HArray_mem_adress__impl", (DL_FUNC) &savvy_HArray_mem_adress__impl, 1},
{"savvy_HArray_is_standard_layout__impl", (DL_FUNC) &savvy_HArray_is_standard_layout__impl, 1},
{"savvy_HArray_invalidate__impl", (DL_FUNC) &savvy_HArray_invalidate__impl, 1},
{"savvy_HAudioOp_nchannels__impl", (DL_FUNC) &savvy_HAudioOp_nchannels__impl, 1},
{"savvy_HAudioOp_nframes__impl", (DL_FUNC) &savvy_HAudioOp_nframes__impl, 1},
Expand Down
1 change: 1 addition & 0 deletions r-harmonium/src/rust/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SEXP savvy_HArray_collect__ffi(SEXP self__);
SEXP savvy_HArray_dtype__ffi(SEXP self__);
SEXP savvy_HArray_is_shared__ffi(SEXP self__);
SEXP savvy_HArray_mem_adress__ffi(SEXP self__);
SEXP savvy_HArray_is_standard_layout__ffi(SEXP self__);
SEXP savvy_HArray_invalidate__ffi(SEXP self__);

// methods and associated functions for HAudioOp
Expand Down
41 changes: 37 additions & 4 deletions r-harmonium/src/rust/src/harray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl HArray {
///
/// #### Returns
///
/// A `bool`.
/// A bool.
///
/// #### Examples
///
Expand Down Expand Up @@ -353,7 +353,7 @@ impl HArray {
///
/// #### Returns
///
/// A `bool`.
/// A bool.
///
/// #### Examples
///
Expand Down Expand Up @@ -475,7 +475,7 @@ impl HArray {
///
/// #### Returns
///
/// A `bool`.
/// A bool.
///
/// #### Examples
///
Expand Down Expand Up @@ -509,7 +509,7 @@ impl HArray {
///
/// #### Returns
///
/// A `string`.
/// A string.
///
/// #### Examples
///
Expand All @@ -528,6 +528,39 @@ impl HArray {
string_sexp.into()
}

/// HArray
/// ## is_standard_layout
///
/// `is_standard_layout() -> bool`
///
/// Returns true if the array data is laid out in contiguous “C order” in memory (where the last index is the most rapidly varying).
///
/// Returns false otherwise, i.e. the array is possibly not contiguous in memory, it has custom strides, etc.
///
/// This function is useful mainly to check if an `HArray` is contiguous after some operation as, for example, `slice()`.
///
/// #### Returns
///
/// A bool.
///
/// #### Examples
///
/// ```r
/// library(harmonium)
/// arr = array(c(1,2,3,4,5,6,7,8,9,10,11,12), c(3,4))
/// dtype = HDataType$Float32
/// harray = HArray$new_from_values(arr, dtype)
/// harray$is_standard_layout() # TRUE, contiguous data
/// sliced_harray = harray$slice(list(c(0L, 2L, 1L), c(1L, 3L, 1L)))
/// sliced_harray$is_standard_layout() # FALSE, non contiguous data
/// ```
///
/// _________
///
pub fn is_standard_layout(&self) -> savvy::Result<Sexp> {
self.0.is_standard_layout()
}

/// HArray
/// ## invalidate
///
Expand Down
Loading

0 comments on commit e3944b8

Please sign in to comment.