MethodError when dispatching on a parametric vector of vectors
By : Victor_Chou
Date : September 06 2020, 06:00 AM

I hope this helps you . The notation here is a little subtle. The parametric type that you've declared for the x argument, Vector{Vector{<:Integer}} is a shorthand notation for Vector{Vector{T} where T<:Integer}: code :
julia> Vector{Vector{<:Integer}}
Array{Array{#s17,1} where #s17<:Integer,1}
julia> Vector{Vector{T} where T<:Integer}
Array{Array{#s17,1} where #s17<:Integer,1}
julia> typeof([Int8(1), Int16(2)])
Array{Int16,1}
julia> typeof([Int8[1], Int16[2, 3]])
Array{Array{Int16,1},1}
julia> foo(x::Vector{Vector{<:Integer}}) = last(last(x));
julia> y = Vector{<:Integer}[Int8[1], Int16[2, 3], Int32[4, 5, 6]]
3element Array{Array{#s17,1} where #s17<:Integer,1}:
Int8[1]
Int16[2, 3]
Int32[4, 5, 6]
julia> foo(y)
6
julia> bar(x::Vector{Vector{T}}) where T<:Integer = last(last(x));
julia> x = [[1], [2, 3], [4, 5, 6]]
3element Array{Array{Int64,1},1}:
[1]
[2, 3]
[4, 5, 6]
julia> bar(x)
6
julia> bar(y)
ERROR: MethodError: no method matching bar(::Array{Array{#s17,1} where #s17<:Integer,1})
Closest candidates are:
bar(::Array{Array{T,1},1}) where T<:Integer at REPL[35]:1
Share :

OpenCV storing vectors of vectors of points vector<vector<Point> >
By : Hamza Deutz
Date : March 29 2020, 07:55 AM
I wish did fix the issue. For the moment, I solved this by just not using OpenCV's FileStorage. Here is what I did for storing a vector of vector of Point since there are good routines for printing the vectors. code :
bool writeVectorVectorPoint(string fname, vector<vector<Point> > vvP)
{
ofstream fsOut;
vector<vector<Point> >::iterator p;
fsOut.open(fname.c_str());
if(fsOut.fail())
{
cout << "Failed to open " << fname << endl;
return(false);
}
for(p = vvP.begin(); p != vvP.end(); p++)
{
fsOut << (*p) << endl;
}
fsOut.close();
return(true);
}
bool readVectorVectorPoint(string fname, vector<vector<Point> >& vvP)
{
ifstream fsIn;
fsIn.open(fname.c_str());
if(fsIn.fail())
{
cout << "Failed to open: " << fname << endl;
return(false);
}
Point pt;
vector<Point> vPt;
vector<Point>::iterator p;
string line;
while(getline(fsIn, line))
{
cout << line << endl;
string ptStr;
stringstream s(line.substr(1,line.size()1));
vPt.clear();
while(getline(s, ptStr, ';'))
{
stringstream s1(ptStr);
string lastStr;
getline(s1, lastStr, ',');
pt.x = atoi(lastStr.c_str());
getline(s1, lastStr, ',');
pt.y = atoi(lastStr.c_str());
vPt.push_back(pt);
}
vvP.push_back(vPt);
}
fsIn.close();
return(true);
}

Is parametric polymorphism the same as dispatching on arity?
By : Mike Schaf
Date : March 29 2020, 07:55 AM
this will help Parametric Polymorphism The idea behind parametric polymorphism is that you don't dispatch—a parametrically polymorphic function is one that behaves in the same way for all input types. Let's consider a very simple example (I'm going to use Haskell1): code :
id x = x
id :: a > a
id x = x
reverse :: [a] > [a]
reverse [] = []
reverse (x:xs) = reverse xs ++ [x]
 `x:xs` is the list whose first element is `x` and whose second element is
 `xs`; `++` is the listappend operator.
map :: (a > b) > [a] > [b]
map f [] = []
map f (x:xs) = f x : map f xs
 In Haskell, function application is whitespace, so `map f xs` is like
 `map(f,xs)` in a Clike language.
class Eq a where  To say that a type `a` is comparable for equality, implement
 these functions:
(==) :: a > a > Bool  Equality
(/=) :: a > a > Bool  Inequality
 We can also define default implementations for those functions:
x == y = not (x /= y)
x /= y = not (x == y)
instance Eq Bool where
True == True = True
False == False = True
_ == _ = False
 `_` means "don't care".
elem :: Eq a => a > [a] > Bool
elem _ [] = False
elem y (x:xs) = x == y  elem y xs
 Haskell supports an infix syntax that would have allowed us to write
 `y `elem` xs`, with the backticks around `elem`.
public static <T> T id(T t) { return t; }

Does vector.swap() and vector.erase() free all the allocated memory if the vector is a vector of vectors?
By : Nenad Pavicevic
Date : March 29 2020, 07:55 AM
help you fix your problem 1) yes, the object (vector here) is destroyed. But it is worth noting that the outer vector (the one you called erase() on) will not change its capacity. 2) yes, it would be emptied. You can also call a.clear() but it won't change your outer vector's capacity.

MethodError calling constructor of parametric struct
By : Jani
Date : March 29 2020, 07:55 AM
I wish did fix the issue. When you write LLNode(0,nothing,nothing), Julia is able to figure out that it needs to construct an LLNode{Int} based upon the type of the first argument. But in LinkedList(0, nothing, nothing), there's quite literally nothing for it to go on to determine what the type parameter should be, so it doesn't know what to construct. Instead, you either need to explicitly choose what you want T to be: code :
julia> LinkedList{Int}(0, nothing, nothing)
LinkedList{Int64}(0, nothing, nothing)
julia> LinkedList(0, LLNode(0, nothing, nothing), nothing)
LinkedList{Int64}(0, LLNode{Int64}(0, nothing, nothing), nothing)

Initialize empty vector of vectors with elements of vector of vectors
By : adriibrugudui
Date : March 29 2020, 07:55 AM
this one helps. You made a simple error, which is easy to fix. Your 2 dimensional vector code :
std::vector<std::vector<std::string>> data_extract;
std::vector<std::vector<std::string>> data_extract(array.size());
data_extract.resize(array.size());
std::vector<std::vector<std::string>> data_extract(array.size(),std::vector<std::string>(array[0].size(),""));
while (event_iterator <= nr_of_events)



Related Posts :
