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
!2
Tanguy
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Tanguy
david.carballo/poo2019numeric:Tanguy
into
master
Overview
0
Commits
28
Pipelines
0
Changes
2
Open
tanguy.dietrich
requested to merge
david.carballo/poo2019numeric:Tanguy
into
master
5 years ago
Overview
0
Commits
28
Pipelines
0
Changes
2
Expand
merge request de tanguy vers master
0
0
Merge request reports
Viewing commit
d55ac700
Prev
Next
Show latest version
2 files
+
12
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
d55ac700
Ecriture de vectorLinespace()
· d55ac700
tanguy.dietrich
authored
5 years ago
src/main/java/ch/hepia/numeric/Vector.java
+
153
−
44
Options
package
ch.hepia.numeric
;
import
java.util.List
;
import
java.util.ArrayList
;
import
java.util.function.DoubleFunction
;
import
java.util.function.Function
;
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
)
{
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
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
)
;
this
.
lstVector
=
elements
;
}
public
Transposed
t
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
new
Transposed
(
this
);
}
public
int
len
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
this
.
lstVector
.
size
(
);
}
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
)
{
th
row
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
th
is
.
lstVector
.
set
(
i
,
value
);
}
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
)
{
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
)
{
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
()
{
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
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
slice
(
i
,
this
.
len
()
);
}
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
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
Vector
removed
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
Vector
concat
(
Vector
that
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
Vector
map
(
DoubleFunction
<
Double
>
f
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
Vector
copy
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
if
(
from
>=
to
){
return
v
;
}
else
{
for
(
double
d
:
this
.
lstVector
.
subList
(
from
,
to
))
{
v
.
lstVector
.
add
(
d
);
}
return
v
;
}
}
public
Vector
removed
(
int
i
)
{
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
){
@@ -77,53 +142,97 @@ final public class Vector {
}
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
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
new
Vector
(
elements
);
}
public
static
Vector
empty
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
new
Vector
(
);
}
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
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
Vector
.
fill
(
nb
,
0.0
);
}
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
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
public
static
Vector
linespace
(
double
from
,
double
to
,
int
nb
)
{
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"
);
}
public
static
Vector
sum
(
List
<
Vector
>
vs
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
public
static
Vector
sum
(
List
<
Vector
>
vs
)
{
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
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
sum
(
vs
).
norm
(
);
}
@Override
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
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