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
!3
Update Vector.java
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Update Vector.java
dylan.mpacko/poo2019numeric:patch-1
into
master
Overview
0
Commits
0
Pipelines
0
Changes
0
Open
dylan.mpacko
requested to merge
dylan.mpacko/poo2019numeric:patch-1
into
master
5 years ago
Overview
0
Commits
0
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
be26202e
1 commit,
5 years ago
1 file
+
100
−
24
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/main/java/ch/hepia/numeric/Vector.java
+
100
−
24
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
List
<
Double
>
values
;
private
Vector
()
{}
private
Vector
(
Double
...
elements
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
vec
=
new
ArrayList
<>();
for
(
double
elem
:
elements
){
vec
.
add
(
elem
);}
this
.
values
=
vec
;
}
private
Vector
(
List
<
Double
>
elements
)
{
th
row
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
)
;
th
is
.
values
=
elements
;
}
public
Transposed
t
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
//return new Transposed(this);
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
List
<
Double
>
getValues
(){
return
this
.
values
;
}
public
int
len
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
this
.
getValues
().
size
(
);
}
public
double
get
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
return
this
.
getValues
().
get
(
i
);
}
void
set
(
int
i
,
double
value
)
{
th
row
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
th
is
.
values
.
set
(
i
,
value
);
}
public
Vector
add
(
Vector
that
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
newVec
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
this
.
len
();
i
++){
newVec
.
add
(
this
.
get
(
i
)+
that
.
get
(
i
));
}
this
.
values
=
newVec
;
return
new
Vector
(
newVec
);
}
public
Vector
mul
(
double
m
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
vec
=
new
ArrayList
<>();
for
(
double
elem
:
this
.
getValues
()){
vec
.
add
(
elem
);}
this
.
values
=
vec
;
return
new
Vector
(
vec
);
}
public
Vector
sub
(
Vector
that
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
vec
=
new
ArrayList
<>();
this
.
add
(
that
.
mul
(-
1.0
));
vec
=
this
.
getValues
();
this
.
values
=
vec
;
return
new
Vector
(
vec
);
}
public
double
norm
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
double
res
=
0
;
for
(
int
i
=
0
;
i
<
this
.
len
();
i
++)
{
res
+=
(
this
.
get
(
i
)*
this
.
get
(
i
));
}
return
res
;
}
public
Vector
sliceFrom
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
vec
=
new
ArrayList
<>();
for
(
int
inc
=
0
;
inc
<
this
.
len
();
inc
++){
if
(
inc
>=
i
){
vec
.
add
(
this
.
get
(
inc
));
}
}
return
new
Vector
(
vec
);
}
public
Vector
sliceTo
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
vec
=
new
ArrayList
<>();
for
(
int
inc
=
0
;
inc
<
i
;
inc
++){
vec
.
add
(
this
.
get
(
inc
));
}
return
new
Vector
(
vec
);
}
public
Vector
slice
(
int
from
,
int
to
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
vec
=
new
ArrayList
<>();
for
(
int
i
=
from
;
i
<
to
;
i
++){
vec
.
add
(
this
.
get
(
i
));
}
return
new
Vector
(
vec
);
}
public
Vector
removed
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
Vec
=
new
ArrayList
<>();
for
(
int
inc
=
0
;
inc
<
this
.
len
();
inc
++){
if
(
inc
!=
i
){
Vec
.
add
(
this
.
get
(
i
));
}
}
return
new
Vector
(
Vec
);
}
public
Vector
concat
(
Vector
that
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
Vec
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
this
.
len
();
i
++){
Vec
.
add
(
this
.
get
(
i
));
}
for
(
int
y
=
0
;
y
<
that
.
len
();
y
++){
Vec
.
add
(
that
.
get
(
y
));
}
return
new
Vector
(
Vec
);
}
public
Vector
map
(
DoubleFunction
<
Double
>
f
)
{
@@ -69,7 +127,11 @@ final public class Vector {
}
public
Vector
copy
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
Vec
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
this
.
len
();
i
++){
Vec
.
add
(
this
.
get
(
i
));
}
return
new
Vector
(
Vec
);
}
void
checkVectorLengthOrThrow
(
Vector
that
){
@@ -77,27 +139,41 @@ 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"
);
List
<
Double
>
vec
=
new
ArrayList
<>();
return
new
Vector
(
vec
);
}
public
static
Vector
fill
(
int
nb
,
double
value
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
Vec
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
nb
;
i
++){
Vec
.
add
(
value
);
}
return
new
Vector
(
Vec
);
}
public
static
Vector
zeros
(
int
nb
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
Vec
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
nb
;
i
++){
Vec
.
add
(
0.0
);
}
return
new
Vector
(
Vec
);
}
public
static
Vector
ones
(
int
nb
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Double
>
Vec
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
nb
;
i
++){
Vec
.
add
(
1.0
);
}
return
new
Vector
(
Vec
);
}
public
static
Vector
linespace
(
double
from
,
double
to
,
int
nb
)
{
@@ -126,4 +202,4 @@ final public class Vector {
public
boolean
equals
(
Object
obj
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
}
}
\ No newline at end of file
Loading