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
francois.hofer
poo2019numeric
Commits
c458dcf4
Commit
c458dcf4
authored
5 years ago
by
fefe
Browse files
Options
Downloads
Patches
Plain Diff
Ended tabulate function and tested
parent
e30233e7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/numeric/Matrix.java
+13
-3
13 additions, 3 deletions
src/main/java/ch/hepia/numeric/Matrix.java
src/test/java/ch/hepia/numeric/AppTest.java
+26
-0
26 additions, 0 deletions
src/test/java/ch/hepia/numeric/AppTest.java
with
39 additions
and
3 deletions
src/main/java/ch/hepia/numeric/Matrix.java
+
13
−
3
View file @
c458dcf4
...
...
@@ -40,7 +40,7 @@ public class Matrix {
return
this
.
cols
().
get
(
i
).
get
(
j
);
}
void
set
(
int
row
,
int
col
,
double
value
)
{
th
row
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
th
is
.
col
.
get
(
col
).
set
(
row
,
value
);
}
public
Matrix
map
(
DoubleFunction
<
Double
>
f
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
...
...
@@ -174,7 +174,11 @@ public class Matrix {
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
static
Matrix
fill
(
int
rows
,
int
cols
,
double
value
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
Vector
>
newLst
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
cols
;
i
++){
newLst
.
add
(
Vector
.
fill
(
rows
,
value
));
}
return
Matrix
.
of
(
newLst
);
}
public
static
Matrix
zeros
(
int
rows
,
int
cols
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
...
...
@@ -183,7 +187,13 @@ public class Matrix {
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
public
static
Matrix
tabulate
(
int
rows
,
int
cols
,
BiFunction
<
Integer
,
Integer
,
Double
>
f
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Matrix
newMat
=
Matrix
.
fill
(
rows
,
cols
,
0
);
for
(
int
i
=
0
;
i
<
newMat
.
nbCols
();
i
++){
for
(
int
y
=
0
;
y
<
newMat
.
nbRows
();
y
++){
newMat
.
set
(
y
,
i
,
f
.
apply
(
y
,
i
));
}
}
return
newMat
;
}
public
static
Matrix
diag
(
double
...
ds
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/numeric/AppTest.java
+
26
−
0
View file @
c458dcf4
...
...
@@ -214,4 +214,30 @@ class VectorTest {
lstVec
.
add
(
Vector
.
of
(
4.0
,
8.0
,
12.0
,
16.0
));
assertEquals
(
Matrix
.
of
(
lstVec
).
det
(),
0.0
);
}
@Test
void
matrixSet
()
{
List
<
Vector
>
lstVec
=
new
ArrayList
<>();
lstVec
.
add
(
Vector
.
of
(
1.0
,
4.0
,
7.0
));
lstVec
.
add
(
Vector
.
of
(
2.0
,
5.0
,
8.0
));
lstVec
.
add
(
Vector
.
of
(
3.0
,
6.0
,
9.0
));
Matrix
mat
=
Matrix
.
of
(
lstVec
);
mat
.
set
(
1
,
1
,
10.0
);
lstVec
=
new
ArrayList
<>();
lstVec
.
add
(
Vector
.
of
(
1.0
,
4.0
,
7.0
));
lstVec
.
add
(
Vector
.
of
(
2.0
,
10.0
,
8.0
));
lstVec
.
add
(
Vector
.
of
(
3.0
,
6.0
,
9.0
));
assertEquals
(
mat
.
cols
().
get
(
1
).
get
(
1
),
10.0
);
}
@Test
void
matrixTabulate
()
{
List
<
Vector
>
lstVec
=
new
ArrayList
<>();
lstVec
.
add
(
Vector
.
of
(
0.0
,
1.0
,
2.0
));
lstVec
.
add
(
Vector
.
of
(
1.0
,
2.0
,
3.0
));
Matrix
m
=
Matrix
.
of
(
lstVec
);
assertEquals
(
m
,
Matrix
.
tabulate
(
3
,
2
,
(
i
,
j
)
->
{
return
(
double
)
i
+
j
;
}));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment