Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exercises
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
ISC2
oop
exercises
Commits
74ea09e9
"slides_2023/gen_index.sh" did not exist on "049f5d319268cbe72e43a05f36cecc7bfbc5ddf4"
Commit
74ea09e9
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
vectors
parent
32cf5495
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
serie1/Vector.java
+106
-0
106 additions, 0 deletions
serie1/Vector.java
with
106 additions
and
0 deletions
serie1/Vector.java
0 → 100644
+
106
−
0
View file @
74ea09e9
import
com.sun.tools.javac.util.List
;
public
class
Vector
{
public
static
double
[]
add
(
double
[]
lhs
,
double
[]
rhs
)
{
double
res
[]
=
new
double
[
3
];
for
(
int
i
=
0
;
i
<
res
.
length
;
i
++)
{
res
[
i
]
=
lhs
[
i
]
+
rhs
[
i
];
}
return
res
;
}
public
static
double
[]
scalar_mul
(
double
[]
vec
,
int
scalar
)
{
double
res
[]
=
new
double
[
3
];
for
(
int
i
=
0
;
i
<
vec
.
length
;
i
++)
{
res
[
i
]
=
vec
[
i
]
*
scalar
;
}
return
res
;
}
public
static
double
[]
sub
(
double
[]
lhs
,
double
[]
rhs
)
{
double
invert_lhs
[]
=
scalar_mul
(
lhs
,
-
1
);
double
res
[]
=
add
(
rhs
,
invert_lhs
);
return
res
;
}
public
static
int
len
(
double
[]
vec
)
{
return
vec
.
length
;
}
public
static
double
norm
(
double
[]
vec
)
{
double
res
;
for
(
int
i
=
0
;
i
<
vec
.
length
;
i
++)
{
sum
+=
vec
[
i
];
}
return
Math
.
sqrt
(
res
);
}
public
static
double
[]
sum
(
List
<
double
[]>
vec_list
)
{
double
[]
res
;
for
(
int
i
=
0
;
i
<
vec_list
.
length
;
i
++)
{
res
+=
add
(
res
,
vec_list
[
i
]);
}
return
res
;
}
public
static
double
[]
norms
(
List
<
double
[]>
vec_list
)
{
double
[]
res
;
for
(
int
i
=
0
;
i
<
vec_list
.
length
;
i
++)
{
res
+=
norm
(
vec_list
[
i
]);
}
return
res
;
}
public
static
double
[]
concat
(
double
[]
lhs
,
double
[]
rhs
)
{
int
len
=
lhs
.
length
+
rhs
.
length
;
double
res
[]
=
new
double
[
len
];
for
(
int
i
=
0
;
i
<
lhs
.
length
;
i
++)
{
res
[
i
]
=
lhs
[
i
];
}
for
(
int
i
=
lhs
.
length
;
i
<
res
.
length
;
i
++)
{
res
[
i
]
=
rhs
[
i
-
lhs
.
length
];
}
return
res
;
}
public
static
double
[]
sliceFrom
(
double
vec
[],
int
stop_idx
)
{
double
[]
res
;
if
(
stop_idx
<
0
)
{
throw
new
Exception
(
"Specified index: "
+
stop_idx
+
" is smaller than zero"
);
}
try
{
for
(
int
i
=
0
;
i
<
stop_idx
;
i
++)
{
res
[
i
]
=
vec
[
i
];
}
}
catch
(
IndexOutOfBoundsException
e
)
{
System
.
err
.
println
(
"L'indice spécifié "
+
i
+
" dépasse la capacité du vecteur"
);
}
}
public
static
double
[]
slice
(
double
[]
vec
,
int
start_idx
,
int
stop_idx
)
{
if
(
start_idx
<
0
||
stop_idx
<
0
)
{
throw
new
Exception
(
"Index or indices out of bounds"
);
}
double
[]
up_to_stop
=
sliceFrom
(
vec
,
stop_idx
);
}
public
static
void
main
(
String
[]
args
)
{
}
}
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