Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
poo2019numeric
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steven.liatti
poo2019numeric
Merge requests
!1
David
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
David
david.carballo/poo2019numeric:David
into
master
Overview
0
Commits
30
Pipelines
0
Changes
2
Open
david.carballo
requested to merge
david.carballo/poo2019numeric:David
into
master
5 years ago
Overview
0
Commits
30
Pipelines
0
Changes
2
Expand
merge de david vers master
0
0
Merge request reports
Viewing commit
acd989f8
Prev
Next
Show latest version
2 files
+
17
−
5
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
acd989f8
ajout des fonction slice -to -from
· acd989f8
david
authored
5 years ago
src/main/java/ch/hepia/numeric/Vector.java
+
157
−
45
Options
package
ch.hepia.numeric
;
package
ch.hepia.numeric
;
import
java.util.List
;
import
java.util.List
;
import
java.util.ArrayList
;
import
java.util.function.DoubleFunction
;
import
java.util.function.DoubleFunction
;
import
java.util.function.Function
;
import
java.util.function.Function
;
final
public
class
Vector
{
final
public
class
Vector
{
private
Vector
()
{}
final
private
List
<
Double
>
lstVector
;
// = new ArrayList<Double>();
private
Vector
()
{
this
.
lstVector
=
new
ArrayList
<
Double
>();
}
private
Vector
(
Double
...
elements
)
{
private
Vector
(
Double
...
elements
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
this
.
lstVector
=
new
ArrayList
<
Double
>();
for
(
double
e:
elements
)
{
lstVector
.
add
(
e
);
}
}
}
private
Vector
(
List
<
Double
>
elements
)
{
private
Vector
(
List
<
Double
>
elements
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
)
;
this
.
lstVector
=
elements
;
}
}
public
Transposed
t
()
{
public
Transposed
t
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
new
Transposed
(
this
);
}
}
public
int
len
()
{
public
int
len
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
this
.
lstVector
.
size
(
);
}
}
public
double
get
(
int
i
)
{
public
double
get
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
this
.
lstVector
.
get
(
i
);
}
}
void
set
(
int
i
,
double
value
)
{
void
set
(
int
i
,
double
value
)
{
th
row
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
th
is
.
lstVector
.
set
(
i
,
value
);
}
}
public
Vector
add
(
Vector
that
)
{
public
Vector
add
(
Vector
that
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
for
(
int
i
=
0
;
i
<
this
.
len
();
i
++)
{
v
.
lstVector
.
add
(
Double
.
sum
(
this
.
get
(
i
),
that
.
get
(
i
)));
}
return
v
;
}
}
public
Vector
mul
(
double
m
)
{
public
Vector
mul
(
double
m
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
for
(
double
e:
this
.
lstVector
)
{
v
.
lstVector
.
add
(
e
*
m
);
}
return
v
;
}
}
public
Vector
sub
(
Vector
that
)
{
public
Vector
sub
(
Vector
that
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
for
(
int
i
=
0
;
i
<
this
.
len
();
i
++)
{
v
.
lstVector
.
add
(
this
.
get
(
i
)-
that
.
get
(
i
));
}
return
v
;
}
}
public
double
norm
()
{
public
double
norm
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
double
power
=
0
;
for
(
double
e:
this
.
lstVector
)
{
power
+=(
e
*
e
);
}
return
Math
.
sqrt
(
power
);
}
}
public
Vector
sliceFrom
(
int
i
)
{
public
Vector
sliceFrom
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
slice
(
i
,
this
.
len
()
);
}
}
public
Vector
sliceTo
(
int
i
)
{
public
Vector
sliceTo
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
slice
(
0
,
i
);
}
}
public
Vector
slice
(
int
from
,
int
to
)
{
public
Vector
slice
(
int
from
,
int
to
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
}
if
(
from
>=
to
){
return
v
;
public
Vector
removed
(
int
i
)
{
}
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
else
}
{
for
(
double
d
:
this
.
lstVector
.
subList
(
from
,
to
))
public
Vector
concat
(
Vector
that
)
{
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
v
.
lstVector
.
add
(
d
);
}
}
return
v
;
public
Vector
map
(
DoubleFunction
<
Double
>
f
)
{
}
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
}
public
Vector
removed
(
int
i
)
public
Vector
copy
()
{
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
this
.
copy
();
v
.
lstVector
.
remove
(
i
);
return
v
;
}
public
Vector
concat
(
Vector
that
)
{
Vector
v
=
Vector
.
zeros
(
this
.
len
()+
that
.
len
());
for
(
int
i
=
0
;
i
<
v
.
len
();
i
++)
{
if
(
i
<
this
.
len
())
{
v
.
set
(
i
,
this
.
get
(
i
));
}
else
{
v
.
set
(
i
,
that
.
get
(
i
-
this
.
len
()));
}
}
return
v
;
}
public
Vector
map
(
DoubleFunction
<
Double
>
f
)
{
//ne pas faire
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
Vector
copy
()
{
Vector
v
=
Vector
.
zeros
(
this
.
len
());
for
(
int
i
=
0
;
i
<
v
.
len
();
i
++)
{
v
.
set
(
i
,
this
.
get
(
i
));
}
return
v
;
}
}
void
checkVectorLengthOrThrow
(
Vector
that
){
void
checkVectorLengthOrThrow
(
Vector
that
){
@@ -77,53 +142,100 @@ final public class Vector {
@@ -77,53 +142,100 @@ final public class Vector {
}
}
public
static
Vector
of
(
Double
...
elements
)
{
public
static
Vector
of
(
Double
...
elements
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
new
Vector
(
elements
);
}
}
public
static
Vector
of
(
List
<
Double
>
elements
)
{
public
static
Vector
of
(
List
<
Double
>
elements
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
new
Vector
(
elements
);
}
}
public
static
Vector
empty
()
{
public
static
Vector
empty
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
new
Vector
(
);
}
}
public
static
Vector
fill
(
int
nb
,
double
value
)
{
public
static
Vector
fill
(
int
nb
,
double
value
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
for
(
int
i
=
0
;
i
<
nb
;
i
++)
{
v
.
lstVector
.
add
(
value
);
}
return
v
;
}
}
public
static
Vector
zeros
(
int
nb
)
{
public
static
Vector
zeros
(
int
nb
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
Vector
.
fill
(
nb
,
0.0
);
}
}
public
static
Vector
ones
(
int
nb
)
{
public
static
Vector
ones
(
int
nb
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
Vector
.
fill
(
nb
,
1.0
);
}
}
public
static
Vector
linespace
(
double
from
,
double
to
,
int
nb
)
{
public
static
Vector
linespace
(
double
from
,
double
to
,
int
nb
)
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
{
double
step
=(
to
-
from
)/(
nb
-
1
);
Vector
v
=
Vector
.
zeros
(
nb
);
for
(
int
i
=
0
;
i
<
nb
;
i
++)
{
v
.
set
(
i
,
from
+(
step
*
i
));
}
return
v
;
}
}
public
static
Vector
tabulate
(
int
nb
,
Function
<
Integer
,
Double
>
f
)
{
//ne pas faire
public
static
Vector
tabulate
(
int
nb
,
Function
<
Integer
,
Double
>
f
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
}
public
static
Vector
sum
(
List
<
Vector
>
vs
)
{
public
static
Vector
sum
(
List
<
Vector
>
vs
)
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
{
int
length
=
vs
.
get
(
0
).
len
();
Vector
v
=
Vector
.
zeros
(
length
);
for
(
int
e
=
0
;
e
<
length
;
e
++)
{
for
(
Vector
vLst:
vs
)
{
v
.
set
(
e
,
Double
.
sum
(
v
.
get
(
e
),
vLst
.
get
(
e
)));
}
}
return
v
;
}
}
public
static
double
norms
(
List
<
Vector
>
vs
)
{
public
static
double
norms
(
List
<
Vector
>
vs
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
sum
(
vs
).
norm
(
);
}
}
/*
Overrides ecrits avant le cours sur le sujet ces fonctions sont
a reecrire avec les nouvelles connaisances d'ici le deuxieme tag.
*/
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
String
>
strings
=
new
ArrayList
<
String
>();
for
(
Double
d
:
this
.
lstVector
)
{
// Apply formatting to the string if necessary
strings
.
add
(
d
.
toString
());
}
return
"Vector"
+
String
.
valueOf
(
strings
);
}
}
@Override
@Override
public
boolean
equals
(
Object
obj
)
{
public
boolean
equals
(
Object
obj
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
if
(
obj
instanceof
Vector
)
{
for
(
int
i
=
0
;
i
<
this
.
len
();
i
++)
{
if
(((
Vector
)
obj
).
get
(
i
)!=
this
.
get
(
i
))
{
return
false
;
}
}
return
true
;
}
else
{
return
false
;
}
}
}
}
}
Loading