no matching function for call to 'WaveHC::WaveHC()' Arduino Error - arduino

I'm working on a arduino(uno) talking clock project. I'm using the code on this site : https://learn.adafruit.com/wave-shield-talking-clock/overview
add the WaveHC library when I get the following error :
Arduino:1.6.6 (Windows 10), Card:"Arduino/Genuino Uno"
TalkingClock:44: error: no matching function for call to 'WaveHC::WaveHC()'
WaveHC wave;
^
\Arduino\TalkingClock\TalkingClock.ino:44:12: note: candidates are:
In file included from \Arduino\TalkingClock\TalkingClock.ino:26:0:
\Arduino\libraries\WaveHC/WaveHC.h:113:3: note: WaveHC::WaveHC(HardwareSerial&)
WaveHC(HardwareSerial& serial);
^
\Arduino\libraries\WaveHC/WaveHC.h:113:3: note: candidate expects 1 argument, 0 provided
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: constexpr WaveHC::WaveHC(const WaveHC&)
class WaveHC
^
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: candidate expects 1 argument, 0 provided
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: constexpr WaveHC::WaveHC(WaveHC&&)
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: candidate expects 1 argument, 0 provided
TalkingClock:64: error: variable 'hours' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*hours[] = { h12, h01, h02, h03, h04, h05, h06, h07, h08, h09, h10, h11 },
^
TalkingClock:65: error: variable 'mTens' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mTens[] = { m00, m10, m20, m30, m40, m50 },
^
TalkingClock:66: error: variable 'mTeens' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mTeens[] = { m11, m12, m13, m14, m15, m16, m17, m18, m19 },
^
TalkingClock:67: error: variable 'mTenX' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mTenX[] = { m0x, NULL, m2x, m3x, m4x, m5x },
^
TalkingClock:68: error: variable 'mins' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mins[] = { m1, m2, m3, m4, m5, m6, m7, m8, m9 },
^
TalkingClock:69: error: variable 'ampm' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*ampm[] = { am, pm };
^
exit status 1
no matching function for call to 'WaveHC::WaveHC()'

Related

How can I call a rust function from R that returns Vec<Vec<f64>>?

I have implemented a function for sampling from M different normal distributions N times in Rust because my R code was too slow. It is also parallelized. Here is the pure Rust code:
use rand_distr::{Normal, Distribution};
use rayon::prelude::*;
fn rust_rprednorm(n: i32, means: Vec<f64>, sds: Vec<f64>) -> Vec<Vec<f64>> {
let mut preds = vec![vec![0.0; n as usize]; means.len()];
preds.par_iter_mut().enumerate().for_each(|(i, e)| {
let mut rng = rand::thread_rng();
(0..n).into_iter().for_each(|j| {
let normal = Normal::new(means[i], sds[i]).unwrap();
e[j as usize] = normal.sample(&mut rng);
})
});
preds
}
Which I am trying to call from R using the rextendr library. The code is inside a utils.R file I import using source():
code <- r"(
use rand_distr::{Normal, Distribution};
use rayon::prelude::*;
#[extendr]
fn rust_rprednorm(n: i32, means: Vec<f64>, sds: Vec<f64>) -> Vec<Vec<f64>> {
let mut preds = vec![vec![0.0; n as usize]; means.len()];
preds.par_iter_mut().enumerate().for_each(|(i, e)| {
let mut rng = rand::thread_rng();
(0..n).into_iter().for_each(|j| {
let normal = Normal::new(means[i], sds[i]).unwrap();
e[j as usize] = normal.sample(&mut rng);
})
});
preds
}
)"
rust_source(code = code, dependencies = list(`rand` = "0.8.5", `rand_distr` ="0.4.3", `rayon` = "1.6.1"))
The error is:
Error in `invoke_cargo()`:
! Rust code could not be compiled successfully. Aborting.
✖ error[E0277]: the trait bound `Robj: From<Vec<Vec<f64>>>` is not satisfied
--> src\lib.rs:6:5
|
6 | #[extendr]
| ^^^^^^^^^^ the trait `From<Vec<Vec<f64>>>` is not implemented for `Robj`
|
= help: the following other types implement trait `From<T>`:
<Robj as From<&'a [T]>>
<Robj as From<&Altrep>>
<Robj as From<&Primitive>>
<Robj as From<&Robj>>
<Robj as From<&Vec<T>>>
<Robj as From<&extendr_api::Complexes>>
<Robj as From<&extendr_api::Doubles>>
<Robj as From<&extendr_api::Environment>>
and 71 others
= note: this error originates in the attribute macro `extendr` (in Nightly builds, run with -Z macro-backtrace for more info)
✖ error: aborting due to previous error
Traceback:
1. source("inla_predictive_distribution_utils.R")
2. withVisible(eval(ei, envir))
3. eval(ei, envir)
4. eval(ei, envir)
5. rust_source(code = code, dependencies = list(rand = "0.8.5",
. rand_distr = "0.4.3", rayon = "1.6.1"))
6. invoke_cargo(toolchain = toolchain, specific_target = specific_target,
. dir = dir, profile = profile, quiet = quiet, use_rtools = use_rtools)
7. check_cargo_output(compilation_result, message_buffer, tty_has_colors(),
. quiet)
8. ui_throw("Rust code could not be compiled successfully. Aborting.",
. error_messages, call = call, glue_open = "{<{", glue_close = "}>}")
9. withr::with_options(list(warning.length = message_limit_bytes),
. rlang::abort(message, class = "rextendr_error", call = call))
10. force(code)
11. rlang::abort(message, class = "rextendr_error", call = call)
12. signal_abort(cnd, .file)
I figured a nested vector would be supported since a regular vector is, but it appears not, do I need to implement this trait for Robj, or is there another way to go about it? I am also not sure if this is the recommended way to call Rust code from R.

pyparsing flatten indented block

The following code analyse the left spaces and set all objects on one line.
The script checks if the position is equal then: update the temp array on this position and write all object with the deleminiter on the stack
If the position is greater then: update the temp array on this position and right all object with the deleminiter on the stack up to this postition
If the position is less then: update the temp array on this position, delete all higher object and write all object with the deleminiter on the stack up to this postition
Is there a better,shorter way to achieve the same?
import pyparsing as pp
class Parser(object):
def __init__(self):
self.__config_line = []
self.__config_all = []
self.__loc_last = 0
self.__position_last = 0
self.__dimension = 20
start = pp.OneOrMore(pp.Word(pp.printables))
self.__pattern = pp.Combine((start+pp.restOfLine), joinString='').setParseAction(self.test)
def test(self,s, loc, toks):
position_current = loc - self.__loc_last
self.__loc_last = loc + 1 + len(toks[0])
position_delta = position_current - self.__position_last
self.__position_last = position_current
if position_current == 0:
self.__config_line = [''] * self.__dimension
self.__config_line[position_current] = toks[0]
elif position_delta == 0:
self.__config_line[position_current] = toks[0]
elif position_delta < 0:
self.__config_line[position_current:self.__dimension] = [''] * (self.__dimension - 1 - position_current)
self.__config_line[position_current] = toks[0]
elif position_delta > 0:
self.__config_line[self.__position_last + 1:self.__dimension] = [''] * (self.__dimension - 1 - self.__position_last)
self.__config_line[position_current] = toks[0]
self.__position_last = position_current
self.__config_all.append(list(self.__config_line))
def parse(self, line):
try:
parsed = self.__pattern.searchString(line)
return self.__config_all
except pp.ParseException as x:
#print x
#return False
pass
If I run the code with the following parameter:
if __name__ == "__main__":
parser = Parser()
test="""first level config parameter 1-n
second level config parameter 1-n
thirt level config parameter 1-n
second level config parameter 1-n
thirt level config parameter 1-n
first level config parameter 1-n"""
print ("## Test String level based ##")
print ("#############################")
print(test)
print ("## Test String formal translated ##")
print ("###################################")
a = "\n".join(map("|".join, parser.parse(test)))
print (a)
print (parser.parse(test))
I got the following output:
first level config parameter 1-n|||||||||||||||||||
first level config parameter 1-n|second level config parameter 1-n||||||||||||||||||
first level config parameter 1-n|second level config parameter 1-n|thirt level config parameter 1-n|||||||||||||||||
first level config parameter 1-n|second level config parameter 1-n|||||||||||||||||
first level config parameter 1-n|second level config parameter 1-n|thirt level config parameter 1-n|||||||||||||||||
first level config parameter 1-n|||||||||||||||||||
........

S4 method for Rcpp generated S4 class still seems to need .onLoad()

I cannot find a way to add an S4 show method to the exported S4 class without using .onLoad. The Rcpp gallery example suggests "Rcpp_yourclassname" as the object name should be sufficient but in practise my package complains it cannot not find the class:
Loading RcppS4show
in method for ‘show’ with signature ‘"Rcpp_Num"’: no definition for class “Rcpp_Num”
One can easily reproduce this by using the Rcpp module package skeleton:
# R console:
Rcpp::Rcpp.package.skeleton("RcppS4show", path = "/tmp", module = TRUE)
# In /tmp/RcppS4show edit the file:
# R/zzz.R
# ... as described below.
setwd("/tmp/RcppS4show")
devtools::load_all()
Add this to the bottom of R/zzz.R:
setMethod("show", "Rcpp_Num", function(object) {
writeLines(paste("Num(x, y) =", object$x, object$y))
})
I can workaround this by wrapping the loadModule and setMethod functions in .onLoad:
.onLoad <- function(libname, pkgname) {
loadModule("NumEx", TRUE)
setMethod("show", "Rcpp_Num", function(object) {
writeLines(paste("Num(x, y) =", object$x, object$y))
})
}
Now I can see my show method works:
# R console:
new(Num)
#> Num(x, y) = 0 0
However both the module skeleton documentation and the Rcpp-modules vignette explain that .onLoad has been deprecated in favor of using loadModule().
Additionally, having to abuse .onLoad() causes devtools::check() to note that writeLines() from my show method is bad practise:
> checking R code for possible problems ... NOTE
File ‘RcppS4show/R/zzz.R’:
.onLoad calls:
writeLines(paste("Num(x, y) =", object$x, object$y))
Package startup functions should use ‘packageStartupMessage’ to
generate messages.
See section ‘Good practice’ in '?.onAttach'.
Is there any way to register S4 methods without using .onLoad?
Perhaps I'm missing something, but...
Why not just define the show method on the C++ side? (Perhaps this is what Dirk meant when he said "I simply define my Modules all at once").
After running
Rcpp::Rcpp.package.skeleton("RcppS4show", path = "/tmp", module = TRUE)
to create the package, I edited Num.cpp to the following
#include <Rcpp.h>
class Num { // simple class with two private variables
public: // which have a getter/setter and getter
Num() : x(0.0), y(0){} ;
double getX() { return x ; }
void setX(double value){ x = value ; }
int getY() { return y ; }
// Show method
void show() { Rcpp::Rcout << "Num(x, y) = " << x << " " << y << "\n"; }
private:
double x ;
int y ;
};
RCPP_MODULE(NumEx){
using namespace Rcpp ;
class_<Num>( "Num" )
.default_constructor()
// read and write property
.property( "x", &Num::getX, &Num::setX )
// read-only property
.property( "y", &Num::getY )
// show method
.method("show", &Num::show)
;
}
Then from R
setwd("/tmp/RcppS4show")
devtools::load_all()
new(Num)
# Num(x, y) = 0 0
devtools::check()
# Most of the output is omitted, but...
# Status: OK
#
# R CMD check results
# 0 errors | 0 warnings | 0 notes
showMethods("show")
# Function: show (package methods)
# Some output omitted...
# object="Rcpp_Num"
# More output omitted...

function Base.+ must be explicitly imported to be extended

i'm pretty new to julia forgive me if my question is dumb,
for exmaple i defined a type like this:
type Vector2D
x::Float64
y::Float64
end
and 2 object w and v:
v = Vector2D(3, 4)
w = Vector2D(5, 6)
if i add them up it will raise this err : MethodError: no method matching +(::Vector2D, ::Vector2D) it's ok , but when i want to define a method for
summing theses object
+(a::Vector2D, b::Vector2D) = Vector2D(a.x+b.x, a.y+b.y)
it raise this error :
error in method definition: function Base.+ must be explicitly imported to be extended
julia version 0.5
As the error message says, you must tell Julia that you want to extend the + function from Base (the standard library):
import Base: +, -
+(a::Vector2D, b::Vector2D) = Vector2D(a.x + b.x, a.y + b.y)
-(a::Vector2D, b::Vector2D) = Vector2D(a.x - b.x, a.y - b.y)

Struct member selected from type, it is not visible and will not be selected

I have a function that uses the Unix lib for its time functions:
let rfc822 (t: Unix.tm) : string =
Printf.sprintf "%s, %s %s %d %s:%s:%s %s"
(List.nth short_days t.tm_wday)
(padInt t.tm_yday 2 "0")
(List.nth short_month t.tm_mon)
(t.tm_year + 1900)
(padInt t.tm_hour 2 "0")
(padInt t.tm_min 2 "0")
(padInt t.tm_sec 2 "0")
"GMT"
I'm getting this warning:
ocamlbuild -libs unix,str -Is recore/src,ostd/src,owebl/src app.native
+ /usr/bin/ocamlc -c -I recore/src -I ostd/src -I owebl/src -o recore/src/time.cmo recore/src/time.ml
File "recore/src/time.ml", line 45, characters 27-34:
Warning 40: tm_wday was selected from type Unix.tm.
It is not visible in the current scope, and will not
be selected if the type becomes unknown.
File "recore/src/time.ml", line 46, characters 14-21:
Warning 40: tm_yday was selected from type Unix.tm.
It is not visible in the current scope, and will not
be selected if the type becomes unknown.
File "recore/src/time.ml", line 46, characters 4-28:
Error: This expression has type 'a -> string
but an expression was expected of type string
Command exited with code 2.
Compilation unsuccessful after building 13 targets (12 cached) in 00:00:00.
Makefile:8: recipe for target 'old' failed
make: *** [old] Error 10
How do I deal with this warning? I would much rather avoid opening the Unix module if possible.
(Please ignore the actual compile error.)
You can write t.Unix.tm_yday
$ ocaml
OCaml version 4.02.1
# let f (t: Unix.tm) = t.tm_yday;;
Warning 40: tm_yday was selected from type Unix.tm.
It is not visible in the current scope, and will not
be selected if the type becomes unknown.
val f : Unix.tm -> int = <fun>
# let f (t: Unix.tm) = t.Unix.tm_yday;;
val f : Unix.tm -> int = <fun>
Update
To find this in the documents, you need to look for the definition of field:
field ::= [ module-path . ] field-name
A field name can include a module name (or a sequence of module names, for nested modules) before the field name itself.
Update 2
There are also two syntaxes for opening a module locally. They look like overkill for this tiny function, but might be tidier for more complex ones. The module's symbols are directly available throughout the subexpression.
$ ocaml
OCaml version 4.02.1
# let f t = Unix.(t.tm_yday);;
val f : Unix.tm -> int = <fun>
# let f t = let open Unix in t.tm_yday;;
val f : Unix.tm -> int = <fun>
These are documented as language extensions in Local opens.

Resources