Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
1957ae49
Commit
1957ae49
authored
Jun 24, 2022
by
Paul
Browse files
Format
parent
6f41d56f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
19 deletions
+22
-19
src/driver/argument_parser.hpp
src/driver/argument_parser.hpp
+16
-14
src/include/migraphx/algorithm.hpp
src/include/migraphx/algorithm.hpp
+6
-5
No files found.
src/driver/argument_parser.hpp
View file @
1957ae49
...
@@ -409,22 +409,23 @@ struct argument_parser
...
@@ -409,22 +409,23 @@ struct argument_parser
std
::
ptrdiff_t
distance
=
std
::
numeric_limits
<
std
::
ptrdiff_t
>::
max
();
std
::
ptrdiff_t
distance
=
std
::
numeric_limits
<
std
::
ptrdiff_t
>::
max
();
};
};
result_t
result
;
result_t
result
;
for
(
const
auto
&
input
:
inputs
)
for
(
const
auto
&
input
:
inputs
)
{
{
if
(
input
.
empty
())
if
(
input
.
empty
())
continue
;
continue
;
if
(
input
[
0
]
!=
'-'
)
if
(
input
[
0
]
!=
'-'
)
continue
;
continue
;
for
(
const
auto
&
arg
:
arguments
)
for
(
const
auto
&
arg
:
arguments
)
{
{
for
(
const
auto
&
flag
:
arg
.
flags
)
for
(
const
auto
&
flag
:
arg
.
flags
)
{
{
if
(
flag
.
empty
())
if
(
flag
.
empty
())
continue
;
continue
;
if
(
flag
[
0
]
!=
'-'
)
if
(
flag
[
0
]
!=
'-'
)
continue
;
continue
;
auto
d
=
levenshtein_distance
(
flag
.
begin
(),
flag
.
end
(),
input
.
begin
(),
input
.
end
());
auto
d
=
if
(
d
<
result
.
distance
)
levenshtein_distance
(
flag
.
begin
(),
flag
.
end
(),
input
.
begin
(),
input
.
end
());
if
(
d
<
result
.
distance
)
result
=
result_t
{
&
arg
,
flag
,
input
,
d
};
result
=
result_t
{
&
arg
,
flag
,
input
,
d
};
}
}
}
}
...
@@ -452,12 +453,13 @@ struct argument_parser
...
@@ -452,12 +453,13 @@ struct argument_parser
auto
sc
=
spellcheck
(
inputs
);
auto
sc
=
spellcheck
(
inputs
);
std
::
cout
<<
sc
.
distance
<<
std
::
endl
;
std
::
cout
<<
sc
.
distance
<<
std
::
endl
;
std
::
cout
<<
sc
.
correct
<<
std
::
endl
;
std
::
cout
<<
sc
.
correct
<<
std
::
endl
;
if
(
sc
.
distance
<
5
)
if
(
sc
.
distance
<
5
)
{
{
std
::
cout
<<
"Found argument '"
<<
color
::
fg_yellow
<<
sc
.
incorrect
<<
"'"
;
std
::
cout
<<
"Found argument '"
<<
color
::
fg_yellow
<<
sc
.
incorrect
<<
"'"
;
std
::
cout
<<
" which wasn't expected, or isn't valid in this context"
<<
std
::
endl
;
std
::
cout
<<
" which wasn't expected, or isn't valid in this context"
<<
std
::
endl
;
std
::
cout
<<
" "
;
std
::
cout
<<
" "
;
std
::
cout
<<
"Did you mean "
<<
color
::
fg_green
<<
sc
.
correct
<<
color
::
reset
<<
"?"
<<
std
::
endl
;
std
::
cout
<<
"Did you mean "
<<
color
::
fg_green
<<
sc
.
correct
<<
color
::
reset
<<
"?"
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
print_usage_for
(
*
sc
.
arg
,
sc
.
correct
);
print_usage_for
(
*
sc
.
arg
,
sc
.
correct
);
}
}
...
...
src/include/migraphx/algorithm.hpp
View file @
1957ae49
...
@@ -51,14 +51,15 @@ void group_unique(Iterator start, Iterator last, Output out, Predicate pred)
...
@@ -51,14 +51,15 @@ void group_unique(Iterator start, Iterator last, Output out, Predicate pred)
}
}
}
}
template
<
class
Iterator1
,
class
Iterator2
>
template
<
class
Iterator1
,
class
Iterator2
>
std
::
ptrdiff_t
levenshtein_distance
(
Iterator1
first1
,
Iterator1
last1
,
Iterator2
first2
,
Iterator2
last2
)
std
::
ptrdiff_t
levenshtein_distance
(
Iterator1
first1
,
Iterator1
last1
,
Iterator2
first2
,
Iterator2
last2
)
{
{
if
(
first1
==
last1
)
if
(
first1
==
last1
)
return
std
::
distance
(
first2
,
last2
);
return
std
::
distance
(
first2
,
last2
);
if
(
first2
==
last2
)
if
(
first2
==
last2
)
return
std
::
distance
(
first1
,
last1
);
return
std
::
distance
(
first1
,
last1
);
if
(
*
first1
==
*
first2
)
if
(
*
first1
==
*
first2
)
return
levenshtein_distance
(
std
::
next
(
first1
),
last1
,
std
::
next
(
first2
),
last2
);
return
levenshtein_distance
(
std
::
next
(
first1
),
last1
,
std
::
next
(
first2
),
last2
);
auto
x1
=
levenshtein_distance
(
std
::
next
(
first1
),
last1
,
std
::
next
(
first2
),
last2
);
auto
x1
=
levenshtein_distance
(
std
::
next
(
first1
),
last1
,
std
::
next
(
first2
),
last2
);
auto
x2
=
levenshtein_distance
(
first1
,
last1
,
std
::
next
(
first2
),
last2
);
auto
x2
=
levenshtein_distance
(
first1
,
last1
,
std
::
next
(
first2
),
last2
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment