Skip to content
Snippets Groups Projects
Commit 65960886 authored by Mélina Vanel's avatar Mélina Vanel
Browse files

Adding AbsoluteDateArrayHandlingin order to vectorize better pyrugged

inverse location
parent bddead86
No related branches found
No related tags found
1 merge request!6Adding AbsoluteDateArrayHandlingin order to vectorize better pyrugged
Pipeline #3166 passed
/* Copyright 2013-2022 CS GROUP
* Licensed to CS GROUP (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.rugged.utils;
import org.orekit.time.AbsoluteDate;
/** AbsoluteDateForVectorisation consist of additions to AbsoluteDate to handle arrays for vectorization
* @author Melina Vanel
*/
public class AbsoluteDateArrayHandling {
/** Dates array on which we want to apply time shift or compute duration */
public AbsoluteDate[] dates;
/** Simple constructor.
* @param dates is an array of absolute dates on which we want to apply time shift or
* compute duration
*/
public AbsoluteDateArrayHandling(final AbsoluteDate[] dates) {
this.dates = dates;
}
/** Get time-shifted dates for several dates or several time shifts.
* @param dts time shifts array in seconds we want to apply to dates
* @return a matrix of new dates, shifted with respect to wanted time
* shifts. If instance dates = [date1, date2, ..., daten] each line
* correspond to one date (for example date1 shiftedBy all timeshifts
* (building the different columns))
*/
public AbsoluteDate[][] shiftedBySeveralTimeShift(final double[] dts) {
AbsoluteDate[][] datesShifted = new AbsoluteDate[dates.length][dts.length];
int index_dates = 0;
for (AbsoluteDate date: this.dates) {
AbsoluteDate[] dateShifted = new AbsoluteDate[dts.length];
int index_dts = 0;
for (double dt: dts) {
dateShifted[index_dts] = date.shiftedBy(dt);
index_dts += 1;
}
datesShifted[index_dates] = dateShifted;
index_dates += 1;
}
return (AbsoluteDate[][]) datesShifted;
}
/** Get array with durations between instances dates and given dates
* @param datesForDuration dates for which we want to compute the duration form instances dates
* @return a matrix of double representing durations from instance dates
* If instance dates = [date1, date2, ..., daten] each line
* correspond to one date (for example date1 duration from all given dates in arguments
* (building the different columns))
*/
public double[][] durationsFromSeveralTimeShifts(final AbsoluteDate[] datesForDuration) {
double[][] durationsFromDates = new double[dates.length][datesForDuration.length];
int index_dates = 0;
for (AbsoluteDate date: this.dates) {
double[] durationFromDate = new double[datesForDuration.length];
int index_datesForDuration = 0;
for (AbsoluteDate dateForDuration: datesForDuration) {
durationFromDate[index_datesForDuration] = date.durationFrom(dateForDuration);
index_datesForDuration += 1;
}
durationsFromDates[index_dates] = durationFromDate;
index_dates += 1;
}
return (double[][]) durationsFromDates;
}
}
/* Copyright 2013-2022 CS GROUP
* Licensed to CS GROUP (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.rugged.utils;
import org.junit.Assert;
import org.junit.Test;
import org.orekit.time.AbsoluteDate;
public class AbsoluteDateForVectorisationTest {
@Test
public void testShiftedBySeveralTimeShiftOneDate() {
AbsoluteDate date1 = new AbsoluteDate();
AbsoluteDate[] dates = new AbsoluteDate[] {date1};
double[] dts = new double[] {10.0, 20.0, 30.0};
AbsoluteDateArrayHandling datesForVect = new AbsoluteDateArrayHandling(dates);
AbsoluteDate[][] datesShifted = datesForVect.shiftedBySeveralTimeShift(dts);
Assert.assertEquals(datesShifted[0][0].durationFrom(date1.shiftedBy(10)), 0.0, 1e-5);
Assert.assertEquals(datesShifted[0][1].durationFrom(date1.shiftedBy(20)), 0.0, 1e-5);
}
@Test
public void testShiftedBySeveralTimeShiftSeveralDates() {
AbsoluteDate date1 = new AbsoluteDate();
AbsoluteDate date2 = date1.shiftedBy(10000);
AbsoluteDate[] dates = new AbsoluteDate[] {date1, date2};
double[] dts = new double[] {10.0, 20.0, 30.0};
AbsoluteDateArrayHandling datesForVect = new AbsoluteDateArrayHandling(dates);
AbsoluteDate[][] datesShifted = datesForVect.shiftedBySeveralTimeShift(dts);
Assert.assertEquals(datesShifted[0][0].durationFrom(date1.shiftedBy(10)), 0.0, 1e-5);
Assert.assertEquals(datesShifted[0][1].durationFrom(date1.shiftedBy(20)), 0.0, 1e-5);
Assert.assertEquals(datesShifted[1][1].durationFrom(date2.shiftedBy(20)), 0.0, 1e-5);
Assert.assertEquals(datesShifted[1][2].durationFrom(date2.shiftedBy(30)), 0.0, 1e-5);
}
@Test
public void testDurationFromSeveralDates() {
AbsoluteDate date1 = new AbsoluteDate();
AbsoluteDate date2 = date1.shiftedBy(10000);
AbsoluteDate date3 = date1.shiftedBy(20000);
AbsoluteDate date4 = date1.shiftedBy(100000);
AbsoluteDate[] dates = new AbsoluteDate[] {date1, date2, date3};
AbsoluteDate[] datesComputeDuration = new AbsoluteDate[] {date4, date1};
AbsoluteDateArrayHandling datesForVect = new AbsoluteDateArrayHandling(dates);
double[][] datesDurations = datesForVect.durationsFromSeveralTimeShifts(datesComputeDuration);
Assert.assertEquals(datesDurations[0][0], date1.durationFrom(date4), 1e-5);
Assert.assertEquals(datesDurations[0][1], date1.durationFrom(date1), 1e-5);
Assert.assertEquals(datesDurations[1][0], date2.durationFrom(date4), 1e-5);
Assert.assertEquals(datesDurations[1][1], date2.durationFrom(date1), 1e-5);
Assert.assertEquals(datesDurations[2][0], date3.durationFrom(date4), 1e-5);
Assert.assertEquals(datesDurations[2][1], date3.durationFrom(date1), 1e-5);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment