Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
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
Julien Lopez
QueryR
Commits
3b456f5e
Commit
3b456f5e
authored
8 years ago
by
Zbynek Slajchrt
Browse files
Options
Downloads
Patches
Plain Diff
Diag builtin refactored
parent
fe1cc11e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Diag.java
+16
-6
16 additions, 6 deletions
...tin/src/com/oracle/truffle/r/nodes/builtin/base/Diag.java
with
16 additions
and
6 deletions
com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Diag.java
+
16
−
6
View file @
3b456f5e
...
...
@@ -24,6 +24,7 @@ import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import
com.oracle.truffle.r.nodes.unary.CastDoubleNode
;
import
com.oracle.truffle.r.runtime.RError
;
import
com.oracle.truffle.r.runtime.RError.Message
;
import
com.oracle.truffle.r.runtime.RRuntime
;
import
com.oracle.truffle.r.runtime.builtins.RBuiltin
;
import
com.oracle.truffle.r.runtime.data.RComplex
;
import
com.oracle.truffle.r.runtime.data.RDataFactory
;
...
...
@@ -37,7 +38,7 @@ public abstract class Diag extends RBuiltinNode {
@Override
protected
void
createCasts
(
CastBuilder
casts
)
{
casts
.
arg
(
"x"
).
as
Vector
();
casts
.
arg
(
"x"
).
mapIf
(
complexValue
().
not
(),
asDouble
Vector
()
)
;
casts
.
arg
(
"nrow"
).
asIntegerVector
().
findFirst
().
mustBe
(
notIntNA
(),
Message
.
INVALID_LARGE_NA_VALUE
,
"nrow"
).
mustBe
(
gte0
(),
Message
.
INVALID_NEGATIVE_VALUE
,
"nrow"
);
...
...
@@ -62,6 +63,17 @@ public abstract class Diag extends RBuiltinNode {
}
}
@Specialization
protected
Object
diag
(
double
x
,
int
nrow
,
int
ncol
)
{
int
mn
=
(
nrow
<
ncol
)
?
nrow
:
ncol
;
double
[]
data
=
new
double
[
nrow
*
ncol
];
for
(
int
j
=
0
;
j
<
mn
;
j
++)
{
data
[
j
*
(
nrow
+
1
)]
=
x
;
}
return
RDataFactory
.
createDoubleVector
(
data
,
RRuntime
.
isNA
(
x
),
new
int
[]{
nrow
,
ncol
});
}
@Specialization
protected
Object
diag
(
RAbstractComplexVector
x
,
int
nrow
,
int
ncol
)
{
int
mn
=
checkX
(
x
,
nrow
,
ncol
);
...
...
@@ -77,12 +89,10 @@ public abstract class Diag extends RBuiltinNode {
return
RDataFactory
.
createComplexVector
(
data
,
x
.
isComplete
(),
new
int
[]{
nrow
,
ncol
});
}
@Specialization
(
guards
=
"!isRAbstractComplexVector(x)"
)
protected
Object
diag
(
RAbstractVector
x
,
int
nrow
,
int
ncol
,
//
@Cached
(
"create()"
)
CastDoubleNode
cast
)
{
int
mn
=
checkX
(
x
,
nrow
,
ncol
);
@Specialization
protected
Object
diag
(
RAbstractDoubleVector
source
,
int
nrow
,
int
ncol
)
{
int
mn
=
checkX
(
source
,
nrow
,
ncol
);
RAbstractDoubleVector
source
=
(
RAbstractDoubleVector
)
cast
.
execute
(
x
);
double
[]
data
=
new
double
[
nrow
*
ncol
];
int
nx
=
source
.
getLength
();
for
(
int
j
=
0
;
j
<
mn
;
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